Cryo Explorer Ethereum Mainnet

Address Contract Verified

Address 0xEB6915F71BB18BcD8a6763187Fcb004Ff91e8695
Balance 0 ETH
Nonce 1
Code Size 3984 bytes
Indexed Transactions 1 (24,426,17624,426,176)
Gas Used (indexed) 194,436
External Etherscan · Sourcify

Contract Bytecode

3984 bytes
0x608060405234801561001057600080fd5b50600436106100625760003560e01c80633a5381b51461006757806365a1930d146100975780639431219e146100b2578063b7aa7a9d146100c9578063b8ff3d80146100d2578063efe871f1146100e7575b600080fd5b60005461007a906001600160a01b031681565b6040516001600160a01b0390911681526020015b60405180910390f35b6001546002546040805192835260208301919091520161008e565b6100bb60025481565b60405190815260200161008e565b6100bb60035481565b6100e56100e0366004610b09565b6100f0565b005b6100bb60015481565b60006100fb8461037f565b6003548151919250146101715760405162461bcd60e51b815260206004820152603360248201527f416e63686f72696e673a20626c6f636b206973206e6f742066726f6d207379736044820152723a32b69030b731b437b934b7339031b430b4b760691b60648201526084015b60405180910390fd5b600060015411801561018957506001548160a0015111155b1561020b5760405162461bcd60e51b815260206004820152604660248201527f416e63686f72696e673a20686569676874206973206c6f776572207468616e2060448201527f6f7220657175616c20746f2070726576696f75736c7920616e63686f726564206064820152651a195a59da1d60d21b608482015260a401610168565b60005460208201516040516311c3b75760e31b81526001600160a01b0390921691638e1dbab8916102429187908790600401610c68565b602060405180830381865afa15801561025f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102839190610cfd565b6102dd5760405162461bcd60e51b815260206004820152602560248201527f416e63686f72696e673a20626c6f636b207369676e617475726520697320696e6044820152641d985b1a5960da1b6064820152608401610168565b60a081015160015560208101516002556040517f489bb9aad0c2bb835c6986a976c420c890858717a465ef1bfa27d007d17551c790610371908390600061010082019050825182526020830151602083015260408301516040830152606083015160608301526080830151608083015260a083015160a083015260c083015160c083015260e083015160e083015292915050565b60405180910390a150505050565b6040805161010081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e08101919091526000828060200190518101906103d69190610d26565b90506000600260006103eb8460000151610738565b6103f88560400151610738565b60405160200161040a93929190610db6565b60408051601f198184030181529082905261042491610ddb565b602060405180830381855afa158015610441573d6000803e3d6000fd5b5050506040513d601f19601f820116820180604052508101906104649190610df7565b9050600060026000846060015161047e86608001516107dd565b60405160200161049093929190610db6565b60408051601f19818403018152908290526104aa91610ddb565b602060405180830381855afa1580156104c7573d6000803e3d6000fd5b5050506040513d601f19601f820116820180604052508101906104ea9190610df7565b90506000600260006104ff8660a001516107dd565b8660c0015160405160200161051693929190610db6565b60408051601f198184030181529082905261053091610ddb565b602060405180830381855afa15801561054d573d6000803e3d6000fd5b5050506040513d601f19601f820116820180604052508101906105709190610df7565b9050600060026000858560405160200161058c93929190610db6565b60408051601f19818403018152908290526105a691610ddb565b602060405180830381855afa1580156105c3573d6000803e3d6000fd5b5050506040513d601f19601f820116820180604052508101906105e69190610df7565b9050600060026000848860e0015160405160200161060693929190610db6565b60408051601f198184030181529082905261062091610ddb565b602060405180830381855afa15801561063d573d6000803e3d6000fd5b5050506040513d601f19601f820116820180604052508101906106609190610df7565b9050600060026007848460405160200161067c93929190610db6565b60408051601f198184030181529082905261069691610ddb565b602060405180830381855afa1580156106b3573d6000803e3d6000fd5b5050506040513d601f19601f820116820180604052508101906106d69190610df7565b90508660200151811461072b5760405162461bcd60e51b815260206004820152601f60248201527f506f7374636861696e3a20696e76616c696420626c6f636b20686561646572006044820152606401610168565b5094979650505050505050565b604051600160f81b602082015260a160f81b6021820152601160f91b6022820152600160fa1b6023820152600160fd1b60248201526025810182905260009060029060450160408051601f198184030181529082905261079791610ddb565b602060405180830381855afa1580156107b4573d6000803e3d6000fd5b5050506040513d601f19601f820116820180604052508101906107d79190610df7565b92915050565b60006001600883901c5b8015610802576107f8600183610e26565b915060081c6107e7565b60008260ff1667ffffffffffffffff811115610820576108206109ad565b6040519080825280601f01601f19166020018201604052801561084a576020820181803683370190505b50859250905060015b8360ff168160ff16116108c25760ff83166001600160f81b031960f885901b168361087e8488610e3f565b60ff168151811061089157610891610e58565b60200101906001600160f81b031916908160001a9053505060089290921c91806108ba81610e6e565b915050610853565b506000816000815181106108d8576108d8610e58565b60209101015160f81c6080161115610984576002600160a36108fb866003610e26565b6002610908886001610e26565b6000876040516020016109219796959493929190610e8d565b60408051601f198184030181529082905261093b91610ddb565b602060405180830381855afa158015610958573d6000803e3d6000fd5b5050506040513d601f19601f8201168201806040525081019061097b9190610df7565b95945050505050565b6002600160a36109948684610e26565b6002878660405160200161092196959493929190610ef9565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff811182821017156109ec576109ec6109ad565b604052919050565b600082601f830112610a0557600080fd5b813567ffffffffffffffff811115610a1f57610a1f6109ad565b610a32601f8201601f19166020016109c3565b818152846020838601011115610a4757600080fd5b816020850160208301376000918101602001919091529392505050565b600067ffffffffffffffff821115610a7e57610a7e6109ad565b5060051b60200190565b600082601f830112610a9957600080fd5b81356020610aae610aa983610a64565b6109c3565b82815260059290921b84018101918181019086841115610acd57600080fd5b8286015b84811015610afe5780356001600160a01b0381168114610af15760008081fd5b8352918301918301610ad1565b509695505050505050565b600080600060608486031215610b1e57600080fd5b833567ffffffffffffffff80821115610b3657600080fd5b610b42878388016109f4565b9450602091508186013581811115610b5957600080fd5b8601601f81018813610b6a57600080fd5b8035610b78610aa982610a64565b81815260059190911b8201840190848101908a831115610b9757600080fd5b8584015b83811015610bcf57803586811115610bb35760008081fd5b610bc18d89838901016109f4565b845250918601918601610b9b565b5096505050506040860135915080821115610be957600080fd5b50610bf686828701610a88565b9150509250925092565b60005b83811015610c1b578181015183820152602001610c03565b50506000910152565b600081518084526020808501945080840160005b83811015610c5d5781516001600160a01b031687529582019590820190600101610c38565b509495945050505050565b600060608201858352602060608185015281865180845260808601915060808160051b870101935082880160005b82811015610cdc57878603607f1901845281518051808852610cbd81888a01898501610c00565b601f01601f191696909601850195509284019290840190600101610c96565b50505050508281036040840152610cf38185610c24565b9695505050505050565b600060208284031215610d0f57600080fd5b81518015158114610d1f57600080fd5b9392505050565b6000610100808385031215610d3a57600080fd5b6040519081019067ffffffffffffffff82118183101715610d5d57610d5d6109ad565b81604052835181526020840151602082015260408401516040820152606084015160608201526080840151608082015260a084015160a082015260c084015160c082015260e084015160e0820152809250505092915050565b60f89390931b6001600160f81b03191683526001830191909152602182015260410190565b60008251610ded818460208701610c00565b9190910192915050565b600060208284031215610e0957600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b60ff81811683821601908111156107d7576107d7610e10565b60ff82811682821603908111156107d7576107d7610e10565b634e487b7160e01b600052603260045260246000fd5b600060ff821660ff8103610e8457610e84610e10565b60010192915050565b6001600160f81b031960f889811b8216835288811b8216600184015287811b8216600284015286811b8216600384015285811b8216600484015284901b1660058201528151600090610ee6816006850160208701610c00565b9190910160060198975050505050505050565b600060ff60f81b808960f81b168352808860f81b166001840152808760f81b166002840152808660f81b166003840152808560f81b166004840152508251610f48816005850160208701610c00565b9190910160050197965050505050505056fea2646970667358221220745fc6e118ea95ee63a78243a42dd2153211d06aef0101f64771dafe7668d66364736f6c63430008140033

