Cryo Explorer Ethereum Mainnet

Address Contract Verified

Address 0x7A3c0C5fADde89185947639f256A3AC3D162CEbB
Balance 0 ETH
Nonce 1
Code Size 3784 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

3784 bytes
0x608060405234801561000f575f5ffd5b5060043610610106575f3560e01c806371c5ecb11161009e578063ae0b51df1161006e578063ae0b51df1461022a578063c503101e1461023d578063d2ef079514610250578063f221c20c1461027d578063f2fde38b14610290575f5ffd5b806371c5ecb1146101c957806382bfefc8146101dc5780638920a8c2146102075780638da5cb5b1461021a575f5ffd5b80633ccfd60b116100d95780633ccfd60b146101585780634b25bfce146101605780636dc7a6271461019d578063715018a6146101c1575f5ffd5b8063144fa6d71461010a57806318712c211461011f5780633323c80714610132578063379607f514610145575b5f5ffd5b61011d610118366004610bdc565b6102a3565b005b61011d61012d366004610bf5565b6102cd565b61011d610140366004610c15565b6102f8565b61011d610153366004610c15565b610334565b61011d6104ca565b61018a61016e366004610c2c565b600560209081525f928352604080842090915290825290205481565b6040519081526020015b60405180910390f35b6003546101b190600160a01b900460ff1681565b6040519015158152602001610194565b61011d6105e8565b61018a6101d7366004610c15565b6105fb565b6003546101ef906001600160a01b031681565b6040516001600160a01b039091168152602001610194565b61011d610215366004610c9e565b61061a565b5f546001600160a01b03166101ef565b61011d610238366004610d17565b610719565b61011d61024b366004610d73565b610946565b6101b161025e366004610c2c565b600460209081525f928352604080842090915290825290205460ff1681565b61011d61028b366004610d8e565b6109a6565b61011d61029e366004610bdc565b610a57565b6102ab610a96565b600380546001600160a01b0319166001600160a01b0392909216919091179055565b6102d5610a96565b80600283815481106102e9576102e9610dd6565b5f918252602090912001555050565b610300610a96565b600280546001810182555f919091527f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace0155565b61033c610ac2565b5f818152600560209081526040808320338452909152902054819061037457604051632d85515d60e11b815260040160405180910390fd5b600354600160a01b900460ff1661039e57604051630110efd560e61b815260040160405180910390fd5b5f82815260046020908152604080832033845290915290205460ff16156103d857604051630c8d9eab60e31b815260040160405180910390fd5b5f8281526005602090815260408083203380855290835281842054868552600480855283862083875290945293829020805460ff19166001179055600354915163a9059cbb60e01b815292830152602482018390526001600160a01b03169063a9059cbb906044016020604051808303815f875af115801561045c573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906104809190610dea565b50604080518481526020810183905233917f4ec90e965519d92681267467f775ada5bd214aa92c0dc93d90a5e880ce9ed026910160405180910390a250506104c760018055565b50565b6104d2610a96565b6003546040516370a0823160e01b81523060048201525f916001600160a01b0316906370a0823190602401602060405180830381865afa158015610518573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061053c9190610e05565b60035460405163a9059cbb60e01b8152336004820152602481018390529192506001600160a01b03169063a9059cbb906044016020604051808303815f875af115801561058b573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906105af9190610dea565b5060405181815233907f7084f5476618d8e60b11ef0d7d3f06914655adb8793e28ff7f018d4c76d505d59060200160405180910390a250565b6105f0610a96565b6105f95f610aec565b565b6002818154811061060a575f80fd5b5f91825260209091200154905081565b610622610a96565b82811461064257604051631985132360e31b815260040160405180910390fd5b5f5b838110156106bf5782828281811061065e5761065e610dd6565b9050602002013560055f8881526020019081526020015f205f87878581811061068957610689610dd6565b905060200201602081019061069e9190610bdc565b6001600160a01b0316815260208101919091526040015f2055600101610644565b5083836040516106d0929190610e1c565b6040518091039020857f694fe5adecedc7ad5a3f8391f8a2cf836d4f3aa6984399831388c19ae0fb0d48848460405161070a929190610e5b565b60405180910390a35050505050565b610721610ac2565b600354600160a01b900460ff1661074b57604051630110efd560e61b815260040160405180910390fd5b5f831161076b5760405163162908e360e11b815260040160405180910390fd5b5f84815260046020908152604080832033845290915290205460ff16156107a557604051630c8d9eab60e31b815260040160405180910390fd5b604080513360208201529081018490525f9060600160408051601f19818403018152828252805160209182012090830152016040516020818303038152906040528051906020012090506108498383808060200260200160405190810160405280939291908181526020018383602002808284375f920191909152505060028054909250899150811061083a5761083a610dd6565b905f5260205f20015483610b3b565b610866576040516309bde33960e01b815260040160405180910390fd5b5f85815260046020818152604080842033808652925292839020805460ff19166001179055600354925163a9059cbb60e01b815291820152602481018690526001600160a01b039091169063a9059cbb906044016020604051808303815f875af11580156108d6573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906108fa9190610dea565b50604080518681526020810186905233917f4ec90e965519d92681267467f775ada5bd214aa92c0dc93d90a5e880ce9ed026910160405180910390a25061094060018055565b50505050565b61094e610a96565b60038054821515600160a01b0260ff60a01b199091161790556040517f288bc2dc4daa42daed2dc8f75a041199ec3b44228839d53fcdcd655319c6ba279061099b90831515815260200190565b60405180910390a150565b6109ae610a96565b5f5b81811015610a10575f848152600560205260408120908484848181106109d8576109d8610dd6565b90506020020160208101906109ed9190610bdc565b6001600160a01b0316815260208101919091526040015f908120556001016109b0565b508181604051610a21929190610e1c565b6040519081900381209084907f4ef352f25cdeac845ac72666cd403ec5e67035abb4002b310ebdfef3d564dac2905f90a3505050565b610a5f610a96565b6001600160a01b038116610a8d57604051631e4fbdf760e01b81525f60048201526024015b60405180910390fd5b6104c781610aec565b5f546001600160a01b031633146105f95760405163118cdaa760e01b8152336004820152602401610a84565b600260015403610ae557604051633ee5aeb560e01b815260040160405180910390fd5b6002600155565b5f80546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b5f82610b478584610b50565b14949350505050565b5f81815b8451811015610b8a57610b8082868381518110610b7357610b73610dd6565b6020026020010151610b92565b9150600101610b54565b509392505050565b5f818310610bac575f828152602084905260409020610bba565b5f8381526020839052604090205b9392505050565b80356001600160a01b0381168114610bd7575f5ffd5b919050565b5f60208284031215610bec575f5ffd5b610bba82610bc1565b5f5f60408385031215610c06575f5ffd5b50508035926020909101359150565b5f60208284031215610c25575f5ffd5b5035919050565b5f5f60408385031215610c3d575f5ffd5b82359150610c4d60208401610bc1565b90509250929050565b5f5f83601f840112610c66575f5ffd5b50813567ffffffffffffffff811115610c7d575f5ffd5b6020830191508360208260051b8501011115610c97575f5ffd5b9250929050565b5f5f5f5f5f60608688031215610cb2575f5ffd5b85359450602086013567ffffffffffffffff811115610ccf575f5ffd5b610cdb88828901610c56565b909550935050604086013567ffffffffffffffff811115610cfa575f5ffd5b610d0688828901610c56565b969995985093965092949392505050565b5f5f5f5f60608587031215610d2a575f5ffd5b8435935060208501359250604085013567ffffffffffffffff811115610d4e575f5ffd5b610d5a87828801610c56565b95989497509550505050565b80151581146104c7575f5ffd5b5f60208284031215610d83575f5ffd5b8135610bba81610d66565b5f5f5f60408486031215610da0575f5ffd5b83359250602084013567ffffffffffffffff811115610dbd575f5ffd5b610dc986828701610c56565b9497909650939450505050565b634e487b7160e01b5f52603260045260245ffd5b5f60208284031215610dfa575f5ffd5b8151610bba81610d66565b5f60208284031215610e15575f5ffd5b5051919050565b5f8184825b85811015610e50576001600160a01b03610e3a83610bc1565b1683526020928301929190910190600101610e21565b509095945050505050565b602080825281018290525f6001600160fb1b03831115610e79575f5ffd5b8260051b8085604085013791909101604001939250505056fea2646970667358221220b1f5731ba2cd92284e63fc33981aa190d895369d91b511da413a1f7ad3a247c464736f6c634300081b0033

