diff --git a/constraint-evaluation-generator/src/constraints.rs b/constraint-evaluation-generator/src/constraints.rs index 2ad6da65..9c5c5fb8 100644 --- a/constraint-evaluation-generator/src/constraints.rs +++ b/constraint-evaluation-generator/src/constraints.rs @@ -219,10 +219,8 @@ impl Constraints { #[cfg(test)] pub(crate) mod tests { use twenty_first::bfe; - use twenty_first::xfe; use triton_vm::prelude::BFieldElement; - use triton_vm::prelude::XFieldElement; use triton_vm::table::challenges::ChallengeId; use triton_vm::table::constraint_circuit::DualRowIndicator; @@ -232,7 +230,7 @@ pub(crate) mod tests { pub(crate) fn mini_constraints() -> Self { let circuit_builder = ConstraintCircuitBuilder::new(); let challenge = |c| circuit_builder.challenge(c); - let constant = |c: u32| circuit_builder.b_constant(bfe!(c)); + let constant = |c: u32| circuit_builder.b_constant(c); let base_row = |i| circuit_builder.input(SingleRowIndicator::BaseRow(i)); let ext_row = |i| circuit_builder.input(SingleRowIndicator::ExtRow(i)); @@ -275,7 +273,7 @@ pub(crate) mod tests { fn small_transition_constraints() -> Vec> { let circuit_builder = ConstraintCircuitBuilder::new(); let challenge = |c| circuit_builder.challenge(c); - let constant = |c: u32| circuit_builder.x_constant(xfe!(c)); + let constant = |c: u32| circuit_builder.x_constant(c); let curr_base_row = |col| circuit_builder.input(DualRowIndicator::CurrentBaseRow(col)); let next_base_row = |col| circuit_builder.input(DualRowIndicator::NextBaseRow(col)); diff --git a/triton-vm/src/table/cascade_table.rs b/triton-vm/src/table/cascade_table.rs index 3cb4cba7..3a61ce84 100644 --- a/triton-vm/src/table/cascade_table.rs +++ b/triton-vm/src/table/cascade_table.rs @@ -138,9 +138,9 @@ impl ExtCascadeTable { }; let challenge = |challenge_id: ChallengeId| circuit_builder.challenge(challenge_id); - let one = circuit_builder.b_constant(b_field_element::BFIELD_ONE); - let two = circuit_builder.b_constant(bfe!(2)); - let two_pow_8 = circuit_builder.b_constant(bfe!(1 << 8)); + let one = || circuit_builder.b_constant(1); + let two = || circuit_builder.b_constant(2); + let two_pow_8 = circuit_builder.b_constant(1 << 8); let lookup_arg_default_initial = circuit_builder.x_constant(LookupArg::default_initial()); let is_padding = base_row(IsPadding); @@ -170,7 +170,7 @@ impl ExtCascadeTable { - lookup_arg_default_initial.clone()) * (hash_indeterminate - compressed_row_hash) - lookup_multiplicity; - let hash_table_log_derivative_is_initialized_correctly = (one.clone() - is_padding.clone()) + let hash_table_log_derivative_is_initialized_correctly = (one() - is_padding.clone()) * hash_table_log_derivative_has_accumulated_first_row + is_padding.clone() * hash_table_log_derivative_is_default_initial; @@ -185,10 +185,10 @@ impl ExtCascadeTable { (lookup_table_client_log_derivative - lookup_arg_default_initial) * (lookup_indeterminate.clone() - compressed_row_lo.clone()) * (lookup_indeterminate.clone() - compressed_row_hi.clone()) - - two * lookup_indeterminate + - two() * lookup_indeterminate + compressed_row_lo + compressed_row_hi; - let lookup_table_log_derivative_is_initialized_correctly = (one - is_padding.clone()) + let lookup_table_log_derivative_is_initialized_correctly = (one() - is_padding.clone()) * lookup_table_log_derivative_has_accumulated_first_row + is_padding * lookup_table_log_derivative_is_default_initial; @@ -205,7 +205,7 @@ impl ExtCascadeTable { circuit_builder.input(BaseRow(col_id.master_base_table_index())) }; - let one = circuit_builder.b_constant(b_field_element::BFIELD_ONE); + let one = circuit_builder.b_constant(1); let is_padding = base_row(IsPadding); let is_padding_is_0_or_1 = is_padding.clone() * (one - is_padding); @@ -216,7 +216,7 @@ impl ExtCascadeTable { circuit_builder: &ConstraintCircuitBuilder, ) -> Vec> { let challenge = |c| circuit_builder.challenge(c); - let constant = |c: u64| circuit_builder.b_constant(c.into()); + let constant = |c: u64| circuit_builder.b_constant(c); let current_base_row = |column_idx: CascadeBaseTableColumn| { circuit_builder.input(CurrentBaseRow(column_idx.master_base_table_index())) diff --git a/triton-vm/src/table/constraint_circuit.rs b/triton-vm/src/table/constraint_circuit.rs index f4ee2b9e..2e2271aa 100644 --- a/triton-vm/src/table/constraint_circuit.rs +++ b/triton-vm/src/table/constraint_circuit.rs @@ -954,27 +954,33 @@ impl ConstraintCircuitBuilder { /// The unique monad representing the constant value 0. pub fn zero(&self) -> ConstraintCircuitMonad { - self.b_constant(bfe!(0)) + self.b_constant(0) } /// The unique monad representing the constant value 1. pub fn one(&self) -> ConstraintCircuitMonad { - self.b_constant(bfe!(1)) + self.b_constant(1) } /// The unique monad representing the constant value -1. pub fn minus_one(&self) -> ConstraintCircuitMonad { - self.b_constant(bfe!(-1)) + self.b_constant(-1) } - /// Create constant leaf node. - pub fn x_constant(&self, xfe: XFieldElement) -> ConstraintCircuitMonad { - self.make_leaf(XConstant(xfe)) + /// Leaf node with constant over the [base field][BFieldElement]. + pub fn b_constant(&self, bfe: B) -> ConstraintCircuitMonad + where + B: Into, + { + self.make_leaf(BConstant(bfe.into())) } - /// Create constant leaf node. - pub fn b_constant(&self, bfe: BFieldElement) -> ConstraintCircuitMonad { - self.make_leaf(BConstant(bfe)) + /// Leaf node with constant over the [extension field][XFieldElement]. + pub fn x_constant(&self, xfe: X) -> ConstraintCircuitMonad + where + X: Into, + { + self.make_leaf(XConstant(xfe.into())) } /// Create deterministic input leaf node. @@ -1096,13 +1102,13 @@ mod tests { 5..=9 => circuit_builder.input(DualRowIndicator::NextBaseRow(base_col_index)), 10..=14 => circuit_builder.input(DualRowIndicator::CurrentExtRow(ext_col_index)), 15..=19 => circuit_builder.input(DualRowIndicator::NextExtRow(ext_col_index)), - 20..=24 => circuit_builder.b_constant(rng.gen()), - 25..=29 => circuit_builder.x_constant(rng.gen()), + 20..=24 => circuit_builder.b_constant(rng.gen::()), + 25..=29 => circuit_builder.x_constant(rng.gen::()), 30..=34 => circuit_builder.challenge(random_challenge_id()), - 35 => circuit_builder.b_constant(bfe!(0)), - 36 => circuit_builder.x_constant(xfe!(0)), - 37 => circuit_builder.b_constant(bfe!(1)), - 38 => circuit_builder.x_constant(xfe!(1)), + 35 => circuit_builder.b_constant(0), + 36 => circuit_builder.x_constant(0), + 37 => circuit_builder.b_constant(1), + 38 => circuit_builder.x_constant(1), _ => unreachable!(), } } @@ -1147,7 +1153,7 @@ mod tests { let hash0 = hasher0.finish(); assert_eq!(circuit, circuit); - let zero = circuit.builder.x_constant(0.into()); + let zero = circuit.builder.x_constant(0); let same_circuit = circuit.clone() + zero; let mut hasher1 = DefaultHasher::new(); same_circuit.hash(&mut hasher1); @@ -1204,9 +1210,9 @@ mod tests { ConstraintCircuitBuilder::new(); let var_0 = circuit_builder.input(DualRowIndicator::CurrentBaseRow(0)); let var_4 = circuit_builder.input(DualRowIndicator::NextBaseRow(4)); - let four = circuit_builder.x_constant(4.into()); - let one = circuit_builder.x_constant(1.into()); - let zero = circuit_builder.x_constant(0.into()); + let four = circuit_builder.x_constant(4); + let one = circuit_builder.x_constant(1); + let zero = circuit_builder.x_constant(0); assert_ne!(var_0, var_4); assert_ne!(var_0, four); @@ -1267,8 +1273,8 @@ mod tests { fn constant_folding_pbt() { for _ in 0..200 { let circuit = random_circuit(); - let one = circuit.builder.x_constant(1.into()); - let zero = circuit.builder.x_constant(0.into()); + let one = circuit.builder.x_constant(1); + let zero = circuit.builder.x_constant(0); // Verify that constant folding can handle a = a * 1 let copy_0 = deep_copy(&circuit.circuit.borrow()); @@ -1580,7 +1586,7 @@ mod tests { let builder = ConstraintCircuitBuilder::new(); let x = |i| builder.input(BaseRow(i)); let y = |i| builder.input(ExtRow(i)); - let b_con = |i: u64| builder.b_constant(i.into()); + let b_con = |i: u64| builder.b_constant(i); let constraint_0 = x(0) * x(0) * (x(1) - x(2)) - x(0) * x(2) - b_con(42); let constraint_1 = x(1) * (x(1) - b_con(5)) * x(2) * (x(2) - b_con(1)); @@ -2134,7 +2140,7 @@ mod tests { let builder = ConstraintCircuitBuilder::new(); let x = |i| builder.input(BaseRow(i)); - let b_con = |i: u64| builder.b_constant(i.into()); + let b_con = |i: u64| builder.b_constant(i); let sub_tree_0 = x(0) * x(1) * (x(2) - b_con(1)) * x(3) * x(4); let sub_tree_1 = x(0) * x(1) * (x(2) - b_con(1)) * x(3) * x(5); diff --git a/triton-vm/src/table/hash_table.rs b/triton-vm/src/table/hash_table.rs index eb99a98c..50fd5888 100644 --- a/triton-vm/src/table/hash_table.rs +++ b/triton-vm/src/table/hash_table.rs @@ -147,7 +147,7 @@ impl ExtHashTable { mid_low: ConstraintCircuitMonad, lowest: ConstraintCircuitMonad, ) -> ConstraintCircuitMonad { - let constant = |c: u64| circuit_builder.b_constant(c.into()); + let constant = |c: u64| circuit_builder.b_constant(c); let montgomery_modulus_inv = circuit_builder.b_constant(MONTGOMERY_MODULUS.inverse()); let sum_of_shifted_limbs = highest * constant(1 << 48) @@ -161,7 +161,7 @@ impl ExtHashTable { circuit_builder: &ConstraintCircuitBuilder, ) -> Vec> { let challenge = |c| circuit_builder.challenge(c); - let constant = |c: u64| circuit_builder.b_constant(c.into()); + let constant = |c: u64| circuit_builder.b_constant(c); let base_row = |column: HashBaseTableColumn| { circuit_builder.input(BaseRow(column.master_base_table_index())) @@ -338,7 +338,7 @@ impl ExtHashTable { round_number_to_deselect <= NUM_ROUNDS, "Round number must be in [0, {NUM_ROUNDS}] but got {round_number_to_deselect}." ); - let constant = |c: u64| circuit_builder.b_constant(c.into()); + let constant = |c: u64| circuit_builder.b_constant(c); // To not subtract zero from the first factor: some special casing. let first_factor = match round_number_to_deselect { @@ -358,7 +358,7 @@ impl ExtHashTable { mode_circuit_node: &ConstraintCircuitMonad, mode_to_select: HashTableMode, ) -> ConstraintCircuitMonad { - mode_circuit_node.clone() - circuit_builder.b_constant(mode_to_select.into()) + mode_circuit_node.clone() - circuit_builder.b_constant(mode_to_select) } /// A constraint circuit evaluating to zero if and only if the given `mode_circuit_node` is @@ -368,7 +368,7 @@ impl ExtHashTable { mode_circuit_node: &ConstraintCircuitMonad, mode_to_deselect: HashTableMode, ) -> ConstraintCircuitMonad { - let constant = |c: u64| circuit_builder.b_constant(c.into()); + let constant = |c: u64| circuit_builder.b_constant(c); HashTableMode::iter() .filter(|&mode| mode != mode_to_deselect) .map(|mode| mode_circuit_node.clone() - constant(mode.into())) @@ -380,7 +380,7 @@ impl ExtHashTable { current_instruction_node: &ConstraintCircuitMonad, instruction_to_deselect: Instruction, ) -> ConstraintCircuitMonad { - let constant = |c: u64| circuit_builder.b_constant(c.into()); + let constant = |c: u64| circuit_builder.b_constant(c); let opcode = |instruction: Instruction| circuit_builder.b_constant(instruction.opcode_b()); let relevant_instructions = [Hash, SpongeInit, SpongeAbsorb, SpongeSqueeze]; assert!(relevant_instructions.contains(&instruction_to_deselect)); @@ -396,7 +396,7 @@ impl ExtHashTable { circuit_builder: &ConstraintCircuitBuilder, ) -> Vec> { let opcode = |instruction: Instruction| circuit_builder.b_constant(instruction.opcode_b()); - let constant = |c: u64| circuit_builder.b_constant(c.into()); + let constant = |c: u64| circuit_builder.b_constant(c); let base_row = |column_id: HashBaseTableColumn| { circuit_builder.input(BaseRow(column_id.master_base_table_index())) }; @@ -617,7 +617,7 @@ impl ExtHashTable { ) -> Vec> { let challenge = |c| circuit_builder.challenge(c); let opcode = |instruction: Instruction| circuit_builder.b_constant(instruction.opcode_b()); - let constant = |c: u64| circuit_builder.b_constant(c.into()); + let constant = |c: u64| circuit_builder.b_constant(c); let opcode_hash = opcode(Hash); let opcode_sponge_init = opcode(SpongeInit); @@ -1070,7 +1070,7 @@ impl ExtHashTable { [ConstraintCircuitMonad; STATE_SIZE], [ConstraintCircuitMonad; STATE_SIZE], ) { - let constant = |c: u64| circuit_builder.b_constant(c.into()); + let constant = |c: u64| circuit_builder.b_constant(c); let b_constant = |c| circuit_builder.b_constant(c); let current_base_row = |column_idx: HashBaseTableColumn| { circuit_builder.input(CurrentBaseRow(column_idx.master_base_table_index())) @@ -1221,7 +1221,7 @@ impl ExtHashTable { ) -> ConstraintCircuitMonad { let challenge = |c| circuit_builder.challenge(c); let opcode = |instruction: Instruction| circuit_builder.b_constant(instruction.opcode_b()); - let constant = |c: u32| circuit_builder.b_constant(c.into()); + let constant = |c: u32| circuit_builder.b_constant(c); let next_base_row = |column_idx: HashBaseTableColumn| { circuit_builder.input(NextBaseRow(column_idx.master_base_table_index())) }; @@ -1271,7 +1271,7 @@ impl ExtHashTable { ) -> Vec> { let challenge = |c| circuit_builder.challenge(c); let opcode = |instruction: Instruction| circuit_builder.b_constant(instruction.opcode_b()); - let constant = |c: u64| circuit_builder.b_constant(c.into()); + let constant = |c: u64| circuit_builder.b_constant(c); let base_row = |column_idx: HashBaseTableColumn| { circuit_builder.input(BaseRow(column_idx.master_base_table_index())) }; diff --git a/triton-vm/src/table/jump_stack_table.rs b/triton-vm/src/table/jump_stack_table.rs index d8aa37d1..1acaf3cf 100644 --- a/triton-vm/src/table/jump_stack_table.rs +++ b/triton-vm/src/table/jump_stack_table.rs @@ -73,7 +73,7 @@ impl ExtJumpStackTable { pub fn transition_constraints( circuit_builder: &ConstraintCircuitBuilder, ) -> Vec> { - let one = circuit_builder.b_constant(1u32.into()); + let one = || circuit_builder.b_constant(1); let call_opcode = circuit_builder.b_constant(Instruction::Call(BFieldElement::default()).opcode_b()); let return_opcode = circuit_builder.b_constant(Instruction::Return.opcode_b()); @@ -104,13 +104,13 @@ impl ExtJumpStackTable { // 1. The jump stack pointer jsp increases by 1 // or the jump stack pointer jsp does not change let jsp_inc_or_stays = - (jsp_next.clone() - jsp.clone() - one.clone()) * (jsp_next.clone() - jsp.clone()); + (jsp_next.clone() - jsp.clone() - one()) * (jsp_next.clone() - jsp.clone()); // 2. The jump stack pointer jsp increases by 1 // or current instruction ci is return // or the jump stack origin jso does not change let jsp_inc_by_one_or_ci_is_return = - (jsp_next.clone() - jsp.clone() - one.clone()) * (ci.clone() - return_opcode.clone()); + (jsp_next.clone() - jsp.clone() - one()) * (ci.clone() - return_opcode.clone()); let jsp_inc_or_jso_stays_or_ci_is_ret = jsp_inc_by_one_or_ci_is_return.clone() * (jso_next.clone() - jso); @@ -124,11 +124,10 @@ impl ExtJumpStackTable { // or the cycle count clk increases by 1 // or current instruction ci is call // or current instruction ci is return - let jsp_inc_or_clk_inc_or_ci_call_or_ci_ret = - (jsp_next.clone() - jsp.clone() - one.clone()) - * (clk_next.clone() - clk.clone() - one.clone()) - * (ci.clone() - call_opcode) - * (ci - return_opcode); + let jsp_inc_or_clk_inc_or_ci_call_or_ci_ret = (jsp_next.clone() - jsp.clone() - one()) + * (clk_next.clone() - clk.clone() - one()) + * (ci.clone() - call_opcode) + * (ci - return_opcode); // The running product for the permutation argument `rppa` accumulates one row in each // row, relative to weights `a`, `b`, `c`, `d`, `e`, and indeterminate `α`. @@ -152,8 +151,8 @@ impl ExtJumpStackTable { let log_derivative_accumulates = (clock_jump_diff_log_derivative_next - clock_jump_diff_log_derivative) * (circuit_builder.challenge(ClockJumpDifferenceLookupIndeterminate) - clk_diff) - - one.clone(); - let log_derivative_updates_correctly = (jsp_next.clone() - jsp.clone() - one) + - one(); + let log_derivative_updates_correctly = (jsp_next.clone() - jsp.clone() - one()) * log_derivative_accumulates + (jsp_next - jsp) * log_derivative_remains; diff --git a/triton-vm/src/table/lookup_table.rs b/triton-vm/src/table/lookup_table.rs index b3653caa..686b2913 100644 --- a/triton-vm/src/table/lookup_table.rs +++ b/triton-vm/src/table/lookup_table.rs @@ -166,7 +166,7 @@ impl ExtLookupTable { pub fn consistency_constraints( circuit_builder: &ConstraintCircuitBuilder, ) -> Vec> { - let constant = |c: u64| circuit_builder.b_constant(c.into()); + let constant = |c: u64| circuit_builder.b_constant(c); let base_row = |col_id: LookupBaseTableColumn| { circuit_builder.input(BaseRow(col_id.master_base_table_index())) }; @@ -179,7 +179,7 @@ impl ExtLookupTable { pub fn transition_constraints( circuit_builder: &ConstraintCircuitBuilder, ) -> Vec> { - let one = circuit_builder.b_constant(b_field_element::BFIELD_ONE); + let one = || circuit_builder.b_constant(1); let current_base_row = |col_id: LookupBaseTableColumn| { circuit_builder.input(CurrentBaseRow(col_id.master_base_table_index())) @@ -211,14 +211,13 @@ impl ExtLookupTable { // Padding section is contiguous: if the current row is a padding row, then the next row // is also a padding row. let if_current_row_is_padding_row_then_next_row_is_padding_row = - is_padding * (one.clone() - is_padding_next.clone()); + is_padding * (one() - is_padding_next.clone()); // Lookup Table's input increments by 1 if and only if the next row is not a padding row let if_next_row_is_padding_row_then_lookup_input_next_is_0 = is_padding_next.clone() * lookup_input_next.clone(); - let if_next_row_is_not_padding_row_then_lookup_input_next_increments_by_1 = (one.clone() - - is_padding_next.clone()) - * (lookup_input_next.clone() - lookup_input - one.clone()); + let if_next_row_is_not_padding_row_then_lookup_input_next_increments_by_1 = + (one() - is_padding_next.clone()) * (lookup_input_next.clone() - lookup_input - one()); let lookup_input_increments_if_and_only_if_next_row_is_not_padding_row = if_next_row_is_padding_row_then_lookup_input_next_is_0 + if_next_row_is_not_padding_row_then_lookup_input_next_increments_by_1; @@ -234,7 +233,7 @@ impl ExtLookupTable { * (cascade_table_indeterminate - compressed_row) - lookup_multiplicity_next; let cascade_table_log_derivative_updates_if_and_only_if_next_row_is_not_padding_row = - (one.clone() - is_padding_next.clone()) * cascade_table_log_derivative_updates + (one() - is_padding_next.clone()) * cascade_table_log_derivative_updates + is_padding_next.clone() * cascade_table_log_derivative_remains; // public Evaluation Argument @@ -245,7 +244,7 @@ impl ExtLookupTable { - public_evaluation_argument * public_indeterminate - lookup_output_next; let public_evaluation_argument_updates_if_and_only_if_next_row_is_not_padding_row = - (one - is_padding_next.clone()) * public_evaluation_argument_updates + (one() - is_padding_next.clone()) * public_evaluation_argument_updates + is_padding_next * public_evaluation_argument_remains; vec![ diff --git a/triton-vm/src/table/processor_table.rs b/triton-vm/src/table/processor_table.rs index 41eca22d..3e070446 100644 --- a/triton-vm/src/table/processor_table.rs +++ b/triton-vm/src/table/processor_table.rs @@ -492,7 +492,7 @@ impl ExtProcessorTable { pub fn initial_constraints( circuit_builder: &ConstraintCircuitBuilder, ) -> Vec> { - let constant = |c: u32| circuit_builder.b_constant(c.into()); + let constant = |c: u32| circuit_builder.b_constant(c); let x_constant = |x| circuit_builder.x_constant(x); let challenge = |c| circuit_builder.challenge(c); let base_row = |col: ProcessorBaseTableColumn| { @@ -647,7 +647,7 @@ impl ExtProcessorTable { pub fn consistency_constraints( circuit_builder: &ConstraintCircuitBuilder, ) -> Vec> { - let constant = |c: u32| circuit_builder.b_constant(c.into()); + let constant = |c: u32| circuit_builder.b_constant(c); let base_row = |col: ProcessorBaseTableColumn| { circuit_builder.input(BaseRow(col.master_base_table_index())) }; @@ -697,7 +697,7 @@ impl ExtProcessorTable { circuit_builder: &ConstraintCircuitBuilder, index: usize, ) -> ConstraintCircuitMonad { - let one = || circuit_builder.b_constant(1_u32.into()); + let one = || circuit_builder.b_constant(1); let hv = |idx| Self::helper_variable(circuit_builder, idx); match index { @@ -770,7 +770,7 @@ impl ExtProcessorTable { .max() .unwrap(); - let zero_poly = circuit_builder.b_constant(0_u32.into()); + let zero_poly = circuit_builder.b_constant(0); let all_tc_polys_for_all_instructions_transposed = (0..max_number_of_constraints) .map(|idx| { all_tc_polys_for_all_instructions @@ -797,7 +797,7 @@ impl ExtProcessorTable { circuit_builder: &ConstraintCircuitBuilder, instruction_transition_constraints: Vec>, ) -> Vec> { - let constant = |c: u64| circuit_builder.b_constant(c.into()); + let constant = |c: u64| circuit_builder.b_constant(c); let curr_base_row = |col: ProcessorBaseTableColumn| { circuit_builder.input(CurrentBaseRow(col.master_base_table_index())) }; @@ -846,7 +846,7 @@ impl ExtProcessorTable { fn instruction_group_decompose_arg( circuit_builder: &ConstraintCircuitBuilder, ) -> Vec> { - let constant = |c: u32| circuit_builder.b_constant(c.into()); + let constant = |c: u32| circuit_builder.b_constant(c); let curr_base_row = |col: ProcessorBaseTableColumn| { circuit_builder.input(CurrentBaseRow(col.master_base_table_index())) }; @@ -970,7 +970,7 @@ impl ExtProcessorTable { fn instruction_group_grow_op_stack_and_top_two_elements_unconstrained( circuit_builder: &ConstraintCircuitBuilder, ) -> Vec> { - let constant = |c: u32| circuit_builder.b_constant(c.into()); + let constant = |c: u32| circuit_builder.b_constant(c); let curr_base_row = |col: ProcessorBaseTableColumn| { circuit_builder.input(CurrentBaseRow(col.master_base_table_index())) }; @@ -1020,7 +1020,7 @@ impl ExtProcessorTable { fn instruction_group_op_stack_shrinks_and_top_three_elements_unconstrained( circuit_builder: &ConstraintCircuitBuilder, ) -> Vec> { - let constant = |c: u32| circuit_builder.b_constant(c.into()); + let constant = |c: u32| circuit_builder.b_constant(c); let curr_base_row = |col: ProcessorBaseTableColumn| { circuit_builder.input(CurrentBaseRow(col.master_base_table_index())) }; @@ -1108,7 +1108,7 @@ impl ExtProcessorTable { fn instruction_group_step_1( circuit_builder: &ConstraintCircuitBuilder, ) -> Vec> { - let constant = |c: u32| circuit_builder.b_constant(c.into()); + let constant = |c: u32| circuit_builder.b_constant(c); let curr_base_row = |col: ProcessorBaseTableColumn| { circuit_builder.input(CurrentBaseRow(col.master_base_table_index())) }; @@ -1128,7 +1128,7 @@ impl ExtProcessorTable { fn instruction_group_step_2( circuit_builder: &ConstraintCircuitBuilder, ) -> Vec> { - let constant = |c: u32| circuit_builder.b_constant(c.into()); + let constant = |c: u32| circuit_builder.b_constant(c); let curr_base_row = |col: ProcessorBaseTableColumn| { circuit_builder.input(CurrentBaseRow(col.master_base_table_index())) }; @@ -1152,7 +1152,7 @@ impl ExtProcessorTable { instruction: Instruction, instruction_bit_polynomials: [ConstraintCircuitMonad; InstructionBit::COUNT], ) -> ConstraintCircuitMonad { - let one = circuit_builder.b_constant(1_u32.into()); + let one = || circuit_builder.b_constant(1); let selector_bits: [_; InstructionBit::COUNT] = [ instruction.ib(InstructionBit::IB0), @@ -1163,14 +1163,13 @@ impl ExtProcessorTable { instruction.ib(InstructionBit::IB5), instruction.ib(InstructionBit::IB6), ]; - let deselector_polynomials = - selector_bits.map(|b| one.clone() - circuit_builder.b_constant(b)); + let deselector_polynomials = selector_bits.map(|b| one() - circuit_builder.b_constant(b)); instruction_bit_polynomials .into_iter() .zip_eq(deselector_polynomials) .map(|(instruction_bit_poly, deselector_poly)| instruction_bit_poly - deselector_poly) - .fold(one, ConstraintCircuitMonad::mul) + .fold(one(), ConstraintCircuitMonad::mul) } /// A polynomial that has no solutions when `ci` is `instruction`. @@ -1346,7 +1345,7 @@ impl ExtProcessorTable { fn instruction_swap( circuit_builder: &ConstraintCircuitBuilder, ) -> Vec> { - let one = || circuit_builder.b_constant(1_u32.into()); + let one = || circuit_builder.b_constant(1); let indicator_poly = |idx| Self::indicator_polynomial(circuit_builder, idx); let curr_base_row = |col: ProcessorBaseTableColumn| { circuit_builder.input(CurrentBaseRow(col.master_base_table_index())) @@ -1436,7 +1435,7 @@ impl ExtProcessorTable { fn instruction_skiz( circuit_builder: &ConstraintCircuitBuilder, ) -> Vec> { - let constant = |c: u32| circuit_builder.b_constant(c.into()); + let constant = |c: u32| circuit_builder.b_constant(c); let one = || constant(1); let curr_base_row = |col: ProcessorBaseTableColumn| { circuit_builder.input(CurrentBaseRow(col.master_base_table_index())) @@ -1496,7 +1495,7 @@ impl ExtProcessorTable { fn next_instruction_range_check_constraints_for_instruction_skiz( circuit_builder: &ConstraintCircuitBuilder, ) -> Vec> { - let constant = |c: u32| circuit_builder.b_constant(c.into()); + let constant = |c: u32| circuit_builder.b_constant(c); let curr_base_row = |col: ProcessorBaseTableColumn| { circuit_builder.input(CurrentBaseRow(col.master_base_table_index())) }; @@ -1522,7 +1521,7 @@ impl ExtProcessorTable { fn instruction_call( circuit_builder: &ConstraintCircuitBuilder, ) -> Vec> { - let constant = |c: u32| circuit_builder.b_constant(c.into()); + let constant = |c: u32| circuit_builder.b_constant(c); let curr_base_row = |col: ProcessorBaseTableColumn| { circuit_builder.input(CurrentBaseRow(col.master_base_table_index())) }; @@ -1560,7 +1559,7 @@ impl ExtProcessorTable { fn instruction_return( circuit_builder: &ConstraintCircuitBuilder, ) -> Vec> { - let constant = |c: u32| circuit_builder.b_constant(c.into()); + let constant = |c: u32| circuit_builder.b_constant(c); let curr_base_row = |col: ProcessorBaseTableColumn| { circuit_builder.input(CurrentBaseRow(col.master_base_table_index())) }; @@ -1610,7 +1609,7 @@ impl ExtProcessorTable { fn instruction_assert( circuit_builder: &ConstraintCircuitBuilder, ) -> Vec> { - let constant = |c: u32| circuit_builder.b_constant(c.into()); + let constant = |c: u32| circuit_builder.b_constant(c); let curr_base_row = |col: ProcessorBaseTableColumn| { circuit_builder.input(CurrentBaseRow(col.master_base_table_index())) }; @@ -1683,7 +1682,7 @@ impl ExtProcessorTable { fn instruction_hash( circuit_builder: &ConstraintCircuitBuilder, ) -> Vec> { - let constant = |c: u32| circuit_builder.b_constant(c.into()); + let constant = |c: u32| circuit_builder.b_constant(c); let curr_base_row = |col: ProcessorBaseTableColumn| { circuit_builder.input(CurrentBaseRow(col.master_base_table_index())) }; @@ -1718,7 +1717,7 @@ impl ExtProcessorTable { fn instruction_divine_sibling( circuit_builder: &ConstraintCircuitBuilder, ) -> Vec> { - let constant = |c: u32| circuit_builder.b_constant(c.into()); + let constant = |c: u32| circuit_builder.b_constant(c); let one = || constant(1); let curr_base_row = |col: ProcessorBaseTableColumn| { circuit_builder.input(CurrentBaseRow(col.master_base_table_index())) @@ -1884,7 +1883,7 @@ impl ExtProcessorTable { fn instruction_invert( circuit_builder: &ConstraintCircuitBuilder, ) -> Vec> { - let constant = |c: u32| circuit_builder.b_constant(c.into()); + let constant = |c: u32| circuit_builder.b_constant(c); let one = || constant(1); let curr_base_row = |col: ProcessorBaseTableColumn| { circuit_builder.input(CurrentBaseRow(col.master_base_table_index())) @@ -1907,7 +1906,7 @@ impl ExtProcessorTable { fn instruction_eq( circuit_builder: &ConstraintCircuitBuilder, ) -> Vec> { - let constant = |c: u32| circuit_builder.b_constant(c.into()); + let constant = |c: u32| circuit_builder.b_constant(c); let one = || constant(1); let curr_base_row = |col: ProcessorBaseTableColumn| { circuit_builder.input(CurrentBaseRow(col.master_base_table_index())) @@ -1949,7 +1948,7 @@ impl ExtProcessorTable { fn instruction_split( circuit_builder: &ConstraintCircuitBuilder, ) -> Vec> { - let constant = |c: u64| circuit_builder.b_constant(c.into()); + let constant = |c: u64| circuit_builder.b_constant(c); let one = || constant(1); let curr_base_row = |col: ProcessorBaseTableColumn| { circuit_builder.input(CurrentBaseRow(col.master_base_table_index())) @@ -2170,7 +2169,7 @@ impl ExtProcessorTable { fn instruction_xinv( circuit_builder: &ConstraintCircuitBuilder, ) -> Vec> { - let constant = |c: u64| circuit_builder.b_constant(c.into()); + let constant = |c: u64| circuit_builder.b_constant(c); let curr_base_row = |col: ProcessorBaseTableColumn| { circuit_builder.input(CurrentBaseRow(col.master_base_table_index())) }; @@ -2472,7 +2471,7 @@ impl ExtProcessorTable { fn log_derivative_for_instruction_lookup_updates_correctly( circuit_builder: &ConstraintCircuitBuilder, ) -> ConstraintCircuitMonad { - let one = || circuit_builder.b_constant(1_u32.into()); + let one = || circuit_builder.b_constant(1); let challenge = |c: ChallengeId| circuit_builder.challenge(c); let next_base_row = |col: ProcessorBaseTableColumn| { circuit_builder.input(NextBaseRow(col.master_base_table_index())) @@ -2501,7 +2500,7 @@ impl ExtProcessorTable { fn constraints_for_shrinking_stack_by_3_and_top_3_unconstrained( circuit_builder: &ConstraintCircuitBuilder, ) -> Vec> { - let constant = |c: u64| circuit_builder.b_constant(c.into()); + let constant = |c: u64| circuit_builder.b_constant(c); let curr_base_row = |col: ProcessorBaseTableColumn| { circuit_builder.input(CurrentBaseRow(col.master_base_table_index())) }; @@ -2601,7 +2600,7 @@ impl ExtProcessorTable { let constraint_group_lengths = all_constraint_groups.iter().map(|x| x.len()); let num_constraints = constraint_group_lengths.max().unwrap_or(0); - let zero_constraint = || circuit_builder.b_constant(0_u32.into()); + let zero_constraint = || circuit_builder.b_constant(0); let mut combined_constraints = vec![]; for i in 0..num_constraints { let combined_constraint = all_constraint_groups @@ -2617,7 +2616,7 @@ impl ExtProcessorTable { circuit_builder: &ConstraintCircuitBuilder, n: usize, ) -> Vec> { - let constant = |c: usize| circuit_builder.b_constant(u32::try_from(c).unwrap().into()); + let constant = |c: usize| circuit_builder.b_constant(u64::try_from(c).unwrap()); let curr_base_row = |col: ProcessorBaseTableColumn| { circuit_builder.input(CurrentBaseRow(col.master_base_table_index())) }; @@ -2647,7 +2646,7 @@ impl ExtProcessorTable { circuit_builder: &ConstraintCircuitBuilder, n: usize, ) -> Vec> { - let constant = |c: usize| circuit_builder.b_constant(u32::try_from(c).unwrap().into()); + let constant = |c: usize| circuit_builder.b_constant(u32::try_from(c).unwrap()); let curr_base_row = |col: ProcessorBaseTableColumn| { circuit_builder.input(CurrentBaseRow(col.master_base_table_index())) }; @@ -2697,7 +2696,7 @@ impl ExtProcessorTable { circuit_builder: &ConstraintCircuitBuilder, n: usize, ) -> ConstraintCircuitMonad { - let constant = |c: u32| circuit_builder.b_constant(c.into()); + let constant = |c: u32| circuit_builder.b_constant(c); let curr_ext_row = |col: ProcessorExtTableColumn| { circuit_builder.input(CurrentExtRow(col.master_ext_table_index())) }; @@ -2724,7 +2723,7 @@ impl ExtProcessorTable { circuit_builder: &ConstraintCircuitBuilder, n: usize, ) -> ConstraintCircuitMonad { - let constant = |c: u32| circuit_builder.b_constant(c.into()); + let constant = |c: u32| circuit_builder.b_constant(c); let curr_ext_row = |col: ProcessorExtTableColumn| { circuit_builder.input(CurrentExtRow(col.master_ext_table_index())) }; @@ -2752,7 +2751,7 @@ impl ExtProcessorTable { row_with_shorter_stack_indicator: fn(usize) -> DualRowIndicator, op_stack_pointer_offset: usize, ) -> ConstraintCircuitMonad { - let constant = |c: u32| circuit_builder.b_constant(c.into()); + let constant = |c: u32| circuit_builder.b_constant(c); let challenge = |c: ChallengeId| circuit_builder.challenge(c); let curr_base_row = |col: ProcessorBaseTableColumn| { circuit_builder.input(CurrentBaseRow(col.master_base_table_index())) @@ -2829,7 +2828,7 @@ impl ExtProcessorTable { circuit_builder: &ConstraintCircuitBuilder, n: usize, ) -> Vec> { - let constant = |c: usize| circuit_builder.b_constant(u32::try_from(c).unwrap().into()); + let constant = |c: usize| circuit_builder.b_constant(u32::try_from(c).unwrap()); let curr_base_row = |col: ProcessorBaseTableColumn| { circuit_builder.input(CurrentBaseRow(col.master_base_table_index())) }; @@ -2863,7 +2862,7 @@ impl ExtProcessorTable { circuit_builder: &ConstraintCircuitBuilder, n: usize, ) -> Vec> { - let constant = |c: usize| circuit_builder.b_constant(u32::try_from(c).unwrap().into()); + let constant = |c: usize| circuit_builder.b_constant(u64::try_from(c).unwrap()); let curr_base_row = |col: ProcessorBaseTableColumn| { circuit_builder.input(CurrentBaseRow(col.master_base_table_index())) }; @@ -2897,7 +2896,7 @@ impl ExtProcessorTable { circuit_builder: &ConstraintCircuitBuilder, n: usize, ) -> ConstraintCircuitMonad { - let constant = |c: u32| circuit_builder.b_constant(c.into()); + let constant = |c: u32| circuit_builder.b_constant(c); let curr_ext_row = |col: ProcessorExtTableColumn| { circuit_builder.input(CurrentExtRow(col.master_ext_table_index())) }; @@ -2925,7 +2924,7 @@ impl ExtProcessorTable { circuit_builder: &ConstraintCircuitBuilder, n: usize, ) -> ConstraintCircuitMonad { - let constant = |c: u32| circuit_builder.b_constant(c.into()); + let constant = |c: u32| circuit_builder.b_constant(c); let curr_ext_row = |col: ProcessorExtTableColumn| { circuit_builder.input(CurrentExtRow(col.master_ext_table_index())) }; @@ -2955,7 +2954,7 @@ impl ExtProcessorTable { instruction_type: BFieldElement, ram_pointer_offset: usize, ) -> ConstraintCircuitMonad { - let constant = |c: u32| circuit_builder.b_constant(c.into()); + let constant = |c: u32| circuit_builder.b_constant(c); let b_constant = |c| circuit_builder.b_constant(c); let challenge = |c: ChallengeId| circuit_builder.challenge(c); let curr_base_row = |col: ProcessorBaseTableColumn| { @@ -3017,7 +3016,7 @@ impl ExtProcessorTable { fn running_evaluation_hash_input_updates_correctly( circuit_builder: &ConstraintCircuitBuilder, ) -> ConstraintCircuitMonad { - let constant = |c: u32| circuit_builder.b_constant(c.into()); + let constant = |c: u32| circuit_builder.b_constant(c); let challenge = |c: ChallengeId| circuit_builder.challenge(c); let next_base_row = |col: ProcessorBaseTableColumn| { circuit_builder.input(NextBaseRow(col.master_base_table_index())) @@ -3065,7 +3064,7 @@ impl ExtProcessorTable { fn running_evaluation_hash_digest_updates_correctly( circuit_builder: &ConstraintCircuitBuilder, ) -> ConstraintCircuitMonad { - let constant = |c: u32| circuit_builder.b_constant(c.into()); + let constant = |c: u32| circuit_builder.b_constant(c); let challenge = |c: ChallengeId| circuit_builder.challenge(c); let curr_base_row = |col: ProcessorBaseTableColumn| { circuit_builder.input(CurrentBaseRow(col.master_base_table_index())) @@ -3111,7 +3110,7 @@ impl ExtProcessorTable { fn running_evaluation_sponge_updates_correctly( circuit_builder: &ConstraintCircuitBuilder, ) -> ConstraintCircuitMonad { - let constant = |c: u32| circuit_builder.b_constant(c.into()); + let constant = |c: u32| circuit_builder.b_constant(c); let challenge = |c: ChallengeId| circuit_builder.challenge(c); let curr_base_row = |col: ProcessorBaseTableColumn| { circuit_builder.input(CurrentBaseRow(col.master_base_table_index())) @@ -3184,7 +3183,7 @@ impl ExtProcessorTable { fn log_derivative_with_u32_table_updates_correctly( circuit_builder: &ConstraintCircuitBuilder, ) -> ConstraintCircuitMonad { - let constant = |c: u32| circuit_builder.b_constant(c.into()); + let constant = |c: u32| circuit_builder.b_constant(c); let one = || constant(1); let two_inverse = circuit_builder.b_constant(bfe!(2).inverse()); let challenge = |c: ChallengeId| circuit_builder.challenge(c); @@ -3289,7 +3288,7 @@ impl ExtProcessorTable { pub fn transition_constraints( circuit_builder: &ConstraintCircuitBuilder, ) -> Vec> { - let constant = |c: u64| circuit_builder.b_constant(c.into()); + let constant = |c: u64| circuit_builder.b_constant(c); let curr_base_row = |col: ProcessorBaseTableColumn| { circuit_builder.input(CurrentBaseRow(col.master_base_table_index())) }; diff --git a/triton-vm/src/table/program_table.rs b/triton-vm/src/table/program_table.rs index 11e4be7e..97a29461 100644 --- a/triton-vm/src/table/program_table.rs +++ b/triton-vm/src/table/program_table.rs @@ -88,7 +88,7 @@ impl ExtProgramTable { pub fn consistency_constraints( circuit_builder: &ConstraintCircuitBuilder, ) -> Vec> { - let constant = |c: u32| circuit_builder.b_constant(c.into()); + let constant = |c: u32| circuit_builder.b_constant(c); let base_row = |col: ProgramBaseTableColumn| { circuit_builder.input(BaseRow(col.master_base_table_index())) }; @@ -125,7 +125,7 @@ impl ExtProgramTable { circuit_builder: &ConstraintCircuitBuilder, ) -> Vec> { let challenge = |c| circuit_builder.challenge(c); - let constant = |c: u64| circuit_builder.b_constant(c.into()); + let constant = |c: u64| circuit_builder.b_constant(c); let current_base_row = |col: ProgramBaseTableColumn| { circuit_builder.input(CurrentBaseRow(col.master_base_table_index())) @@ -259,7 +259,7 @@ impl ExtProgramTable { pub fn terminal_constraints( circuit_builder: &ConstraintCircuitBuilder, ) -> Vec> { - let constant = |c: u64| circuit_builder.b_constant(c.into()); + let constant = |c: u64| circuit_builder.b_constant(c); let base_row = |col: ProgramBaseTableColumn| { circuit_builder.input(BaseRow(col.master_base_table_index())) }; diff --git a/triton-vm/src/table/ram_table.rs b/triton-vm/src/table/ram_table.rs index d809b2c3..4e51c19f 100644 --- a/triton-vm/src/table/ram_table.rs +++ b/triton-vm/src/table/ram_table.rs @@ -501,7 +501,7 @@ impl ExtRamTable { pub fn terminal_constraints( circuit_builder: &ConstraintCircuitBuilder, ) -> Vec> { - let constant = |c: u32| circuit_builder.b_constant(c.into()); + let constant = |c: u32| circuit_builder.b_constant(c); let ext_row = |column: RamExtTableColumn| { circuit_builder.input(ExtRow(column.master_ext_table_index())) }; diff --git a/triton-vm/src/table/u32_table.rs b/triton-vm/src/table/u32_table.rs index caf9bd6c..8fe95eb7 100644 --- a/triton-vm/src/table/u32_table.rs +++ b/triton-vm/src/table/u32_table.rs @@ -117,7 +117,7 @@ impl ExtU32Table { circuit_builder: &ConstraintCircuitBuilder, ) -> Vec> { let challenge = |c| circuit_builder.challenge(c); - let one = circuit_builder.b_constant(1_u32.into()); + let one = circuit_builder.b_constant(1); let copy_flag = circuit_builder.input(BaseRow(CopyFlag.master_base_table_index())); let lhs = circuit_builder.input(BaseRow(LHS.master_base_table_index())); @@ -152,8 +152,8 @@ impl ExtU32Table { pub fn consistency_constraints( circuit_builder: &ConstraintCircuitBuilder, ) -> Vec> { - let one = circuit_builder.b_constant(1_u32.into()); - let two = circuit_builder.b_constant(2_u32.into()); + let one = || circuit_builder.b_constant(1); + let two = || circuit_builder.b_constant(2); let copy_flag = circuit_builder.input(BaseRow(CopyFlag.master_base_table_index())); let bits = circuit_builder.input(BaseRow(Bits.master_base_table_index())); @@ -172,51 +172,51 @@ impl ExtU32Table { Self::instruction_deselector(instruction_to_select, circuit_builder, &ci) }; - let copy_flag_is_bit = copy_flag.clone() * (one.clone() - copy_flag.clone()); + let copy_flag_is_bit = copy_flag.clone() * (one() - copy_flag.clone()); let copy_flag_is_0_or_bits_is_0 = copy_flag.clone() * bits.clone(); let bits_minus_33_inv_is_inverse_of_bits_minus_33 = - one.clone() - bits_minus_33_inv * (bits - circuit_builder.b_constant(bfe!(33))); + one() - bits_minus_33_inv * (bits - circuit_builder.b_constant(33)); let lhs_inv_is_0_or_the_inverse_of_lhs = - lhs_inv.clone() * (one.clone() - lhs.clone() * lhs_inv.clone()); + lhs_inv.clone() * (one() - lhs.clone() * lhs_inv.clone()); let lhs_is_0_or_lhs_inverse_is_the_inverse_of_lhs = - lhs.clone() * (one.clone() - lhs.clone() * lhs_inv.clone()); + lhs.clone() * (one() - lhs.clone() * lhs_inv.clone()); let rhs_inv_is_0_or_the_inverse_of_rhs = - rhs_inv.clone() * (one.clone() - rhs.clone() * rhs_inv.clone()); + rhs_inv.clone() * (one() - rhs.clone() * rhs_inv.clone()); let rhs_is_0_or_rhs_inverse_is_the_inverse_of_rhs = - rhs.clone() * (one.clone() - rhs.clone() * rhs_inv.clone()); + rhs.clone() * (one() - rhs.clone() * rhs_inv.clone()); let result_is_initialized_correctly_for_lt_with_copy_flag_0 = instruction_deselector(Instruction::Lt) - * (copy_flag.clone() - one.clone()) - * (one.clone() - lhs.clone() * lhs_inv.clone()) - * (one.clone() - rhs.clone() * rhs_inv.clone()) - * (result.clone() - two); + * (copy_flag.clone() - one()) + * (one() - lhs.clone() * lhs_inv.clone()) + * (one() - rhs.clone() * rhs_inv.clone()) + * (result.clone() - two()); let result_is_initialized_correctly_for_lt_with_copy_flag_1 = instruction_deselector(Instruction::Lt) * copy_flag.clone() - * (one.clone() - lhs.clone() * lhs_inv.clone()) - * (one.clone() - rhs.clone() * rhs_inv.clone()) + * (one() - lhs.clone() * lhs_inv.clone()) + * (one() - rhs.clone() * rhs_inv.clone()) * result.clone(); let result_is_initialized_correctly_for_and = instruction_deselector(Instruction::And) - * (one.clone() - lhs.clone() * lhs_inv.clone()) - * (one.clone() - rhs.clone() * rhs_inv.clone()) + * (one() - lhs.clone() * lhs_inv.clone()) + * (one() - rhs.clone() * rhs_inv.clone()) * result.clone(); let result_is_initialized_correctly_for_pow = instruction_deselector(Instruction::Pow) - * (one.clone() - rhs * rhs_inv) - * (result.clone() - one.clone()); + * (one() - rhs * rhs_inv) + * (result.clone() - one()); let result_is_initialized_correctly_for_log_2_floor = instruction_deselector(Instruction::Log2Floor) - * (copy_flag.clone() - one.clone()) - * (one.clone() - lhs.clone() * lhs_inv.clone()) - * (result.clone() + one.clone()); + * (copy_flag.clone() - one()) + * (one() - lhs.clone() * lhs_inv.clone()) + * (result.clone() + one()); let result_is_initialized_correctly_for_pop_count = instruction_deselector(Instruction::PopCount) - * (one.clone() - lhs.clone() * lhs_inv.clone()) + * (one() - lhs.clone() * lhs_inv.clone()) * result; let if_log_2_floor_on_0_then_vm_crashes = instruction_deselector(Instruction::Log2Floor) * copy_flag.clone() - * (one.clone() - lhs * lhs_inv); + * (one() - lhs * lhs_inv); let if_copy_flag_is_0_then_lookup_multiplicity_is_0 = - (copy_flag - one) * lookup_multiplicity; + (copy_flag - one()) * lookup_multiplicity; vec![ copy_flag_is_bit, @@ -241,8 +241,8 @@ impl ExtU32Table { circuit_builder: &ConstraintCircuitBuilder, ) -> Vec> { let challenge = |c| circuit_builder.challenge(c); - let one = circuit_builder.b_constant(1_u32.into()); - let two = circuit_builder.b_constant(2_u32.into()); + let one = || circuit_builder.b_constant(1); + let two = || circuit_builder.b_constant(2); let copy_flag = circuit_builder.input(CurrentBaseRow(CopyFlag.master_base_table_index())); let bits = circuit_builder.input(CurrentBaseRow(Bits.master_base_table_index())); @@ -273,124 +273,124 @@ impl ExtU32Table { // helpful aliases let ci_is_pow = ci.clone() - circuit_builder.b_constant(Instruction::Pow.opcode_b()); - let lhs_lsb = lhs.clone() - two.clone() * lhs_next.clone(); - let rhs_lsb = rhs.clone() - two.clone() * rhs_next.clone(); + let lhs_lsb = lhs.clone() - two() * lhs_next.clone(); + let rhs_lsb = rhs.clone() - two() * rhs_next.clone(); // general constraints let if_copy_flag_next_is_1_then_lhs_is_0_or_ci_is_pow = copy_flag_next.clone() * lhs.clone() * ci_is_pow.clone(); let if_copy_flag_next_is_1_then_rhs_is_0 = copy_flag_next.clone() * rhs.clone(); let if_copy_flag_next_is_0_then_ci_stays = - (copy_flag_next.clone() - one.clone()) * (ci_next.clone() - ci); + (copy_flag_next.clone() - one()) * (ci_next.clone() - ci); let if_copy_flag_next_is_0_and_lhs_next_is_nonzero_and_ci_not_pow_then_bits_increases_by_1 = - (copy_flag_next.clone() - one.clone()) + (copy_flag_next.clone() - one()) * lhs.clone() * ci_is_pow.clone() - * (bits_next.clone() - bits.clone() - one.clone()); + * (bits_next.clone() - bits.clone() - one()); let if_copy_flag_next_is_0_and_rhs_next_is_nonzero_then_bits_increases_by_1 = - (copy_flag_next.clone() - one.clone()) * rhs * (bits_next - bits.clone() - one.clone()); + (copy_flag_next.clone() - one()) * rhs * (bits_next - bits.clone() - one()); let if_copy_flag_next_is_0_and_ci_not_pow_then_lhs_lsb_is_a_bit = (copy_flag_next.clone() - - one.clone()) + - one()) * ci_is_pow * lhs_lsb.clone() - * (lhs_lsb.clone() - one.clone()); - let if_copy_flag_next_is_0_then_rhs_lsb_is_a_bit = (copy_flag_next.clone() - one.clone()) - * rhs_lsb.clone() - * (rhs_lsb.clone() - one.clone()); + * (lhs_lsb.clone() - one()); + let if_copy_flag_next_is_0_then_rhs_lsb_is_a_bit = + (copy_flag_next.clone() - one()) * rhs_lsb.clone() * (rhs_lsb.clone() - one()); // instruction lt let if_copy_flag_next_is_0_and_ci_is_lt_and_result_next_is_0_then_result_is_0 = - (copy_flag_next.clone() - one.clone()) + (copy_flag_next.clone() - one()) * instruction_deselector(Instruction::Lt) - * (result_next.clone() - one.clone()) - * (result_next.clone() - two.clone()) + * (result_next.clone() - one()) + * (result_next.clone() - two()) * result.clone(); let if_copy_flag_next_is_0_and_ci_is_lt_and_result_next_is_1_then_result_is_1 = - (copy_flag_next.clone() - one.clone()) + (copy_flag_next.clone() - one()) * instruction_deselector(Instruction::Lt) * result_next.clone() - * (result_next.clone() - two.clone()) - * (result.clone() - one.clone()); + * (result_next.clone() - two()) + * (result.clone() - one()); let if_copy_flag_next_is_0_and_ci_is_lt_and_result_next_is_2_and_lt_is_0_then_result_is_0 = - (copy_flag_next.clone() - one.clone()) + (copy_flag_next.clone() - one()) * instruction_deselector(Instruction::Lt) * result_next.clone() - * (result_next.clone() - one.clone()) - * (lhs_lsb.clone() - one.clone()) + * (result_next.clone() - one()) + * (lhs_lsb.clone() - one()) * rhs_lsb.clone() - * (result.clone() - one.clone()); + * (result.clone() - one()); let if_copy_flag_next_is_0_and_ci_is_lt_and_result_next_is_2_and_lt_is_1_then_result_is_1 = - (copy_flag_next.clone() - one.clone()) + (copy_flag_next.clone() - one()) * instruction_deselector(Instruction::Lt) * result_next.clone() - * (result_next.clone() - one.clone()) + * (result_next.clone() - one()) * lhs_lsb.clone() - * (rhs_lsb.clone() - one.clone()) + * (rhs_lsb.clone() - one()) * result.clone(); let if_copy_flag_next_is_0_and_ci_is_lt_and_result_still_not_known_then_result_is_2 = - (copy_flag_next.clone() - one.clone()) + (copy_flag_next.clone() - one()) * instruction_deselector(Instruction::Lt) * result_next.clone() - * (result_next.clone() - one.clone()) - * (one.clone() - lhs_lsb.clone() - rhs_lsb.clone() - + two.clone() * lhs_lsb.clone() * rhs_lsb.clone()) - * (copy_flag.clone() - one.clone()) - * (result.clone() - two.clone()); + * (result_next.clone() - one()) + * (one() - lhs_lsb.clone() - rhs_lsb.clone() + + two() * lhs_lsb.clone() * rhs_lsb.clone()) + * (copy_flag.clone() - one()) + * (result.clone() - two()); let if_copy_flag_next_is_0_and_ci_is_lt_and_copy_flag_dictates_result_then_result_is_0 = - (copy_flag_next.clone() - one.clone()) + (copy_flag_next.clone() - one()) * instruction_deselector(Instruction::Lt) * result_next.clone() - * (result_next.clone() - one.clone()) - * (one.clone() - lhs_lsb.clone() - rhs_lsb.clone() - + two.clone() * lhs_lsb.clone() * rhs_lsb.clone()) + * (result_next.clone() - one()) + * (one() - lhs_lsb.clone() - rhs_lsb.clone() + + two() * lhs_lsb.clone() * rhs_lsb.clone()) * copy_flag * result.clone(); // instruction and - let if_copy_flag_next_is_0_and_ci_is_and_then_results_updates_correctly = - (copy_flag_next.clone() - one.clone()) - * instruction_deselector(Instruction::And) - * (result.clone() - two * result_next.clone() - lhs_lsb.clone() * rhs_lsb.clone()); + let if_copy_flag_next_is_0_and_ci_is_and_then_results_updates_correctly = (copy_flag_next + .clone() + - one()) + * instruction_deselector(Instruction::And) + * (result.clone() - two() * result_next.clone() - lhs_lsb.clone() * rhs_lsb.clone()); // instruction log_2_floor let if_copy_flag_next_is_0_and_ci_is_log_2_floor_lhs_next_0_for_first_time_then_set_result = - (copy_flag_next.clone() - one.clone()) + (copy_flag_next.clone() - one()) * instruction_deselector(Instruction::Log2Floor) - * (one.clone() - lhs_next.clone() * lhs_inv_next) + * (one() - lhs_next.clone() * lhs_inv_next) * lhs.clone() * (result.clone() - bits); let if_copy_flag_next_is_0_and_ci_is_log_2_floor_and_lhs_next_not_0_then_copy_result = - (copy_flag_next.clone() - one.clone()) + (copy_flag_next.clone() - one()) * instruction_deselector(Instruction::Log2Floor) * lhs_next.clone() * (result_next.clone() - result.clone()); // instruction pow let if_copy_flag_next_is_0_and_ci_is_pow_then_lhs_remains_unchanged = - (copy_flag_next.clone() - one.clone()) + (copy_flag_next.clone() - one()) * instruction_deselector(Instruction::Pow) * (lhs_next.clone() - lhs.clone()); let if_copy_flag_next_is_0_and_ci_is_pow_and_rhs_lsb_is_0_then_result_squares = - (copy_flag_next.clone() - one.clone()) + (copy_flag_next.clone() - one()) * instruction_deselector(Instruction::Pow) - * (rhs_lsb.clone() - one.clone()) + * (rhs_lsb.clone() - one()) * (result.clone() - result_next.clone() * result_next.clone()); let if_copy_flag_next_is_0_and_ci_is_pow_and_rhs_lsb_is_1_then_result_squares_and_mults = - (copy_flag_next.clone() - one.clone()) + (copy_flag_next.clone() - one()) * instruction_deselector(Instruction::Pow) * rhs_lsb * (result.clone() - result_next.clone() * result_next.clone() * lhs); let if_copy_flag_next_is_0_and_ci_is_pop_count_then_result_increases_by_lhs_lsb = - (copy_flag_next.clone() - one.clone()) + (copy_flag_next.clone() - one()) * instruction_deselector(Instruction::PopCount) * (result - result_next.clone() - lhs_lsb); // running sum for Lookup Argument with Processor Table let if_copy_flag_next_is_0_then_running_sum_log_derivative_stays = (copy_flag_next.clone() - - one) + - one()) * (running_sum_log_derivative_next.clone() - running_sum_log_derivative.clone()); let compressed_row_next = challenge(U32CiWeight) * ci_next