code-423n4 / 2022-07-swivel-findings

0 stars 1 forks source link

Gas Optimizations #187

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

x = x + y is a cheaper operation than x += y

There are multiple instances in the code VaultTracker.sol

vlt.redeemable += interest;
vlt.notional += a;
vlt.redeemable += interest;
from.redeemable += interest;
to.redeemable += newVaultInterest;
to.notional += a;
sVault.redeemable += interest;
sVault.notional += a;

Swivel.sol

filled[hash] += a;

for loops length comparison can use != len instead of < len for cheaper gas

#L85 #L247 #L409 #L552

use constant/literals (e.g. type(uint256).max) instead of 2**x

#L549

++i will consume less gas than i++ if the optimizer isn't enabled

#L100 #L269 #L418 #L564

robrobbins commented 2 years ago

some changes done elsewhere

!= vs < implemented : https://github.com/Swivel-Finance/gost/pull/430