Platform: Code4rena
Start Date: 08/12/2021
Pot Size: $30,000 ETH
Total HM: 12
Participants: 26
Period: 3 days
Judge: leastwood
Total Solo HM: 9
Id: 65
League: ETH
Rank: 13/26
Findings: 2
Award: $54.23
🌟 Selected for report: 2
🚀 Solo Findings: 0
🌟 Selected for report: 0x0x0x
Also found by: Jujic, pmerkleplant, ye0lde
ye0lde
Gas savings
"> 0" is used in the following locations: https://github.com/code-423n4/2021-12-defiprotocol/blob/205d3766044171e325df6a8bf2e79b37856eece1/contracts/contracts/Basket.sol#L68 https://github.com/code-423n4/2021-12-defiprotocol/blob/205d3766044171e325df6a8bf2e79b37856eece1/contracts/contracts/Basket.sol#L77 https://github.com/code-423n4/2021-12-defiprotocol/blob/205d3766044171e325df6a8bf2e79b37856eece1/contracts/contracts/Basket.sol#L93 https://github.com/code-423n4/2021-12-defiprotocol/blob/205d3766044171e325df6a8bf2e79b37856eece1/contracts/contracts/Basket.sol#L110 https://github.com/code-423n4/2021-12-defiprotocol/blob/205d3766044171e325df6a8bf2e79b37856eece1/contracts/contracts/Basket.sol#L291
Visual Studio Code, Remix
Change "> 0" to "!=0" for small gas savings.
#0 - 0xleastwood
2022-03-27T10:26:47Z
Duplicate of #139
🌟 Selected for report: GiveMeTestEther
Also found by: Jujic, TomFrenchBlockchain, WatchPug, gzeon, kenzo, sirhashalot, ye0lde
ye0lde
A variable is being assigned its default value in the constructor which is unnecessary. Removing the assignment will save gas when deploying.
Visual Studio Code, Remix
Remove line #22
#0 - 0xleastwood
2022-03-27T22:47:53Z
Duplicate of #45
18.4266 USDC - $18.43
ye0lde
Gas savings and code clarity
Below are several occurrences of comparison with literal boolean values of true or false: https://github.com/code-423n4/2021-12-defiprotocol/blob/205d3766044171e325df6a8bf2e79b37856eece1/contracts/contracts/Auction.sol#L37
https://github.com/code-423n4/2021-12-defiprotocol/blob/205d3766044171e325df6a8bf2e79b37856eece1/contracts/contracts/Basket.sol#L92 https://github.com/code-423n4/2021-12-defiprotocol/blob/205d3766044171e325df6a8bf2e79b37856eece1/contracts/contracts/Basket.sol#L259
Visual Studio Code, Remix
Use the compared expression itself in place of comparison with a boolean literal. The expression can be replaced as is when the expression is expected to evaluate to true and negation can be used when the expression is expected to have a false value.
#0 - 0xleastwood
2022-03-27T23:01:31Z
Duplicate of #138
🌟 Selected for report: ye0lde
Also found by: neslinesli93
ye0lde
Reducing redundant code and state variable references can reduce gas usage and improve code clarity.
The changePublisher
function:
https://github.com/code-423n4/2021-12-defiprotocol/blob/205d3766044171e325df6a8bf2e79b37856eece1/contracts/contracts/Basket.sol#L157-L173
I suggest this refactoring:
function changePublisher(address newPublisher) onlyPublisher public override { require(newPublisher != address(0)); if (pendingPublisher.publisher != address(0) && pendingPublisher.publisher == newPublisher) { require(block.timestamp >= pendingPublisher.timestamp + TIMELOCK_DURATION); pendingPublisher.publisher = address(0); emit ChangedPublisher(publisher = newPublisher); } else { pendingPublisher.timestamp = block.timestamp; emit NewPublisherSubmitted(pendingPublisher.publisher = newPublisher); } }
Similar changes can be made to these functions: https://github.com/code-423n4/2021-12-defiprotocol/blob/205d3766044171e325df6a8bf2e79b37856eece1/contracts/contracts/Basket.sol#L175-L192 https://github.com/code-423n4/2021-12-defiprotocol/blob/205d3766044171e325df6a8bf2e79b37856eece1/contracts/contracts/Basket.sol#L194-L212
Visual Studio Code, Remix
See POC for details.
🌟 Selected for report: ye0lde
Also found by: GiveMeTestEther, WatchPug, kenzo
ye0lde
Eliminating intermediate variables and reducing state variable references can reduce gas usage and improve code clarity.
The handleFees
function is here:
https://github.com/code-423n4/2021-12-defiprotocol/blob/205d3766044171e325df6a8bf2e79b37856eece1/contracts/contracts/Basket.sol#L148-L151
I suggest this refactoring for #L148-L151:
emit NewIBRatio(ibRatio = ibRatio * startSupply / totalSupply());
The updateIBRatio
function is here:
https://github.com/code-423n4/2021-12-defiprotocol/blob/205d3766044171e325df6a8bf2e79b37856eece1/contracts/contracts/Basket.sol#L266-L272
I suggest this refactoring:
function updateIBRatio(uint256 newRatio) onlyAuction external override returns (uint256) { emit NewIBRatio(ibRatio = newRatio); return newRatio; }
Visual Studio Code, Remix
See POC for details.