Platform: Code4rena
Start Date: 16/02/2023
Pot Size: $144,750 USDC
Total HM: 17
Participants: 154
Period: 19 days
Judge: Trust
Total Solo HM: 5
Id: 216
League: ETH
Rank: 131/154
Findings: 1
Award: $42.07
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: c3phas
Also found by: 0x3b, 0x6980, 0x73696d616f, 0xSmartContract, 0xackermann, 0xhacksmithh, 0xsomeone, Bnke0x0, Bough, Budaghyan, Darshan, DeFiHackLabs, Deivitto, GalloDaSballo, JCN, LethL, Madalad, MiniGlome, Morraez, P-384, PaludoX0, Phantasmagoria, Praise, RHaO-sec, Rageur, RaymondFam, ReyAdmirado, Rickard, Rolezn, SaeedAlipoor01988, Saintcode_, Sathish9098, TheSavageTeddy, Tomio, Viktor_Cortess, abiih, arialblack14, atharvasama, banky, codeislight, cryptonue, ddimitrov22, dec3ntraliz3d, descharre, dharma09, emmac002, favelanky, hl_, hunter_w3b, kaden, kodyvim, matrix_0wl, oyc_109, pavankv, scokaf, seeu, yamapyblack
42.0697 USDC - $42.07
yieldGenerator[collateral]
In the _rebalance
function, we make multiple storage reads from yieldGenerator[collateral]
. Storage is read in the following lines:
The address has already been stored in memory here and the IERC4626
vault has also been stored in memory here. By reading from memory instead of storage, we can save users gas.
vars.yieldingAmount
We calculate
yieldingAmount = yieldingAmount - toWithdraw
However,
yieldingAmount = currentAllocated
We recalculate yieldingAmount
here as
yieldingAmount = yieldingAmount - toWithdraw
where toWithdraw = currentAllocated - finalYieldingAmount
Substituting values for toWithdraw
,
yieldingAmount = currentAllocated - currentAllocated + finalYieldingAmount
yieldingAmount = finalYieldingAmount
Thus, these extra computation steps are unnecessary and only waste gas. I suggest replacing this line with
vars.yieldingAmount = vars.finalYieldingAmount
This same logic can be applied to the calculation here
>
instead of !=
In the conditional check here, we can save 3 gas by using >
instead of !=
since _collTopUp
is a uint
and thus must be >= 0
LUSD_GAS_COMPENSATION
constant aroundWe are passing around the constant LUSD_GAS_COMPENSATION
instead of just using the value where it is needed directly. This defeats some of the benefit of constants where the compiler will directly replace the values in code. The value is used in these locations
I suggest not saving this value into memory and instead using the constant directly where it is needed.
#0 - c4-judge
2023-03-09T18:55:45Z
trust1995 marked the issue as grade-b