-
Notifications
You must be signed in to change notification settings - Fork 286
fix(parallel): align stack word max index bound #3014
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
base: next
Are you sure you want to change the base?
Changes from all commits
e47f3ef
9c45a78
78119ee
092502d
7507695
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -255,7 +255,7 @@ impl StackInterface for ReplayProcessor { | |
| } | ||
|
|
||
| fn get_word(&self, start_idx: usize) -> Word { | ||
| debug_assert!(start_idx < MIN_STACK_DEPTH - 4); | ||
| debug_assert!(start_idx <= MIN_STACK_DEPTH - WORD_SIZE); | ||
|
|
||
| let word_start_idx = MIN_STACK_DEPTH - start_idx - 4; | ||
| let mut result: [Felt; WORD_SIZE] = | ||
|
|
@@ -274,7 +274,7 @@ impl StackInterface for ReplayProcessor { | |
| } | ||
|
|
||
| fn set_word(&mut self, start_idx: usize, word: &Word) { | ||
| debug_assert!(start_idx < MIN_STACK_DEPTH - 4); | ||
| debug_assert!(start_idx <= MIN_STACK_DEPTH - WORD_SIZE); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Related to this bound, would it help to switch the next line to |
||
| let word_start_idx = MIN_STACK_DEPTH - start_idx - 4; | ||
|
|
||
| // Reverse so word[0] ends up at the top of stack (highest internal index) | ||
|
|
@@ -506,3 +506,45 @@ impl Stopper for ReplayStopper { | |
| } | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use crate::trace::trace_state::{ | ||
| AdviceReplay, ExecutionContextReplay, HasherResponseReplay, MastForestResolutionReplay, | ||
| MemoryReadsReplay, StackOverflowReplay, StackState, SystemState, | ||
| }; | ||
|
|
||
| fn build_replay_processor() -> ReplayProcessor { | ||
| let system = SystemState { | ||
| clk: 0_u32.into(), | ||
| ctx: ContextId::root(), | ||
| fn_hash: Word::default(), | ||
| pc_transcript_state: Word::default(), | ||
| }; | ||
| let stack = StackState::new([ZERO; MIN_STACK_DEPTH], MIN_STACK_DEPTH, ZERO); | ||
|
|
||
| ReplayProcessor::new( | ||
| system, | ||
| stack, | ||
| StackOverflowReplay::default(), | ||
| ExecutionContextReplay::default(), | ||
| AdviceReplay::default(), | ||
| MemoryReadsReplay::default(), | ||
| HasherResponseReplay::default(), | ||
| MastForestResolutionReplay::default(), | ||
| 1_u32.into(), | ||
| ) | ||
| } | ||
|
|
||
| #[test] | ||
| fn stack_set_word_allows_max_start_idx() { | ||
| let mut processor = build_replay_processor(); | ||
| let start_idx = MIN_STACK_DEPTH - WORD_SIZE; | ||
| let word = [Felt::new(1), Felt::new(2), Felt::new(3), Felt::new(4)].into(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this test is about the |
||
|
|
||
| processor.set_word(start_idx, &word); | ||
|
|
||
| assert_eq!(processor.get_word(start_idx), word); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be clearer to write this as
debug_assert!(start_idx + WORD_SIZE <= MIN_STACK_DEPTH)? That states the full-word-fit invariant directly, which makes the later offset math easier to check at a glance.