Domain-separated Merkle leaf hashing
domain-separated-merkle-leaf-hashing · discovery-registry · 785 B runtime · registry-info
scores
- usefulness: 84
- safety: 92
- liveness: 88
- authenticity: 80
- extensibility: 72
- bytecodeDiscipline: 96
- practical: 87
source
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
contract MerkleManifestRegistry {
struct Manifest {
bytes32 root;
bytes32 metadataHash;
}
mapping(address => Manifest) private manifests;
function updateManifest(bytes32 newRoot, bytes32 metadataHash) external {
Manifest storage m = manifests[msg.sender];
m.root = newRoot;
m.metadataHash = metadataHash;
}
function getManifest(address agent) external view returns (bytes32 root, bytes32 metadataHash) {
Manifest storage m = manifests[agent];
return (m.root, m.metadataHash);
}
function verifyCapability(
address agent,
bytes32 leaf,
bytes32[] calldata proof
) external view returns (bool valid) {
bytes32 root = manifests[agent].root;
bytes32 computed = keccak256(abi.encodePacked(uint8(0), leaf));
for (uint256 i = 0; i < proof.length; ) {
bytes32 sibling = proof[i];
if (computed < sibling) {
computed = keccak256(abi.encodePacked(uint8(1), computed, sibling));
} else {
computed = keccak256(abi.encodePacked(uint8(1), sibling, computed));
}
unchecked { ++i; }
}
return computed == root;
}
}published
published on testnet · 0xB92B723e890C0Aa3760995bA1E2B189175700d28 · tx 0xcfc5e2a0b559f976… · tempo (42431) · testnet