DeFiHardhat
21,000 USDC
View results
Submission Details
Severity: low
Invalid

Custom Errors 02

Summary

The provided audit concerns optimizing gas usage by replacing a require() statement with Custom Errors.

Vulnerability Detail

The require() statements in the UnripeFacet::pick function is currently used to ensure a safe run. These checks could potentially be optimized to use a Custom Error instead.

Impact

Gas optimization is the primary impact of this change. By using Custom Errors, gas costs could potentially be reduced.

Code Snippet

function pick(
address token,
uint256 amount,
bytes32[] memory proof,
LibTransfer.To mode
) external payable nonReentrant {
bytes32 root = s.u[token].merkleRoot;
require(root != bytes32(0), "UnripeClaim: invalid token");
require(!picked(msg.sender, token), "UnripeClaim: already picked");
bytes32 leaf = keccak256(abi.encodePacked(msg.sender, amount));
require(MerkleProof.verify(proof, root, leaf), "UnripeClaim: invalid proof");
s.unripeClaimed[token][msg.sender] = true;
LibTransfer.sendToken(IERC20(token), amount, msg.sender, mode);
emit Pick(msg.sender, token, amount);
}

Tool used

Manual Review

Recommendation

The function should use Custom Errors as shown below:

function pick(
address token,
uint256 amount,
bytes32[] memory proof,
LibTransfer.To mode
) external payable nonReentrant {
bytes32 root = s.u[token].merkleRoot;
if(root == bytes32(0)) {
revert("UnripeClaim: invalid token");
}
if(picked(msg.sender, token)) {
revert("UnripeClaim: already picked");
}
bytes32 leaf = keccak256(abi.encodePacked(msg.sender, amount));
if(!MerkleProof.verify(proof, root, leaf)) {
revert("UnripeClaim: invalid proof");
}
s.unripeClaimed[token][msg.sender] = true;
LibTransfer.sendToken(IERC20(token), amount, msg.sender, mode);
emit Pick(msg.sender, token, amount);
}
Updates

Lead Judging Commences

giovannidisiena Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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