Skip to content

fix: replace panicking .expect() / assert! on PC access counter overflow in ProgramMemCheckChip#608

Open
amathxbt wants to merge 1 commit into
nexus-xyz:mainfrom
amathxbt:fix/prog-mem-check-counter-panic
Open

fix: replace panicking .expect() / assert! on PC access counter overflow in ProgramMemCheckChip#608
amathxbt wants to merge 1 commit into
nexus-xyz:mainfrom
amathxbt:fix/prog-mem-check-counter-panic

Conversation

@amathxbt
Copy link
Copy Markdown

@amathxbt amathxbt commented May 7, 2026

Problem

ProgramMemCheckChip::fill_main_trace panics in two places when a PC is accessed more than u32::MAX times:

let new_access_counter = last_access_counter
    .checked_add(1)
    .expect("access counter overflow"); // panic 1
// ...
assert!(!carry_bits[WORD_SIZE - 1]); // panic 2 — redundant overflow check

An adversarially crafted program with a tight infinite loop (j 0) will eventually push the counter past u32::MAX, triggering an unconditional panic that kills the prover process. This is a denial-of-service vector: a malicious guest program can crash the prover without producing a verifiable trace.

Fix

  • Replace .expect() with a let…else that returns early on overflow. The constraint system's carry-overflow constraint (Don't allow overflow in add_constraints) will reject the resulting trace as unsound — no panic required.
  • Downgrade the two redundant assert! calls to debug_assert! since checked_add already guarantees the invariant on the non-overflow path.

fill_main_trace calls checked_add(1).expect("access counter overflow") and
then asserts !carry_bits[WORD_SIZE-1]. Both panic if a PC is accessed more
than u32::MAX times, which is reachable with an adversarially crafted
infinite-loop program, crashing the prover process (denial-of-service).

Replace .expect() with a let-else that returns early on overflow. The carry
/ equality assertions are downgraded to debug_assert! since checked_add
already guarantees no overflow on the success path.
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@amathxbt
Copy link
Copy Markdown
Author

amathxbt commented May 7, 2026

I have read the CLA Document and I hereby sign the CLA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant