Sepolia Testnet

Contract

0x8092237EeA6f3e6A9e44aB48c0e735E5615ABd18

Overview

ETH Balance

0 ETH

Multichain Info

N/A
Transaction Hash
Method
Block
From
To

There are no matching entries

Please try again later

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Loading...
Loading

Similar Match Source Code
This contract matches the deployed Bytecode of the Source Code for Contract 0xE3058258...83eaFe360
The constructor portion of the code might be different and could alter the actual behaviour of the contract

Contract Name:
PolygonZkEVMGlobalExitRootV2

Compiler Version
v0.8.20+commit.a1b79de6

Optimization Enabled:
Yes with 999999 runs

Other Settings:
shanghai EvmVersion

Contract Source Code (Solidity Standard Json-Input format)

File 1 of 6 : PolygonZkEVMGlobalExitRootV2.sol
// SPDX-License-Identifier: AGPL-3.0

pragma solidity 0.8.20;

import "./interfaces/IPolygonZkEVMGlobalExitRootV2.sol";
import "./lib/PolygonZkEVMGlobalExitRootBaseStorage.sol";
import "../lib/GlobalExitRootLib.sol";
import "./lib/DepositContractBase.sol";

/**
 * Contract responsible for managing the exit roots across multiple networks
 */
contract PolygonZkEVMGlobalExitRootV2 is
    PolygonZkEVMGlobalExitRootBaseStorage,
    DepositContractBase
{
    // PolygonZkEVMBridge address
    address public immutable bridgeAddress;

    // Rollup manager contract address
    address public immutable rollupManager;

    /**
     * @dev Emitted when the global exit root is updated
     */
    event UpdateL1InfoTree(
        bytes32 indexed mainnetExitRoot,
        bytes32 indexed rollupExitRoot
    );

    /**
     * @param _rollupManager Rollup manager contract address
     * @param _bridgeAddress PolygonZkEVMBridge contract address
     */
    constructor(address _rollupManager, address _bridgeAddress) {
        rollupManager = _rollupManager;
        bridgeAddress = _bridgeAddress;
    }

    /**
     * @notice Update the exit root of one of the networks and the global exit root
     * @param newRoot new exit tree root
     */
    function updateExitRoot(bytes32 newRoot) external {
        // Store storage variables into temporal variables since will be used multiple times
        bytes32 cacheLastRollupExitRoot;
        bytes32 cacheLastMainnetExitRoot;

        if (msg.sender == bridgeAddress) {
            lastMainnetExitRoot = newRoot;
            cacheLastMainnetExitRoot = newRoot;
            cacheLastRollupExitRoot = lastRollupExitRoot;
        } else if (msg.sender == rollupManager) {
            lastRollupExitRoot = newRoot;
            cacheLastRollupExitRoot = newRoot;
            cacheLastMainnetExitRoot = lastMainnetExitRoot;
        } else {
            revert OnlyAllowedContracts();
        }

        bytes32 newGlobalExitRoot = GlobalExitRootLib.calculateGlobalExitRoot(
            cacheLastMainnetExitRoot,
            cacheLastRollupExitRoot
        );

        // If it already exists, do not modify the blockhash
        if (globalExitRootMap[newGlobalExitRoot] == 0) {
            uint256 lastBlockHash = uint256(blockhash(block.number - 1));
            globalExitRootMap[newGlobalExitRoot] = lastBlockHash;

            // save new leaf in L1InfoTree
            _addLeaf(
                getLeafValue(
                    newGlobalExitRoot,
                    lastBlockHash,
                    uint64(block.timestamp)
                )
            );

            emit UpdateL1InfoTree(
                cacheLastMainnetExitRoot,
                cacheLastRollupExitRoot
            );
        }
    }

    /**
     * @notice Return last global exit root
     */
    function getLastGlobalExitRoot() public view returns (bytes32) {
        return
            GlobalExitRootLib.calculateGlobalExitRoot(
                lastMainnetExitRoot,
                lastRollupExitRoot
            );
    }

    /**
     * @notice Computes and returns the merkle root of the L1InfoTree
     */
    function getRoot()
        public
        view
        override(DepositContractBase, IPolygonZkEVMGlobalExitRootV2)
        returns (bytes32)
    {
        return super.getRoot();
    }

    /**
     * @notice Given the leaf data returns the leaf hash
     * @param newGlobalExitRoot Last global exit root
     * @param lastBlockHash Last accesible block hash
     * @param timestamp Ethereum timestamp in seconds
     */
    function getLeafValue(
        bytes32 newGlobalExitRoot,
        uint256 lastBlockHash,
        uint64 timestamp
    ) public pure returns (bytes32) {
        return
            keccak256(
                abi.encodePacked(newGlobalExitRoot, lastBlockHash, timestamp)
            );
    }
}

