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

Audit fixes #2

Merged
merged 3 commits into from
Oct 22, 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
5 changes: 0 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ jobs:
run: |
forge --version
- name: Run Forge fmt
run: |
forge fmt --check
id: fmt

- name: Run Forge build
run: |
forge build --sizes
Expand Down
6 changes: 6 additions & 0 deletions src/MerkleAirdrop.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import "./@openzeppelin/utils/Address.sol";

error MerkleAirdrop__AlreadyClaimed();
error MerkleAirdrop__InvalidProof();
error MerkleAirdrop__SameRoot();
error MerkleAirdrop__ZeroAddress();

contract MerkleAirdrop is Ownable2Step {
bytes32 public merkleRoot;
Expand All @@ -24,6 +26,8 @@ contract MerkleAirdrop is Ownable2Step {
}

function setMerkleRoot(bytes32 _merkleRoot) external onlyOwner {
require (_merkleRoot != merkleRoot, MerkleAirdrop__SameRoot());

merkleRoot = _merkleRoot;
emit MerkleAirdrop__MerkleRootSet(_merkleRoot);
}
Expand All @@ -47,6 +51,8 @@ contract MerkleAirdrop is Ownable2Step {
}

function recoverEther(address payable _recipient) external onlyOwner {
require (_recipient != address(0), MerkleAirdrop__ZeroAddress());

emit MerkleAirdrop__EtherRecovered(_recipient, address(this).balance);
Address.sendValue(_recipient, address(this).balance);
}
Expand Down
41 changes: 41 additions & 0 deletions test/TestMerkleAirdrop.sol
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,47 @@ contract TestMerkleAirdrop is Test {
assertEq(balanceAfter - balanceBefore, claims[i].amount);
}
}

function test_SetMerkleRoot() external {
vm.startPrank(deployer);
merkleAirdrop.transferOwnership(owner);
vm.stopPrank();

vm.startPrank(owner);
merkleAirdrop.acceptOwnership();

vm.expectRevert(MerkleAirdrop__SameRoot.selector);
merkleAirdrop.setMerkleRoot(root);

merkleAirdrop.setMerkleRoot(bytes32(uint256(42)));
vm.stopPrank();
}

function test_RecoverEther() external {
vm.startPrank(deployer);
merkleAirdrop.transferOwnership(owner);
vm.stopPrank();

vm.startPrank(owner);
merkleAirdrop.acceptOwnership();

uint256 balanceBefore = address(merkleAirdrop).balance;
Address.sendValue(payable(address(merkleAirdrop)), TOTAL_ETHER);
uint256 balanceAfter = address(merkleAirdrop).balance;
assertEq(balanceAfter - balanceBefore, TOTAL_ETHER);

vm.expectRevert(MerkleAirdrop__ZeroAddress.selector);
merkleAirdrop.recoverEther(payable(address(0)));

uint256 balance42Before = address(42).balance;
merkleAirdrop.recoverEther(payable(address(42)));
uint256 balance42After = address(42).balance;

assertEq(address(merkleAirdrop).balance, 0);
assertEq(balance42After - balance42Before, TOTAL_ETHER);

vm.stopPrank();
}
}

struct Claim {
Expand Down