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

Fixes for less-than instructions: LT32Chip STARK constraints and handling instructions with second operand immediate #166

Merged
merged 12 commits into from
May 6, 2024
Merged
Prev Previous commit
Next Next commit
refactor: logic to set different_signs
morganthomas committed May 4, 2024
commit 5a4bf94af010f8e4dcf1aa87b5777b201c34661a
28 changes: 18 additions & 10 deletions alu_u32/src/lt/mod.rs
Original file line number Diff line number Diff line change
@@ -96,28 +96,32 @@ impl Lt32Chip {
match op {
Operation::Lt32(a, b, c) => {
cols.is_lt = F::one();
self.set_cols(cols, a, b, c);
cols.different_signs = F::zero();
self.set_cols(cols, false, a, b, c);
}
Operation::Lte32(a, b, c) => {
cols.is_lte = F::one();
self.set_cols(cols, a, b, c);
cols.different_signs = F::zero();
self.set_cols(cols, false, a, b, c);
}
Operation::Slt32(a, b, c) => {
cols.is_slt = F::one();
self.set_cols(cols, a, b, c);
self.set_cols(cols, true, a, b, c);
}
Operation::Sle32(a, b, c) => {
cols.is_sle = F::one();
self.set_cols(cols, a, b, c);
self.set_cols(cols, true, a, b, c);
}
}
row
}

fn set_cols<F>(&self, cols: &mut Lt32Cols<F>, a: &Word<u8>, b: &Word<u8>, c: &Word<u8>)
where
fn set_cols<F>(
&self,
cols: &mut Lt32Cols<F>,
is_signed: bool,
a: &Word<u8>,
b: &Word<u8>,
c: &Word<u8>,
) where
F: PrimeField,
{
// Set the input columns
@@ -148,8 +152,12 @@ impl Lt32Chip {
cols.top_bits_2[i] = F::from_canonical_u8(c[0] >> i & 1);
}
// check if sign bits agree and set different_signs accordingly
cols.different_signs = if cols.top_bits_1[7] != cols.top_bits_2[7] {
F::one()
cols.different_signs = if is_signed {
if cols.top_bits_1[7] != cols.top_bits_2[7] {
F::one()
} else {
F::zero()
}
} else {
F::zero()
};