Inconsistent Multiplicity Increment in `read_ghost_addr`
The read_ghost_addr method incorrectly increments the multiplicity counter for ghost reads, unlike other ghost read methods. This inconsistency could cause circuit constraint verification to fail in zero-knowledge proof systems.
Source: https://github.com/sherlock-audit/2025-08-pico-judging/issues/108
Found by
0xgh0st
Summary
A logic bug exists in the read_ghost_addr method in compiler where it incorrectly increments the multiplicity counter for ghost reads. This violates the ghost read semantics and could lead to incorrect circuit constraint verification in zero-knowledge proof systems.
Root Cause
The read_ghost_addr method calls read_addr_internal with increment_mult: true, which increments the multiplicity counter. This is inconsistent with other ghost read methods:
read_ghost_vaddrcorrectly usesincrement_mult: falseread_ghost_constinitializes multiplicity to zero without incrementing
Ghost reads are intended for non-computational operations that should not affect memory access counts used in circuit constraints.
pub fn read_ghost_addr(&mut self, addr: Address<FC::F>) -> &mut FC::F {
self.read_addr_internal(addr, true)
}
fn read_addr_internal(&mut self, addr: Address<FC::F>, increment_mult: bool) -> &mut FC::F {
use vec_map::Entry;
match self.addr_to_mult.entry(addr.as_usize()) {
Entry::Vacant(_) => panic!("expected entry: addr_to_mult[{:?}]", addr.as_usize()),
Entry::Occupied(entry) => {
// This is a read, so we increment the mult.
let mult = entry.into_mut();
if increment_mult {
*mult += FC::F::ONE;
}
mult
}
}
}
Internal Pre-conditions
NA
External Pre-conditions
- Code must use raw
Address<FC::F>objects in ghost operations rather than higher-level types likeFelt<FC::F>orExt<FC::F, FC::EF>
Attack Path
- Trigger Condition: Use an
Address<FC::F>object directly in a ghost operation (e.g.,print_f(address)) - Bug Activation: The
read_ghostmethod callsread_ghost_addrwhich incorrectly increments multiplicity - Propagation: Incorrect multiplicity values get backfilled into circuit instructions during compilation
Impact
Circuit constraint verification may fail due to inconsistent memory access counts
PoC
No response
Mitigation
Change line 390 in read_ghost_addr from:
self.read_addr_internal(addr, true)
to:
self.read_addr_internal(addr, false)
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
Likely the read_ghost_addr method passes true for increment_mult instead of false, causing an unintended increment of the multiplicity counter.
Impact
Circuit constraint verification may fail due to inconsistent memory access counts.
What the attacker needed
Code uses raw Address objects in ghost operations
The fix
The protocol team fixed this issue by changing the increment_mult argument to false in read_ghost_addr.
How it was found
- Use an Address object directly in a ghost operation such as print_f(address).
- The read_ghost method calls read_ghost_addr, which incorrectly increments multiplicity.
- Incorrect multiplicity values get backfilled into circuit instructions during compilation.
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 zero-knowledge proof systems, a circuit tracks how many times each memory address is read or written. A 'ghost read' is a special read that should not change that count. Here, one ghost read function accidentally increased the count, which could make the circuit's checks fail.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.