#[jolt::provable] macro is the primary attribute macro for creating zero-knowledge provable functions in Jolt. It generates all necessary infrastructure for compiling, proving, and verifying function execution.
Overview
When applied to a function,#[jolt::provable] generates:
- A
mainfunction for the guest program (RISC-V target) - Memory configuration functions
- Build, prove, and verify functions for the host
- Preprocessing and compilation utilities
- Program analysis and tracing tools
Basic Usage
prove_add, build_verifier_add, compile_add, etc. that can be called from the host side.
Parameters
All parameters are optional and specified using the attribute syntax:u64
default:"4096"
Maximum size in bytes for serialized input parameters.
u64
default:"4096"
Maximum size in bytes for serialized return value.
u64
default:"0"
Maximum size in bytes for untrusted advice parameters.
u64
default:"0"
Maximum size in bytes for trusted advice parameters (requires commitment).
u64
default:"4096"
Stack size in bytes for the guest program.
u64
default:"4096"
Heap size in bytes for the guest program.
u64
default:"1048576"
Maximum number of CPU cycles (trace length) for execution.
bool
default:"false"
Enable backtrace support for debugging guest panics.
bool
default:"false"
Enable profiling instrumentation in the guest program.
bool
default:"false"
Generate only guest code, skip host-side utilities (for library functions).
bool
default:"false"
Generate WebAssembly verifier bindings.
Examples
Simple Function
Custom Memory Configuration
With Advice Parameters
Generated Functions
For a function namedfoo, the macro generates (on the host side):
compile_foo(target_dir: &str) -> jolt::host::Program- Compiles the guest programpreprocess_shared_foo(program: &mut Program) -> JoltSharedPreprocessing- Generates shared preprocessingpreprocess_prover_foo(shared: JoltSharedPreprocessing) -> JoltProverPreprocessing- Generates prover preprocessingpreprocess_verifier_foo(shared: JoltSharedPreprocessing, setup: VerifierSetup) -> JoltVerifierPreprocessing- Generates verifier preprocessingbuild_prover_foo(program: Program, preprocessing: JoltProverPreprocessing) -> impl Fn(...)- Creates a prover closurebuild_verifier_foo(preprocessing: JoltVerifierPreprocessing) -> impl Fn(...)- Creates a verifier closureprove_foo(program: Program, preprocessing: JoltProverPreprocessing, ...) -> (ReturnType, Proof, JoltDevice)- Generates a proofanalyze_foo(...) -> ProgramSummary- Analyzes program without provingtrace_foo_to_file(target_dir: &str, ...)- Exports execution tracememory_config_foo() -> MemoryConfig- Returns the memory configuration
Parameter Types
Function parameters can be:- Public inputs: Regular parameters (e.g.,
x: u32) - Untrusted advice: Wrapped in
jolt::UntrustedAdvice<T>- provided by prover, not committed - Trusted advice: Wrapped in
jolt::TrustedAdvice<T>- committed via Pedersen, verified by constraints
serde::Serialize and serde::Deserialize.
Advice Parameters
Trusted and untrusted advice parameters allow the prover to provide additional data:Multiple Functions
You can mark multiple functions with#[jolt::provable] in the same crate:
JOLT_FUNC_NAME environment variable to select which function to compile:
Related
- #[jolt::advice] - Define advice functions
- check_advice! macros - Verify advice correctness