Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mitigations: Validate drop id #8

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Dropper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ contract Dropper {
error InsufficientTokensRemaining();
error InvalidMerkleProof();
error ArityMismatch();
error DropIdInvalid();

mapping(uint256 => DropData) public drops;
mapping(uint256 => mapping(address => bool)) private _claimed;
Expand Down Expand Up @@ -185,6 +186,7 @@ contract Dropper {
* @param dropId The drop ID of the drop to refund
*/
function refundToRecipient(uint256 dropId) external {
if (dropId > numDrops || dropId == 0) revert DropIdInvalid();
DropData storage drop = drops[dropId];
if (drop.expirationTimestamp > block.timestamp) revert DropStillLive();
if (drop.totalTokens == drop.claimedTokens) revert AllTokensClaimed();
Expand All @@ -206,6 +208,7 @@ contract Dropper {
* @param merkleProof The merkle inclusion proof
*/
function claim(uint256 dropId, uint256 amount, bytes32[] calldata merkleProof) public {
if (dropId > numDrops || dropId == 0) revert DropIdInvalid();
DropData storage drop = drops[dropId];

if (drop.expirationTimestamp <= block.timestamp || block.timestamp < drop.startTimestamp) revert DropNotLive();
Expand Down
13 changes: 13 additions & 0 deletions test/Dropper.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,19 @@ contract DropperTest is PRBTest, StdCheats {
assertEq(token.balanceOf(address(this)), tokensToRefund);
}

function test_refundToRecipient_reverts_dropIdInvalid() public {
(uint256 dropId,) =
testCreateDrop([address(1), address(2), address(3), address(4)], [uint40(100), 1000, 1000, 1000]);

vm.warp(block.timestamp + 3601);

vm.expectRevert(Dropper.DropIdInvalid.selector);
dropper.refundToRecipient(dropId + 1);

vm.expectRevert(Dropper.DropIdInvalid.selector);
dropper.refundToRecipient(0);
}

function test_createDrop_fail_endBeforeStart() external {
vm.expectRevert(Dropper.EndBeforeStart.selector);
dropper.createDrop(
Expand Down