Skip to Content
Scalus Club is now open! Join us to get an early access to new features 🎉
DocumentationAdvanced Data Structures

Advanced Data Structures

Starting from 0.16.0, Scalus includes a library of authenticated collections: data structures where you store data off-chain and keep only a small hash commitment on-chain. Cryptographic proofs verify that operations (membership, insert, delete) are valid — without the on-chain validator ever seeing the full dataset.

This matters on Cardano because of eUTxO constraints: limited transaction size, expensive on-chain storage, and tight script execution budgets. Authenticated collections let you work with arbitrarily large datasets while keeping transactions small and cheap.

When to Use Each Collection

CollectionVerification CostProof SizeGrows with N?Use Case
Merkle Treelog₂(N)+1 blake2b calls33 × ceil(log₂(N)) bytesYes (logarithmic)Static set known at deploy time. Airdrop allowlists, governance voter registries.
Incremental Merkle TreeVerify: log₂(N)+1 blake2b. Append: 2×log₂(N)+2 blake2b32–33 × ceil(log₂(N)) bytesYes (logarithmic)Append-only sets. Oracle price feeds, event logs, audit trails.
Frontier Merkle TreeSame as Incremental MTSame as Incremental MTYes (logarithmic)Same as Incremental MT but with O(depth) off-chain memory instead of O(N).
Merkle Patricia Forestry~5–15 blake2b calls per step~200–800 bytes (Data-encoded)No (max 2²⁵⁶ entries)General key-value with insert/delete/update + non-membership proofs. Aiken-compatible. DEX order books, token registries.
Fused MPF~8–12% less CPU than MPF~100–500 bytes (flat ByteString)No (max 2²⁵⁶ entries)Same as MPF but cheaper on-chain. Not Aiken-compatible.
Bilinear Accumulators2 pairings + MSM (~35× more CPU)~48–96 bytesNo (constant, 1 group element)Large sets where constant proof size matters. Many proofs per tx, tight size limits.

Decision Flowchart

  1. Static set?Merkle Tree (cheapest possible)
  2. Append-only?Incremental Merkle Tree / Frontier Merkle Tree
  3. Need insert + delete?Fused MPF (cheapest) or MPF (Aiken-compatible)
  4. Proof size critical?Bilinear Accumulator (smallest constant proof, ~35× CPU)
  5. Need non-membership proofs? → MPF, Fused MPF, or Bilinear Accumulator
What collection do you need? ┌──────▼──────┐ │ Static set? │── Yes ──→ Merkle Tree (MT) @ cheapest └──────┬──────┘ │ No ┌──────▼───────┐ │ Append-only? │── Yes ──→ Incremental MT / Frontier MT └──────┬───────┘ │ No ┌────────────▼────────────┐ │ Proof size critical? │── Yes ──→ Bilinear Accumulator │ (many proofs per tx, │ (smallest constant proof size, ~35x CPU) │ tight tx size limits) │ └────────────┬────────────┘ │ No ┌────────────▼────────────┐ │ Need Aiken │── Yes ──→ Merkle Patricia Forestry (MPF) │ compatibility? │ └────────────┬────────────┘ │ No Fused MPF (10% cheaper than MPF)

Supported Operations

OperationMerkle TreeIncremental MT / Frontier MTMerkle Patricia ForestryFused MPFBilinear Accumulator
Verify membershipyesyesyesyesyes
Verify non-membershipyesyesyes
Insert (with proof)append onlyyesyes
Delete (with proof)yesyes
Update (with proof)yesyes

Frontier Merkle Tree uses the same on-chain verifier as Incremental Merkle Tree — it is an off-chain memory optimization.

Benchmarks

For detailed performance benchmarks — including radix comparisons, fusing optimizations, and full Cardano transaction fee breakdowns — see Benchmarking Authenticated Collections on Cardano .

Examples

Each data structure page includes on-chain and off-chain code snippets from real validators in the scalus-examples  module:

Last updated on