Verified Source Code Full Match

Compiler: v0.8.27+commit.40a35a09 EVM: shanghai Optimization: Yes (200 runs)
MerkleDistributor.sol 166 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.27;

import {Ownable} from "openzeppelin/access/Ownable.sol";
import {IERC20} from "openzeppelin/token/ERC20/IERC20.sol";
import {MerkleProof} from "openzeppelin/utils/cryptography/MerkleProof.sol";
import {ReentrancyGuard} from "openzeppelin/utils/ReentrancyGuard.sol";

/// @title MerkleDistributor
/// @dev A contract for distributing ERC20 tokens based on Merkle tree proofs and whitelisting.
contract MerkleDistributor is Ownable, ReentrancyGuard {
    // errors
    error NotInWhitelist();
    error AlreadyClaimed();
    error InvalidProof();
    error InvalidAmount();
    error LengthNotMatch();
    error PausedClaim();

    /// @dev Store the Merkle root hashes
    bytes32[] public merkleRoots;

    /// @dev Interface for the ERC20 token contract
    IERC20 public TOKEN;

    /// @dev Indicates whether claiming is allowed
    bool public canClaim;

    /// @dev Mapping to track if an address has already claimed their tokens
    mapping(uint256 => mapping(address => bool)) public isClaimed;

    /// @dev Mapping to store whitelisted addresses and their corresponding claim amounts
    mapping(uint256 => mapping(address => uint256)) public whitelist;

    // This event is emitted whenever a successful call to #claim occurs.
    event Claimed(uint256 index, address indexed account, uint256 amount);

    // Tokens withdrawn
    event Withdrawn(address indexed recipient, uint256 amount);

    event CanClaimChanged(bool canClaim);

    event AddWhitelists(uint256 indexed index, address[] indexed account, uint256[] amount);
    event RemoveWhitelists(uint256 indexed index, address[] indexed account);

    /// @notice Constructor to initialize the contract
    /// @param _merkleRoots Array of Merkle root hashes
    /// @param _token Address of the ERC20 token contract
    /// @param _owner Address of the contract owner
    constructor(bytes32[] memory _merkleRoots, address _token, address _owner) Ownable(_owner) {
        merkleRoots = _merkleRoots;
        TOKEN = IERC20(_token);
    }

    /// @dev Modifier to restrict access to whitelisted addresses only
    /// @param index The index of the Merkle root being used
    modifier onlyWhitelisted(uint256 index) {
        require(whitelist[index][msg.sender] > 0, NotInWhitelist()); // Check if the caller is whitelisted
        _;
    }

    /// @notice Set a new Merkle root
    /// @param index The index of the Merkle root to set
    /// @param _merkleRoot The new Merkle root hash
    function setMerkleRoot(uint256 index, bytes32 _merkleRoot) external onlyOwner {
        merkleRoots[index] = _merkleRoot;
    }

    /// @notice Set new Merkle root list
    /// @param _merkleRoot The new Merkle root hash
    function addMerkleRoot(bytes32 _merkleRoot) external onlyOwner {
        merkleRoots.push(_merkleRoot);
    }

    /// @notice Enable or disable claiming of tokens
    /// @param _canClaim Flag to indicate whether claiming is allowed
    function setCanClaim(bool _canClaim) external onlyOwner {
        canClaim = _canClaim;
        emit CanClaimChanged(_canClaim);
    }

    /// @notice Set a new ERC20 token address
    /// @param _token The new token address
    function setToken(address _token) external onlyOwner {
        TOKEN = IERC20(_token);
    }

    /**
     * @notice Add addresses to the whitelist
     * @param index The index for the specified Merkle root
     * @param addresses Array of addresses to be added
     * @param amounts Corresponding claim amounts for each address
     */
    function addToWhitelist(uint256 index, address[] calldata addresses, uint256[] calldata amounts)
        external
        onlyOwner
    {
        require(addresses.length == amounts.length, LengthNotMatch());
        for (uint256 i = 0; i < addresses.length; i++) {
            whitelist[index][addresses[i]] = amounts[i]; // Add address and amount to whitelist
        }
        emit AddWhitelists(index, addresses, amounts);
    }

    /**
     * @notice Remove addresses from the whitelist
     * @param index The index for the specified Merkle root
     * @param addresses Array of addresses to be removed
     */
    function removeFromWhitelist(uint256 index, address[] calldata addresses) external onlyOwner {
        for (uint256 i = 0; i < addresses.length; i++) {
            delete whitelist[index][addresses[i]]; // Remove address from whitelist
        }
        emit RemoveWhitelists(index, addresses);
    }

    /**
     * @notice Claim tokens (only for whitelisted users)
     * @dev Users can call this function to claim their allocated tokens
     * @param index The index for the specified Merkle root
     */
    function claim(uint256 index) external nonReentrant onlyWhitelisted(index) {
        require(canClaim, PausedClaim());
        require(!isClaimed[index][msg.sender], AlreadyClaimed()); // Check if the user has already claimed

        uint256 amount = whitelist[index][msg.sender]; // Get the claimable amount for the user
        isClaimed[index][msg.sender] = true; // Mark as claimed
        TOKEN.transfer(msg.sender, amount); // Transfer tokens to the user

        emit Claimed(index, msg.sender, amount); // Emit event for withdrawal
    }

    /**
     * @notice Claim tokens using Merkle proof
     * @param index The index for the specified Merkle root
     * @param amount The amount the user wants to claim
     * @param merkleProof The Merkle proof for verification
     * @dev Users can call this function to claim their tokens with a valid proof
     */
    function claim(uint256 index, uint256 amount, bytes32[] calldata merkleProof) external nonReentrant {
        require(canClaim, PausedClaim());
        require(amount > 0, InvalidAmount()); // Check if the requested amount is valid
        require(!isClaimed[index][msg.sender], AlreadyClaimed()); // Check if the user has already claimed

        // Verify the Merkle proof
        bytes32 _messageHash = keccak256(bytes.concat(keccak256(abi.encode(msg.sender, amount))));
        require(MerkleProof.verify(merkleProof, merkleRoots[index], _messageHash), InvalidProof()); // Verify the proof

        // Mark as claimed and send the tokens
        isClaimed[index][msg.sender] = true;
        TOKEN.transfer(msg.sender, amount);

        emit Claimed(index, msg.sender, amount); // Emit event for claimed tokens
    }

    /**
     * @notice Withdraw tokens from the contract (only for the contract owner)
     * @dev Allows the owner to withdraw any remaining tokens in the contract
     */
    function withdraw() external onlyOwner {
        uint256 _remainingBalance = TOKEN.balanceOf(address(this)); // Get the remaining token balance of the contract
        TOKEN.transfer(msg.sender, _remainingBalance); // Transfer the balance to the contract owner

        emit Withdrawn(msg.sender, _remainingBalance); // Emit event for withdrawal
    }
}
Context.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)

