Skip to content
anomaPublic

About

Anoma Abstract Resource Machine Implementation using RISC Zero zkVM

Resources

Stars

13 stars

Watchers

11 watching

Forks

Latest commit

Β 

History

600 Commits

Folders and files

Repository files navigation

Anoma Risc0 Resource Machine

This is a shielded resource machine implementation based on Risc0-zkvm

Docs

ARM-RISC0 Directory Structure

  • arm/: The main Anoma Shielded Resource Machine implementation providing the core functionality for Anoma SDK and Validator.

  • arm_core/: The data types of the Anoma Shielded Resource Machine, shared by arm/ and arm_solana/. It does not depend on RISC0 zkVM or k256.

  • arm_circuits/: Demonstration circuits for arms and applications:

    • compliance: Basic compliance checking circuit
    • trivial_logic: Minimal logic circuit example, also used in padding resources
    • proof aggregation (batch): Circuit for single-run aggregation
  • arm_gadgets/: It provides a range of commonly used components for resource logic circuits, such as verifiable encryption and ECDSA signature authentication.

  • arm_solana/: Transaction verification for Solana programs, built on arm_core/ and the syscalls of the Solana runtime.

  • arm_tests/: It encompasses a basic resource logic instantiation and transaction tests.

Audits

Our software undergoes regular audits:

  1. Informal Systems

    πŸ“„ Audit Report (pdf)

  2. Informal Systems

    πŸ“„ Audit Report (pdf)

  3. Nethermind

    πŸ“„ Audit Report (pdf)

Security

If you believe you've found a security issue, we encourage you to notify us via Email at [email protected].

Please do not use the issue tracker for security issues. We welcome working with you to resolve the issue promptly.

ARM-RISC0 Application Examples

Several application examples are available at here, including the simple counter application, token transfer application, and the kudo application.

Getting Started

Dependencies

Note: The installation of the Risc0 toolchain is required only if you intend to develop resource logics(circuits).

Build and Test

  • Compile arm libs
cargo build
  • Run arm tests
# run tests in dev-mode: no real proofs are generated
RISC0_DEV_MODE=1 cargo test

# run tests in release mode: default succinct(stark) proofs are generated
cargo test --release

Run tests and examples on Bonsai

Bonsai is a remote and high-performance service provided by RISC0 for generating proofs. To use Bonsai, you can request an API key here, and then set the environment variables. Once set up, your proof generation tasks will be automatically offloaded to Bonsai.

export BONSAI_API_URL=<BONSAI_URL>
export BONSAI_API_KEY=<YOUR_API_KEY>

Benchmark

Feature flags

We have the following feature flags in arm lib:

Feature Implies Description
compliance_circuit A specific feature for compliance circuit
transaction (default) compliance_circuit It provides full transaction processing capabilities and supports Succinct(STARK) and Groth16 proof types. Groth16 proofs require x86_64 machines.
prove (default) Enables RISC0 proving capabilities (required for actual proof generation)
bonsai Enables RISC0 bonsai sdk
cuda Enables CUDA GPU acceleration for the prover. Requires CUDA toolkit to be installed.
aggregation transaction Enables batch proof aggregation (the inner proofs must be succinct)

Usage Examples

# Default configuration
anoma-rm-risc0 = "2.0.0"

# Proof aggregation (a single succinct proof per transaction)
anoma-rm-risc0 = { version = "2.0.0", features = ["aggregation"] }

# Logic-circuit-only usage
anoma-rm-risc0 = { version = "2.0.0", default-features = false }

Reproducibly generate proving and verifying keys (ELF and ImageID)

You may generate different ELFs and ImageIDs on different machines and environments. To reproduce the same output and publicly verify that the ELF and ImageID correspond to the specific circuit source code, use the following tool and command.

For example, build the compliance circuit in RM:

cargo risczero build --manifest-path arm_circuits/compliance/methods/guest/Cargo.toml

