Adding Unchecked Directive will Save Gas for BurnMath.sol#getAsset and BurnMath.sol#getCollateral functions #183
Labels
bug
Something isn't working
G (Gas Optimization)
resolved
Finding has been patched by sponsor (sponsor pls link to PR containing fix)
sponsor confirmed
Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Handle
Rhynorater
Vulnerability details
In
BurnMath.sol
we have the following function defined;Since the above
if
statement ensures thatstate.reserves.asset
is not less than or equal tostate.totalClaims.bond
, it is impossible for the_assetOut -= state.totalClaims.bond;
line to underflow. As a result, adding theunchecked
directive around this will save on gas.By the same reasoning, in the
getCollateral
function:is already checked by the
if
statement. Surrounding this withunchecked
will also save on gas.Lastly, this also applies in
WithdrawMath.sol#getCollateral
:The deficit will never underflow here, so adding
unchecked
will save on gas.##References
https://github.com/code-423n4/2022-01-timeswap/blob/5960e07d39f2b4a60cfabde1bd51f4b1e62e7e85/Timeswap/Timeswap-V1-Core/contracts/libraries/BurnMath.sol#L22
https://github.com/code-423n4/2022-01-timeswap/blob/5960e07d39f2b4a60cfabde1bd51f4b1e62e7e85/Timeswap/Timeswap-V1-Core/contracts/libraries/BurnMath.sol#L41
https://github.com/code-423n4/2022-01-timeswap/blob/5960e07d39f2b4a60cfabde1bd51f4b1e62e7e85/Timeswap/Timeswap-V1-Core/contracts/libraries/WithdrawMath.sol#L33
The text was updated successfully, but these errors were encountered: