Skip to content

Commit

Permalink
style: Use bfe_array! and bfe_vec! macros more
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-ferdinand committed Jun 10, 2024
1 parent dd496f7 commit 6ff8500
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
4 changes: 2 additions & 2 deletions triton-vm/src/arithmetic_domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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] {
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion triton-vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
6 changes: 3 additions & 3 deletions triton-vm/src/table/ram_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
19 changes: 9 additions & 10 deletions triton-vm/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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`.
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 6ff8500

Please sign in to comment.