Skip to content

Commit

Permalink
Sprinkle in from_u64 in more places
Browse files Browse the repository at this point in the history
  • Loading branch information
moodlezoup committed Feb 24, 2024
1 parent 2af6a5a commit b6bbf51
Show file tree
Hide file tree
Showing 20 changed files with 240 additions and 166 deletions.
4 changes: 2 additions & 2 deletions jolt-core/src/jolt/subtable/and.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl<F: PrimeField> LassoSubtable<F> for AndSubtable<F> {
// Materialize table entries in order where (x | y) ranges 0..M
for idx in 0..M {
let (x, y) = split_bits(idx, bits_per_operand);
let row = F::from((x & y) as u64);
let row = F::from_u64((x & y) as u64).unwrap();
entries.push(row);
}
entries
Expand All @@ -42,7 +42,7 @@ impl<F: PrimeField> LassoSubtable<F> for AndSubtable<F> {
for i in 0..b {
let x = x[b - i - 1];
let y = y[b - i - 1];
result += F::from(1u64 << i) * x * y;
result += F::from_u64(1u64 << i).unwrap() * x * y;
}
result
}
Expand Down
4 changes: 2 additions & 2 deletions jolt-core/src/jolt/subtable/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ impl<F: PrimeField> IdentitySubtable<F> {

impl<F: PrimeField> LassoSubtable<F> for IdentitySubtable<F> {
fn materialize(&self, M: usize) -> Vec<F> {
(0..M).map(|i| F::from(i as u64)).collect()
(0..M).map(|i| F::from_u64(i as u64).unwrap()).collect()
}

fn evaluate_mle(&self, point: &[F]) -> F {
let mut result = F::zero();
for i in 0..point.len() {
result += F::from(1u64 << i) * point[point.len() - 1 - i];
result += F::from_u64(1u64 << i).unwrap() * point[point.len() - 1 - i];
}
result
}
Expand Down
2 changes: 1 addition & 1 deletion jolt-core/src/jolt/subtable/lt_abs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl<F: PrimeField> LassoSubtable<F> for LtAbsSubtable<F> {
// Skip i=0
for i in 1..b {
result += (F::one() - x[i]) * y[i] * eq_term;
eq_term *= F::one() - x[i] - y[i] + F::from(2u64) * x[i] * y[i];
eq_term *= F::one() - x[i] - y[i] + F::from_u64(2u64).unwrap() * x[i] * y[i];
}
result
}
Expand Down
2 changes: 1 addition & 1 deletion jolt-core/src/jolt/subtable/ltu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl<F: PrimeField> LassoSubtable<F> for LtuSubtable<F> {
let mut eq_term = F::one();
for i in 0..b {
result += (F::one() - x[i]) * y[i] * eq_term;
eq_term *= F::one() - x[i] - y[i] + F::from(2u64) * x[i] * y[i];
eq_term *= F::one() - x[i] - y[i] + F::from_u64(2u64).unwrap() * x[i] * y[i];
}
result
}
Expand Down
4 changes: 2 additions & 2 deletions jolt-core/src/jolt/subtable/or.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl<F: PrimeField> LassoSubtable<F> for OrSubtable<F> {
// Materialize table entries in order where (x | y) ranges 0..M
for idx in 0..M {
let (x, y) = split_bits(idx, bits_per_operand);
let row = F::from((x | y) as u64);
let row = F::from_u64((x | y) as u64).unwrap();
entries.push(row);
}
entries
Expand All @@ -42,7 +42,7 @@ impl<F: PrimeField> LassoSubtable<F> for OrSubtable<F> {
for i in 0..b {
let x = x[b - i - 1];
let y = y[b - i - 1];
result += F::from(1u64 << i) * (x + y - x * y);
result += F::from_u64(1u64 << i).unwrap() * (x + y - x * y);
}
result
}
Expand Down
6 changes: 3 additions & 3 deletions jolt-core/src/jolt/subtable/sll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl<F: PrimeField, const CHUNK_INDEX: usize, const WORD_SIZE: usize> LassoSubta
.checked_shr(suffix_length as u32)
.unwrap_or(0);

entries.push(F::from(row as u64));
entries.push(F::from_u64(row as u64).unwrap());
}
entries
}
Expand All @@ -64,7 +64,7 @@ impl<F: PrimeField, const CHUNK_INDEX: usize, const WORD_SIZE: usize> LassoSubta
let k_bits = (k as usize)
.get_bits(log_WORD_SIZE)
.iter()
.map(|bit| F::from(*bit as u64))
.map(|bit| F::from_u64(*bit as u64).unwrap())
.collect::<Vec<F>>(); // big-endian

let mut eq_term = F::one();
Expand All @@ -84,7 +84,7 @@ impl<F: PrimeField, const CHUNK_INDEX: usize, const WORD_SIZE: usize> LassoSubta

let shift_x_by_k = (0..m_prime)
.enumerate()
.map(|(j, _)| F::from(1_u64 << (j + k)) * x[b - 1 - j])
.map(|(j, _)| F::from_u64(1_u64 << (j + k)).unwrap() * x[b - 1 - j])
.fold(F::zero(), |acc, val| acc + val);

result += eq_term * shift_x_by_k;
Expand Down
10 changes: 5 additions & 5 deletions jolt-core/src/jolt/subtable/sra_sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ impl<F: PrimeField, const WORD_SIZE: usize> LassoSubtable<F> for SraSignSubtable
for idx in 0..M {
let (x, y) = split_bits(idx, operand_chunk_width);

let x_sign = F::from(((x >> sign_bit_index) & 1) as u64);
let x_sign = F::from_u64(((x >> sign_bit_index) & 1) as u64).unwrap();

let row = (0..(y % WORD_SIZE) as u32)
.into_iter()
.fold(F::zero(), |acc, i: u32| {
acc + F::from(1_u64 << (WORD_SIZE as u32 - 1 - i)) * x_sign
acc + F::from_u64(1_u64 << (WORD_SIZE as u32 - 1 - i)).unwrap() * x_sign
});

entries.push(F::from(row));
entries.push(row);
}
entries
}
Expand All @@ -64,7 +64,7 @@ impl<F: PrimeField, const WORD_SIZE: usize> LassoSubtable<F> for SraSignSubtable
let k_bits = (k as usize)
.get_bits(log_WORD_SIZE)
.iter()
.map(|bit| F::from(*bit as u64))
.map(|bit| F::from(*bit))
.collect::<Vec<F>>(); // big-endian

let mut eq_term = F::one();
Expand All @@ -75,7 +75,7 @@ impl<F: PrimeField, const WORD_SIZE: usize> LassoSubtable<F> for SraSignSubtable
}

