Contract 6eb010fb5779d83a858e6fc6a42679936c93e1c6aa243425eb32257231d63b8a

← Back to Index 📥 Download WASM

Meta

cliver 27.0.0#5a7c5fe76530bf4248477ac812fc757146b98cc4
rssdkver 26.0.0#e1bf74ba6c3ddb591593f5eb5dfb85458ff714c1
rsver 1.92.0

Instances

  • CBCTBWDS5BXW6NW72763DEIOF5PXDI2FBWK6EESJLHLNMXP5BLN4M2TP

Interface

Find a key in the tree

Public entry point for searching the tree. Returns comprehensive information about the key including whether it exists, its value, and the Merkle path siblings required for proof generation.

Arguments

  • env - The Soroban environment
  • key - Key to search for in the tree

Returns

Returns Ok(FindResult) containing whether the key was found, siblings along the path, and collision information for non-membership proofs, or an error if database operations fail.

Errors

  • Error::KeyNotFound - Database operations failed or invalid node structure
fn find_key(
    env: soroban_sdk::Env,
    key: soroban_sdk::U256,
) -> Result

Get the current root of the tree

Returns the root hash of the Sparse Merkle tree. Returns zero if the tree is empty or hasn't been initialized yet.

Arguments

  • env - The Soroban environment

Returns

Returns the current root hash as a U256 value, or zero if empty

fn get_root(env: soroban_sdk::Env) -> Result

Delete a key from the tree

Removes a leaf from the Sparse Merkle tree, handling both sparse branches (single child) and mixed branches (two populated children). When a leaf is deleted, its sibling may be promoted to replace the parent node, collapsing the tree structure. Requires admin authorization.

Arguments

  • env - The Soroban environment
  • key - Key to delete from the tree

Returns

Returns Ok(()) on success, emitting a LeafDeletedEvent with the new root.

Errors

  • Error::KeyNotFound - Key does not exist in the tree or database operations failed
fn delete_leaf(
    env: soroban_sdk::Env,
    key: soroban_sdk::U256,
) -> Result<(), soroban_sdk::Error>

Insert a new key-value pair into the tree

Adds a new leaf to the Sparse Merkle tree, building any missing intermediate nodes. Handles collision cases where a new key shares a path prefix with an existing leaf by extending the tree depth. Requires admin authorization.

Arguments

  • env - The Soroban environment
  • key - Key to insert
  • value - Value to associate with the key

Returns

Returns Ok(()) on success, emitting a LeafInsertedEvent with the new root.

Errors

  • Error::KeyAlreadyExists - Key already exists in the tree
  • Error::KeyNotFound - Database operations failed
fn insert_leaf(
    env: soroban_sdk::Env,
    key: soroban_sdk::U256,
    value: soroban_sdk::U256,
) -> Result<(), soroban_sdk::Error>

Update the admin address

Transfers administrative control to a new address. Requires authorization from the current admin.

Arguments

  • env - The Soroban environment
  • new_admin - New address that will have permission to modify the tree
fn update_admin(env: soroban_sdk::Env, new_admin: soroban_sdk::Address)

Constructor: initialize the contract with an admin address and an empty tree

Sets up the contract with the specified admin and initializes an empty Sparse Merkle Tree with root = 0. This function can only be called once.

Arguments

  • env - The Soroban environment
  • admin - Address that will have permission to modify the tree

Returns

Returns Ok(()) on success

fn __constructor(
    env: soroban_sdk::Env,
    admin: soroban_sdk::Address,
) -> Result<(), soroban_sdk::Error>

Verify non-membership proof for a key

Verifies that a key is NOT in the tree by checking the provided Merkle proof. The proof includes siblings along the path and collision information (not_found_key/value at the leaf). Reconstructs the root from the proof and compares it with the stored root.

Arguments

  • env - The Soroban environment
  • key - Key to verify is not in the tree
  • siblings - Sibling hashes along the path from root to leaf
  • not_found_key - Key at the collision point (or queried key if empty path)
  • not_found_value - Value at the collision point (or zero if empty path)

Returns

Returns Ok(true) if non-membership is verified, Ok(false) if the key actually exists in the tree.

fn verify_non_membership(
    env: soroban_sdk::Env,
    key: soroban_sdk::U256,
    siblings: soroban_sdk::Vec,
    not_found_key: soroban_sdk::U256,
    not_found_value: soroban_sdk::U256,
) -> Result
fn approve(
    env: soroban_sdk::Env,
    from: soroban_sdk::Address,
    spender: soroban_sdk::Address,
    amount: i128,
)
fn balance(env: soroban_sdk::Env, id: soroban_sdk::Address) -> i128
fn transfer(
    env: soroban_sdk::Env,
    from: soroban_sdk::Address,
    to: soroban_sdk::Address,
    amount: i128,
)
fn allowance(
    env: soroban_sdk::Env,
    from: soroban_sdk::Address,
    spender: soroban_sdk::Address,
) -> i128
fn transfer_from(
    env: soroban_sdk::Env,
    from: soroban_sdk::Address,
    to: soroban_sdk::Address,
    amount: i128,
)

Imports

WebAssembly Text (WAT) ▶