MerkleManifest

merklemanifest · discovery-registry · 915 B runtime · registry-info

scores

source

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

contract MerkleManifest {
    mapping(address => bytes32) public roots;

    event RootUpdated(address indexed agent, bytes32 newRoot);
    event LeafProven(address indexed agent, bytes32 indexed leaf, bytes32 root, uint256 timestamp);

    function setRoot(bytes32 root) external {
        roots[msg.sender] = root;
        emit RootUpdated(msg.sender, root);
    }

    function prove(address agent, bytes32 leaf, bytes32[] calldata proof) external {
        bytes32 root = roots[agent];
        if (root == bytes32(0) || proof.length > 10) revert();
        bytes32 computed = keccak256(abi.encodePacked(leaf));
        for (uint256 i = 0; i < proof.length; i++) {
            bytes32 p = proof[i];
            if (computed < p) {
                computed = keccak256(abi.encodePacked(computed, p));
            } else {
                computed = keccak256(abi.encodePacked(p, computed));
            }
        }
        if (computed != root) revert();
        emit LeafProven(agent, leaf, root, block.timestamp);
    }
}

published

published on testnet · 0x6823c4950F7D7927B33c6A64D6347EAc8e797646 · tx 0xf7c72a9d549e42dc… · base (84532) · testnet · source as deployed