From 63d165160d1e62c19e809d1810a26538333cb765 Mon Sep 17 00:00:00 2001 From: Manuel Montenegro Date: Wed, 12 Jun 2024 08:27:46 +0200 Subject: [PATCH] Replace Merkle verify function for OZ one --- contracts/CumulativeMerkleDrop.sol | 31 ++---------------------------- 1 file changed, 2 insertions(+), 29 deletions(-) diff --git a/contracts/CumulativeMerkleDrop.sol b/contracts/CumulativeMerkleDrop.sol index 306fdfb8..4a9d74c1 100644 --- a/contracts/CumulativeMerkleDrop.sol +++ b/contracts/CumulativeMerkleDrop.sol @@ -40,7 +40,7 @@ contract CumulativeMerkleDrop is Ownable, ICumulativeMerkleDrop { require(IERC20(token_).totalSupply() > 0, "Token contract must be set"); require(rewardsHolder_ != address(0), "Rewards Holder must be an address"); require(address(application_) != address(0), "Application must be an address"); - + transferOwnership(newOwner); token = token_; application = application_; @@ -69,7 +69,7 @@ contract CumulativeMerkleDrop is Ownable, ICumulativeMerkleDrop { // Verify the merkle proof bytes32 leaf = keccak256(abi.encodePacked(stakingProvider, beneficiary, cumulativeAmount)); - require(_verifyAsm(merkleProof, expectedMerkleRoot, leaf), "Invalid proof"); + require(verify(merkleProof, expectedMerkleRoot, leaf), "Invalid proof"); // Mark it claimed uint256 preclaimed = cumulativeClaimed[stakingProvider]; @@ -128,31 +128,4 @@ contract CumulativeMerkleDrop is Ownable, ICumulativeMerkleDrop { function verify(bytes32[] calldata merkleProof, bytes32 root, bytes32 leaf) public pure returns (bool) { return merkleProof.verify(root, leaf); } - - function _verifyAsm(bytes32[] calldata proof, bytes32 root, bytes32 leaf) private pure returns (bool valid) { - // solhint-disable-next-line no-inline-assembly - assembly { - let mem1 := mload(0x40) - let mem2 := add(mem1, 0x20) - let ptr := proof.offset - - for { let end := add(ptr, mul(0x20, proof.length)) } lt(ptr, end) { ptr := add(ptr, 0x20) } { - let node := calldataload(ptr) - - switch lt(leaf, node) - case 1 { - mstore(mem1, leaf) - mstore(mem2, node) - } - default { - mstore(mem1, node) - mstore(mem2, leaf) - } - - leaf := keccak256(mem1, 0x40) - } - - valid := eq(root, leaf) - } - } }