Verified Source Code Full Match

Compiler: v0.8.20+commit.a1b79de6 EVM: paris Optimization: Yes (100 runs)
Data.sol 18 lines
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity 0.8.20;

library Data {
    struct ExtraProofData {
        bytes leaf;
        bytes32 hashedLeaf;
        uint position;
        bytes32 extraRoot;
        bytes32[] extraMerkleProofs;
    }

    struct Proof {
        bytes32 leaf;
        uint position;
        bytes32[] merkleProofs;
    }
}
Postchain.sol 94 lines
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity 0.8.20;

// Interfaces
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

// Internal libraries
import "./utils/cryptography/Hash.sol";
import "./utils/cryptography/MerkleProof.sol";
import "./Data.sol";

library Postchain {
    using MerkleProof for bytes32[];

    struct Event {
        uint256 serialNumber;
        uint256 networkId;
        IERC20 token;
        address beneficiary;
        uint256 amount;
    }

    struct BlockHeaderData {
        bytes32 blockchainRid;
        bytes32 blockRid;
        bytes32 previousBlockRid;
        bytes32 merkleRootHashHashedLeaf;
        uint timestamp;
        uint height;
        bytes32 dependenciesHashedLeaf;
        bytes32 extraDataHashedLeaf;
    }

    function verifyEvent(bytes32 _hash, bytes memory _event) internal pure returns (IERC20, address, uint256, uint256) {
        Event memory evt = abi.decode(_event, (Event));
        bytes32 hash = keccak256(_event);
        if (hash != _hash) {
            revert("Postchain: invalid event");
        }
        return (evt.token, evt.beneficiary, evt.amount, evt.networkId);
    }

    function verifyBlockHeader(
        bytes32 blockchainRid,
        bytes memory blockHeader,
        Data.ExtraProofData memory proof
    ) internal pure returns (uint, bytes32) {
        BlockHeaderData memory header = decodeBlockHeader(blockHeader);
        if (blockchainRid != header.blockchainRid) revert("Postchain: invalid blockchain rid");
        require(proof.extraRoot == header.extraDataHashedLeaf, "Postchain: invalid extra data root");
        if (!proof.extraMerkleProofs.verifySHA256(proof.hashedLeaf, proof.position, proof.extraRoot)) {
            revert("Postchain: invalid extra merkle proof");
        }
        return (header.height, header.blockRid);
    }

    function decodeBlockHeader(
        bytes memory blockHeader
    ) internal pure returns (BlockHeaderData memory) {
        BlockHeaderData memory header = abi.decode(blockHeader, (BlockHeaderData));

        bytes32 node12 = sha256(
            abi.encodePacked(
                uint8(0x00),
                Hash.hashGtvBytes32Leaf(header.blockchainRid),
                Hash.hashGtvBytes32Leaf(header.previousBlockRid)
            )
        );

        bytes32 node34 = sha256(
            abi.encodePacked(uint8(0x00), header.merkleRootHashHashedLeaf, Hash.hashGtvIntegerLeaf(header.timestamp))
        );

        bytes32 node56 = sha256(
            abi.encodePacked(uint8(0x00), Hash.hashGtvIntegerLeaf(header.height), header.dependenciesHashedLeaf)
        );

        bytes32 node1234 = sha256(abi.encodePacked(uint8(0x00), node12, node34));

        bytes32 node5678 = sha256(abi.encodePacked(uint8(0x00), node56, header.extraDataHashedLeaf));

        bytes32 blockRid = sha256(
            abi.encodePacked(
                uint8(0x7), // Gtv merkle tree Array Root Node prefix
                node1234,
                node5678
            )
        );

        if (blockRid != header.blockRid) revert("Postchain: invalid block header");
        return header;
    }

}
IValidator.sol 8 lines
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity 0.8.20;

