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

0 stars 0 forks source link

Assigning keccak operations to constant variables results in extra gas costs #281

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Handle

Dravee

Vulnerability details

Impact

Increased gas costs

Proof of Concept

"constants" expressions are expressions. As such, keccak assigned to a constant variable are re-computed at each use of the variable, which will consume gas unnecessarily. To save gas, Changing the variable from constant to immutable will make the computation run only once and therefore save gas.

Places with the issue: https://github.com/code-423n4/2021-12-amun/blob/main/contracts/basket/contracts/facets/Basket/LibBasketStorage.sol#L7-L8 https://github.com/code-423n4/2021-12-amun/blob/main/contracts/basket/contracts/facets/Call/LibCallStorage.sol#L5-L6 https://github.com/code-423n4/2021-12-amun/blob/main/contracts/basket/contracts/facets/ERC20/LibERC20Storage.sol#L5-L9 https://github.com/code-423n4/2021-12-amun/blob/main/contracts/basket/contracts/facets/shared/Reentry/LibReentryProtectionStorage.sol#L5-L6

Tools Used

VS Code

Recommended Mitigation Steps

Change the variable from constant to immutable