File 2 of 6 : IBasePolygonZkEVMGlobalExitRoot.sol
// SPDX-License-Identifier: AGPL-3.0

pragma solidity ^0.8.20;

interface IBasePolygonZkEVMGlobalExitRoot {
    /**
     * @dev Thrown when the caller is not the allowed contracts
     */
    error OnlyAllowedContracts();

    function updateExitRoot(bytes32 newRollupExitRoot) external;

    function globalExitRootMap(
        bytes32 globalExitRootNum
    ) external returns (uint256);
}

File 3 of 6 : GlobalExitRootLib.sol
// SPDX-License-Identifier: AGPL-3.0

pragma solidity 0.8.20;

/**
 * @dev A library that provides the necessary calculations to calculate the global exit root
 */
library GlobalExitRootLib {
    function calculateGlobalExitRoot(
        bytes32 mainnetExitRoot,
        bytes32 rollupExitRoot
    ) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked(mainnetExitRoot, rollupExitRoot));
    }
}

File 4 of 6 : IPolygonZkEVMGlobalExitRootV2.sol
// SPDX-License-Identifier: AGPL-3.0

pragma solidity ^0.8.20;
import "../../interfaces/IBasePolygonZkEVMGlobalExitRoot.sol";

interface IPolygonZkEVMGlobalExitRootV2 is IBasePolygonZkEVMGlobalExitRoot {
    function getLastGlobalExitRoot() external view returns (bytes32);

    function getRoot() external view returns (bytes32);
}

File 5 of 6 : DepositContractBase.sol
// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.20;

/**
 * This contract will be used as a helper for all the sparse merkle tree related functions
 * Based on the implementation of the deposit eth2.0 contract https://github.com/ethereum/consensus-specs/blob/dev/solidity_deposit_contract/deposit_contract.sol
 */
contract DepositContractBase {
    /**
     * @dev Thrown when the merkle tree is full
     */
    error MerkleTreeFull();

    // Merkle tree levels
    uint256 internal constant _DEPOSIT_CONTRACT_TREE_DEPTH = 32;

    // This ensures `depositCount` will fit into 32-bits
    uint256 internal constant _MAX_DEPOSIT_COUNT =
        2 ** _DEPOSIT_CONTRACT_TREE_DEPTH - 1;

    // Branch array which contains the necessary sibilings to compute the next root when a new
    // leaf is inserted
    bytes32[_DEPOSIT_CONTRACT_TREE_DEPTH] internal _branch;

    // Counter of current deposits
    uint256 public depositCount;

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     */
    uint256[10] private _gap;

    /**
     * @notice Computes and returns the merkle root
     */
    function getRoot() public view virtual returns (bytes32) {
        bytes32 node;
        uint256 size = depositCount;
        bytes32 currentZeroHashHeight = 0;

        for (
            uint256 height = 0;
            height < _DEPOSIT_CONTRACT_TREE_DEPTH;
            height++
        ) {
            if (((size >> height) & 1) == 1)
                node = keccak256(abi.encodePacked(_branch[height], node));
            else
                node = keccak256(abi.encodePacked(node, currentZeroHashHeight));

            currentZeroHashHeight = keccak256(
                abi.encodePacked(currentZeroHashHeight, currentZeroHashHeight)
            );
        }
        return node;
    }

    /**
     * @notice Add a new leaf to the merkle tree
     * @param leaf Leaf
     */
    function _addLeaf(bytes32 leaf) internal {
        bytes32 node = leaf;

        // Avoid overflowing the Merkle tree (and prevent edge case in computing `_branch`)
        if (depositCount >= _MAX_DEPOSIT_COUNT) {
            revert MerkleTreeFull();
        }

        // Add deposit data root to Merkle tree (update a single `_branch` node)
        uint256 size = ++depositCount;
        for (
            uint256 height = 0;
            height < _DEPOSIT_CONTRACT_TREE_DEPTH;
            height++
        ) {
            if (((size >> height) & 1) == 1) {
                _branch[height] = node;
                return;
            }
            node = keccak256(abi.encodePacked(_branch[height], node));
        }
        // As the loop should always end prematurely with the `return` statement,
        // this code should be unreachable. We assert `false` just to be safe.
        assert(false);
    }

    /**
     * @notice Verify merkle proof
     * @param leafHash Leaf hash
     * @param smtProof Smt proof
     * @param index Index of the leaf
     * @param root Merkle root
     */
    function verifyMerkleProof(
        bytes32 leafHash,
        bytes32[_DEPOSIT_CONTRACT_TREE_DEPTH] calldata smtProof,
        uint32 index,
        bytes32 root
    ) public pure returns (bool) {
        return calculateRoot(leafHash, smtProof, index) == root;
    }

    /**
     * @notice Calculate root from merkle proof
     * @param leafHash Leaf hash
     * @param smtProof Smt proof
     * @param index Index of the leaf
     */
    function calculateRoot(
        bytes32 leafHash,
        bytes32[_DEPOSIT_CONTRACT_TREE_DEPTH] calldata smtProof,
        uint32 index
    ) public pure returns (bytes32) {
        bytes32 node = leafHash;

        // Compute root
        for (
            uint256 height = 0;
            height < _DEPOSIT_CONTRACT_TREE_DEPTH;
            height++
        ) {
            if (((index >> height) & 1) == 1)
                node = keccak256(abi.encodePacked(smtProof[height], node));
            else node = keccak256(abi.encodePacked(node, smtProof[height]));
        }

        return node;
    }
}