interface IValidator {
    function isValidSignatures(bytes32 hash, bytes[] memory signatures, address[] memory signers) external view returns (bool);

    function isValidator(address _addr) external view returns (bool);
}
Anchoring.sol 40 lines
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity 0.8.20;

// Internal libraries
import "../Postchain.sol";
import "../IValidator.sol";

contract Anchoring {
    IValidator public validator;

    uint public lastAnchoredHeight = 0;
    bytes32 public lastAnchoredBlockRid;
    bytes32 public systemAnchoringBlockchainRid;

    event AnchoredBlock(Postchain.BlockHeaderData blockHeader);

    constructor(IValidator _validator, bytes32 _systemAnchoringBlockchainRid) {
        validator = _validator;
        systemAnchoringBlockchainRid = _systemAnchoringBlockchainRid;
    }

    function anchorBlock(bytes memory blockHeaderRawData, bytes[] memory signatures, address[] memory signers) public {
        Postchain.BlockHeaderData memory blockHeaderData = Postchain.decodeBlockHeader(blockHeaderRawData);

        if (blockHeaderData.blockchainRid != systemAnchoringBlockchainRid) revert("Anchoring: block is not from system anchoring chain");
        if (lastAnchoredHeight > 0 && blockHeaderData.height <= lastAnchoredHeight) revert("Anchoring: height is lower than or equal to previously anchored height");
        if (!validator.isValidSignatures(blockHeaderData.blockRid, signatures, signers)) revert("Anchoring: block signature is invalid");

        lastAnchoredHeight = blockHeaderData.height;
        lastAnchoredBlockRid = blockHeaderData.blockRid;
        emit AnchoredBlock(blockHeaderData);
    }

    /**
     * Provides an atomic read of both height and hash
     */
    function getLastAnchoredBlock() public view returns (uint, bytes32) {
        return (lastAnchoredHeight, lastAnchoredBlockRid);
    }
}
Hash.sol 80 lines
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity 0.8.20;

