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

0 stars 0 forks source link

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

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

Handle

kenzo

Vulnerability details

As the title says. The constant keccak variables are defined all throughout the diamond storage contracts. So they are used often.

Warden TomFrench has written a good description of the issue here, so I'm copying it: (Cheers Tom... 🙂🥂)

" In a number of places a keccak("string") expression is assigned to a constant variable. Due to how constant variables are implemented this results in the hash being recomputed each time that the variable is used, spending the gas necessary to perform this action.

If these variables were to be immutable this hash is calculated once at deploy time and then the result is saved to be used directly at runtime rather than recalculating, saving the cost of hashing.

See: ethereum/solidity#9232

Recommended Mitigation Steps

Change all constant hashes to be immutable "

0xleastwood commented 2 years ago

Duplicate of #281