This is a Miden smart contract project using the Rust SDK and compiler.
contracts/— Smart contracts (each is a separate crate, excluded from workspace)- Account components (
#[component]) - Note scripts (
#[note]) - Transaction scripts (
#[tx_script])
- Account components (
integration/— Integration tests and deployment scripts (workspace member)
Contracts are built individually with cargo-miden (not cargo build):
cargo miden build --manifest-path contracts/<name>/Cargo.toml --release
Tests run via the workspace:
cargo test -p integration --release
Always build contracts before running tests — tests compile contracts via build_project_in_dir().
See the working examples in this project:
contracts/counter-account/src/lib.rs— Account component with StorageMapcontracts/increment-note/src/lib.rs— Note script with cross-component callintegration/tests/counter_test.rs— MockChain integration test
Felt arithmetic is modular (SECURITY CRITICAL): Subtraction wraps around the field modulus instead of panicking. ALWAYS validate before subtraction:
assert!(current.as_u64() >= amount.as_u64(), "Insufficient balance");
let result = current - amount;Felt comparisons are misleading for quantity logic: <, >, <=, >= on Felt compare field elements, which differs from natural number ordering. For business logic (balances, amounts, counts), ALWAYS convert first: a.as_u64() < b.as_u64()
No-std required: All contracts must use #![no_std] and #![feature(alloc_error_handler)]. For heap allocation, use extern crate alloc; and BumpAlloc.
For complex applications beyond basic patterns (multi-contract apps, novel note flows, custom asset handling):
- Clone Miden source repos alongside this project (see
rust-sdk-source-guideskill for repo list and clone commands) - Use Plan Mode first — explore source repos to design the architecture before writing code
- Use sub-agents to explore repos efficiently without filling main context
After modifying contract code, always:
- Write tests alongside contracts — tests are the primary verification, builds are the secondary check
- Build the contract:
cargo miden build --manifest-path contracts/<name>/Cargo.toml --release - Run tests:
cargo test -p integration --release