code-423n4 / 2022-01-xdefi-findings

0 stars 0 forks source link

Adding unchecked directive can save gas #185

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Handle

defsec

Vulnerability details

Impact

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.

Proof of Concept

https://github.com/XDeFi-tech/xdefi-distribution/blob/master/contracts/XDEFIDistribution.sol#L274

Tools Used

None

Recommended Mitigation Steps

Consider applying unchecked arithmetic where overflow/underflow is not possible.

deluca-mike commented 2 years ago

Agreed, we'll do unchecked where possible.

deluca-mike commented 2 years ago

In the release candidate XDEFIDistribution contract and release candidate XDEFIDistributionHelper contract, unchecked math is now used throughout.

Specifically for this issue, expiry: uint32(block.timestamp + duration_) is now done in an unchecked block.

Ivshti commented 2 years ago

valid finding & resolved