Overview
AdviceWriter provides low-level access to write data to the advice tape during the compute_advice phase of a zkVM program. The advice tape allows the guest program to send non-deterministic inputs to the prover that can later be read during the proving phase.
Type Definition
Methods
get
Returns a reference to the global advice writer.AdviceWriter instance
Example:
write_u8
Writes a single byte (u8) to the advice tape.The byte value to write
write_u16
Writes a halfword (2 bytes, u16) to the advice tape in little-endian format.The u16 value to write
write_u32
Writes a word (4 bytes, u32) to the advice tape in little-endian format.The u32 value to write
write_u64
Writes a doubleword (8 bytes, u64) to the advice tape in little-endian format.The u64 value to write
Usage Example
Basic Writing
Writing Complex Types
For writing complex types, use theAdviceTapeIO trait:
Complete Advice Flow
Platform Support
The following table shows platform-specific behavior:| Target | Supported | Notes |
|---|---|---|
riscv32 | Yes | Uses custom RISC-V instructions |
riscv64 | Yes | Uses custom RISC-V instructions |
| Others | No | All methods panic |
Implementation Details
RISC-V Custom Instructions
AdviceWriter uses the VirtualHostIO custom instruction (opcode 0x5B, funct3 2) to write bytes to the advice tape. The internal write_bytes method handles the actual I/O:
Data Format
All multi-byte values are written in little-endian format:write_u16(0x1234)writes bytes[0x34, 0x12]write_u32(0x12345678)writes bytes[0x78, 0x56, 0x34, 0x12]write_u64(0x0123456789ABCDEF)writes bytes[0xEF, 0xCD, 0xAB, 0x89, 0x67, 0x45, 0x23, 0x01]
Best Practices
Use AdviceTapeIO for complex types
Use AdviceTapeIO for complex types
Instead of manually writing each field of a struct or vector, use the
AdviceTapeIO trait which handles serialization automatically:Match reads with writes
Match reads with writes
Ensure that the order and types of writes in
compute_advice match the reads in your provable function:Verify untrusted advice
Verify untrusted advice
Always verify values read from the advice tape using
check_advice! or check_advice_eq! to ensure correctness:See Also
- AdviceReader - Reading advice data from the advice tape
- TrustedAdvice<T> - Wrapper for trusted advice inputs
- UntrustedAdvice<T> - Wrapper for untrusted advice inputs
- #[jolt::advice] macro - Macro for advice computation functions
- check_advice! macro - Macro for verifying advice