-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor/fiat shamir statement streamlined #617
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
diegokingston
merged 5 commits into
main
from
refactor/fiat-shamir-statement-streamlined
May 26, 2026
+263
−10
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0ce7bac
refactor(prover): bind the proven statement into the Fiat-Shamir tran…
diegokingston 28f2776
Merge branch 'main' into harden/fiat-shamir-statement-binding
diegokingston 93131de
refactor(prover): streamline statement absorption into transcript
MauroToscano 86a1217
refactor(prover): use exhaustive destructure to guard statement encoding
MauroToscano 3347cce
Merge branch 'main' into refactor/fiat-shamir-statement-streamlined
diegokingston File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| //! Statement absorbed into the Fiat-Shamir transcript before Phase A. | ||
| //! | ||
| //! Streams a canonical, domain-separated, length-prefixed encoding directly | ||
| //! into the transcript. The transcript is itself a Keccak256 absorber | ||
| //! (`DefaultTranscript`), so a single hash suffices — no external digest | ||
| //! needed beyond the ELF. | ||
| //! | ||
| //! All three call sites (prove, verify, bus-balance replay) must absorb | ||
| //! identical bytes; any divergence makes every derived challenge differ and | ||
| //! verification reject. | ||
|
|
||
| use crypto::fiat_shamir::is_transcript::IsTranscript; | ||
| use sha3::{Digest, Keccak256}; | ||
|
|
||
| use crate::test_utils::E; | ||
| use crate::{RuntimePageRange, TableCounts}; | ||
|
|
||
| /// Domain-separation tag. Bump the suffix (`_V2`, ...) on any encoding change. | ||
| const DOMAIN_TAG: &[u8] = b"LAMBDAVM_STARK_STATEMENT_V1"; | ||
|
|
||
| fn elf_digest(elf: &[u8]) -> [u8; 32] { | ||
| let mut h = Keccak256::new(); | ||
| h.update(elf); | ||
| h.finalize().into() | ||
| } | ||
|
|
||
| pub(crate) fn absorb_statement( | ||
| t: &mut impl IsTranscript<E>, | ||
| elf_bytes: &[u8], | ||
| public_output: &[u8], | ||
| table_counts: &TableCounts, | ||
| num_private_input_pages: usize, | ||
| runtime_page_ranges: &[RuntimePageRange], | ||
| ) { | ||
| t.append_bytes(DOMAIN_TAG); | ||
|
|
||
| // ELF: fixed 32-byte digest — no length prefix needed. | ||
| t.append_bytes(&elf_digest(elf_bytes)); | ||
|
|
||
| // public_output: variable length → length-prefix to prevent boundary collisions. | ||
| t.append_bytes(&(public_output.len() as u64).to_le_bytes()); | ||
| t.append_bytes(public_output); | ||
|
|
||
| // table_counts: fixed-width u64s in declared order. The exhaustive | ||
| // destructure makes any field added to TableCounts a compile error here — | ||
| // that's the signal to extend the loop below and bump DOMAIN_TAG. | ||
| let &TableCounts { | ||
| cpu, | ||
| lt, | ||
| memw, | ||
| memw_aligned, | ||
| load, | ||
| mul, | ||
| dvrm, | ||
| shift, | ||
| branch, | ||
| memw_register, | ||
| } = table_counts; | ||
| for count in [ | ||
| cpu, | ||
| lt, | ||
| memw, | ||
| memw_aligned, | ||
| load, | ||
| mul, | ||
| dvrm, | ||
| shift, | ||
| branch, | ||
| memw_register, | ||
| ] { | ||
| t.append_bytes(&(count as u64).to_le_bytes()); | ||
| } | ||
|
|
||
| t.append_bytes(&(num_private_input_pages as u64).to_le_bytes()); | ||
|
|
||
| // runtime_page_ranges: count-prefixed; each entry fixed width. | ||
| t.append_bytes(&(runtime_page_ranges.len() as u64).to_le_bytes()); | ||
| for r in runtime_page_ranges { | ||
| // Exhaustive destructure: any field added to RuntimePageRange becomes | ||
| // a compile error here. | ||
| let &RuntimePageRange { base, count } = r; | ||
| t.append_bytes(&base.to_le_bytes()); | ||
| t.append_bytes(&count.to_le_bytes()); | ||
| } | ||
| } | ||
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.