fix: replace panicking .expect() / assert! on PC access counter overflow in ProgramMemCheckChip#608
Open
amathxbt wants to merge 1 commit into
Open
Conversation
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.
|
All contributors have signed the CLA ✍️ ✅ |
Author
|
I have read the CLA Document and I hereby sign the CLA |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ProgramMemCheckChip::fill_main_tracepanics in two places when a PC is accessed more thanu32::MAXtimes:An adversarially crafted program with a tight infinite loop (
j 0) will eventually push the counter pastu32::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
.expect()with alet…elsethat returns early on overflow. The constraint system's carry-overflow constraint (Don't allow overflowinadd_constraints) will reject the resulting trace as unsound — no panic required.assert!calls todebug_assert!sincechecked_addalready guarantees the invariant on the non-overflow path.