-
Notifications
You must be signed in to change notification settings - Fork 145
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
Arithmic/word address #412
base: main
Are you sure you want to change the base?
Conversation
* combine four sum check into one
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.
still reviewing, but leaving some initial feedback here
|
||
|
||
//proof.read_write_openings.v_read_ram ; |
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.
nit: delete
fn pad_zeros(vector: &mut Vec<u64>) { | ||
let next_power_of_two_of_length = vector.len().next_power_of_two(); | ||
for _ in vector.len()..next_power_of_two_of_length { | ||
vector.push(0); | ||
} | ||
} |
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.
use resize instead
let input_vector_word: Vec<Vec<u64>> = (0..WORD_BYTES) | ||
.map(|i| word_vector.iter().map(|row| row.bytes[i]).collect()) | ||
.collect(); | ||
|
||
let mut output_array: [Vec<u64>; WORD_BYTES] = Default::default(); | ||
|
||
for (i, row) in input_vector_word.iter().enumerate() { | ||
output_array[i] = row.clone(); | ||
} | ||
|
||
output_array |
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.
I think something like this should work
let input_vector_word: Vec<Vec<u64>> = (0..WORD_BYTES) | |
.map(|i| word_vector.iter().map(|row| row.bytes[i]).collect()) | |
.collect(); | |
let mut output_array: [Vec<u64>; WORD_BYTES] = Default::default(); | |
for (i, row) in input_vector_word.iter().enumerate() { | |
output_array[i] = row.clone(); | |
} | |
output_array | |
std::array::from_fn(|i| word_vector.iter().map(|row| row.bytes[i]).collect()) |
|| map_to_polys(&[t_read_ram.clone()])[0].clone(), | ||
|| map_to_polys(&[t_write_ram])[0].clone(), | ||
|| map_to_polys(&[remainder_vec])[0].clone() |
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.
Similar to how we handle [ a_ram, v_write_rd, v_init_reg, v_final_reg, t_final_reg, t_final_ram ]
above
|| map_to_polys(&[t_read_ram.clone()])[0].clone(), | |
|| map_to_polys(&[t_write_ram])[0].clone(), | |
|| map_to_polys(&[remainder_vec])[0].clone() | |
|| map_to_polys(&[t_read_ram, t_write_ram, remainder_vec]), |
.read_write_memory | ||
.v_final_ram | ||
.iter() | ||
.take(WORD_BYTES) |
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.
unnecessary take
I think
// println!("The length of v_final_reg_commitments is {:?}", commitment.read_write_memory.v_final_reg_commitment; | ||
|
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.
delete
) { | ||
Ok(_) => {} | ||
Err(error) => { | ||
return Err(error); | ||
} | ||
} |
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.
we can just directly return the result of the batch_verify
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.
A few syntax comments.
|
||
// remainder * (remainder - 2) -> remainder02 | ||
let remainder = JoltIn::Remainder; | ||
let remainder_minus_2_term = LC::sum2(JoltIn::Remainder, cs.create_term_with_constant_variable(-2)); |
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.
You can simplify all these now thanks to the implementation of std::ops::{add, mul, sub, neg}
for most of the things that Impl<Into<LC>>
For example: let remainder: LC<JoltIn> = JoltIn::Remainder - 2;
I won't drop comments on all of the lines below but this lets you remove ConstraintSystem::{create_term, create_term_with_constant_variable}
, LC::{sum2, sum3, sum_any}
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.
Also, I think it's more efficient to do 2 - remainder
rather than remainder - 2
(same with remainder - 1
and remainder - 3
)
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.
LC::sub2(JoltIn::RAM_Write_Byte0, JoltIn::LookupOutput),
@moodlezoup Is this the right way to handle the above statement?
let byte0: LC<JoltIn> = JoltIn::RAM_Write_Byte0.into();
let lookup_output: LC<JoltIn> = JoltIn::LookupOutput.into();
byte0 - lookup_output,
// 2^{24}memory_read[3] - combined_z_chunks) ] = 0 | ||
|
||
let read_memory = LC::sum_any(vec![ | ||
cs.create_term(JoltIn::RAM_Read_Byte0, 1), |
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.
For these you can use let term: Term<JoltIn> = JoltIn::RAM_Read_Byte0 * (1<<8);
read2_minus_packed_query, | ||
read3_minus_packed_query.into(), | ||
]); | ||
cs.constrain_prod(JoltIn::OpFlags_IsLb, term0, LC::zero()); |
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.
This and following uses of constrain prod seem to conditionally check that term0 is 0.
I think it would be clearer to use cs.constrain_eq_conditional(JoltIn::OpFlags_X, term, 0)
Note, again you can just inline the 0 term here rather than LC::zero()
because i64 impl Into<LC>
.
cs.create_term(JoltIn::RAM_Write_Byte2, 1 << 16), | ||
cs.create_term(JoltIn::RAM_Write_Byte3, 1 << 24), | ||
]); | ||
cs.constrain_prod( |
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.
We should make a cs.constrain_pack_be_conditional
so the format would look as follows.
cs.constrain_pack_be_conditional(JoltIn::OpFlags_IsSw, input_range!(JoltIn::RAM_Write_Byte0, JoltIn::RAM_Write_Byte3), packed_query, 8)
There's a TODO(sragss)
above to do this. I can add, leave this comment open.
For this constraint: Isn't the first term guaranteed to be zero? For
|
Not sure how we can remove it. |
No description provided.