code-423n4 / 2021-11-streaming-findings

0 stars 0 forks source link

Adding unchecked directive can save gas #238

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Handle

WatchPug

Vulnerability details

For the arithmetic operations that will never over/underflow, using the unchecked directive (Solidity v0.8 has default overflow/underflow checks) can save some gas from the unnecessary internal over/underflow checks.

For example:

https://github.com/code-423n4/2021-11-streaming/blob/56d81204a00fc949d29ddd277169690318b36821/Streaming/src/Locke.sol#L463-L464

require(ts.tokens >= amount, "amt");
ts.tokens -= amount;

ts.tokens -= amount will never overflow.