From 92e6378d73a17601e76a23ab6a3d5a5057f96a5f Mon Sep 17 00:00:00 2001 From: "alexander.biryukov" Date: Tue, 22 Oct 2024 11:37:07 +0400 Subject: [PATCH 1/3] L1 --- src/MerkleAirdrop.sol | 5 +++++ test/TestMerkleAirdrop.sol | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/MerkleAirdrop.sol b/src/MerkleAirdrop.sol index d09c049..013b7b4 100644 --- a/src/MerkleAirdrop.sol +++ b/src/MerkleAirdrop.sol @@ -9,6 +9,7 @@ import "./@openzeppelin/utils/Address.sol"; error MerkleAirdrop__AlreadyClaimed(); error MerkleAirdrop__InvalidProof(); +error MerkleAirdrop__SameRoot(); contract MerkleAirdrop is Ownable2Step { bytes32 public merkleRoot; @@ -24,6 +25,10 @@ contract MerkleAirdrop is Ownable2Step { } function setMerkleRoot(bytes32 _merkleRoot) external onlyOwner { + if (_merkleRoot == merkleRoot) { + revert MerkleAirdrop__SameRoot(); + } + merkleRoot = _merkleRoot; emit MerkleAirdrop__MerkleRootSet(_merkleRoot); } diff --git a/test/TestMerkleAirdrop.sol b/test/TestMerkleAirdrop.sol index 11bc345..2554e5d 100644 --- a/test/TestMerkleAirdrop.sol +++ b/test/TestMerkleAirdrop.sol @@ -91,6 +91,21 @@ 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(); + } } struct Claim { From ef5da54550e8983325057a41b6cf4ba11736bbca Mon Sep 17 00:00:00 2001 From: "alexander.biryukov" Date: Tue, 22 Oct 2024 11:45:23 +0400 Subject: [PATCH 2/3] L2 --- src/MerkleAirdrop.sol | 7 ++++--- test/TestMerkleAirdrop.sol | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/MerkleAirdrop.sol b/src/MerkleAirdrop.sol index 013b7b4..a9ad1e6 100644 --- a/src/MerkleAirdrop.sol +++ b/src/MerkleAirdrop.sol @@ -10,6 +10,7 @@ import "./@openzeppelin/utils/Address.sol"; error MerkleAirdrop__AlreadyClaimed(); error MerkleAirdrop__InvalidProof(); error MerkleAirdrop__SameRoot(); +error MerkleAirdrop__ZeroAddress(); contract MerkleAirdrop is Ownable2Step { bytes32 public merkleRoot; @@ -25,9 +26,7 @@ contract MerkleAirdrop is Ownable2Step { } function setMerkleRoot(bytes32 _merkleRoot) external onlyOwner { - if (_merkleRoot == merkleRoot) { - revert MerkleAirdrop__SameRoot(); - } + require (_merkleRoot != merkleRoot, MerkleAirdrop__SameRoot()); merkleRoot = _merkleRoot; emit MerkleAirdrop__MerkleRootSet(_merkleRoot); @@ -52,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); } diff --git a/test/TestMerkleAirdrop.sol b/test/TestMerkleAirdrop.sol index 2554e5d..988c305 100644 --- a/test/TestMerkleAirdrop.sol +++ b/test/TestMerkleAirdrop.sol @@ -106,6 +106,32 @@ contract TestMerkleAirdrop is Test { 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 { From 1dadb419b5cbf551964c113bc07e312f4c10dab5 Mon Sep 17 00:00:00 2001 From: Alexander Biryukov Date: Tue, 22 Oct 2024 00:57:28 -0700 Subject: [PATCH 3/3] rm forge fmt --check --- .github/workflows/test.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 762a296..130a421 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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