CommitmentTree
An append-only Merkle tree that stores all Ghost Protocol commitments. Uses Poseidon hashing for ZK-friendly proofs.
Address: 0xB7E37E652F3024bAaaf84b12ae301f8E1feC4D87
Parameters
| Parameter | Value |
|---|---|
| Tree depth | 20 |
| Capacity | ~1,048,576 leaves |
| Hash function | PoseidonT3 |
| Root history | Last 100 roots |
Key functions
// Insert a new commitment (only callable by vault)
function insert(bytes32 commitment) external;
// Get the most recent root
function getLastRoot() external view returns (bytes32);
// Check if a root is in the history window
function isKnownRoot(bytes32 root) external view returns (bool);
// Get the current leaf index (number of commitments)
function nextIndex() external view returns (uint256);
Root history
The tree maintains a circular buffer of the last 100 roots. When a new commitment is inserted, the root is recalculated and added to the buffer. Reveal proofs must use a root from this window — proofs against older roots will fail.
Usage examples
# Get current root
cast call 0xB7E37E652F3024bAaaf84b12ae301f8E1feC4D87 \
"getLastRoot()(bytes32)" \
--rpc-url https://testnet.specterchain.com
# Check if root is known
cast call 0xB7E37E652F3024bAaaf84b12ae301f8E1feC4D87 \
"isKnownRoot(bytes32)(bool)" $ROOT \
--rpc-url https://testnet.specterchain.com
# Get number of commitments
cast call 0xB7E37E652F3024bAaaf84b12ae301f8E1feC4D87 \
"nextIndex()(uint256)" \
--rpc-url https://testnet.specterchain.com
Events
event CommitmentAdded(bytes32 indexed commitment, uint256 index);
event RootUpdated(bytes32 indexed root);
The root updater relayer watches CommitmentAdded events to rebuild the off-chain tree and submit updated roots.
Off-chain tree
The full Merkle tree is maintained off-chain by relayer services. This design saves gas — inserting a leaf on-chain only requires storing the commitment, not recomputing the entire tree. The relayer rebuilds the tree, computes the new root, and calls updateRoot().
Clients building Merkle proofs for reveals must reconstruct the tree by indexing all CommitmentAdded events.