Skip to content

Commit 802054d

Browse files
Yoichi Hiraisjudson
authored andcommitted
Stop committing to SgnA and SgnB in BltChip (#611)
1 parent 54cebc7 commit 802054d

File tree

1 file changed

+16
-19
lines changed
  • prover/src/chips/instructions

1 file changed

+16
-19
lines changed

prover/src/chips/instructions/blt.rs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
use num_traits::One;
2-
use stwo_prover::{constraint_framework::EvalAtRow, core::fields::FieldExpOps};
2+
use stwo_prover::{
3+
constraint_framework::EvalAtRow,
4+
core::fields::{m31::BaseField, FieldExpOps},
5+
};
36

47
use nexus_vm::{riscv::BuiltinOpcode, WORD_SIZE};
58

@@ -106,8 +109,6 @@ impl MachineChip for BltChip {
106109

107110
traces.fill_columns(row_idx, diff_bytes, Column::Helper1);
108111
traces.fill_columns(row_idx, borrow_bits, Column::BorrowFlag);
109-
traces.fill_columns(row_idx, vm_step.get_sgn_a(), Column::SgnA);
110-
traces.fill_columns(row_idx, vm_step.get_sgn_b(), Column::SgnB);
111112
traces.fill_columns(row_idx, h2, Column::Helper2);
112113
traces.fill_columns(row_idx, h3, Column::Helper3);
113114
traces.fill_columns(row_idx, lt_flag, Column::LtFlag);
@@ -126,7 +127,7 @@ impl MachineChip for BltChip {
126127
_lookup_elements: &AllLookupElements,
127128
) {
128129
let modulus = E::F::from(256u32.into());
129-
let modulus_7 = E::F::from(128u32.into());
130+
let modulus_7_inv = E::F::from(BaseField::from(128u32).inverse());
130131
let value_a = trace_eval!(trace_eval, ValueA);
131132
let value_b = trace_eval!(trace_eval, ValueB);
132133
let value_c = trace_eval!(trace_eval, ValueC);
@@ -140,8 +141,12 @@ impl MachineChip for BltChip {
140141
let [lt_flag] = trace_eval!(trace_eval, Column::LtFlag);
141142
let h2 = trace_eval!(trace_eval, Column::Helper2);
142143
let h3 = trace_eval!(trace_eval, Column::Helper3);
143-
let [sgn_a] = trace_eval!(trace_eval, Column::SgnA);
144-
let [sgn_b] = trace_eval!(trace_eval, Column::SgnB);
144+
// sgn_a is taken to be abbreviation of (a_val_4 - h2) / 2^7
145+
let sgn_a =
146+
(value_a[WORD_SIZE - 1].clone() - h2[WORD_SIZE - 1].clone()) * modulus_7_inv.clone();
147+
// sgn_b is taken to be abbreviation of (b_val_4 - h3) / 2^7
148+
let sgn_b =
149+
(value_b[WORD_SIZE - 1].clone() - h3[WORD_SIZE - 1].clone()) * modulus_7_inv.clone();
145150

146151
// is_blt・(a_val_1 + a_val_2 * 256 - b_val_1 - b_val_2 * 256 - h1_1 - h1_2 * 256 + borrow_1・2^{16}) = 0
147152
eval.add_constraint(
@@ -165,19 +170,6 @@ impl MachineChip for BltChip {
165170
- borrow_bits[0].clone()),
166171
);
167172

168-
// is_blt・ (h2 + sgna・2^7 - a_val_4) = 0
169-
// is_blt・ (h3 + sgnb・2^7 - b_val_4) = 0
170-
eval.add_constraint(
171-
is_blt.clone()
172-
* (h2[WORD_SIZE - 1].clone() + sgn_a.clone() * modulus_7.clone()
173-
- value_a[WORD_SIZE - 1].clone()),
174-
);
175-
eval.add_constraint(
176-
is_blt.clone()
177-
* (h3[WORD_SIZE - 1].clone() + sgn_b.clone() * modulus_7.clone()
178-
- value_b[WORD_SIZE - 1].clone()),
179-
);
180-
181173
// is_blt・ (sgna・(1-sgnb) + ltu_flag・(sgna・sgnb+(1-sgna)・(1-sgnb)) - lt_flag) =0
182174
eval.add_constraint(
183175
is_blt.clone()
@@ -213,6 +205,11 @@ impl MachineChip for BltChip {
213205
- pc_next[2].clone()
214206
- pc_next[3].clone() * modulus.clone()),
215207
);
208+
209+
// sgn_a is 0 or 1
210+
eval.add_constraint(is_blt.clone() * (sgn_a.clone() * (E::F::one() - sgn_a.clone())));
211+
// sgn_b is 0 or 1
212+
eval.add_constraint(is_blt * (sgn_b.clone() * (E::F::one() - sgn_b.clone())));
216213
}
217214
}
218215

0 commit comments

Comments
 (0)