// 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); } }