Upgrade this contract to a new WASM (admin only).
fn upgrade(
env: soroban_sdk::Env,
admin: soroban_sdk::Address,
new_wasm_hash: soroban_sdk::BytesN<32>,
) -> Result<(), MerkleError>
Get the current root.
fn get_root(env: soroban_sdk::Env) -> soroban_sdk::U256
Get the admin address.
fn get_admin(env: soroban_sdk::Env) -> Result
Hash a leaf value before insertion.
Leaves should be hashed with a domain separator to prevent second preimage attacks.
fn hash_leaf(env: soroban_sdk::Env, value: soroban_sdk::U256) -> soroban_sdk::U256
Compute Poseidon hash of two values.
This is the core operation for building the tree. H(left, right) combines two nodes into their parent.
fn hash_pair(
env: soroban_sdk::Env,
left: soroban_sdk::U256,
right: soroban_sdk::U256,
) -> soroban_sdk::U256
Initialize the tree with zero values and set the admin.
Sets up the "filled subtrees" array with the hash of empty leaves. This is called once when deploying the contract.
fn initialize(env: soroban_sdk::Env, admin: soroban_sdk::Address)
Insert a new leaf into the tree.
Returns the new root after insertion.
fn insert_leaf(env: soroban_sdk::Env, leaf: soroban_sdk::U256) -> soroban_sdk::U256
Compute a simple Merkle root from a list of leaves (for testing).
Builds a complete binary tree and returns the root. Number of leaves must be a power of 2.
fn compute_root(
env: soroban_sdk::Env,
leaves: soroban_sdk::Vec,
) -> soroban_sdk::U256
Verify a Merkle proof.
Given a leaf, its index, and a proof (sibling hashes from leaf to root), verify that the leaf exists in the tree with the given root.
leaf - The leaf value to verifyleaf_index - Position of the leaf (0-indexed from left)proof - Vector of sibling hashes (length = TREE_DEPTH)root - The root to verify againsttrue if the proof is valid
fn verify_proof(
env: soroban_sdk::Env,
leaf: soroban_sdk::U256,
leaf_index: u32,
proof: soroban_sdk::Vec,
root: soroban_sdk::U256,
) -> bool
Check if a root exists in the history.
This allows verifying proofs against historical roots, important for privacy pools where the root may have changed between deposit and withdrawal.
fn is_known_root(env: soroban_sdk::Env, root: soroban_sdk::U256) -> bool
Get the next leaf index (number of leaves inserted).
fn get_next_index(env: soroban_sdk::Env) -> u32