Platform: Code4rena
Start Date: 24/10/2023
Pot Size: $36,500 USDC
Total HM: 4
Participants: 147
Period: 6 days
Judge: 0xDjango
Id: 299
League: ETH
Rank: 94/147
Findings: 1
Award: $6.46
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: 0xVolcano
Also found by: 0x11singh99, 0xAadi, 0xAnah, 0xgrbr, 0xhacksmithh, 0xhex, 0xpiken, 0xta, J4X, JCK, K42, Raihan, Rolezn, SAQ, SM3_SS, Sathish9098, SovaSlava, ThreeSigma, Udsen, arjun16, aslanbek, brakelessak, castle_chain, evmboi32, hunter_w3b, lsaudit, naman1778, niser93, nuthan2x, oakcobalt, pavankv, petrichor, phenom80, radev_sw, shamsulhaq123, tabriz, thekmj, unique, yashgoel72, ybansal2403
6.4563 USDC - $6.46
Using != 0
instead of > 0
saves gas.
StakedUSDe.sol if (getUnvestedAmount() > 0) revert StillVesting(); if (_totalSupply > 0 && _totalSupply < MIN_SHARES) revert MinSharesViolation(); EthenaMinting.sol if (remainingBalance > 0) { token.safeTransferFrom(benefactor, addresses[addresses.length - 1], remainingBalance); }
Instead of using address(this), it is more gas-efficient to pre-calculate and use the hardcoded address. Foundry’s script.sol and solmate’s LibRlp.sol contracts can help achieve this.
When a modifier is used only once and is not inherited by any other contracts, inlining it can reduce gas costs. Inlining means that the modifier’s code is directly inserted into the function where it is applied, rather than creating a separate function call for the modifier.
By inlining the modifier, you avoid the overhead of the additional function call, which results in lower gas consumption. This optimization is especially useful when the modifier’s code is short or simple.
The following two modifiers in EthenaMinting.sol
are only used once:
modifier belowMaxMintPerBlock(uint256 mintAmount) { if (mintedPerBlock[block.number] + mintAmount > maxMintPerBlock) revert MaxMintPerBlockExceeded(); _; } modifier belowMaxRedeemPerBlock(uint256 redeemAmount) { if (redeemedPerBlock[block.number] + redeemAmount > maxRedeemPerBlock) revert MaxRedeemPerBlockExceeded(); _; }
Caching of a state variable replaces each Gwarmaccess (100 gas) with a much cheaper stack read. We can avoid unecessary SLOADs by caching storage values that were previously accessed and emitting those cached values.
If
statements that use &
can be refactored into nested if
statementsThis way we can save some gas
#0 - c4-pre-sort
2023-11-01T15:42:56Z
raymondfam marked the issue as sufficient quality report
#1 - c4-judge
2023-11-10T20:07:12Z
fatherGoose1 marked the issue as grade-b