code-423n4 / 2021-12-vader-findings

0 stars 0 forks source link

Save Gas With The Unchecked Keyword #130

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Handle

Dravee

Vulnerability details

Impact

Redundant arithmetic underflow/overflow checks can be avoided when an underflow/overflow cannot happen.

Proof of Concept

The "unchecked" keyword can be applied here since there is an "if" statement before to ensure the arithmetic operations, would not cause an integer underflow or overflow.

Instances include: https://github.com/code-423n4/2021-12-vader/blob/main/contracts/dex-v2/pool/VaderPoolV2.sol#L78-L79

Tools Used

Recommended Mitigation Steps

Add the "unchecked" keyword.

if(a < b){
  unchecked { b - a }
}

Or move the line inside the unchecked statement right below it