library Hash {

    function hash(bytes32 left, bytes32 right) internal pure returns (bytes32) {
        if (left == 0x0 && right == 0x0) {
            return 0x0;
        } else if (left == 0x0) {
            return keccak256(abi.encodePacked(right));
        } else if (right == 0x0) {
            return keccak256(abi.encodePacked(left));
        } else {
            return keccak256(abi.encodePacked(left, right));
        }
    }

    function hashGtvBytes32Leaf(bytes32 value) internal pure returns (bytes32) {
        return sha256(abi.encodePacked(
                uint8(0x1),  // Gtv merkle tree leaf prefix
                uint8(0xA1), // // Gtv ByteArray tag: CONTEXT_CLASS, CONSTRUCTED, 1
                uint8(32 + 2),
                uint8(0x4), // DER ByteArray tag
                uint8(32),
                value
        ));
    }

    function hashGtvBytes64Leaf(bytes memory value) internal pure returns (bytes32) {
        if (value.length != 64) {
            revert("Hash: value must be 64 bytes long");
        }
        return sha256(abi.encodePacked(
                uint8(0x1),  // Gtv merkle tree leaf prefix
                uint8(0xA1), // // Gtv ByteArray tag: CONTEXT_CLASS, CONSTRUCTED, 1
                uint8(64 + 2),
                uint8(0x4), // DER ByteArray tag
                uint8(64),
                value
        ));
    }

    function hashGtvIntegerLeaf(uint value) internal pure returns (bytes32) {
        uint8 nbytes = 1;
        uint remainingValue = value >> 8; // minimal length is 1 so we skip the first byte
        while (remainingValue > 0) {
            nbytes += 1;
            remainingValue = remainingValue >> 8;
        }
        bytes memory b = new bytes(nbytes);
        remainingValue = value;
        for (uint8 i = 1; i <= nbytes; i++) {
            uint8 v = uint8(remainingValue & 0xFF);
            b[nbytes - i] = bytes1(v);
            remainingValue = remainingValue >> 8;
        }

        if (uint8(b[0]) & 0x80 > 0) {
            return sha256(abi.encodePacked(
                uint8(0x1),  // Gtv merkle tree leaf prefix
                uint8(0xA3), // GtvInteger tag: CONTEXT_CLASS, CONSTRUCTED, 3
                uint8(nbytes + 3),
                uint8(0x2), // DER integer tag
                nbytes+1,
                uint8(0),
                b
            ));
        } 

        return sha256(abi.encodePacked(
                uint8(0x1),  // Gtv merkle tree leaf prefix
                uint8(0xA3), // GtvInteger tag: CONTEXT_CLASS, CONSTRUCTED, 3
                uint8(nbytes + 2),
                uint8(0x2), // DER integer tag
                nbytes,
                b
            ));
    }

}
MerkleProof.sol 53 lines
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity 0.8.20;

