#[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:Maximum size in bytes for serialized input parameters.
Maximum size in bytes for serialized return value.
Maximum size in bytes for untrusted advice parameters.
Maximum size in bytes for trusted advice parameters (requires commitment).
Stack size in bytes for the guest program.
Heap size in bytes for the guest program.
Maximum number of CPU cycles (trace length) for execution.
Enable backtrace support for debugging guest panics.
Enable profiling instrumentation in the guest program.
Generate only guest code, skip host-side utilities (for library functions).
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