Skip to content
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

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

arithmic-ASHISH
Copy link

No description provided.

Copy link
Collaborator

@moodlezoup moodlezoup left a 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

Comment on lines 378 to 380


//proof.read_write_openings.v_read_ram ;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: delete

common/src/constants.rs Outdated Show resolved Hide resolved
Comment on lines 359 to 364
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);
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use resize instead

Comment on lines 324 to 334
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
Copy link
Collaborator

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

Suggested change
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())

Comment on lines 975 to 977
|| map_to_polys(&[t_read_ram.clone()])[0].clone(),
|| map_to_polys(&[t_write_ram])[0].clone(),
|| map_to_polys(&[remainder_vec])[0].clone()
Copy link
Collaborator

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

Suggested change
|| 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]),

jolt-core/src/jolt/vm/read_write_memory.rs Show resolved Hide resolved
.read_write_memory
.v_final_ram
.iter()
.take(WORD_BYTES)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary take I think

Comment on lines 1414 to 1415
// println!("The length of v_final_reg_commitments is {:?}", commitment.read_write_memory.v_final_reg_commitment;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete

Comment on lines +2200 to +2205
) {
Ok(_) => {}
Err(error) => {
return Err(error);
}
}
Copy link
Collaborator

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

Copy link
Collaborator

@sragss sragss left a 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));
Copy link
Collaborator

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}

Copy link
Collaborator

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)

Copy link
Author

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),
Copy link
Collaborator

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());
Copy link
Collaborator

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(
Copy link
Collaborator

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.

@sragss
Copy link
Collaborator

sragss commented Jul 18, 2024

For this constraint: (LB_flag + LBU_flag + SB_flag) [remainder*(remainder -1)*(remainder -2)*(remainder-3)] + (LH_flag + LHU_flag + SH_flag) [remainder*(remainder -2)] + (LW_flag + SW_flag)*remainder = 0

Isn't the first term guaranteed to be zero? [remainder*(remainder -1)*(remainder -2)*(remainder-3)] == 0 remainder \in {0,1,2,3} If the goal is just to check that remainder is in fact {0,1,2,3} then we can get rid of the flat term out front.

For (LH_flag + LHU_flag + SH_flag) [remainder*(remainder -2)] I believe it would be clearer to structure it as:

let is_half_mem = JoltIn::IF_LH + JoltIn::IF_LHU + JoltIn::IF_SH`;
let remainder_is_0_or_2 = cs.allocate_prod(JoltIn::remainder, JoltIn::remainder - 2);
cs.constrain_eq_conditional(half_mem, remainder_is_0_or_2, 0);

@vineet-n
Copy link

vineet-n commented Jul 29, 2024

For this constraint: (LB_flag + LBU_flag + SB_flag) [remainder*(remainder -1)*(remainder -2)*(remainder-3)] + (LH_flag + LHU_flag + SH_flag) [remainder*(remainder -2)] + (LW_flag + SW_flag)*remainder = 0

Isn't the first term guaranteed to be zero? [remainder*(remainder -1)*(remainder -2)*(remainder-3)] == 0 remainder \in {0,1,2,3} If the goal is just to check that remainder is in fact {0,1,2,3} then we can get rid of the flat term out front.

Not sure how we can remove it.
The first term ensures that the remainder is in {0,1,2,3} when the instruction is LB, LBU, or SB. For example if the instruction is LB and remainder is 5 then constraint is non-zero, and hence an invalid execution. This cannot be captured if we remove this term.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants