Open code423n4 opened 2 years ago
First point is invalid, those are not stored but are only ever used calldata. Second point is technically valid, but the impact is not enough to be worth the readability change as the only time this would be helpful is when a user attempts to call the implementation. We emit events at the end by convention for readability, since these are governance/admin functions anyway, we don't see much value in implementing this.
Using delete doesn't seem to make sense to me either, as this would add logic in certain cases and I find setting a boolean to false
is clearer for readability. This should be handled by the optimizer and the impact appears negligible, if any. Finally using the storage pointer actually increased gas, so we're not doing that either.
Still, though these points are not valid for our case, they are still pretty well thought out!
GAS
The following structs could be optimized moving the position of certains values in order to save slot storages:
sig
close tofollowModule
in DataTypes.sol#L125sig
close toreferenceModule
in DataTypes.sol#L208, DataTypes.sol#L257 and DataTypes.sol#L294sig
close tofollower
in DataTypes.sol#L310sig
close tocollector
in DataTypes.sol#L328Avoid declare variables before use it:
Emit the event before change the state in order to save one variable:
before:
after:
This logic could be used to save gas in:
Use delete instead of set to default value (
false
or0
)whitelist=false
in LensHub.sol#L107whitelist=false
in LensHub.sol#L113whitelist=false
in LensHub.sol#L123toWhitelist=false
in ModuleGlobals.sol#L118Use
storage
keyword for save gas in order to cache a storage pointer._dataByPublicationByProfile[profileId][pubId]
in FeeCollectModule.sol#L75-L78_dataByPublicationByProfile[profileId][pubId]
in LimitedFeeCollectModule.sol#L82-L86_dataByPublicationByProfile[profileId][pubId]
in LimitedTimedFeeCollectModule.sol#L89-L94_dataByPublicationByProfile[profileId][pubId]
in TimedFeeCollectModule.sol#L84-L88