File 6 of 6 : PolygonZkEVMGlobalExitRootBaseStorage.sol
// SPDX-License-Identifier: AGPL-3.0

pragma solidity ^0.8.20;
import "../interfaces/IPolygonZkEVMGlobalExitRootV2.sol";

/**
 * Since the current contract of PolygonZkEVMGlobalExitRoot will be upgraded to a PolygonZkEVMGlobalExitRootV2, and it will implement
 * the DepositContractBase, this base is needed to preserve the previous storage slots
 */
abstract contract PolygonZkEVMGlobalExitRootBaseStorage is
    IPolygonZkEVMGlobalExitRootV2
{
    // Rollup root, contains all exit roots of all rollups
    bytes32 public lastRollupExitRoot;

    // Mainnet exit root, this will be updated every time a deposit is made in mainnet
    bytes32 public lastMainnetExitRoot;

    // Store every global exit root: Root --> blockhash
    // Note that previously recoded global exit roots in previous versions, timestamp was recorded instead of blockhash
    mapping(bytes32 => uint256) public globalExitRootMap;
}

Settings
{
  "optimizer": {
    "enabled": true,
    "runs": 999999
  },
  "evmVersion": "shanghai",
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "libraries": {}
}

Contract ABI

[{"inputs":[{"internalType":"address","name":"_rollupManager","type":"address"},{"internalType":"address","name":"_bridgeAddress","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"MerkleTreeFull","type":"error"},{"inputs":[],"name":"OnlyAllowedContracts","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"mainnetExitRoot","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"rollupExitRoot","type":"bytes32"}],"name":"UpdateL1InfoTree","type":"event"},{"inputs":[],"name":"bridgeAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"leafHash","type":"bytes32"},{"internalType":"bytes32[32]","name":"smtProof","type":"bytes32[32]"},{"internalType":"uint32","name":"index","type":"uint32"}],"name":"calculateRoot","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"depositCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getLastGlobalExitRoot","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"newGlobalExitRoot","type":"bytes32"},{"internalType":"uint256","name":"lastBlockHash","type":"uint256"},{"internalType":"uint64","name":"timestamp","type":"uint64"}],"name":"getLeafValue","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"getRoot","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"globalExitRootMap","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastMainnetExitRoot","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastRollupExitRoot","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rollupManager","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"newRoot","type":"bytes32"}],"name":"updateExitRoot","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"leafHash","type":"bytes32"},{"internalType":"bytes32[32]","name":"smtProof","type":"bytes32[32]"},{"internalType":"uint32","name":"index","type":"uint32"},{"internalType":"bytes32","name":"root","type":"bytes32"}],"name":"verifyMerkleProof","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"}]

Deployed Bytecode

