From bbbc52c89f8b07a3cffc28779eeb88d836319782 Mon Sep 17 00:00:00 2001 From: Jan Ferdinand Sauer Date: Thu, 3 Aug 2023 14:55:50 +0200 Subject: [PATCH] simplify indexing of `Challenges` through `Index` trait --- constraint-evaluation-generator/src/main.rs | 2 +- triton-vm/src/stark.rs | 10 +- triton-vm/src/table/cascade_table.rs | 12 +- triton-vm/src/table/challenges.rs | 28 +++- triton-vm/src/table/constraint_circuit.rs | 2 +- triton-vm/src/table/hash_table.rs | 33 ++--- triton-vm/src/table/jump_stack_table.rs | 14 +- triton-vm/src/table/lookup_table.rs | 8 +- triton-vm/src/table/op_stack_table.rs | 12 +- triton-vm/src/table/processor_table.rs | 146 +++++++++----------- triton-vm/src/table/program_table.rs | 15 +- triton-vm/src/table/ram_table.rs | 15 +- triton-vm/src/table/u32_table.rs | 10 +- 13 files changed, 145 insertions(+), 162 deletions(-) diff --git a/constraint-evaluation-generator/src/main.rs b/constraint-evaluation-generator/src/main.rs index 35c6a082a..8fe681423 100644 --- a/constraint-evaluation-generator/src/main.rs +++ b/constraint-evaluation-generator/src/main.rs @@ -566,7 +566,7 @@ fn get_binding_name(circuit: &ConstraintCircuit) -> Toke CircuitExpression::Input(idx) => quote!(#idx), CircuitExpression::Challenge(challenge) => { let challenge_ident = format_ident!("{challenge}"); - quote!(challenges.get_challenge(#challenge_ident)) + quote!(challenges[#challenge_ident]) } CircuitExpression::BinaryOperation(_, _, _) => { let node_ident = format_ident!("node_{}", circuit.id); diff --git a/triton-vm/src/stark.rs b/triton-vm/src/stark.rs index ac6e95394..08ba9e4f5 100644 --- a/triton-vm/src/stark.rs +++ b/triton-vm/src/stark.rs @@ -1315,7 +1315,7 @@ pub(crate) mod triton_stark_tests { let ine = EvalArg::compute_terminal( &claim.input, EvalArg::default_initial(), - all_challenges.get_challenge(StandardInputIndeterminate), + all_challenges[StandardInputIndeterminate], ); assert_eq!(ptie, ine, "The input evaluation arguments do not match."); @@ -1323,7 +1323,7 @@ pub(crate) mod triton_stark_tests { let oute = EvalArg::compute_terminal( &claim.output, EvalArg::default_initial(), - all_challenges.get_challenge(StandardOutputIndeterminate), + all_challenges[StandardOutputIndeterminate], ); assert_eq!(ptoe, oute, "The output evaluation arguments do not match."); } @@ -1353,12 +1353,12 @@ pub(crate) mod triton_stark_tests { let processor_table = master_ext_table.table(ProcessorTable); let processor_table_last_row = processor_table.slice(s![-1, ..]); assert_eq!( - challenges.get_challenge(StandardInputTerminal), + challenges[StandardInputTerminal], processor_table_last_row[InputTableEvalArg.ext_table_index()], "The input terminal must match for TASM snippet #{code_idx}." ); assert_eq!( - challenges.get_challenge(StandardOutputTerminal), + challenges[StandardOutputTerminal], processor_table_last_row[OutputTableEvalArg.ext_table_index()], "The output terminal must match for TASM snippet #{code_idx}." ); @@ -1366,7 +1366,7 @@ pub(crate) mod triton_stark_tests { let lookup_table = master_ext_table.table(LookupTable); let lookup_table_last_row = lookup_table.slice(s![-1, ..]); assert_eq!( - challenges.get_challenge(LookupTablePublicTerminal), + challenges[LookupTablePublicTerminal], lookup_table_last_row[PublicEvaluationArgument.ext_table_index()], "The lookup's terminal must match for TASM snippet #{code_idx}." ); diff --git a/triton-vm/src/table/cascade_table.rs b/triton-vm/src/table/cascade_table.rs index 1841b887e..06e59dd57 100644 --- a/triton-vm/src/table/cascade_table.rs +++ b/triton-vm/src/table/cascade_table.rs @@ -79,13 +79,13 @@ impl CascadeTable { let two_pow_8 = BFieldElement::new(1 << 8); - let hash_indeterminate = challenges.get_challenge(HashCascadeLookupIndeterminate); - let hash_input_weight = challenges.get_challenge(HashCascadeLookInWeight); - let hash_output_weight = challenges.get_challenge(HashCascadeLookOutWeight); + let hash_indeterminate = challenges[HashCascadeLookupIndeterminate]; + let hash_input_weight = challenges[HashCascadeLookInWeight]; + let hash_output_weight = challenges[HashCascadeLookOutWeight]; - let lookup_indeterminate = challenges.get_challenge(CascadeLookupIndeterminate); - let lookup_input_weight = challenges.get_challenge(LookupTableInputWeight); - let lookup_output_weight = challenges.get_challenge(LookupTableOutputWeight); + let lookup_indeterminate = challenges[CascadeLookupIndeterminate]; + let lookup_input_weight = challenges[LookupTableInputWeight]; + let lookup_output_weight = challenges[LookupTableOutputWeight]; for row_idx in 0..base_table.nrows() { let base_row = base_table.row(row_idx); diff --git a/triton-vm/src/table/challenges.rs b/triton-vm/src/table/challenges.rs index f1ff78fff..f4c07b708 100644 --- a/triton-vm/src/table/challenges.rs +++ b/triton-vm/src/table/challenges.rs @@ -20,6 +20,9 @@ use std::fmt::Debug; use std::hash::Hash; +use std::ops::Index; +use std::ops::Range; +use std::ops::RangeInclusive; use strum::EnumCount; use strum_macros::Display; @@ -292,10 +295,29 @@ impl Challenges { let stand_in_challenges = random_elements(Self::num_challenges_to_sample()); Self::new(stand_in_challenges, claim) } +} + +impl Index for Challenges { + type Output = XFieldElement; + + fn index(&self, id: ChallengeId) -> &Self::Output { + &self.challenges[id.index()] + } +} + +impl Index> for Challenges { + type Output = [XFieldElement]; + + fn index(&self, indices: Range) -> &Self::Output { + &self.challenges[indices.start.index()..indices.end.index()] + } +} + +impl Index> for Challenges { + type Output = [XFieldElement]; - #[inline(always)] - pub fn get_challenge(&self, id: ChallengeId) -> XFieldElement { - self.challenges[id.index()] + fn index(&self, indices: RangeInclusive) -> &Self::Output { + &self.challenges[indices.start().index()..=indices.end().index()] } } diff --git a/triton-vm/src/table/constraint_circuit.rs b/triton-vm/src/table/constraint_circuit.rs index c3772b9fa..5fa2729a2 100644 --- a/triton-vm/src/table/constraint_circuit.rs +++ b/triton-vm/src/table/constraint_circuit.rs @@ -572,7 +572,7 @@ impl ConstraintCircuit { XConstant(xfe) => xfe, BConstant(bfe) => bfe.lift(), Input(input) => input.evaluate(base_table, ext_table), - Challenge(challenge_id) => challenges.get_challenge(challenge_id), + Challenge(challenge_id) => challenges[challenge_id], BinaryOperation(binop, lhs, rhs) => { let lhs_value = lhs .as_ref() diff --git a/triton-vm/src/table/hash_table.rs b/triton-vm/src/table/hash_table.rs index 8869244ba..cec5679e7 100644 --- a/triton-vm/src/table/hash_table.rs +++ b/triton-vm/src/table/hash_table.rs @@ -1580,13 +1580,12 @@ impl HashTable { assert_eq!(EXT_WIDTH, ext_table.ncols()); assert_eq!(base_table.nrows(), ext_table.nrows()); - let ci_weight = challenges.get_challenge(HashCIWeight); - let hash_digest_eval_indeterminate = challenges.get_challenge(HashDigestIndeterminate); - let hash_input_eval_indeterminate = challenges.get_challenge(HashInputIndeterminate); - let sponge_eval_indeterminate = challenges.get_challenge(SpongeIndeterminate); - let cascade_indeterminate = challenges.get_challenge(HashCascadeLookupIndeterminate); - let send_chunk_indeterminate = - challenges.get_challenge(ProgramAttestationSendChunkIndeterminate); + let ci_weight = challenges[HashCIWeight]; + let hash_digest_eval_indeterminate = challenges[HashDigestIndeterminate]; + let hash_input_eval_indeterminate = challenges[HashInputIndeterminate]; + let sponge_eval_indeterminate = challenges[SpongeIndeterminate]; + let cascade_indeterminate = challenges[HashCascadeLookupIndeterminate]; + let send_chunk_indeterminate = challenges[ProgramAttestationSendChunkIndeterminate]; let mut hash_input_running_evaluation = EvalArg::default_initial(); let mut hash_digest_running_evaluation = EvalArg::default_initial(); @@ -1675,19 +1674,7 @@ impl HashTable { ] }; - let state_weights = [ - challenges.get_challenge(HashStateWeight0), - challenges.get_challenge(HashStateWeight1), - challenges.get_challenge(HashStateWeight2), - challenges.get_challenge(HashStateWeight3), - challenges.get_challenge(HashStateWeight4), - challenges.get_challenge(HashStateWeight5), - challenges.get_challenge(HashStateWeight6), - challenges.get_challenge(HashStateWeight7), - challenges.get_challenge(HashStateWeight8), - challenges.get_challenge(HashStateWeight9), - ]; - + let state_weights = &challenges[HashStateWeight0..HashStateWeight10]; let compressed_row = |row: ArrayView1| -> XFieldElement { rate_registers(row) .iter() @@ -1696,8 +1683,8 @@ impl HashTable { .sum() }; - let cascade_look_in_weight = challenges.get_challenge(HashCascadeLookInWeight); - let cascade_look_out_weight = challenges.get_challenge(HashCascadeLookOutWeight); + let cascade_look_in_weight = challenges[HashCascadeLookInWeight]; + let cascade_look_out_weight = challenges[HashCascadeLookOutWeight]; let log_derivative_summand = |row: ArrayView1, @@ -1725,7 +1712,7 @@ impl HashTable { let compressed_chunk_of_instructions = EvalArg::compute_terminal( &rate_registers(row), EvalArg::default_initial(), - challenges.get_challenge(ProgramAttestationPrepareChunkIndeterminate), + challenges[ProgramAttestationPrepareChunkIndeterminate], ); receive_chunk_running_evaluation = receive_chunk_running_evaluation * send_chunk_indeterminate diff --git a/triton-vm/src/table/jump_stack_table.rs b/triton-vm/src/table/jump_stack_table.rs index 8adb1f619..2cf7f64be 100644 --- a/triton-vm/src/table/jump_stack_table.rs +++ b/triton-vm/src/table/jump_stack_table.rs @@ -318,14 +318,14 @@ impl JumpStackTable { assert_eq!(EXT_WIDTH, ext_table.ncols()); assert_eq!(base_table.nrows(), ext_table.nrows()); - let clk_weight = challenges.get_challenge(JumpStackClkWeight); - let ci_weight = challenges.get_challenge(JumpStackCiWeight); - let jsp_weight = challenges.get_challenge(JumpStackJspWeight); - let jso_weight = challenges.get_challenge(JumpStackJsoWeight); - let jsd_weight = challenges.get_challenge(JumpStackJsdWeight); - let perm_arg_indeterminate = challenges.get_challenge(JumpStackIndeterminate); + let clk_weight = challenges[JumpStackClkWeight]; + let ci_weight = challenges[JumpStackCiWeight]; + let jsp_weight = challenges[JumpStackJspWeight]; + let jso_weight = challenges[JumpStackJsoWeight]; + let jsd_weight = challenges[JumpStackJsdWeight]; + let perm_arg_indeterminate = challenges[JumpStackIndeterminate]; let clock_jump_difference_lookup_indeterminate = - challenges.get_challenge(ClockJumpDifferenceLookupIndeterminate); + challenges[ClockJumpDifferenceLookupIndeterminate]; let mut running_product = PermArg::default_initial(); let mut clock_jump_diff_lookup_log_derivative = LookupArg::default_initial(); diff --git a/triton-vm/src/table/lookup_table.rs b/triton-vm/src/table/lookup_table.rs index 71c84294c..371204d6f 100644 --- a/triton-vm/src/table/lookup_table.rs +++ b/triton-vm/src/table/lookup_table.rs @@ -86,10 +86,10 @@ impl LookupTable { assert_eq!(EXT_WIDTH, ext_table.ncols()); assert_eq!(base_table.nrows(), ext_table.nrows()); - let look_in_weight = challenges.get_challenge(LookupTableInputWeight); - let look_out_weight = challenges.get_challenge(LookupTableOutputWeight); - let cascade_indeterminate = challenges.get_challenge(CascadeLookupIndeterminate); - let public_indeterminate = challenges.get_challenge(LookupTablePublicIndeterminate); + let look_in_weight = challenges[LookupTableInputWeight]; + let look_out_weight = challenges[LookupTableOutputWeight]; + let cascade_indeterminate = challenges[CascadeLookupIndeterminate]; + let public_indeterminate = challenges[LookupTablePublicIndeterminate]; let mut cascade_table_running_sum_log_derivative = LookupArg::default_initial(); let mut public_running_evaluation = EvalArg::default_initial(); diff --git a/triton-vm/src/table/op_stack_table.rs b/triton-vm/src/table/op_stack_table.rs index b7ec6398e..165d051db 100644 --- a/triton-vm/src/table/op_stack_table.rs +++ b/triton-vm/src/table/op_stack_table.rs @@ -297,13 +297,13 @@ impl OpStackTable { assert_eq!(EXT_WIDTH, ext_table.ncols()); assert_eq!(base_table.nrows(), ext_table.nrows()); - let clk_weight = challenges.get_challenge(OpStackClkWeight); - let ib1_weight = challenges.get_challenge(OpStackIb1Weight); - let osp_weight = challenges.get_challenge(OpStackOspWeight); - let osv_weight = challenges.get_challenge(OpStackOsvWeight); - let perm_arg_indeterminate = challenges.get_challenge(OpStackIndeterminate); + let clk_weight = challenges[OpStackClkWeight]; + let ib1_weight = challenges[OpStackIb1Weight]; + let osp_weight = challenges[OpStackOspWeight]; + let osv_weight = challenges[OpStackOsvWeight]; + let perm_arg_indeterminate = challenges[OpStackIndeterminate]; let clock_jump_difference_lookup_indeterminate = - challenges.get_challenge(ClockJumpDifferenceLookupIndeterminate); + challenges[ClockJumpDifferenceLookupIndeterminate]; let mut running_product = PermArg::default_initial(); let mut clock_jump_diff_lookup_log_derivative = LookupArg::default_initial(); diff --git a/triton-vm/src/table/processor_table.rs b/triton-vm/src/table/processor_table.rs index 72bc04f3a..420fac5a1 100644 --- a/triton-vm/src/table/processor_table.rs +++ b/triton-vm/src/table/processor_table.rs @@ -165,7 +165,7 @@ impl ProcessorTable { if prev_row[CI.base_table_index()] == Instruction::ReadIo.opcode_b() { let input_symbol = current_row[ST0.base_table_index()]; input_table_running_evaluation = input_table_running_evaluation - * challenges.get_challenge(StandardInputIndeterminate) + * challenges[StandardInputIndeterminate] + input_symbol; } } @@ -174,7 +174,7 @@ impl ProcessorTable { if current_row[CI.base_table_index()] == Instruction::WriteIo.opcode_b() { let output_symbol = current_row[ST0.base_table_index()]; output_table_running_evaluation = output_table_running_evaluation - * challenges.get_challenge(StandardOutputIndeterminate) + * challenges[StandardOutputIndeterminate] + output_symbol; } @@ -183,12 +183,10 @@ impl ProcessorTable { let ip = current_row[IP.base_table_index()]; let ci = current_row[CI.base_table_index()]; let nia = current_row[NIA.base_table_index()]; - let compressed_row_for_instruction_lookup = ip - * challenges.get_challenge(ProgramAddressWeight) - + ci * challenges.get_challenge(ProgramInstructionWeight) - + nia * challenges.get_challenge(ProgramNextInstructionWeight); - instruction_lookup_log_derivative += (challenges - .get_challenge(InstructionLookupIndeterminate) + let compressed_row_for_instruction_lookup = ip * challenges[ProgramAddressWeight] + + ci * challenges[ProgramInstructionWeight] + + nia * challenges[ProgramNextInstructionWeight]; + instruction_lookup_log_derivative += (challenges[InstructionLookupIndeterminate] - compressed_row_for_instruction_lookup) .inverse(); } @@ -199,69 +197,56 @@ impl ProcessorTable { let osp = current_row[OSP.base_table_index()]; let osv = current_row[OSV.base_table_index()]; let compressed_row_for_op_stack_table_permutation_argument = clk - * challenges.get_challenge(OpStackClkWeight) - + ib1 * challenges.get_challenge(OpStackIb1Weight) - + osp * challenges.get_challenge(OpStackOspWeight) - + osv * challenges.get_challenge(OpStackOsvWeight); - op_stack_table_running_product *= challenges.get_challenge(OpStackIndeterminate) + * challenges[OpStackClkWeight] + + ib1 * challenges[OpStackIb1Weight] + + osp * challenges[OpStackOspWeight] + + osv * challenges[OpStackOsvWeight]; + op_stack_table_running_product *= challenges[OpStackIndeterminate] - compressed_row_for_op_stack_table_permutation_argument; // RAM Table let ramv = current_row[RAMV.base_table_index()]; let ramp = current_row[RAMP.base_table_index()]; let previous_instruction = current_row[PreviousInstruction.base_table_index()]; - let compressed_row_for_ram_table_permutation_argument = clk - * challenges.get_challenge(RamClkWeight) - + ramp * challenges.get_challenge(RamRampWeight) - + ramv * challenges.get_challenge(RamRamvWeight) - + previous_instruction * challenges.get_challenge(RamPreviousInstructionWeight); - ram_table_running_product *= challenges.get_challenge(RamIndeterminate) - - compressed_row_for_ram_table_permutation_argument; + let compressed_row_for_ram_table_permutation_argument = clk * challenges[RamClkWeight] + + ramp * challenges[RamRampWeight] + + ramv * challenges[RamRamvWeight] + + previous_instruction * challenges[RamPreviousInstructionWeight]; + ram_table_running_product *= + challenges[RamIndeterminate] - compressed_row_for_ram_table_permutation_argument; // JumpStack Table let ci = current_row[CI.base_table_index()]; let jsp = current_row[JSP.base_table_index()]; let jso = current_row[JSO.base_table_index()]; let jsd = current_row[JSD.base_table_index()]; - let compressed_row_for_jump_stack_table = clk - * challenges.get_challenge(JumpStackClkWeight) - + ci * challenges.get_challenge(JumpStackCiWeight) - + jsp * challenges.get_challenge(JumpStackJspWeight) - + jso * challenges.get_challenge(JumpStackJsoWeight) - + jsd * challenges.get_challenge(JumpStackJsdWeight); - jump_stack_running_product *= challenges.get_challenge(JumpStackIndeterminate) - - compressed_row_for_jump_stack_table; + let compressed_row_for_jump_stack_table = clk * challenges[JumpStackClkWeight] + + ci * challenges[JumpStackCiWeight] + + jsp * challenges[JumpStackJspWeight] + + jso * challenges[JumpStackJsoWeight] + + jsd * challenges[JumpStackJsdWeight]; + jump_stack_running_product *= + challenges[JumpStackIndeterminate] - compressed_row_for_jump_stack_table; // Hash Table – Hash's input from Processor to Hash Coprocessor let st_0_through_9 = [ST0, ST1, ST2, ST3, ST4, ST5, ST6, ST7, ST8, ST9] .map(|st| current_row[st.base_table_index()]); - let hash_state_weights = [ - HashStateWeight0, - HashStateWeight1, - HashStateWeight2, - HashStateWeight3, - HashStateWeight4, - HashStateWeight5, - HashStateWeight6, - HashStateWeight7, - HashStateWeight8, - HashStateWeight9, - ] - .map(|id| challenges.get_challenge(id)); + let hash_state_weights = &challenges[HashStateWeight0..HashStateWeight10]; let compressed_row_for_hash_input_and_sponge: XFieldElement = st_0_through_9 .into_iter() - .zip_eq(hash_state_weights.into_iter()) - .map(|(st, weight)| weight * st) + .zip_eq(hash_state_weights.iter()) + .map(|(st, &weight)| weight * st) .sum(); + let hash_digest_weights = &challenges[HashStateWeight0..HashStateWeight5]; let compressed_row_for_hash_digest: XFieldElement = st_0_through_9[5..=9] .iter() - .zip_eq(hash_state_weights[0..=4].iter()) + .zip_eq(hash_digest_weights.iter()) .map(|(&st, &weight)| weight * st) .sum(); if current_row[CI.base_table_index()] == Instruction::Hash.opcode_b() { hash_input_running_evaluation = hash_input_running_evaluation - * challenges.get_challenge(HashInputIndeterminate) + * challenges[HashInputIndeterminate] + compressed_row_for_hash_input_and_sponge; } @@ -269,7 +254,7 @@ impl ProcessorTable { if let Some(prev_row) = previous_row { if prev_row[CI.base_table_index()] == Instruction::Hash.opcode_b() { hash_digest_running_evaluation = hash_digest_running_evaluation - * challenges.get_challenge(HashDigestIndeterminate) + * challenges[HashDigestIndeterminate] + compressed_row_for_hash_digest; } } @@ -281,8 +266,8 @@ impl ProcessorTable { || prev_row[CI.base_table_index()] == Instruction::Squeeze.opcode_b() { sponge_running_evaluation = sponge_running_evaluation - * challenges.get_challenge(SpongeIndeterminate) - + challenges.get_challenge(HashCIWeight) * prev_row[CI.base_table_index()] + * challenges[SpongeIndeterminate] + + challenges[HashCIWeight] * prev_row[CI.base_table_index()] + compressed_row_for_hash_input_and_sponge; } } @@ -292,25 +277,23 @@ impl ProcessorTable { let previously_current_instruction = prev_row[CI.base_table_index()]; if previously_current_instruction == Instruction::Split.opcode_b() { let compressed_row = current_row[ST0.base_table_index()] - * challenges.get_challenge(U32LhsWeight) - + current_row[ST1.base_table_index()] - * challenges.get_challenge(U32RhsWeight) - + prev_row[CI.base_table_index()] * challenges.get_challenge(U32CiWeight); + * challenges[U32LhsWeight] + + current_row[ST1.base_table_index()] * challenges[U32RhsWeight] + + prev_row[CI.base_table_index()] * challenges[U32CiWeight]; u32_table_running_sum_log_derivative += - (challenges.get_challenge(U32Indeterminate) - compressed_row).inverse(); + (challenges[U32Indeterminate] - compressed_row).inverse(); } if previously_current_instruction == Instruction::Lt.opcode_b() || previously_current_instruction == Instruction::And.opcode_b() || previously_current_instruction == Instruction::Pow.opcode_b() { let compressed_row = prev_row[ST0.base_table_index()] - * challenges.get_challenge(U32LhsWeight) - + prev_row[ST1.base_table_index()] * challenges.get_challenge(U32RhsWeight) - + prev_row[CI.base_table_index()] * challenges.get_challenge(U32CiWeight) - + current_row[ST0.base_table_index()] - * challenges.get_challenge(U32ResultWeight); + * challenges[U32LhsWeight] + + prev_row[ST1.base_table_index()] * challenges[U32RhsWeight] + + prev_row[CI.base_table_index()] * challenges[U32CiWeight] + + current_row[ST0.base_table_index()] * challenges[U32ResultWeight]; u32_table_running_sum_log_derivative += - (challenges.get_challenge(U32Indeterminate) - compressed_row).inverse(); + (challenges[U32Indeterminate] - compressed_row).inverse(); } if previously_current_instruction == Instruction::Xor.opcode_b() { // Triton VM uses the following equality to compute the results of both the @@ -322,43 +305,38 @@ impl ProcessorTable { let st0 = current_row[ST0.base_table_index()]; let from_xor_in_processor_to_and_in_u32_coprocessor = (st0_prev + st1_prev - st0) / BFieldElement::new(2); - let compressed_row = st0_prev * challenges.get_challenge(U32LhsWeight) - + st1_prev * challenges.get_challenge(U32RhsWeight) - + Instruction::And.opcode_b() * challenges.get_challenge(U32CiWeight) + let compressed_row = st0_prev * challenges[U32LhsWeight] + + st1_prev * challenges[U32RhsWeight] + + Instruction::And.opcode_b() * challenges[U32CiWeight] + from_xor_in_processor_to_and_in_u32_coprocessor - * challenges.get_challenge(U32ResultWeight); + * challenges[U32ResultWeight]; u32_table_running_sum_log_derivative += - (challenges.get_challenge(U32Indeterminate) - compressed_row).inverse(); + (challenges[U32Indeterminate] - compressed_row).inverse(); } if previously_current_instruction == Instruction::Log2Floor.opcode_b() || previously_current_instruction == Instruction::PopCount.opcode_b() { let compressed_row = prev_row[ST0.base_table_index()] - * challenges.get_challenge(U32LhsWeight) - + prev_row[CI.base_table_index()] * challenges.get_challenge(U32CiWeight) - + current_row[ST0.base_table_index()] - * challenges.get_challenge(U32ResultWeight); + * challenges[U32LhsWeight] + + prev_row[CI.base_table_index()] * challenges[U32CiWeight] + + current_row[ST0.base_table_index()] * challenges[U32ResultWeight]; u32_table_running_sum_log_derivative += - (challenges.get_challenge(U32Indeterminate) - compressed_row).inverse(); + (challenges[U32Indeterminate] - compressed_row).inverse(); } if previously_current_instruction == Instruction::Div.opcode_b() { let compressed_row_for_lt_check = current_row[ST0.base_table_index()] - * challenges.get_challenge(U32LhsWeight) - + prev_row[ST1.base_table_index()] * challenges.get_challenge(U32RhsWeight) - + Instruction::Lt.opcode_b() * challenges.get_challenge(U32CiWeight) - + BFieldElement::one() * challenges.get_challenge(U32ResultWeight); + * challenges[U32LhsWeight] + + prev_row[ST1.base_table_index()] * challenges[U32RhsWeight] + + Instruction::Lt.opcode_b() * challenges[U32CiWeight] + + BFieldElement::one() * challenges[U32ResultWeight]; let compressed_row_for_range_check = prev_row[ST0.base_table_index()] - * challenges.get_challenge(U32LhsWeight) - + current_row[ST1.base_table_index()] - * challenges.get_challenge(U32RhsWeight) - + Instruction::Split.opcode_b() * challenges.get_challenge(U32CiWeight); + * challenges[U32LhsWeight] + + current_row[ST1.base_table_index()] * challenges[U32RhsWeight] + + Instruction::Split.opcode_b() * challenges[U32CiWeight]; u32_table_running_sum_log_derivative += - (challenges.get_challenge(U32Indeterminate) - compressed_row_for_lt_check) - .inverse(); - u32_table_running_sum_log_derivative += (challenges - .get_challenge(U32Indeterminate) - - compressed_row_for_range_check) - .inverse(); + (challenges[U32Indeterminate] - compressed_row_for_lt_check).inverse(); + u32_table_running_sum_log_derivative += + (challenges[U32Indeterminate] - compressed_row_for_range_check).inverse(); } } @@ -366,7 +344,7 @@ impl ProcessorTable { let lookup_multiplicity = current_row[ClockJumpDifferenceLookupMultiplicity.base_table_index()]; clock_jump_diff_lookup_op_stack_log_derivative += - (challenges.get_challenge(ClockJumpDifferenceLookupIndeterminate) - clk).inverse() + (challenges[ClockJumpDifferenceLookupIndeterminate] - clk).inverse() * lookup_multiplicity; let mut extension_row = ext_table.row_mut(row_idx); diff --git a/triton-vm/src/table/program_table.rs b/triton-vm/src/table/program_table.rs index 7fb7ab5d5..733d6de55 100644 --- a/triton-vm/src/table/program_table.rs +++ b/triton-vm/src/table/program_table.rs @@ -382,15 +382,12 @@ impl ProgramTable { assert_eq!(base_table.nrows(), ext_table.nrows()); let max_index_in_chunk = StarkHasher::RATE as u64 - 1; - let address_weight = challenges.get_challenge(ProgramAddressWeight); - let instruction_weight = challenges.get_challenge(ProgramInstructionWeight); - let next_instruction_weight = challenges.get_challenge(ProgramNextInstructionWeight); - let instruction_lookup_indeterminate = - challenges.get_challenge(InstructionLookupIndeterminate); - let prepare_chunk_indeterminate = - challenges.get_challenge(ProgramAttestationPrepareChunkIndeterminate); - let send_chunk_indeterminate = - challenges.get_challenge(ProgramAttestationSendChunkIndeterminate); + let address_weight = challenges[ProgramAddressWeight]; + let instruction_weight = challenges[ProgramInstructionWeight]; + let next_instruction_weight = challenges[ProgramNextInstructionWeight]; + let instruction_lookup_indeterminate = challenges[InstructionLookupIndeterminate]; + let prepare_chunk_indeterminate = challenges[ProgramAttestationPrepareChunkIndeterminate]; + let send_chunk_indeterminate = challenges[ProgramAttestationSendChunkIndeterminate]; let mut instruction_lookup_log_derivative = LookupArg::default_initial(); let mut prepare_chunk_running_evaluation = EvalArg::default_initial(); diff --git a/triton-vm/src/table/ram_table.rs b/triton-vm/src/table/ram_table.rs index 4d9f4f905..709e37bfe 100644 --- a/triton-vm/src/table/ram_table.rs +++ b/triton-vm/src/table/ram_table.rs @@ -235,15 +235,14 @@ impl RamTable { assert_eq!(EXT_WIDTH, ext_table.ncols()); assert_eq!(base_table.nrows(), ext_table.nrows()); - let clk_weight = challenges.get_challenge(RamClkWeight); - let ramp_weight = challenges.get_challenge(RamRampWeight); - let ramv_weight = challenges.get_challenge(RamRamvWeight); - let previous_instruction_weight = challenges.get_challenge(RamPreviousInstructionWeight); - let processor_perm_indeterminate = challenges.get_challenge(RamIndeterminate); - let bezout_relation_indeterminate = - challenges.get_challenge(RamTableBezoutRelationIndeterminate); + let clk_weight = challenges[RamClkWeight]; + let ramp_weight = challenges[RamRampWeight]; + let ramv_weight = challenges[RamRamvWeight]; + let previous_instruction_weight = challenges[RamPreviousInstructionWeight]; + let processor_perm_indeterminate = challenges[RamIndeterminate]; + let bezout_relation_indeterminate = challenges[RamTableBezoutRelationIndeterminate]; let clock_jump_difference_lookup_indeterminate = - challenges.get_challenge(ClockJumpDifferenceLookupIndeterminate); + challenges[ClockJumpDifferenceLookupIndeterminate]; let mut running_product_for_perm_arg = PermArg::default_initial(); let mut clock_jump_diff_lookup_log_derivative = LookupArg::default_initial(); diff --git a/triton-vm/src/table/u32_table.rs b/triton-vm/src/table/u32_table.rs index be035d91a..df8b1ad5c 100644 --- a/triton-vm/src/table/u32_table.rs +++ b/triton-vm/src/table/u32_table.rs @@ -570,11 +570,11 @@ impl U32Table { assert_eq!(EXT_WIDTH, ext_table.ncols()); assert_eq!(base_table.nrows(), ext_table.nrows()); - let ci_weight = challenges.get_challenge(U32CiWeight); - let lhs_weight = challenges.get_challenge(U32LhsWeight); - let rhs_weight = challenges.get_challenge(U32RhsWeight); - let result_weight = challenges.get_challenge(U32ResultWeight); - let lookup_indeterminate = challenges.get_challenge(U32Indeterminate); + let ci_weight = challenges[U32CiWeight]; + let lhs_weight = challenges[U32LhsWeight]; + let rhs_weight = challenges[U32RhsWeight]; + let result_weight = challenges[U32ResultWeight]; + let lookup_indeterminate = challenges[U32Indeterminate]; let mut running_sum_log_derivative = LookupArg::default_initial(); for row_idx in 0..base_table.nrows() {