Overview
AdviceReader provides low-level access to read data from the advice tape during the proving phase of a zkVM program. The advice tape is a mechanism for the prover to provide non-deterministic inputs to the guest program that can be verified within the zkVM.
Type Definition
Methods
get
Returns a reference to the global advice reader.AdviceReader instance
Example:
read_u8
Reads a single byte (u8) from the advice tape.This method is only available on RISC-V targets (
riscv32 or riscv64). On other targets, it will panic.read_u16
Reads a halfword (2 bytes, u16) from the advice tape in little-endian format.read_u32
Reads a word (4 bytes, u32) from the advice tape in little-endian format.read_u64
Reads a doubleword (8 bytes, u64) from the advice tape in little-endian format.On 32-bit RISC-V targets (
riscv32), this is performed via two 4-byte reads. On 64-bit targets (riscv64), it’s a single 8-byte read.bytes_remaining
Returns the number of bytes remaining in the advice tape.Usage Example
Basic Reading
Reading with Length Checking
Reading Complex Types
For reading complex types, use theAdviceTapeIO trait:
Platform Support
The following table shows platform-specific behavior:| Target | Supported | Notes |
|---|---|---|
riscv32 | Yes | read_u64 uses two 4-byte reads |
riscv64 | Yes | Full native support |
| Others | No | All methods panic |
Implementation Details
RISC-V Custom Instructions
AdviceReader uses custom RISC-V instructions to read from the advice tape:
FUNCT3_ADVICE_LB(0b011) - Load byteFUNCT3_ADVICE_LH(0b100) - Load halfwordFUNCT3_ADVICE_LW(0b101) - Load wordFUNCT3_ADVICE_LD(0b110) - Load doublewordFUNCT3_ADVICE_LEN(0b111) - Get remaining bytes
0x5B.
Memory Alignment
When reading slices of data (viaAdviceTapeIO trait implementations), AdviceReader optimizes for alignment:
- Performs largest aligned reads possible until 8-byte boundary
- Reads in aligned 8-byte chunks
- Handles remaining bytes greedily with aligned reads/writes
jolt-sdk/src/lib.rs:344 for the internal read_slice implementation.
See Also
- AdviceWriter - Writing advice data to 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