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
93 changes: 0 additions & 93 deletions .github/workflows/rust.yml

This file was deleted.

31 changes: 31 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: 'Settings Test Action'

on:
push:
branches: [ "main", "dev" ]
pull_request:
branches: [ "main", "dev" ]

env:
CARGO_TERM_COLOR: always

permissions:
actions: read
checks: write
contents: read
pull-requests: write

concurrency:
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
cancel-in-progress: true

jobs:
test:
uses: FairgateLabs/BitVMX-CI/.github/workflows/ci_local_template.yml@main
with:
repo: 'FairgateLabs/BitVMX-CPU'
submodule_path: 'BitVMX-CPU'
cargo_lock_path: 'BitVMX-CPU/Cargo.lock'
target_path: 'BitVMX-CPU/target'
clippy: true
secrets: inherit
1 change: 1 addition & 0 deletions bitcoin-script-riscv/src/riscv/challenges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ pub fn trace_hash_zero_challenge(stack: &mut StackTracker) {
stack.not_equal(result, true, hash, true);
}

#[allow(clippy::too_many_arguments)]
fn is_invalid_read(
stack: &mut StackTracker,
half_nibble_table: &StackVariable,
Expand Down
11 changes: 4 additions & 7 deletions bitcoin-script-riscv/src/riscv/instruction_mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ fn name_or_nop_with_micro<X: RdZero>(x: &X, name: &str, micro: u8) -> String {
}

pub fn requires_witness(instruction: &Instruction) -> bool {
match instruction {
Div(_) | Divu(_) | Rem(_) | Remu(_) => true,
_ => false,
}
matches!(instruction, Div(_) | Divu(_) | Rem(_) | Remu(_))
}

pub fn get_key_from_instruction_and_micro(instruction: &Instruction, micro: u8) -> String {
Expand Down Expand Up @@ -224,17 +221,17 @@ pub fn generate_verification_script(
};

let trace_read = STraceRead::define(&mut stack);
let mut result = execute_step(
let result = execute_step(
&mut stack,
&trace_read,
&trace_step,
witness,
&instruction,
instruction,
micro,
program,
)
.unwrap();
compare_trace_step(&mut stack, &trace_step, &mut result);
compare_trace_step(&mut stack, &trace_step, &result);
stack.get_script()
}

Expand Down
9 changes: 5 additions & 4 deletions bitcoin-script-riscv/src/riscv/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ pub fn op_conditional(
trace
}

#[allow(clippy::too_many_arguments)]
pub fn store_if_not_zero(
stack: &mut StackTracker,
tables: &StackTables,
Expand Down Expand Up @@ -787,7 +788,7 @@ pub fn execute_step(
program: ProgramSpec,
) -> Result<STraceStep, ScriptValidation> {
match instruction {
Fence(_) | Ebreak => Ok(op_nop(stack, &trace_read)),
Fence(_) | Ebreak => Ok(op_nop(stack, trace_read)),

Ecall => Ok(op_ecall(stack, trace_read, program.base_register_address)),

Expand Down Expand Up @@ -860,7 +861,7 @@ pub fn execute_step(
Mul(x) | Mulh(x) | Mulhsu(x) | Mulhu(x) | Div(x) | Divu(x) | Rem(x) | Remu(x) | Xor(x)
| And(x) | Or(x) | Slt(x) | Sltu(x) | Sll(x) | Srl(x) | Sra(x) | Add(x) | Sub(x) => {
if x.rd() == 0 {
Ok(op_nop(stack, &trace_read))
Ok(op_nop(stack, trace_read))
} else {
Ok(op_arithmetic(
instruction,
Expand Down Expand Up @@ -948,7 +949,7 @@ pub fn verify_execution(
let instruction = riscv_decode::decode(opcode).unwrap();
println!("instruction to verify: {:?}", instruction);
// println!("instruction to hex: {:2x}", instruction.into());
let mut result_step = execute_step(
let result_step = execute_step(
stack,
&trace_read,
&trace_step,
Expand All @@ -957,7 +958,7 @@ pub fn verify_execution(
micro,
program,
)?;
compare_trace_step(stack, &trace_step, &mut result_step);
compare_trace_step(stack, &trace_step, &result_step);

Ok(())
}
Expand Down
30 changes: 15 additions & 15 deletions bitcoin-script-riscv/src/riscv/script_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,7 @@ pub fn left_rotate(
stack.from_altstack_joined(8, "left_rotated")
}

#[allow(clippy::too_many_arguments)]
fn multiply_nib(
stack: &mut StackTracker,
logic_table: &StackLogicTables,
Expand Down Expand Up @@ -930,9 +931,8 @@ pub fn multiply(
let end_i = if k >= n { k - n + 1 } else { 0 };

let elements_in_diag = (start_i - end_i) + 1;
let mut count = 0;

for i in (end_i..=start_i).rev() {
for (count, i) in (end_i..=start_i).rev().enumerate() {
let j = k - i;
multiply_nib(
stack,
Expand All @@ -946,7 +946,6 @@ pub fn multiply(
elements_in_diag > 1 && count > 0,
);
total_count += 1;
count += 1;
}
}

Expand Down Expand Up @@ -1245,9 +1244,9 @@ pub fn div_by_zero_case(
stack_true.drop(remainder);
stack_true.drop(quotient);
stack_true.drop(divisor);
if result.is_some() {
if let Some(result) = result {
stack_true.drop(dividend);
stack_true.number_u32(result.unwrap());
stack_true.number_u32(result);
}

(stack_true, stack_false)
Expand All @@ -1261,8 +1260,8 @@ pub fn overflow_case(
remainder: StackVariable,
result: Option<u32>,
) -> (StackTracker, StackTracker) {
let minus_one = stack.number_u32(-1 as i32 as u32);
let min_i32 = stack.number_u32(std::i32::MIN as u32);
let minus_one = stack.number_u32(-1_i32 as u32);
let min_i32 = stack.number_u32(i32::MIN as u32);
is_equal_to(stack, &minus_one, &divisor);
is_equal_to(stack, &min_i32, &dividend);
stack.op_booland();
Expand All @@ -1275,14 +1274,15 @@ pub fn overflow_case(
stack_true.drop(remainder);
stack_true.drop(quotient);
stack_true.drop(divisor);
if result.is_some() {
if let Some(result) = result {
stack_true.drop(dividend);
stack_true.number_u32(result.unwrap());
stack_true.number_u32(result);
}

(stack_true, stack_false)
}

#[allow(clippy::too_many_arguments)]
pub fn division_and_remainder(
stack: &mut StackTracker,
tables: &StackTables,
Expand Down Expand Up @@ -1348,7 +1348,7 @@ pub fn divu(
divisor,
quotient,
remainder,
Some(std::u32::MAX),
Some(u32::MAX),
false,
)
}
Expand All @@ -1366,6 +1366,7 @@ pub fn remu(
)
}

#[allow(clippy::too_many_arguments)]
pub fn division_and_remainder_signed(
stack: &mut StackTracker,
tables: &StackTables,
Expand Down Expand Up @@ -1456,8 +1457,8 @@ pub fn div(
divisor,
quotient,
remainder,
Some(-1 as i32 as u32),
Some(std::i32::MIN as u32),
Some(-1_i32 as u32),
Some(i32::MIN as u32),
false,
)
}
Expand Down Expand Up @@ -1510,7 +1511,7 @@ pub fn verify_wrong_chunk_value(
let chunk_table = WordTable::new(stack, chunk.data.clone());

let base_addr = stack.number_u32(chunk.base_addr);
let offset = sub(stack, &tables, address, base_addr);
let offset = sub(stack, tables, address, base_addr);

let index = static_right_shift_2(stack, tables, offset);

Expand Down Expand Up @@ -1548,7 +1549,7 @@ pub fn get_selected_vars<const N: usize>(
stack.op_equal();
let (mut chose_var_1, mut chose_var_2) = stack.open_if();

for (var_1, var_2) in vars_1.into_iter().zip(vars_2.into_iter()) {
for (var_1, var_2) in vars_1.into_iter().zip(vars_2) {
chose_var_1.move_var(var_2);
chose_var_1.drop(var_2);

Expand All @@ -1559,7 +1560,6 @@ pub fn get_selected_vars<const N: usize>(
stack
.end_if(chose_var_1, chose_var_2, consumes, output, 0)
.try_into()
.ok()
.expect("Vec length does not match expected array size")
}

Expand Down
9 changes: 5 additions & 4 deletions definitions/src/challenge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ impl EmulatorResultType {
.map_err(|e| EmulatorResultError::GenericError(format!("Failed to serialize: {}", e)))
}

#[allow(clippy::type_complexity)]
pub fn as_prover_execute(
&self,
) -> Result<(u64, String, Option<(u32, u64)>), EmulatorResultError> {
Expand All @@ -259,7 +260,7 @@ impl EmulatorResultType {
last_step,
last_hash,
halt,
} => Ok((*last_step, last_hash.clone(), halt.clone())),
} => Ok((*last_step, last_hash.clone(), *halt)),
_ => Err(EmulatorResultError::GenericError(
"Expected ProverExecuteResult".to_string(),
)),
Expand All @@ -268,7 +269,7 @@ impl EmulatorResultType {

pub fn as_verifier_check(&self) -> Result<Option<u64>, EmulatorResultError> {
match self {
EmulatorResultType::VerifierCheckExecutionResult { step } => Ok(step.clone()),
EmulatorResultType::VerifierCheckExecutionResult { step } => Ok(*step),
_ => Err(EmulatorResultError::GenericError(
"Expected VerifierCheckExecutionResult".to_string(),
)),
Expand All @@ -278,7 +279,7 @@ impl EmulatorResultType {
pub fn as_prover_hashes(&self) -> Result<(Vec<String>, u8), EmulatorResultError> {
match self {
EmulatorResultType::ProverGetHashesForRoundResult { hashes, round } => {
Ok((hashes.clone(), round.clone()))
Ok((hashes.clone(), *round))
}
_ => Err(EmulatorResultError::GenericError(
"Expected ProverGetHashesForRoundResult".to_string(),
Expand All @@ -289,7 +290,7 @@ impl EmulatorResultType {
pub fn as_v_decision(&self) -> Result<(u32, u8), EmulatorResultError> {
match self {
EmulatorResultType::VerifierChooseSegmentResult { v_decision, round } => {
Ok((*v_decision, round.clone()))
Ok((*v_decision, *round))
}
_ => Err(EmulatorResultError::GenericError(
"Expected VerifierChooseSegmentResult".to_string(),
Expand Down
6 changes: 3 additions & 3 deletions definitions/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ pub enum MemoryAccessType {
Unused,
}

impl Into<u8> for MemoryAccessType {
fn into(self) -> u8 {
match self {
impl From<MemoryAccessType> for u8 {
fn from(value: MemoryAccessType) -> Self {
match value {
MemoryAccessType::Register => memory_access_type::REGISTER,
MemoryAccessType::Memory => memory_access_type::MEMORY,
MemoryAccessType::Unused => memory_access_type::UNUSED,
Expand Down
Loading
Loading