Beginner FriendlyDeFiFoundry
100 EXP
View results
Submission Details
Severity: low
Invalid

Move the if block which checks for invalid fee and invalid merkel proofs to a modifier, for cleaner code and better readability

Description

In the MerkleAirdrop.sol::claim, the "if" blocks make the code cluttered and hard to read

function claim(address account, uint256 amount, bytes32[] calldata merkleProof) external payable {
if (msg.value != FEE) {
revert MerkleAirdrop__InvalidFeeAmount();
}
bytes32 leaf = keccak256(bytes.concat(keccak256(abi.encode(account, amount))));
if (!MerkleProof.verify(merkleProof, i_merkleRoot, leaf)) {
revert MerkleAirdrop__InvalidProof();
}
emit Claimed(account, amount);
i_airdropToken.safeTransfer(account, amount);
}

Impact

Decreased readability and not a best practice

Recommended mitigation

In the MerkleAirdrop.sol::claim, the "if" blocks which check for invalid fee and invalid merkel proofs can be moved to modifiers, like so:

+ modifier validFee() {
+ require(msg.value == FEE, "MerkleAirdrop__InvalidFeeAmount");
+ _;
+ }
+ modifier validMerkleProof(address account, uint256 amount, bytes32[] calldata merkleProof) {
+ bytes32 leaf = keccak256(abi.encode(account, amount));
+ require(MerkleProof.verify(merkleProof, i_merkleRoot, leaf), "MerkleAirdrop__InvalidProof");
+ _;
+ }
+ function claim(address account, uint256 amount, bytes32[] calldata merkleProof) external payable validFee validMerkleProof(account, amount, merkleProof) {
- function claim(address account, uint256 amount, bytes32[] calldata merkleProof) external payable {
- if (msg.value != FEE) {
- revert MerkleAirdrop__InvalidFeeAmount();
- }
- bytes32 leaf = keccak256(bytes.concat(keccak256(abi.encode(account, amount))));
- if (!MerkleProof.verify(merkleProof, i_merkleRoot, leaf)) {
- revert MerkleAirdrop__InvalidProof();
- }
emit Claimed(account, amount);
i_airdropToken.safeTransfer(account, amount);
}
Updates

Lead Judging Commences

inallhonesty Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.