From 6ff8500ec408ecea006fcb6df00a00d7473bcb47 Mon Sep 17 00:00:00 2001 From: Jan Ferdinand Sauer Date: Mon, 10 Jun 2024 12:08:11 +0200 Subject: [PATCH] style: Use `bfe_array!` and `bfe_vec!` macros more --- triton-vm/src/arithmetic_domain.rs | 4 ++-- triton-vm/src/lib.rs | 2 +- triton-vm/src/table/ram_table.rs | 6 +++--- triton-vm/src/vm.rs | 19 +++++++++---------- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/triton-vm/src/arithmetic_domain.rs b/triton-vm/src/arithmetic_domain.rs index cd6804dac..f98abcf71 100644 --- a/triton-vm/src/arithmetic_domain.rs +++ b/triton-vm/src/arithmetic_domain.rs @@ -208,7 +208,7 @@ mod tests { #[test] fn domain_values() { - let x_cubed_coefficients = [0, 0, 0, 1].map(BFieldElement::new).to_vec(); + let x_cubed_coefficients = bfe_vec![0, 0, 0, 1]; let poly = Polynomial::new(x_cubed_coefficients.clone()); for order in [4, 8, 32] { @@ -259,7 +259,7 @@ mod tests { let short_domain = ArithmeticDomain::of_length(short_domain_len).unwrap(); let long_domain = ArithmeticDomain::of_length(long_domain_len).unwrap(); - let polynomial = Polynomial::new([1, 2, 3, 4].map(BFieldElement::new).to_vec()); + let polynomial = Polynomial::new(bfe_vec![1, 2, 3, 4]); let short_codeword = short_domain.evaluate(&polynomial); let long_codeword = short_domain.low_degree_extension(&short_codeword, long_domain); diff --git a/triton-vm/src/lib.rs b/triton-vm/src/lib.rs index 1a24b79e0..6ae88d420 100644 --- a/triton-vm/src/lib.rs +++ b/triton-vm/src/lib.rs @@ -817,7 +817,7 @@ mod tests { let program = triton_program!({ &source_code }); let public_output = program.run([].into(), [].into()).unwrap(); - let expected_output = [9, 8, 7, 6].map(BFieldElement::new).to_vec(); + let expected_output = bfe_vec![9, 8, 7, 6]; assert_eq!(expected_output, public_output); } diff --git a/triton-vm/src/table/ram_table.rs b/triton-vm/src/table/ram_table.rs index 91ace01f1..28068c30e 100644 --- a/triton-vm/src/table/ram_table.rs +++ b/triton-vm/src/table/ram_table.rs @@ -658,11 +658,11 @@ pub(crate) mod tests { #[test] fn bezout_coefficient_polynomials_are_as_expected() { - let rp = [1, 2, 3].map(BFieldElement::new); + let rp = bfe_array![1, 2, 3]; let (a, b) = RamTable::bezout_coefficient_polynomials_coefficients(&rp); - let expected_a = [9, 0x7fff_ffff_7fff_fffc, 0].map(BFieldElement::new); - let expected_b = [5, 0xffff_fffe_ffff_fffb, 0x7fff_ffff_8000_0002].map(BFieldElement::new); + let expected_a = bfe_array![9, 0x7fff_ffff_7fff_fffc_u64, 0]; + let expected_b = bfe_array![5, 0xffff_fffe_ffff_fffb_u64, 0x7fff_ffff_8000_0002_u64]; assert_eq!(expected_a, *a); assert_eq!(expected_b, *b); diff --git a/triton-vm/src/vm.rs b/triton-vm/src/vm.rs index a53bbe60c..062a97b3d 100644 --- a/triton-vm/src/vm.rs +++ b/triton-vm/src/vm.rs @@ -152,7 +152,6 @@ impl VMState { hvs[0] = st0.inverse_or_zero(); let next_opcode = self.next_instruction_or_argument().value(); let decomposition = Self::decompose_opcode_for_instruction_skiz(next_opcode); - let decomposition = decomposition.map(BFieldElement::new); hvs[1..6].copy_from_slice(&decomposition); } RecurseOrReturn => hvs[0] = (self.op_stack[ST6] - self.op_stack[ST5]).inverse_or_zero(), @@ -200,14 +199,14 @@ impl VMState { hvs } - fn decompose_opcode_for_instruction_skiz(opcode: u64) -> [u64; 5] { - let mut decomposition = [0; 5]; - decomposition[0] = opcode % 2; - decomposition[1] = (opcode >> 1) % 4; - decomposition[2] = (opcode >> 3) % 4; - decomposition[3] = (opcode >> 5) % 4; - decomposition[4] = opcode >> 7; - decomposition + fn decompose_opcode_for_instruction_skiz(opcode: u64) -> [BFieldElement; 5] { + bfe_array![ + opcode % 2, + (opcode >> 1) % 4, + (opcode >> 3) % 4, + (opcode >> 5) % 4, + opcode >> 7, + ] } /// Perform the state transition as a mutable operation on `self`. @@ -1560,7 +1559,7 @@ pub(crate) mod tests { let program = triton_program!(push {st0} split read_io 1 eq assert read_io 1 eq assert halt); - ProgramAndInput::new(program).with_input([lo, hi].map(BFieldElement::new)) + ProgramAndInput::new(program).with_input(bfe_array![lo, hi]) } pub(crate) fn test_program_for_eq() -> ProgramAndInput {