code-423n4 / 2021-10-ambire-findings

0 stars 0 forks source link

Pack structs tightly #63

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

Handle

pauliax

Vulnerability details

Impact

There are some structs that could be optimized for storage. 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 In your case, allocPts in DiversificationTrade does not need uint256 type as its max value is 1000. the deadline can also fit in uint32 or uint64 in a realistic scenario.

Recommended Mitigation Steps

Consider optimizing structs for efficient storage.

Ivshti commented 2 years ago

We do not store structs in storage, we use all structs through memory/calldata - so this carries very little optimization (drops some zeroes from the calldata)

GalloDaSballo commented 2 years ago

The suggestion seem to apply for storage However it seems to point to a memory parameter

The suggestion is good, but the finding is invalid for this contest