Bid Beasts

First Flight #49
Beginner FriendlyFoundrySolidityNFT
100 EXP
View results
Submission Details
Impact: medium
Likelihood: low
Invalid

[L-1] Gas waste when instantiating BBERC721 public global variable

Root + Impact

Description

  • Currently the BBERC721 state variable BidBeasts NFT is declared as public and only initialized in the constructor, and because it is not marked as immutable any transaction using this contract incurs in a higher cost of gas for the same operation.

contract BidBeastsNFTMarket is Ownable(msg.sender) {
@> BidBeasts public BBERC721;
// --- Events ---
event NftListed(uint256 tokenId, address seller, uint256 minPrice, uint256 buyNowPrice);

Risk

Likelihood:

  • No risk involved just a way to safe gas

Impact:

  • Higher cost of gas for the same operation

Proof of Concept

Running the simple list_NFT test without immutable and compare it with the same test with the state variable properly set

## Run without immutable BidBeasts state variable
forge test --mt test_listNFT
[⠊] Compiling...
No files changed, compilation skipped
Ran 1 test for test/BidBeastsMarketPlaceTest.t.sol:BidBeastsNFTMarketTest
[PASS] test_listNFT() (gas: 210724) #<<< gas total 210724
Suite result: ok. 1 passed; 0 failed; 0 skipped; finished in 693.52µs (103.54µs CPU time)
## Run with immutable BidBeasts state variable
forge test --mt test_listNFT
[⠊] Compiling...
[⠔] Compiling 2 files with Solc 0.8.20
[⠒] Solc 0.8.20 finished in 411.42ms
Ran 1 test for test/BidBeastsMarketPlaceTest.t.sol:BidBeastsNFTMarketTest
[PASS] test_listNFT() (gas: 208454) #<<< gas total 208454 -> we safe 2270 in gas fees
Suite result: ok. 1 passed; 0 failed; 0 skipped; finished in 1.02ms (147.76µs CPU time)
Ran 1 test suite in 6.51ms (1.02ms CPU time): 1 tests passed, 0 failed, 0 skipped (1 total tests)

Recommended Mitigation

Add the word immutable between public and BBERC721 on line 9 from src/BidBeastsNFTMarketPlace.sol

contract BidBeastsNFTMarket is Ownable(msg.sender) {
- BidBeasts public BBERC721;
+ BidBeasts public immutable BBERC721;
// --- Events ---
event NftListed(uint256 tokenId, address seller, uint256 minPrice, uint256 buyNowPrice);
Updates

Lead Judging Commences

cryptoghost Lead Judge about 1 month ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.