Skip to main content

Batch Operations

The BatchCommitRevealVault enables multiple commit and reveal operations in a single transaction, reducing per-operation gas costs.

How it works

Instead of submitting each commit individually, batch operations:

  1. Collect multiple commitments
  2. Submit them in a single transaction
  3. Distribute across 16 shards in the ShardedTreeRegistry
  4. Each shard has its own Merkle tree and root

Shard assignment

Commitments are assigned to shards based on their hash:

shard = commitment % 16

This distributes load evenly across 16 parallel Merkle trees.

Root updates

The batch root updater service monitors all 16 shards and updates their roots independently. Each shard's root is updated as new commitments are added.

Trade-offs

AdvantageDisadvantage
Lower gas per commitmentSmaller anonymity set per shard
Higher throughput (16x)More complex proof generation
Parallel processing16 separate root updates

When to use

Use batch operations when:

  • You're processing more than 100 commitments per minute
  • Gas cost per commitment is a concern
  • You can accept a smaller per-shard anonymity set

For most applications, the standard CommitRevealVault is sufficient and provides a larger anonymity set (all commitments in one tree).