let x_sign_upper = (0..k).into_iter().fold(F::zero(), |acc, i| {
acc + F::from(1_u64 << (WORD_SIZE - 1 - i)) * x_sign
acc + F::from_u64(1_u64 << (WORD_SIZE - 1 - i)).unwrap() * x_sign
});

result += eq_term * x_sign_upper;
Expand Down
8 changes: 5 additions & 3 deletions jolt-core/src/jolt/subtable/srl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl<F: PrimeField, const CHUNK_INDEX: usize, const WORD_SIZE: usize> LassoSubta
.checked_shr((y % WORD_SIZE) as u32)
.unwrap_or(0);

entries.push(F::from(row as u64));
entries.push(F::from_u64(row as u64).unwrap());
}
entries
}
Expand All @@ -61,7 +61,7 @@ impl<F: PrimeField, const CHUNK_INDEX: usize, const WORD_SIZE: usize> LassoSubta
let k_bits = (k as usize)
.get_bits(log_WORD_SIZE)
.iter()
.map(|bit| F::from(*bit as u64))
.map(|bit| F::from(*bit))
.collect::<Vec<F>>(); // big-endian

let mut eq_term = F::one();
Expand All @@ -86,7 +86,9 @@ impl<F: PrimeField, const CHUNK_INDEX: usize, const WORD_SIZE: usize> LassoSubta

let shift_x_by_k = (m..chunk_length)
.enumerate()
.map(|(_, j)| F::from(1_u64 << (b * CHUNK_INDEX + j - k)) * x[b - 1 - j])
.map(|(_, j)| {
F::from_u64(1_u64 << (b * CHUNK_INDEX + j - k)).unwrap() * x[b - 1 - j]
})
.fold(F::zero(), |acc, val: F| acc + val);

result += eq_term * shift_x_by_k;
Expand Down
4 changes: 2 additions & 2 deletions jolt-core/src/jolt/subtable/truncate_overflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl<F: PrimeField, const WORD_SIZE: usize> LassoSubtable<F>
let mut entries: Vec<F> = Vec::with_capacity(M);
for idx in 0..M {
let (_, lower_bits) = split_bits(idx, cutoff);
let row = F::from(lower_bits as u64);
let row = F::from_u64(lower_bits as u64).unwrap();
entries.push(row);
}
entries
Expand All @@ -43,7 +43,7 @@ impl<F: PrimeField, const WORD_SIZE: usize> LassoSubtable<F>

let mut result = F::zero();
for i in 0..cutoff {
result += F::from(1u64 << i) * point[point.len() - 1 - i];
result += F::from_u64(1u64 << i).unwrap() * point[point.len() - 1 - i];
}
result
}
Expand Down
4 changes: 2 additions & 2 deletions jolt-core/src/jolt/subtable/xor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl<F: PrimeField> LassoSubtable<F> for XorSubtable<F> {
// Materialize table entries in order where (x | y) ranges 0..M
for idx in 0..M {
let (x, y) = split_bits(idx, bits_per_operand);
let row = F::from((x ^ y) as u64);
let row = F::from_u64((x ^ y) as u64).unwrap();
entries.push(row);
}
entries
Expand All @@ -42,7 +42,7 @@ impl<F: PrimeField> LassoSubtable<F> for XorSubtable<F> {
for i in 0..b {
let x = x[b - i - 1];
let y = y[b - i - 1];
result += F::from(1u64 << i) * ((F::one() - x) * y + x * (F::one() - y));
result += F::from_u64(1u64 << i).unwrap() * ((F::one() - x) * y + x * (F::one() - y));
}
result
}
Expand Down
6 changes: 4 additions & 2 deletions jolt-core/src/jolt/subtable/zero_lsb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ impl<F: PrimeField> ZeroLSBSubtable<F> {
impl<F: PrimeField> LassoSubtable<F> for ZeroLSBSubtable<F> {
fn materialize(&self, M: usize) -> Vec<F> {
// always set LSB to 0
(0..M).map(|i| F::from((i - (i % 2)) as u64)).collect()
(0..M)
.map(|i| F::from_u64((i - (i % 2)) as u64).unwrap())
.collect()
}

fn evaluate_mle(&self, point: &[F]) -> F {
let mut result = F::zero();
// skip LSB
for i in 1..point.len() {
result += F::from(1u64 << i) * point[point.len() - 1 - i];
result += F::from_u64(1u64 << i).unwrap() * point[point.len() - 1 - i];
}
result
}
Expand Down
Loading

0 comments on commit b6bbf51

Please sign in to comment.