import "./Hash.sol";

library MerkleProof {
    /**
     * @dev verify merkle proof using keccak256
     */
    function verify(bytes32[] memory proofs, bytes32 leaf, uint position, bytes32 rootHash) internal pure returns (bool) {
        if (leaf == 0x0 || position >= (1 << proofs.length)) {
            return false;
        }
        bytes32 r = leaf;
        for (uint i = 0; i < proofs.length; i++) {
            uint b = position & (1 << i);
            if (b == 0) {
                r = Hash.hash(r, proofs[i]);
            } else {
                r = Hash.hash(proofs[i], r);
            }
        }
        return (r == rootHash);
    }

    /**
     * @dev verify merkle proof using sha256
     * specific for postchain block header extra data in dictionary data format
     */
    function verifySHA256(bytes32[] memory proofs, bytes32 leaf, uint position, bytes32 rootHash) internal pure returns (bool) {
        if (position >= (1 << proofs.length)) {
            return false;
        }
        bytes32 r = leaf; // hashed leaf
        uint last = proofs.length-1;
        for (uint i = 0; i < last; i++) {
            uint b = position & (1 << i);
            if (b == 0) {
                r = sha256(abi.encodePacked(uint8(0x00), r, proofs[i]));
            } else {
                r = sha256(abi.encodePacked(uint8(0x00), proofs[i], r));
            }
        }
        // the last node is fixed in dictionary format, prefix = 0x8
        uint p = position & (1 << last);
        if (p == 0) {
            r = sha256(abi.encodePacked(uint8(0x08), r, proofs[last]));
        } else {
            r = sha256(abi.encodePacked(uint8(0x08), proofs[last], r));
        }
        return (r == rootHash);
    }
}
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);
}

Read Contract

getLastAnchoredBlock 0x65a1930d → uint256, bytes32
lastAnchoredBlockRid 0x9431219e → bytes32
lastAnchoredHeight 0xefe871f1 → uint256
systemAnchoringBlockchainRid 0xb7aa7a9d → bytes32
validator 0x3a5381b5 → address

Write Contract 1 functions

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

anchorBlock 0xb8ff3d80
bytes blockHeaderRawData
bytes[] signatures
address[] signers

Top Interactions

AddressTxnsSentReceived
0xFf92FcD8...063e 1 1

Recent Transactions

CSV
|
Hash Method Block Age From/To Value Txn Fee Type
0x8fc77e28...b3825c 0xb8ff3d80 24,426,176 IN 0xFf92FcD8...063e 0 ETH EIP-1559