Skip to content

Commit

Permalink
Cleaning the binary component (#182)
Browse files Browse the repository at this point in the history
* Executor and pil done

* Update binary_basic.rs

* name change

* traces update
  • Loading branch information
hecmas authored Dec 11, 2024
1 parent 80192db commit a7b1300
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 35 deletions.
4 changes: 2 additions & 2 deletions pil/src/pil_helpers/traces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ trace!(ArithRangeTableRow, ArithRangeTableTrace<F> {
});

trace!(BinaryRow, BinaryTrace<F> {
m_op: F, mode32: F, free_in_a: [F; 8], free_in_b: [F; 8], free_in_c: [F; 8], carry: [F; 8], use_last_carry: F, op_is_min_max: F, has_initial_carry: F, cout: F, result_is_a: F, use_last_carry_mode32: F, use_last_carry_mode64: F, m_op_or_ext: F, free_in_a_or_c: [F; 4], free_in_b_or_zero: [F; 4], multiplicity: F, main_step: F,
m_op: F, mode32: F, free_in_a: [F; 8], free_in_b: [F; 8], free_in_c: [F; 8], carry: [F; 8], use_last_carry: F, op_is_min_max: F, has_initial_carry: F, cout: F, result_is_a: F, use_last_carry_mode32: F, use_last_carry_mode64: F, m_op_or_ext: F, free_in_a_or_c: [F; 4], free_in_b_or_zero: [F; 4], multiplicity: F, debug_main_step: F,
});

trace!(BinaryTableRow, BinaryTableTrace<F> {
multiplicity: F,
});

trace!(BinaryExtensionRow, BinaryExtensionTrace<F> {
op: F, in1: [F; 8], in2_low: F, out: [[F; 2]; 8], op_is_shift: F, in2: [F; 2], main_step: F, multiplicity: F,
op: F, in1: [F; 8], in2_low: F, out: [[F; 2]; 8], op_is_shift: F, in2: [F; 2], debug_main_step: F, multiplicity: F,
});

trace!(BinaryExtensionTableRow, BinaryExtensionTableTrace<F> {
Expand Down
4 changes: 2 additions & 2 deletions state-machines/binary/pil/binary.pil
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,6 @@ airtemplate Binary(const int N = 2**21, const int operation_bus_id) {
expr op = m_op + 0x20 * mode32;

col witness multiplicity;
col witness main_step;
lookup_proves(OPERATION_BUS_ID, [main_step, op, ...a, ...b, ...c, cout - result_is_a], multiplicity);
col witness debug_main_step;
lookup_proves(OPERATION_BUS_ID, [debug_main_step, op, ...a, ...b, ...c, cout - result_is_a], multiplicity);
}
4 changes: 2 additions & 2 deletions state-machines/binary/pil/binary_extension.pil
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ airtemplate BinaryExtension(const int N = 2**18, const int operation_bus_id) {
expr in1_low = in1[0] + in1[1]*2**8 + in1[2]*2**16 + in1[3]*2**24;
expr in1_high = in1[4] + in1[5]*2**8 + in1[6]*2**16 + in1[7]*2**24;

col witness main_step;
col witness debug_main_step;
col witness multiplicity;
lookup_proves(
operation_bus_id,
[
main_step,
debug_main_step,
op,
op_is_shift * (in1_low - in2[0]) + in2[0],
op_is_shift * (in1_high - in2[1]) + in2[1],
Expand Down
29 changes: 1 addition & 28 deletions state-machines/binary/src/binary_basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ impl<F: Field> BinaryBasicSM<F> {
}

// Set main SM step
row.main_step = F::from_canonical_u64(operation.step);
row.debug_main_step = F::from_canonical_u64(operation.step);

// Set use last carry and carry[], based on operation
let mut cout: u64;
Expand Down Expand Up @@ -928,33 +928,6 @@ impl<F: Field> BinaryBasicSM<F> {
row.free_in_b_or_zero[i] = mode64 * row.free_in_b[i + HALF_BYTES];
}

// Set cout
let cout32 = row.carry[HALF_BYTES - 1];
let cout64 = row.carry[BYTES - 1];
row.cout = mode64 * (cout64 - cout32) + cout32;

// Set result_is_a
row.result_is_a = row.op_is_min_max * row.cout;

// Set use_last_carry_mode32 and use_last_carry_mode64
row.use_last_carry_mode32 = F::from_bool(mode32) * row.use_last_carry;
row.use_last_carry_mode64 = mode64 * row.use_last_carry;

// Set micro opcode
row.m_op = F::from_canonical_u8(binary_basic_table_op as u8);

// Set m_op_or_ext
let ext_32_op = F::from_canonical_u8(BinaryBasicTableOp::Ext32 as u8);
row.m_op_or_ext = mode64 * (row.m_op - ext_32_op) + ext_32_op;

// Set free_in_a_or_c and free_in_b_or_zero
for i in 0..HALF_BYTES {
row.free_in_a_or_c[i] = mode64 *
(row.free_in_a[i + HALF_BYTES] - row.free_in_c[HALF_BYTES - 1]) +
row.free_in_c[HALF_BYTES - 1];
row.free_in_b_or_zero[i] = mode64 * row.free_in_b[i + HALF_BYTES];
}

if row.use_last_carry == F::one() {
// Set first and last elements
row.free_in_c[7] = row.free_in_c[0];
Expand Down
2 changes: 1 addition & 1 deletion state-machines/binary/src/binary_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ impl<F: PrimeField> BinaryExtensionSM<F> {
row.in2[1] = F::from_canonical_u64(in2_1);

// Set main SM step
row.main_step = F::from_canonical_u64(operation.step);
row.debug_main_step = F::from_canonical_u64(operation.step);

// Calculate the trace output
let mut t_out: [[u64; 2]; 8] = [[0; 2]; 8];
Expand Down

0 comments on commit a7b1300

Please sign in to comment.