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

0 stars 0 forks source link

`Collateral.sol#maintananceInvariant` can be combined with `collateralnvarant` to save gas #70

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Handle

0x0x0x

Vulnerability details

maintananceInvariant is only used for withdrawTo function, which also uses collateralInvariant. Both modifiers load collateral amount. They can be combined together to avoid loading collateral amount twice to the stack and save gas on withdrawTo function. Since maintananceInvariant is only used for this function, rather than maintananceInvariant it would be more gas efficient to create the modifier maintananceAndCollateralInvariant and remove maintananceInvariant.

GalloDaSballo commented 2 years ago

The finding is factually correct, re-using collateral would save 100 gas (Hot storage load)

GalloDaSballo commented 2 years ago

Note that there's a typo and the variables are maintenance not maintanance