pragma solidity ^0.8.20;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}
Ownable.sol 100 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)

pragma solidity ^0.8.20;

import {Context} from "../utils/Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * The initial owner is set to the address provided by the deployer. This can
 * later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    /**
     * @dev The caller account is not authorized to perform an operation.
     */
    error OwnableUnauthorizedAccount(address account);

    /**
     * @dev The owner is not a valid owner account. (eg. `address(0)`)
     */
    error OwnableInvalidOwner(address owner);

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the address provided by the deployer as the initial owner.
     */
    constructor(address initialOwner) {
        if (initialOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(initialOwner);
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        if (owner() != _msgSender()) {
            revert OwnableUnauthorizedAccount(_msgSender());
        }
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby disabling any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        if (newOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}
IERC20.sol 79 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);

    /**
     * @dev Returns the value of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the value of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 value) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the
     * allowance mechanism. `value` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 value) external returns (bool);
}
ReentrancyGuard.sol 84 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/ReentrancyGuard.sol)

pragma solidity ^0.8.20;

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuard {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant NOT_ENTERED = 1;
    uint256 private constant ENTERED = 2;

    uint256 private _status;

    /**
     * @dev Unauthorized reentrant call.
     */
    error ReentrancyGuardReentrantCall();

    constructor() {
        _status = NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        _nonReentrantBefore();
        _;
        _nonReentrantAfter();
    }

    function _nonReentrantBefore() private {
        // On the first call to nonReentrant, _status will be NOT_ENTERED
        if (_status == ENTERED) {
            revert ReentrancyGuardReentrantCall();
        }

        // Any calls to nonReentrant after this point will fail
        _status = ENTERED;
    }

    function _nonReentrantAfter() private {
        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = NOT_ENTERED;
    }

    /**
     * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
     * `nonReentrant` function in the call stack.
     */
    function _reentrancyGuardEntered() internal view returns (bool) {
        return _status == ENTERED;
    }
}
MerkleProof.sol 232 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/MerkleProof.sol)