will reproduce the output to:

ELFs ready at:
ImageID: 5f337810d11c37f60cde3e52a0b0bc3fc4516fa3daf94c7f24a359efefe86cc8 -
arm-risc0/arm_circuits/compliance/methods/guest/target/riscv32im-risc0-zkvm-elf/docker/compliance-guest.bin

Use the RISC Zero 3.1.0 tools with the matching crate versions:

rzup install cargo-risczero 3.1.0
rzup install r0vm 3.1.0

RISC Zero 3.1.0 changes the proof circuits and control root. Regenerate receipts produced by earlier versions and update deployed verifiers before using new proofs. See the 3.1.0 release notes.

The circuits README lists all five image IDs for 2.0.0 and the Docker regeneration commands.

Starter kind tree

The starter kind tree contains the 2.0.0 padding and test logics under the zero label. Each kind base is the hash to curve of its logic ref and label ref. Its root is:

c5f431396892968610edacbd594780bd3ec3e703ad3ac98408a28b3960974efd

Initialize it with constants::init_starter_kind_tree() and obtain the root with constants::kind_tree_root(). Pass the expected root to transaction::verify. Changing either logic ID requires regenerating its kind base and the tree root; see the kind-tree update steps.

Proof aggregation

If a single transaction bundles too many resources, it is possible to aggregate all compliance and logic proofs into a single aggregation proof, attesting to the validity of them all. This reduces overall verification time and transaction size.

Before aggregation

Generate the transaction in the normal way in your workflow. But note that succinct proofs will yield faster aggregation.

Warning: It does not support in-circuit verification of Groth16 proofs. You would need to generate succinct compliance and logic proofs instead.

Prove aggregations

You need to enable the aggregation feature to be able to prove or verify aggregations.

The aggregation proof type is specified by the ProofType argument. The inner proofs must be Succinct.

We support the batch aggregation strategy. The batch strategy aggregates all proofs in the transaction in a single run.

use anoma_rm_risc0::{
    proving_system::{JournalEncoding, ProofType},
    transaction::{self, Transaction},
};

// Just a dummy tx, for illustration. The inner proofs must be Succinct.
let mut tx: Transaction = /* a transaction with succinct compliance and logic proofs */;

// Upon successful aggregation, compliance and resource logic proofs are erased.
// `proof_type` can be ProofType::Succinct or ProofType::Groth16.
assert!(transaction::aggregate(
    &mut tx,
    ProofType::Succinct,
    JournalEncoding::Risc0Serde,
).is_ok());

Warning: Once again, aggregation erases all the individual proofs from tx and replaces them with the (single) aggregation proof in a dedicated field. This is why the transaction must be mut. This is true independently of the strategy used.

Verify after aggregation

Use transaction::verify(&tx, expected_kind_tree_root, encoding), as when there is no aggregation proof. The aggregation feature must be enabled. Use the same JournalEncoding passed to transaction::aggregate: Risc0Serde for native / Solana verification or Abi for EVM verification.

External verification of the aggregation proof

tx.aggregation holds the bincode-serialized InnerReceipt in proof and the public inputs in instance. An external verifier reconstructs the RISC Zero Receipt using the journal encoding selected during aggregation. The image ID is BATCH_AGGREGATION_VK for Risc0Serde, or BATCH_AGGREGATION_EVM_VK for Abi.

Comparison

Strategy Prover cost Public input size Aggregation scope Memory efficient
batch amortized among all tx proofs linear in #{tx proofs} fixed (single prover) for RISC0 yes. In general, depends on the zkVM (if supports continuations)

[TODO] Parallel proving at the ARM level. It is possible with tree-like transcripts. Currently not supported, but planned.

About

Anoma Abstract Resource Machine Implementation using RISC Zero zkVM

Resources

Stars

13 stars

Watchers

11 watching

Forks

Releases

Packages

Used by

Contributors

Languages