forked from openvm-org/openvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Allow Hint Space Ids for NativeSumcheck Inputs
#31
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
Open
darth-cy
wants to merge
9
commits into
feat/v1.4.1-scroll-ext
Choose a base branch
from
feat/sumcheck_flex_hints
base: feat/v1.4.1-scroll-ext
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
57aa045
Revert "Feat: read `prod_evals` and `logup_evals` from hint in `sumch…
darth-cy 0910b68
consolidate hint slice changes
darth-cy f197f67
debug
darth-cy 43d63ef
debug
darth-cy 32a4c37
fmt
darth-cy 1ddfaa7
cuda
darth-cy 2ddcfef
reduce cell/column usage
darth-cy 63552f2
restore sumcheck hint ids unit test
darth-cy fc9ce55
fix sumcheck test
darth-cy 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
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
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 |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ use std::borrow::Borrow; | |
|
|
||
| use openvm_circuit::{ | ||
| arch::{ExecutionBridge, ExecutionState}, | ||
| system::memory::{offline_checker::MemoryBridge, MemoryAddress}, | ||
| system::memory::{MemoryAddress, offline_checker::{MemoryBridge, MemoryReadAuxCols}}, | ||
| }; | ||
| use openvm_circuit_primitives::utils::{and, assert_array_eq, not}; | ||
| use openvm_instructions::{LocalOpcode, NATIVE_AS}; | ||
|
|
@@ -23,9 +23,8 @@ use crate::{ | |
| }, | ||
| }; | ||
|
|
||
| pub const TOPLEVEL_TIMESTAMP_DIFF: usize = 6; | ||
| pub const NUM_RWS_FOR_PRODUCT: usize = 1; | ||
| pub const NUM_RWS_FOR_LOGUP: usize = 2; | ||
| pub const NUM_RWS_FOR_PRODUCT: usize = 2; | ||
| pub const NUM_RWS_FOR_LOGUP: usize = 3; | ||
|
|
||
| #[derive(Clone, Debug)] | ||
| pub struct NativeSumcheckAir { | ||
|
|
@@ -103,6 +102,7 @@ impl<AB: InteractionBuilder> Air<AB> for NativeSumcheckAir { | |
| within_round_limit, | ||
| should_acc, | ||
| eval_acc, | ||
| is_hint_src_id, | ||
| specific, | ||
| } = local; | ||
|
|
||
|
|
@@ -230,7 +230,7 @@ impl<AB: InteractionBuilder> Air<AB> for NativeSumcheckAir { | |
| .when(next.prod_row + next.logup_row) | ||
| .assert_eq( | ||
| next.start_timestamp, | ||
| start_timestamp + AB::F::from_canonical_usize(TOPLEVEL_TIMESTAMP_DIFF), | ||
| start_timestamp + AB::F::from_canonical_usize(8), | ||
| ); | ||
| builder | ||
| .when(prod_row) | ||
|
|
@@ -294,31 +294,27 @@ impl<AB: InteractionBuilder> Air<AB> for NativeSumcheckAir { | |
| .execute_and_increment_pc( | ||
| AB::Expr::from_canonical_usize(SUMCHECK_LAYER_EVAL.global_opcode().as_usize()), | ||
| [ | ||
| registers[2].into(), | ||
| registers[4].into(), | ||
| registers[0].into(), | ||
| registers[1].into(), | ||
| native_as.into(), | ||
| native_as.into(), | ||
| header_row_specific.prod_id.into(), | ||
| header_row_specific.logup_id.into(), | ||
| registers[2].into(), | ||
| registers[3].into(), | ||
| ], | ||
| ExecutionState::new(header_row_specific.pc, first_timestamp), | ||
| last_timestamp - first_timestamp, | ||
| ) | ||
| .eval(builder, header_row); | ||
|
|
||
| let mut header_timestamp_diff = (0..TOPLEVEL_TIMESTAMP_DIFF) | ||
| .into_iter() | ||
| .map(|i| AB::F::from_canonical_usize(i)); | ||
| let mut header_read_records_iter = header_row_specific.read_records.iter(); | ||
| // Read registers | ||
| for i in 0..3usize { | ||
| for i in 0..5usize { | ||
| self.memory_bridge | ||
| .read( | ||
| MemoryAddress::new(native_as, registers[i]), | ||
| [register_ptrs[i]], | ||
| first_timestamp + header_timestamp_diff.next().unwrap(), | ||
| header_read_records_iter.next().unwrap(), | ||
| first_timestamp + AB::F::from_canonical_usize(i), | ||
| &header_row_specific.read_records[i], | ||
| ) | ||
| .eval(builder, header_row); | ||
| } | ||
|
|
@@ -328,8 +324,8 @@ impl<AB: InteractionBuilder> Air<AB> for NativeSumcheckAir { | |
| .read( | ||
| MemoryAddress::new(native_as, register_ptrs[0]), | ||
| ctx, | ||
| first_timestamp + header_timestamp_diff.next().unwrap(), | ||
| header_read_records_iter.next().unwrap(), | ||
| first_timestamp + AB::F::from_canonical_usize(5), | ||
| &header_row_specific.read_records[5], | ||
| ) | ||
| .eval(builder, header_row); | ||
|
|
||
|
|
@@ -338,8 +334,8 @@ impl<AB: InteractionBuilder> Air<AB> for NativeSumcheckAir { | |
| .read( | ||
| MemoryAddress::new(native_as, register_ptrs[1]), | ||
| challenges, | ||
| first_timestamp + header_timestamp_diff.next().unwrap(), | ||
| header_read_records_iter.next().unwrap(), | ||
| first_timestamp + AB::F::from_canonical_usize(6), | ||
| &header_row_specific.read_records[6], | ||
| ) | ||
| .eval(builder, header_row); | ||
|
|
||
|
|
@@ -350,16 +346,16 @@ impl<AB: InteractionBuilder> Air<AB> for NativeSumcheckAir { | |
| native_as, | ||
| register_ptrs[0] + AB::F::from_canonical_usize(CONTEXT_ARR_BASE_LEN), | ||
| ), | ||
| [max_round], | ||
| first_timestamp + header_timestamp_diff.next().unwrap(), | ||
| header_read_records_iter.next().unwrap(), | ||
| [max_round, is_hint_src_id, header_row_specific.prod_evals_id, header_row_specific.logup_evals_id], | ||
| first_timestamp + AB::F::from_canonical_usize(7), | ||
| &header_row_specific.read_records[7], | ||
| ) | ||
| .eval(builder, header_row); | ||
|
|
||
| // Write final result | ||
| self.memory_bridge | ||
| .write( | ||
| MemoryAddress::new(native_as, register_ptrs[2]), | ||
| MemoryAddress::new(native_as, register_ptrs[4]), | ||
| eval_acc, | ||
| last_timestamp - AB::F::ONE, | ||
| &header_row_specific.write_records, | ||
|
|
@@ -393,17 +389,33 @@ impl<AB: InteractionBuilder> Air<AB> for NativeSumcheckAir { | |
| ); | ||
| builder.assert_eq(prod_row * should_acc, prod_acc); | ||
|
|
||
| let mut prod_timestamp_diff = (0..1).into_iter().map(|i| AB::F::from_canonical_usize(i)); | ||
|
|
||
| // TODO: read from hint space then write to memory | ||
| // self.memory_bridge | ||
| // .read( | ||
| // MemoryAddress::new(native_as, register_ptrs[2] + prod_row_specific.data_ptr), | ||
| // prod_row_specific.p, | ||
| // start_timestamp, | ||
| // &prod_row_specific.read_records[0], | ||
| // ) | ||
| // .eval(builder, prod_row * within_round_limit); | ||
| // Read p1, p2 from witness arrays | ||
| self.memory_bridge | ||
| .read( | ||
| MemoryAddress::new(native_as, register_ptrs[2] + prod_row_specific.data_ptr), | ||
| prod_row_specific.p, | ||
| start_timestamp, | ||
| &MemoryReadAuxCols { | ||
| base: prod_row_specific.ps_record.base, | ||
| }, | ||
| ) | ||
| .eval( | ||
| builder, | ||
| (prod_in_round_evaluation + prod_next_round_evaluation) * not(is_hint_src_id), | ||
| ); | ||
|
|
||
| // Obtain p1, p2 from hint space and write back to witness arrays | ||
| self.memory_bridge | ||
| .write( | ||
| MemoryAddress::new(native_as, register_ptrs[2] + prod_row_specific.data_ptr), | ||
| prod_row_specific.p, | ||
| start_timestamp, | ||
| &prod_row_specific.ps_record, | ||
| ) | ||
| .eval( | ||
| builder, | ||
| (prod_in_round_evaluation + prod_next_round_evaluation) * is_hint_src_id, | ||
| ); | ||
|
|
||
| let p1: [AB::Var; EXT_DEG] = prod_row_specific.p[0..EXT_DEG].try_into().unwrap(); | ||
| let p2: [AB::Var; EXT_DEG] = prod_row_specific.p[EXT_DEG..(EXT_DEG * 2)] | ||
|
|
@@ -414,16 +426,14 @@ impl<AB: InteractionBuilder> Air<AB> for NativeSumcheckAir { | |
| .write( | ||
| MemoryAddress::new( | ||
| native_as, | ||
| register_ptrs[2] + curr_prod_n * AB::F::from_canonical_usize(EXT_DEG), | ||
| register_ptrs[4] + curr_prod_n * AB::F::from_canonical_usize(EXT_DEG), | ||
| ), | ||
| prod_row_specific.p_evals, | ||
| start_timestamp + prod_timestamp_diff.next().unwrap(), | ||
| start_timestamp + AB::F::ONE, | ||
| &prod_row_specific.write_record, | ||
| ) | ||
| .eval(builder, prod_row * within_round_limit); | ||
|
|
||
| assert!(prod_timestamp_diff.next().is_none()); | ||
|
|
||
| // Calculate evaluations | ||
| let next_round_p_evals = FieldExtension::add( | ||
| FieldExtension::multiply::<AB::Var, AB::Expr>(p1, c1), | ||
|
|
@@ -486,17 +496,33 @@ impl<AB: InteractionBuilder> Air<AB> for NativeSumcheckAir { | |
| ); | ||
| builder.assert_eq(logup_row * should_acc, logup_acc); | ||
|
|
||
| let mut logup_timestamp_diff = (0..2).into_iter().map(|i| AB::F::from_canonical_usize(i)); | ||
|
|
||
| // self.memory_bridge | ||
| // .read( | ||
| // MemoryAddress::new(native_as, register_ptrs[3] + logup_row_specific.data_ptr), | ||
| // logup_row_specific.pq, | ||
| // start_timestamp, | ||
| // &logup_row_specific.read_records[0], | ||
| // ) | ||
| // .eval(builder, logup_row * within_round_limit); | ||
|
|
||
| // Read p1, p2, q1, q2 from witness arrays | ||
| self.memory_bridge | ||
| .read( | ||
| MemoryAddress::new(native_as, register_ptrs[3] + logup_row_specific.data_ptr), | ||
| logup_row_specific.pq, | ||
| start_timestamp, | ||
| &MemoryReadAuxCols { | ||
| base: logup_row_specific.pqs_record.base, | ||
| }, | ||
| ) | ||
| .eval( | ||
| builder, | ||
| (logup_in_round_evaluation + logup_next_round_evaluation) * not(is_hint_src_id), | ||
| ); | ||
|
Comment on lines
500
to
512
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. ditto. |
||
|
|
||
| // Obtain p1, p2, q1, q2 from hint space | ||
| self.memory_bridge | ||
| .write( | ||
| MemoryAddress::new(native_as, register_ptrs[3] + logup_row_specific.data_ptr), | ||
| logup_row_specific.pq, | ||
| start_timestamp, | ||
| &logup_row_specific.pqs_record, | ||
| ) | ||
| .eval( | ||
| builder, | ||
| (logup_in_round_evaluation + logup_next_round_evaluation) * is_hint_src_id, | ||
| ); | ||
| let p1: [_; EXT_DEG] = logup_row_specific.pq[0..EXT_DEG].try_into().unwrap(); | ||
| let p2: [_; EXT_DEG] = logup_row_specific.pq[EXT_DEG..(EXT_DEG * 2)] | ||
| .try_into() | ||
|
|
@@ -513,11 +539,11 @@ impl<AB: InteractionBuilder> Air<AB> for NativeSumcheckAir { | |
| .write( | ||
| MemoryAddress::new( | ||
| native_as, | ||
| register_ptrs[2] | ||
| register_ptrs[4] | ||
| + (num_prod_spec + curr_logup_n) * AB::F::from_canonical_usize(EXT_DEG), | ||
| ), | ||
| logup_row_specific.p_evals, | ||
| start_timestamp + logup_timestamp_diff.next().unwrap(), | ||
| start_timestamp + AB::F::ONE, | ||
| &logup_row_specific.write_records[0], | ||
| ) | ||
| .eval(builder, logup_row * within_round_limit); | ||
|
|
@@ -527,12 +553,12 @@ impl<AB: InteractionBuilder> Air<AB> for NativeSumcheckAir { | |
| .write( | ||
| MemoryAddress::new( | ||
| native_as, | ||
| register_ptrs[2] | ||
| register_ptrs[4] | ||
| + (num_prod_spec + num_logup_spec + curr_logup_n) | ||
| * AB::F::from_canonical_usize(EXT_DEG), | ||
| ), | ||
| logup_row_specific.q_evals, | ||
| start_timestamp + logup_timestamp_diff.next().unwrap(), | ||
| start_timestamp + AB::F::TWO, | ||
| &logup_row_specific.write_records[1], | ||
| ) | ||
| .eval(builder, logup_row * within_round_limit); | ||
|
|
||
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.
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.
opt: we can mimic the memory read behavior by reusing
write_ps_recordwith one additional requirement thatwrite_ps_record.prev_data == prod_row_specific.pif it'snot(is_hint_src_id).