Skip to main content

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.
Reading beyond the end of the advice tape will result in a runtime error during proof generation.

Type Definition

Methods

get

Returns a reference to the global advice reader.
Returns: An AdviceReader instance Example:

read_u8

Reads a single byte (u8) from the advice tape.
Returns: The next byte from the advice tape Example:
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.
Returns: The next 2 bytes from the advice tape as a u16 Example:

read_u32

Reads a word (4 bytes, u32) from the advice tape in little-endian format.
Returns: The next 4 bytes from the advice tape as a u32 Example:

read_u64

Reads a doubleword (8 bytes, u64) from the advice tape in little-endian format.
Returns: The next 8 bytes from the advice tape as a u64 Example:
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.
Returns: The count of unread bytes in the advice tape Example:

Usage Example

Basic Reading

Reading with Length Checking

Reading Complex Types

For reading complex types, use the AdviceTapeIO trait:

Platform Support

The following table shows platform-specific behavior:

Implementation Details

RISC-V Custom Instructions

AdviceReader uses custom RISC-V instructions to read from the advice tape:
  • FUNCT3_ADVICE_LB (0b011) - Load byte
  • FUNCT3_ADVICE_LH (0b100) - Load halfword
  • FUNCT3_ADVICE_LW (0b101) - Load word
  • FUNCT3_ADVICE_LD (0b110) - Load doubleword
  • FUNCT3_ADVICE_LEN (0b111) - Get remaining bytes
These are encoded using the custom opcode 0x5B.

Memory Alignment

When reading slices of data (via AdviceTapeIO trait implementations), AdviceReader optimizes for alignment:
  1. Performs largest aligned reads possible until 8-byte boundary
  2. Reads in aligned 8-byte chunks
  3. Handles remaining bytes greedily with aligned reads/writes
See jolt-sdk/src/lib.rs:344 for the internal read_slice implementation.

See Also