read_write chip does not enforce constraints on opcode selectors
The read_write chip in a zero-knowledge virtual machine only enforces the opcode and register values during memory operations, but does not constrain flags such as op_a_0 or the specific load/store type. A malicious prover could therefore alter the read value or write operation without detection.
0xpetern Follow with 1AutumnLeaf777, MissDida and 1 other
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2025-08-pico-judging/issues/62
Found by
0xpetern, 1AutumnLeaf777, MissDida, cergyk
Description
When calling on an opcode for reading/writing to memory, a lookup is made to the read_write chip. Unfortunately the lookup only enforces the correct used opcode, and a, b, c registers:
read_write/constraints.rs#L41-L47:
builder.looked_instruction(
local_memory_chip_value_cols.instruction.opcode,
local_memory_chip_value_cols.op_a_val(),
local_memory_chip_value_cols.op_b_val(),
local_memory_chip_value_cols.op_c_val(),
is_memory_instruction.clone(),
);
As we can see, the flags available in local_memory_chip_value_cols.instruction: op_a_0, is_lb, is_lbu, is_lh, is_lhu, is_lw, is_sb, is_sh, is_sw are not enforced, and can be used freely by the prover to change the read value (op_a_val) or the write.
read_write/columns.rs#L97-L119:
#[derive(AlignedBorrow, Clone, Copy, Debug, Default)]
#[repr(C)]
pub struct MemoryInstructionCols<T> {
/// The opcode for this cycle.
pub opcode: T,
/// Flags to indicate if op_a is register 0.
//@audit this flag is not constrained in the read_write chip
pub op_a_0: T,
/// Memory Instructions.
//@audit these flags are not constrained in the read_write chip
pub is_lb: T,
pub is_lbu: T,
pub is_lh: T,
pub is_lhu: T,
pub is_lw: T,
pub is_sb: T,
pub is_sh: T,
pub is_sw: T,
pub op_a_access: MemoryReadWriteCols<T>,
pub op_b_access: MemoryReadCols<T>,
pub op_c_access: MemoryReadCols<T>,
}
Recommendation
These flags are correctly enforced in the main chip, through the program lookup, but they are not constrained in the read_write chip.
// Contrain the interaction with program table.
self.looking_program(
builder,
local.pc,
//@audit here the whole instruction with its opcode selectors is looked up.
local.instruction,
local.opcode_selector,
local.is_real,
);
Please consider constraining the whole instruction w/ opcode selector and op_a_0 in read_write chip.
Discussion
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/brevis-network/pico/pull/61
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The read_write chip's lookup only enforces the opcode and register values, omitting constraints on the instruction flags (op_a_0 and load/store type selectors), which are instead enforced only in the main chip.
Impact
A malicious prover could change the read value or the write in memory operations, potentially compromising the integrity of the proof system.
What the attacker needed
Malicious prover
The fix
The issue was fixed by constraining the whole instruction with opcode selector and op_a_0 in the read_write chip.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
In a zero-knowledge proof system, a prover tries to convince a verifier that a computation was done correctly. Here, the part of the system that handles memory reads and writes fails to check all the details of the instruction, so a dishonest prover could cheat and change what was read or written without being caught.
What is Crypto?
Encryption, signatures, randomness or certificate checks that do not protect what they claim to.