pragma solidity ^0.8.20;

/**
 * @dev These functions deal with verification of Merkle Tree proofs.
 *
 * The tree and the proofs can be generated using our
 * https://github.com/OpenZeppelin/merkle-tree[JavaScript library].
 * You will find a quickstart guide in the readme.
 *
 * WARNING: You should avoid using leaf values that are 64 bytes long prior to
 * hashing, or use a hash function other than keccak256 for hashing leaves.
 * This is because the concatenation of a sorted pair of internal nodes in
 * the Merkle tree could be reinterpreted as a leaf value.
 * OpenZeppelin's JavaScript library generates Merkle trees that are safe
 * against this attack out of the box.
 */
library MerkleProof {
    /**
     *@dev The multiproof provided is not valid.
     */
    error MerkleProofInvalidMultiproof();

    /**
     * @dev Returns true if a `leaf` can be proved to be a part of a Merkle tree
     * defined by `root`. For this, a `proof` must be provided, containing
     * sibling hashes on the branch from the leaf to the root of the tree. Each
     * pair of leaves and each pair of pre-images are assumed to be sorted.
     */
    function verify(bytes32[] memory proof, bytes32 root, bytes32 leaf) internal pure returns (bool) {
        return processProof(proof, leaf) == root;
    }

    /**
     * @dev Calldata version of {verify}
     */
    function verifyCalldata(bytes32[] calldata proof, bytes32 root, bytes32 leaf) internal pure returns (bool) {
        return processProofCalldata(proof, leaf) == root;
    }

    /**
     * @dev Returns the rebuilt hash obtained by traversing a Merkle tree up
     * from `leaf` using `proof`. A `proof` is valid if and only if the rebuilt
     * hash matches the root of the tree. When processing the proof, the pairs
     * of leafs & pre-images are assumed to be sorted.
     */
    function processProof(bytes32[] memory proof, bytes32 leaf) internal pure returns (bytes32) {
        bytes32 computedHash = leaf;
        for (uint256 i = 0; i < proof.length; i++) {
            computedHash = _hashPair(computedHash, proof[i]);
        }
        return computedHash;
    }

    /**
     * @dev Calldata version of {processProof}
     */
    function processProofCalldata(bytes32[] calldata proof, bytes32 leaf) internal pure returns (bytes32) {
        bytes32 computedHash = leaf;
        for (uint256 i = 0; i < proof.length; i++) {
            computedHash = _hashPair(computedHash, proof[i]);
        }
        return computedHash;
    }

    /**
     * @dev Returns true if the `leaves` can be simultaneously proven to be a part of a Merkle tree defined by
     * `root`, according to `proof` and `proofFlags` as described in {processMultiProof}.
     *
     * CAUTION: Not all Merkle trees admit multiproofs. See {processMultiProof} for details.
     */
    function multiProofVerify(
        bytes32[] memory proof,
        bool[] memory proofFlags,
        bytes32 root,
        bytes32[] memory leaves
    ) internal pure returns (bool) {
        return processMultiProof(proof, proofFlags, leaves) == root;
    }

    /**
     * @dev Calldata version of {multiProofVerify}
     *
     * CAUTION: Not all Merkle trees admit multiproofs. See {processMultiProof} for details.
     */
    function multiProofVerifyCalldata(
        bytes32[] calldata proof,
        bool[] calldata proofFlags,
        bytes32 root,
        bytes32[] memory leaves
    ) internal pure returns (bool) {
        return processMultiProofCalldata(proof, proofFlags, leaves) == root;
    }

    /**
     * @dev Returns the root of a tree reconstructed from `leaves` and sibling nodes in `proof`. The reconstruction
     * proceeds by incrementally reconstructing all inner nodes by combining a leaf/inner node with either another
     * leaf/inner node or a proof sibling node, depending on whether each `proofFlags` item is true or false
     * respectively.
     *
     * CAUTION: Not all Merkle trees admit multiproofs. To use multiproofs, it is sufficient to ensure that: 1) the tree
     * is complete (but not necessarily perfect), 2) the leaves to be proven are in the opposite order they are in the
     * tree (i.e., as seen from right to left starting at the deepest layer and continuing at the next layer).
     */
    function processMultiProof(
        bytes32[] memory proof,
        bool[] memory proofFlags,
        bytes32[] memory leaves
    ) internal pure returns (bytes32 merkleRoot) {
        // This function rebuilds the root hash by traversing the tree up from the leaves. The root is rebuilt by
        // consuming and producing values on a queue. The queue starts with the `leaves` array, then goes onto the
        // `hashes` array. At the end of the process, the last hash in the `hashes` array should contain the root of
        // the Merkle tree.
        uint256 leavesLen = leaves.length;
        uint256 proofLen = proof.length;
        uint256 totalHashes = proofFlags.length;

        // Check proof validity.
        if (leavesLen + proofLen != totalHashes + 1) {
            revert MerkleProofInvalidMultiproof();
        }

        // The xxxPos values are "pointers" to the next value to consume in each array. All accesses are done using
        // `xxx[xxxPos++]`, which return the current value and increment the pointer, thus mimicking a queue's "pop".
        bytes32[] memory hashes = new bytes32[](totalHashes);
        uint256 leafPos = 0;
        uint256 hashPos = 0;
        uint256 proofPos = 0;
        // At each step, we compute the next hash using two values:
        // - a value from the "main queue". If not all leaves have been consumed, we get the next leaf, otherwise we
        //   get the next hash.
        // - depending on the flag, either another value from the "main queue" (merging branches) or an element from the
        //   `proof` array.
        for (uint256 i = 0; i < totalHashes; i++) {
            bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++];
            bytes32 b = proofFlags[i]
                ? (leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++])
                : proof[proofPos++];
            hashes[i] = _hashPair(a, b);
        }

        if (totalHashes > 0) {
            if (proofPos != proofLen) {
                revert MerkleProofInvalidMultiproof();
            }
            unchecked {
                return hashes[totalHashes - 1];
            }
        } else if (leavesLen > 0) {
            return leaves[0];
        } else {
            return proof[0];
        }
    }

    /**
     * @dev Calldata version of {processMultiProof}.
     *
     * CAUTION: Not all Merkle trees admit multiproofs. See {processMultiProof} for details.
     */
    function processMultiProofCalldata(
        bytes32[] calldata proof,
        bool[] calldata proofFlags,
        bytes32[] memory leaves
    ) internal pure returns (bytes32 merkleRoot) {
        // This function rebuilds the root hash by traversing the tree up from the leaves. The root is rebuilt by
        // consuming and producing values on a queue. The queue starts with the `leaves` array, then goes onto the
        // `hashes` array. At the end of the process, the last hash in the `hashes` array should contain the root of
        // the Merkle tree.
        uint256 leavesLen = leaves.length;
        uint256 proofLen = proof.length;
        uint256 totalHashes = proofFlags.length;

        // Check proof validity.
        if (leavesLen + proofLen != totalHashes + 1) {
            revert MerkleProofInvalidMultiproof();
        }

        // The xxxPos values are "pointers" to the next value to consume in each array. All accesses are done using
        // `xxx[xxxPos++]`, which return the current value and increment the pointer, thus mimicking a queue's "pop".
        bytes32[] memory hashes = new bytes32[](totalHashes);
        uint256 leafPos = 0;
        uint256 hashPos = 0;
        uint256 proofPos = 0;
        // At each step, we compute the next hash using two values:
        // - a value from the "main queue". If not all leaves have been consumed, we get the next leaf, otherwise we
        //   get the next hash.
        // - depending on the flag, either another value from the "main queue" (merging branches) or an element from the
        //   `proof` array.
        for (uint256 i = 0; i < totalHashes; i++) {
            bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++];
            bytes32 b = proofFlags[i]
                ? (leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++])
                : proof[proofPos++];
            hashes[i] = _hashPair(a, b);
        }

        if (totalHashes > 0) {
            if (proofPos != proofLen) {
                revert MerkleProofInvalidMultiproof();
            }
            unchecked {
                return hashes[totalHashes - 1];
            }
        } else if (leavesLen > 0) {
            return leaves[0];
        } else {
            return proof[0];
        }
    }

    /**
     * @dev Sorts the pair (a, b) and hashes the result.
     */
    function _hashPair(bytes32 a, bytes32 b) private pure returns (bytes32) {
        return a < b ? _efficientHash(a, b) : _efficientHash(b, a);
    }

    /**
     * @dev Implementation of keccak256(abi.encode(a, b)) that doesn't allocate or expand memory.
     */
    function _efficientHash(bytes32 a, bytes32 b) private pure returns (bytes32 value) {
        /// @solidity memory-safe-assembly
        assembly {
            mstore(0x00, a)
            mstore(0x20, b)
            value := keccak256(0x00, 0x40)
        }
    }
}

Read Contract

TOKEN 0x82bfefc8 → address
canClaim 0x6dc7a627 → bool
isClaimed 0xd2ef0795 → bool
merkleRoots 0x71c5ecb1 → bytes32
owner 0x8da5cb5b → address
whitelist 0x4b25bfce → uint256

Write Contract 11 functions

These functions modify contract state and require a wallet transaction to execute.

addMerkleRoot 0x3323c807
bytes32 _merkleRoot
addToWhitelist 0x8920a8c2
uint256 index
address[] addresses
uint256[] amounts
claim 0x379607f5
uint256 index
claim 0xae0b51df
uint256 index
uint256 amount
bytes32[] merkleProof
removeFromWhitelist 0xf221c20c
uint256 index
address[] addresses
renounceOwnership 0x715018a6
No parameters
setCanClaim 0xc503101e
bool _canClaim
setMerkleRoot 0x18712c21
uint256 index
bytes32 _merkleRoot
setToken 0x144fa6d7
address _token
transferOwnership 0xf2fde38b
address newOwner
withdraw 0x3ccfd60b
No parameters

Recent Transactions

No transactions found for this address