Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Golovanov399 committed Jan 21, 2025
1 parent 4b7f57e commit b772fb0
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 13 deletions.
6 changes: 3 additions & 3 deletions extensions/bigint/circuit/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ fn run_mul_256_rand_test(num_ops: usize) {
);

run_int_256_rand_execute(
MulOpcode::MUL as usize,
MulOpcode::MUL.global_opcode().as_usize(),
num_ops,
&mut chip,
&mut tester,
Expand Down Expand Up @@ -285,7 +285,7 @@ fn run_beq_256_rand_test(opcode: BranchEqualOpcode, num_ops: usize) {
x.iter()
.zip(y.iter())
.fold(true, |acc, (x, y)| acc && (x == y))
^ (opcode == BranchEqualOpcode::BNE as usize)
^ (opcode == BranchEqualOpcode::BNE.global_opcode().as_usize())
};

run_int_256_rand_execute(
Expand Down Expand Up @@ -327,7 +327,7 @@ fn run_blt_256_rand_test(opcode: BranchLessThanOpcode, num_ops: usize) {
);

let branch_fn = |opcode: usize, x: &[u32; INT256_NUM_LIMBS], y: &[u32; INT256_NUM_LIMBS]| {
let opcode = BranchLessThanOpcode::from_usize(opcode);
let opcode = BranchLessThanOpcode::from_usize(opcode - BranchLessThanOpcode::CLASS_OFFSET);
let (is_ge, is_signed) = match opcode {
BranchLessThanOpcode::BLT => (false, true),
BranchLessThanOpcode::BLTU => (false, false),
Expand Down
2 changes: 1 addition & 1 deletion extensions/native/circuit/src/field_extension/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ where
builder.assert_bool(flag);

is_valid += flag.into();
expected_opcode += flag * AB::F::from_canonical_usize(opcode as usize);
expected_opcode += flag * AB::F::from_canonical_usize(opcode.local_usize());

for (j, result_part) in result.into_iter().enumerate() {
expected_result[j] += flag * result_part;
Expand Down
2 changes: 1 addition & 1 deletion extensions/native/circuit/src/poseidon2/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ fn tester_with_random_poseidon2_ops(
tester.write_cell(d, c, BabyBear::from_canonical_usize(rhs));
}

let local_opcode = Poseidon2Opcode::from_usize(opcode - Poseidon2Opcode::CLASS_OFFSET);
let local_opcode = Poseidon2Opcode::from_usize(opcode);

match local_opcode {
Poseidon2Opcode::COMP_POS2 => {
Expand Down
30 changes: 24 additions & 6 deletions extensions/rv32im/circuit/src/less_than/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,14 @@ fn run_rv32_lt_rand_test(opcode: LessThanOpcode, num_ops: usize) {
(Some(imm), c)
};

let (instruction, rd) =
rv32_rand_write_register_or_imm(&mut tester, b, c, c_imm, opcode as usize, &mut rng);
let (instruction, rd) = rv32_rand_write_register_or_imm(
&mut tester,
b,
c,
c_imm,
opcode.global_opcode().as_usize(),
&mut rng,
);
tester.execute(&mut chip, &instruction);

let (cmp, _, _, _) =
Expand All @@ -83,13 +89,25 @@ fn run_rv32_lt_rand_test(opcode: LessThanOpcode, num_ops: usize) {

// Test special case where b = c
let b = [101, 128, 202, 255];
let (instruction, _) =
rv32_rand_write_register_or_imm(&mut tester, b, b, None, opcode as usize, &mut rng);
let (instruction, _) = rv32_rand_write_register_or_imm(
&mut tester,
b,
b,
None,
opcode.global_opcode().as_usize(),
&mut rng,
);
tester.execute(&mut chip, &instruction);

let b = [36, 0, 0, 0];
let (instruction, _) =
rv32_rand_write_register_or_imm(&mut tester, b, b, Some(36), opcode as usize, &mut rng);
let (instruction, _) = rv32_rand_write_register_or_imm(
&mut tester,
b,
b,
Some(36),
opcode.global_opcode().as_usize(),
&mut rng,
);
tester.execute(&mut chip, &instruction);

let tester = tester.build().load(chip).load(bitwise_chip).finalize();
Expand Down
10 changes: 8 additions & 2 deletions extensions/rv32im/circuit/src/shift/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,14 @@ fn run_rv32_shift_rand_test(opcode: ShiftOpcode, num_ops: usize) {
(Some(imm), c)
};

let (instruction, rd) =
rv32_rand_write_register_or_imm(&mut tester, b, c, c_imm, opcode as usize, &mut rng);
let (instruction, rd) = rv32_rand_write_register_or_imm(
&mut tester,
b,
c,
c_imm,
opcode.global_opcode().as_usize(),
&mut rng,
);
tester.execute(&mut chip, &instruction);

let (a, _, _) = run_shift::<RV32_REGISTER_NUM_LIMBS, RV32_CELL_BITS>(opcode, &b, &c);
Expand Down

0 comments on commit b772fb0

Please sign in to comment.