Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions bitcoin-script-riscv/src/riscv/script_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -949,8 +949,8 @@ pub fn multiply(

logic_table.drop(stack);

let modulo = modulo_table(stack, 128);
let quotient = quotient_table_ex(stack, 128);
let modulo = modulo_table(stack, 135);
let quotient = quotient_table_ex(stack, 135);

for _ in 0..15 {
stack.from_altstack();
Expand Down Expand Up @@ -1691,6 +1691,33 @@ mod tests {
test_multiply_aux(0xFFFF_FFFF, 0xFFFF_FFFF, 0xFFFF_FFFE, 0x0000_0001);
test_multiply_aux(0x0, 0xFFFF_FFFF, 0, 0);
test_multiply_aux(0xFFFF_FFFF, 0x1, 0x0, 0xFFFF_FFFF);
test_multiply_aux(0x1B49_F21B, 0x1F51_E1ED, 0x0356_AECC, 0x20C9_DDFF);
}

fn test_mulh_aux(a: i32, b: i32, expected: i32) {
let mut stack = StackTracker::new();
let tables = StackTables::new(&mut stack, true, true, 0, 0, 0);


let a = stack.number_u32(a as u32);
let b = stack.number_u32(b as u32);

let result = mulh(&mut stack, &tables, a, b, false);

let expected = stack.number_u32(expected as u32);

stack.equals(result, true, expected, true);
tables.drop(&mut stack);

stack.op_true();

assert!(stack.run().success);
}

#[test]
fn test_mulh() {
test_mulh_aux(-0x7BDD_925D, -0x7F37_3DED, 0x3D8D_A62D);
test_mulh_aux(0x2A37_E15A, -0xC16_20C2, -0x1FE_44C5);
}

fn test_division_aux(
Expand Down
4 changes: 2 additions & 2 deletions emulator/tests/audit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fn audit_tests() {
if let Ok(path) = path {
let fname = path.file_name();
let fname = fname.to_string_lossy();
if fname.ends_with("verify.elf") && fname.contains("09") {
if fname.ends_with("verify.elf") && (fname.contains("09") || fname.contains("12")) || fname.contains("13") {
let path = path.path();
let path = path.to_string_lossy();

Expand All @@ -31,5 +31,5 @@ fn audit_tests() {
}

info!("Total files executed: {}", count);
assert_eq!(count, 1);
assert_eq!(count, 3);
}
13 changes: 10 additions & 3 deletions emulator/tests/utils/common.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
#![allow(dead_code)]
use bitvmx_cpu_definitions::{memory::SectionDefinition, trace::ProgramCounter};
use emulator::{executor::{fetcher::{execute_program, FullTrace}, utils::FailConfiguration}, loader::program::{load_elf, Program, Registers, Section}, EmulatorError, ExecutionResult};
use emulator::{
executor::{
fetcher::{execute_program, FullTrace},
utils::FailConfiguration,
},
loader::program::{load_elf, Program, Registers, Section},
EmulatorError, ExecutionResult,
};
use rand::Rng;
use riscv_decode::types::{BType, IType, JType, RType, SType, ShiftType, UType};
use tracing::info;
use std::ops::RangeInclusive;
use tracing::info;

const PROGRAM_REG_RANGE: RangeInclusive<u32> = 0x1..=0x1F;

Expand Down Expand Up @@ -106,4 +113,4 @@ pub fn verify_file(
FailConfiguration::default(),
false,
))
}
}