Omniscia Keyko Audit
MerkleDistributor Code Style Findings
MerkleDistributor Code Style Findings
MDR-01C: Redundant Visibility Specifier
Type | Severity | Location |
---|---|---|
Gas Optimization | Informational | MerkleDistributor.sol:L13 |
Description:
The linked variable is meant to be an internally accessible constant
yet is declared as public
.
Example:
10address public immutable override token;11bytes32 public immutable override merkleRoot;12uint256 public claimPeriodEndBlock;13uint256 public constant CLAIM_PERIOD_BLOCKS = 17280 * 365;
Recommendation:
We advise the public
specifier to be replaced by either an internal
or private
one given the variable has no use outside of the contract and can be represented by its literal form.
Alleviation:
The variable is now properly set as private
.
MDR-02C: Statement Inefficiency
Type | Severity | Location |
---|---|---|
Gas Optimization | Informational | MerkleDistributor.sol:L37-L43, L45-L49 |
Description:
The claim
function first validates that a particular index
has not been claimed and then proceeds to claim it, however, in doing so it performs multiple storage reads and memory writes redundantly twice.
Example:
37function isClaimed(uint256 index) public view override returns (bool) {38 uint256 claimedWordIndex = index / 256;39 uint256 claimedBitIndex = index % 256;40 uint256 claimedWord = claimedBitMap[claimedWordIndex];41 uint256 mask = (1 << claimedBitIndex);42 return claimedWord & mask == mask;43}44
45function _setClaimed(uint256 index) private {46 uint256 claimedWordIndex = index / 256;47 uint256 claimedBitIndex = index % 256;48 claimedBitMap[claimedWordIndex] = claimedBitMap[claimedWordIndex] | (1 << claimedBitIndex);49}
Recommendation:
We advise the _setClaimed
function to be adjusted to yield a bool
if the bit map has not already been claimed and the function should be directly used within the require
statement that isClaimed
previously was. The isClaimed
function should still exist for off-chain purposes, however, the on-chain component should strive for maximal gas efficiency.
Alleviation:
The _setClaimed
code has been optimised as per our recommendation and now properly yields a bool
indicating its success.