0x608060405234801561000f575f80fd5b50600436106100cf575f3560e01c806349b7b8021161007d57806383f244031161005857806383f24403146101f8578063a3c573eb1461020b578063fb57083414610232575f80fd5b806349b7b8021461013c5780635ca1e165146101885780635d81050114610190575f80fd5b8063319cf735116100ad578063319cf7351461011657806333d6247d1461011f5780633ed691ef14610134575f80fd5b806301fd9044146100d3578063257b3632146100ee5780632dfdf0b51461010d575b5f80fd5b6100db5f5481565b6040519081526020015b60405180910390f35b6100db6100fc366004610709565b60026020525f908152604090205481565b6100db60235481565b6100db60015481565b61013261012d366004610709565b610255565b005b6100db6103f6565b6101637f00000000000000000000000007ffe6390ec39fcdaa4b9197b3cc27d1048b8b1f81565b60405173ffffffffffffffffffffffffffffffffffffffff90911681526020016100e5565b6100db610409565b6100db61019e366004610720565b604080516020808201959095528082019390935260c09190911b7fffffffffffffffff0000000000000000000000000000000000000000000000001660608301528051604881840301815260689092019052805191012090565b6100db61020636600461078b565b610412565b6101637f0000000000000000000000007d61de48ecae8a1be0a67993977d93fc5f34a56381565b6102456102403660046107c7565b6104e7565b60405190151581526020016100e5565b5f8073ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000007d61de48ecae8a1be0a67993977d93fc5f34a5631633036102a357505060018190555f5481610322565b73ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000007ffe6390ec39fcdaa4b9197b3cc27d1048b8b1f1633036102f05750505f8190556001548190610322565b6040517fb49365dd00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f61032d82846104fe565b5f81815260026020526040812054919250036103f0575f61034f600143610839565b5f8381526002602090815260409182902092409283905581518082018690528083018490527fffffffffffffffff0000000000000000000000000000000000000000000000004260c01b16606082015282518082036048018152606890910190925281519101209091506103c29061052d565b604051849084907fda61aa7823fcd807e37b95aabcbe17f03a6f3efd514176444dae191d27fd66b3905f90a3505b50505050565b5f6104046001545f546104fe565b905090565b5f61040461062d565b5f83815b60208110156104de57600163ffffffff8516821c81169003610481578481602081106104445761044461084c565b602002013582604051602001610464929190918252602082015260400190565b6040516020818303038152906040528051906020012091506104cc565b818582602081106104945761049461084c565b60200201356040516020016104b3929190918252602082015260400190565b6040516020818303038152906040528051906020012091505b806104d681610879565b915050610416565b50949350505050565b5f816104f4868686610412565b1495945050505050565b604080516020808201859052818301849052825180830384018152606090920190925280519101205b92915050565b80600161053c602060026109ce565b6105469190610839565b60235410610580576040517fef5ccf6600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f60235f815461058f90610879565b918290555090505f5b602081101561061f578082901c6001166001036105cb5782600382602081106105c3576105c361084c565b015550505050565b600381602081106105de576105de61084c565b01546040805160208101929092528101849052606001604051602081830303815290604052805190602001209250808061061790610879565b915050610598565b506106286109e0565b505050565b6023545f90819081805b6020811015610700578083901c60011660010361069457600381602081106106615761066161084c565b015460408051602081019290925281018590526060016040516020818303038152906040528051906020012093506106c1565b60408051602081018690529081018390526060016040516020818303038152906040528051906020012093505b604080516020810184905290810183905260600160405160208183030381529060405280519060200120915080806106f890610879565b915050610637565b50919392505050565b5f60208284031215610719575f80fd5b5035919050565b5f805f60608486031215610732575f80fd5b8335925060208401359150604084013567ffffffffffffffff81168114610757575f80fd5b809150509250925092565b806104008101831015610527575f80fd5b803563ffffffff81168114610786575f80fd5b919050565b5f805f610440848603121561079e575f80fd5b833592506107af8560208601610762565b91506107be6104208501610773565b90509250925092565b5f805f8061046085870312156107db575f80fd5b843593506107ec8660208701610762565b92506107fb6104208601610773565b939692955092936104400135925050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b818103818111156105275761052761080c565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b5f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82036108a9576108a961080c565b5060010190565b600181815b8085111561090957817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff048211156108ef576108ef61080c565b808516156108fc57918102915b93841c93908002906108b5565b509250929050565b5f8261091f57506001610527565b8161092b57505f610527565b8160018114610941576002811461094b57610967565b6001915050610527565b60ff84111561095c5761095c61080c565b50506001821b610527565b5060208310610133831016604e8410600b841016171561098a575081810a610527565b61099483836108b0565b807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff048211156109c6576109c661080c565b029392505050565b5f6109d98383610911565b9392505050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52600160045260245ffdfea264697066735822122051a05a35ac88fdcc6044925b155542688003cc311dd484f2331363234620430c64736f6c63430008140033

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits

A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.