Skip to content

Commit

Permalink
fixes soundness gap in LT32 chip
Browse files Browse the repository at this point in the history
  • Loading branch information
tess-eract committed May 3, 2024
1 parent a7e8369 commit 7a6d813
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
3 changes: 3 additions & 0 deletions alu_u32/src/lt/columns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ pub struct Lt32Cols<T> {

pub is_lt: T,
pub is_lte: T,

// inverse of input_1[i] - input_2[i] where i is the first byte that differs
pub diff_inv: T,
}

pub const NUM_LT_COLS: usize = size_of::<Lt32Cols<u8>>();
Expand Down
9 changes: 6 additions & 3 deletions alu_u32/src/lt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ impl Lt32Chip {
F: PrimeField,
{
// Set the input columns
debug_assert_eq!(a.0.len(), 4);
debug_assert_eq!(b.0.len(), 4);
debug_assert_eq!(c.0.len(), 4);
cols.input_1 = b.transform(F::from_canonical_u8);
cols.input_2 = c.transform(F::from_canonical_u8);
cols.output = F::from_canonical_u8(a[3]);
Expand All @@ -133,9 +136,9 @@ impl Lt32Chip {
for i in 0..10 {
cols.bits[i] = F::from_canonical_u16(z >> i & 1);
}
if n < 4 {
cols.byte_flag[n] = F::one();
}
cols.byte_flag[n] = F::one();
// b[n] != c[n] always here, so the difference is never zero.
cols.diff_inv = (cols.input_1[n] - cols.input_2[n]).inverse();
}
cols.multiplicity = F::one();
}
Expand Down
5 changes: 5 additions & 0 deletions alu_u32/src/lt/stark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ where
AB::Expr::from_canonical_u32(256) + local.input_1[i] - local.input_2[i],
bit_comp.clone(),
);
// ensure that when the n-th byte flag is set, the n-th bytes are actually different
builder.when(local.byte_flag[i]).assert_eq(
(local.input_1[i] - local.input_2[i]) * local.diff_inv,
AB::Expr::one(),
);
builder.assert_bool(local.byte_flag[i]);
}

Expand Down

0 comments on commit 7a6d813

Please sign in to comment.