code-423n4 / 2021-08-gravitybridge-findings

1 stars 0 forks source link

Pack structs tightly #36

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Handle

pauliax

Vulnerability details

Impact

Structs LogicCallArgs and ValsetArgs can be optimized for storage efficiency. Struct variables are stored in 32 bytes each so you can group smaller types to occupy less storage. You can read more here: https://fravoll.github.io/solidity-patterns/tight_variable_packing.html or in the official documentation: https://docs.soliditylang.org/en/v0.4.21/miscellaneous.html For example, I think timeOut member does not need to be uint256 as block number is unlikely to reach this capacity anytime soon. Even amounts can be reduced to uint112 as that is what Uniswap and similar AMM uses and they work just fine. I can't tell the exact optimal order, you will need several iterations of changing and testing to find it (probably with the help of gasReporter) but I just wanted you to be aware of this possibility to reduce tx fees.

jkilpatr commented 2 years ago

Appreciate the report here. Probably will not pursue compared to some of the other optimizations offered, but it's good to know it's possible.

Timeout being a u128 is probably viable, or even u64

loudoguno commented 2 years ago

reopening as per judges assessment as "primary issue" on findings sheet