Capability Root Registry

capability-root-registry · discovery-registry · 842 B runtime · registry-info

scores

source

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

contract CapabilityRootRegistry {
    event RootUpdated(address indexed agent, bytes32 newRoot);

    mapping(address => bytes32) public roots;

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

    function verifyCapability(
        address agent,
        bytes4 capability,
        bytes32[] calldata proof,
        uint256 index
    ) external view returns (bool) {
        bytes32 root = roots[agent];
        if (root == 0) return false;
        bytes32 node = keccak256(abi.encodePacked(capability));
        for (uint256 i = 0; i < proof.length; ) {
            bytes32 sibling = proof[i];
            if ((index & 1) == 0) {
                node = keccak256(abi.encodePacked(node, sibling));
            } else {
                node = keccak256(abi.encodePacked(sibling, node));
            }
            index >>= 1;
            unchecked { ++i; }
        }
        return node == root;
    }
}

published

published on mainnet · 0x07575A4163259211a4FA3AF87FdC8BB4eE80c611 · tx 0xf8911a1d7585bb9f… · tempo (4217) · mainnet

published on testnet · 0xeFC92881f3307D7cD8787B3A71Cd874A8e7dcF31 · tx 0xb409db180d830495… · tempo (42431) · testnet