Open code423n4 opened 2 years ago
Valid, but debatable. Putting it as an event means it has to be accessed from archive node, whereas if it's in state, it can be queried from light node.
While the event log vs storage choice is debatable, it's nonetheless a good gas optimization suggestion by the warden.
Contract Storage
Don't save (e.g. merkle tree) where logs or calldata do the trick.
Affected code
https://github.com/code-423n4/2022-05-factorydao/blob/db415804c06143d8af6880bc4cda7222e5463c0e/contracts/MerkleDropFactory.sol#L22
https://github.com/code-423n4/2022-05-factorydao/blob/db415804c06143d8af6880bc4cda7222e5463c0e/contracts/MerkleIdentity.sol#L23
https://github.com/code-423n4/2022-05-factorydao/blob/db415804c06143d8af6880bc4cda7222e5463c0e/contracts/MerkleResistor.sol#L39
https://github.com/code-423n4/2022-05-factorydao/blob/db415804c06143d8af6880bc4cda7222e5463c0e/contracts/MerkleVesting.sol#L32
https://github.com/code-423n4/2022-05-factorydao/blob/db415804c06143d8af6880bc4cda7222e5463c0e/contracts/PermissionlessBasicPoolFactory.sol#L44
Variable packing
We can save storage slots by safely reducing the size of some variables and rearraging them.
Affected code
MerkleIdentity.sol
https://github.com/code-423n4/2022-05-factorydao/blob/db415804c06143d8af6880bc4cda7222e5463c0e/contracts/MerkleIdentity.sol#L21
Save 2 storage slots per Merkle tree by changing to:
Eligibility address, index and price index get packed into one slot.
MerkleResistor.sol
https://github.com/code-423n4/2022-05-factorydao/blob/db415804c06143d8af6880bc4cda7222e5463c0e/contracts/MerkleResistor.sol#L27
Save 2 storage slots per Tranche by changing the struct to:
https://github.com/code-423n4/2022-05-factorydao/blob/db415804c06143d8af6880bc4cda7222e5463c0e/contracts/MerkleResistor.sol#L37
Save 2 storage slots per MerkleTree by changing to:
Times get packed into one slot and address + pctUpFront into another.
MerkleVesting.sol
https://github.com/code-423n4/2022-05-factorydao/blob/db415804c06143d8af6880bc4cda7222e5463c0e/contracts/MerkleVesting.sol#L19
As with the others, save 3 storage slots per Tranche by changing the struct to:
PermissionlessBasicPoolFactory.sol
https://github.com/code-423n4/2022-05-factorydao/blob/db415804c06143d8af6880bc4cda7222e5463c0e/contracts/PermissionlessBasicPoolFactory.sol#L15
Save 2 storage slots per Receipt by packing the times and the id. Change struct to:
Save 4 storage slots per Pool by packing times, id, taxPerCapita and numReceipts:
Unused Parameter
The
initialize
function asks for thedestination
address, but requires it to be themsg.sender
.Recommendation: Remove the parameter and use
msg.sender
directly.Affected Code
https://github.com/code-423n4/2022-05-factorydao/blob/db415804c06143d8af6880bc4cda7222e5463c0e/contracts/MerkleResistor.sol#L134