You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On the L388/L429/L464 (only subtraction)/L508 there is a subtraction than can be done unchecked because the require statement above those line checks for underflow.
Therefore those lines can be put in an unchecked {} block to save gas.
Proof of Concept
Example for L388:
require(newBal < type(uint112).max && newBal > prevBal, "erc");
amount = uint112(newBal - prevBal);
First part of the require statement checks for safe downcasting and the second part for underflow. Therefore we can write:
unchecked { amount = uint112(newBal - prevBal); }
Handle
GiveMeTestEther
Vulnerability details
Impact
On the L388/L429/L464 (only subtraction)/L508 there is a subtraction than can be done unchecked because the require statement above those line checks for underflow.
Therefore those lines can be put in an unchecked {} block to save gas.
Proof of Concept
Example for L388:
require(newBal < type(uint112).max && newBal > prevBal, "erc");
amount = uint112(newBal - prevBal);
First part of the require statement checks for safe downcasting and the second part for underflow. Therefore we can write:
unchecked { amount = uint112(newBal - prevBal); }
https://github.com/code-423n4/2021-11-streaming/blob/56d81204a00fc949d29ddd277169690318b36821/Streaming/src/Locke.sol#L388
https://github.com/code-423n4/2021-11-streaming/blob/56d81204a00fc949d29ddd277169690318b36821/Streaming/src/Locke.sol#L429
https://github.com/code-423n4/2021-11-streaming/blob/56d81204a00fc949d29ddd277169690318b36821/Streaming/src/Locke.sol#L464
https://github.com/code-423n4/2021-11-streaming/blob/56d81204a00fc949d29ddd277169690318b36821/Streaming/src/Locke.sol#L508
Tools Used
Recommended Mitigation Steps
The text was updated successfully, but these errors were encountered: