Skip to main content

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.
Returns: An AdviceWriter instance Example:

write_u8

Writes a single byte (u8) to the advice tape.
u8
required
The byte value to write
Example:

write_u16

Writes a halfword (2 bytes, u16) to the advice tape in little-endian format.
u16
required
The u16 value to write
Example:

write_u32

Writes a word (4 bytes, u32) to the advice tape in little-endian format.
u32
required
The u32 value to write
Example:

write_u64

Writes a doubleword (8 bytes, u64) to the advice tape in little-endian format.
u64
required
The u64 value to write
Example:

Usage Example

Basic Writing

Writing Complex Types

For writing complex types, use the AdviceTapeIO trait:

Complete Advice Flow

Platform Support

The following table shows platform-specific behavior:
Advice tape I/O is only supported on RISC-V targets. Attempting to use AdviceWriter on non-RISC-V platforms will result in a 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

Instead of manually writing each field of a struct or vector, use the AdviceTapeIO trait which handles serialization automatically:
Ensure that the order and types of writes in compute_advice match the reads in your provable function:
Always verify values read from the advice tape using check_advice! or check_advice_eq! to ensure correctness:

See Also