require(length > 0, "No entries");
uint256 i = length;
while (i > 0) {
i = i - 1;
if (stashedWithdraws[i].releaseTime <= block.timestamp) {
totalAvailableToWithdraw += stashedWithdraws[i].amount;
stashedWithdraws[i] = stashedWithdraws[stashedWithdraws.length - 1];
stashedWithdraws.pop();
}
}
Using unchecked decrement:
require(length > 0, "No entries");
uint256 i = length;
while (i > 0) {
unchecked { i = i - 1; }
if (stashedWithdraws[i].releaseTime <= block.timestamp) {
totalAvailableToWithdraw += stashedWithdraws[i].amount;
stashedWithdraws[i] = stashedWithdraws[stashedWithdraws.length - 1];
stashedWithdraws.pop();
}
}
Use unchecked math in StakerVault#transferFrom
Since earlier require statements in StakerVault#transferFrom ensure that startingAllowance and srcTokens are >= the specified transfer amount, subtraction to calculate new allowance and balance can be performed safely using unchecked math.
Gas
Use unchecked decrement in while loop
The
while
loop insideBkdLocker#executeUnlocks
can safely use an unchecked decrement.Impact: 63 gas per loop iteration.
BkdLocker#executeUnlocks
Using unchecked decrement:
Use unchecked math in
StakerVault#transferFrom
Since earlier
require
statements inStakerVault#transferFrom
ensure thatstartingAllowance
andsrcTokens
are>=
the specified transferamount
, subtraction to calculate new allowance and balance can be performed safely using unchecked math.Impact: 190 gas.
StakerVault#transferFrom
:Using unchecked math: