Skip to main content

Crate vote_commitment_tree

Crate vote_commitment_tree 

Source
Expand description

Append-only Poseidon Merkle tree for the Vote Commitment Tree (Gov Steps V1).

This tree holds both Vote Authority Notes (VANs) and Vote Commitments (VCs) as leaves. Domain separation (DOMAIN_VAN / DOMAIN_VC) is applied when constructing leaf values (in circuits / chain); this crate stores and hashes already-committed field elements.

Insertion order (per cosmos-sdk-messages-spec):

  • MsgDelegateVote → append 1 leaf (VAN)
  • MsgCastVote → append 2 leaves (new VAN, then VC)

§Architecture

The crate is split into server and client layers with a sync API boundary:

  • Shared types (MerkleHashVote, Anchor, MerklePath) — used by both sides.
  • TreeServer — authoritative full tree: append, checkpoint, serve data via TreeSyncApi.
  • TreeClient — sparse tree: sync from server, mark positions, generate witnesses.
  • TreeSyncApi — trait defining the communication boundary (in-process for POC, maps to Cosmos SDK endpoints in production).

Built on incrementalmerkletree / shardtree (same crates that back Orchard’s note commitment tree), with two substitutions:

  • Hash: Poseidon (no layer tagging) instead of Sinsemilla
  • Empty leaf: poseidon_hash(0, 0) instead of Fp::from(2)

Re-exports§

pub use client::SyncError;
pub use client::TreeClient;
pub use server::AppendFromKvError;
pub use server::MemoryTreeServer;
pub use server::SyncableServer;
pub use server::TreeServer;
pub use sync_api::TreeSyncApi;

Modules§

client
Client-side vote commitment tree.
kv_shard_store
KvShardStore — a ShardStore implementation backed by Go’s Cosmos KV store via C function pointer callbacks.
memory_server
SyncableServer — augments [GenericTreeServer] with per-block leaf tracking and implements TreeSyncApi for in-process sync.
serde
Binary serialization for shard trees and checkpoints.
server
Generic and production vote commitment tree servers.
sync_api
Communication boundary between server and client.

Structs§

Anchor
A committed vote commitment tree root at a specific block height.
MerkleHashVote
Leaf and internal node digest for the vote commitment tree.
MerklePath
Merkle authentication path from a leaf to the tree root.

Constants§

DOMAIN_VC
Domain tag for Vote Commitments (matches orchard::vote_proof::circuit::DOMAIN_VC).
MERKLE_PATH_BYTES
Serialized size: 4 bytes (position u32 LE) + 32 * TREE_DEPTH bytes (auth path).
TREE_DEPTH
Fixed depth of the Vote Commitment Tree (2^24 ≈ 16.7M leaf capacity).

Functions§

poseidon_hash
Poseidon hash of two field elements (delegates to imt-tree for circuit consistency).
poseidon_hash_6
Poseidon hash of six field elements (ConstantLength<6>, width 3, rate 2).
vote_commitment_hash
Compute the vote commitment leaf hash (arity-5 Poseidon).