From 446de798a9a6b74ae7fda8ef6ff5a30038824c53 Mon Sep 17 00:00:00 2001 From: Kevin Wahle <62912263+KevinWahle@users.noreply.github.com> Date: Mon, 31 Aug 2026 16:39:09 -0300 Subject: [PATCH 1/6] solve clippy --- bitcoin-script-riscv/src/riscv/challenges.rs | 1 + .../src/riscv/instruction_mapping.rs | 11 +-- .../src/riscv/instructions.rs | 9 +- .../src/riscv/script_utils.rs | 33 +++---- definitions/src/challenge.rs | 9 +- definitions/src/memory.rs | 6 +- definitions/src/trace.rs | 4 +- emulator/src/decision/challenge.rs | 11 ++- emulator/src/decision/execution_log.rs | 10 +- emulator/src/decision/nary_search.rs | 19 ++-- emulator/src/executor/fetcher.rs | 97 +++++++++---------- emulator/src/executor/utils.rs | 24 ++--- emulator/src/executor/verifier.rs | 4 +- emulator/src/loader/program.rs | 20 ++-- emulator/src/loader/program_definition.rs | 7 +- emulator/src/main.rs | 14 +-- 16 files changed, 138 insertions(+), 141 deletions(-) diff --git a/bitcoin-script-riscv/src/riscv/challenges.rs b/bitcoin-script-riscv/src/riscv/challenges.rs index 84bf96e..c9239a5 100644 --- a/bitcoin-script-riscv/src/riscv/challenges.rs +++ b/bitcoin-script-riscv/src/riscv/challenges.rs @@ -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, diff --git a/bitcoin-script-riscv/src/riscv/instruction_mapping.rs b/bitcoin-script-riscv/src/riscv/instruction_mapping.rs index e65f003..7c1f3af 100644 --- a/bitcoin-script-riscv/src/riscv/instruction_mapping.rs +++ b/bitcoin-script-riscv/src/riscv/instruction_mapping.rs @@ -58,10 +58,7 @@ fn name_or_nop_with_micro(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 { @@ -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() } diff --git a/bitcoin-script-riscv/src/riscv/instructions.rs b/bitcoin-script-riscv/src/riscv/instructions.rs index a7c43ea..a5e2e85 100644 --- a/bitcoin-script-riscv/src/riscv/instructions.rs +++ b/bitcoin-script-riscv/src/riscv/instructions.rs @@ -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, @@ -787,7 +788,7 @@ pub fn execute_step( program: ProgramSpec, ) -> Result { 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)), @@ -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, @@ -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, @@ -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(()) } diff --git a/bitcoin-script-riscv/src/riscv/script_utils.rs b/bitcoin-script-riscv/src/riscv/script_utils.rs index 9f9d898..d917e91 100644 --- a/bitcoin-script-riscv/src/riscv/script_utils.rs +++ b/bitcoin-script-riscv/src/riscv/script_utils.rs @@ -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, @@ -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, @@ -946,7 +946,6 @@ pub fn multiply( elements_in_diag > 1 && count > 0, ); total_count += 1; - count += 1; } } @@ -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) @@ -1261,8 +1260,8 @@ pub fn overflow_case( remainder: StackVariable, result: Option, ) -> (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, ÷nd); stack.op_booland(); @@ -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, @@ -1348,7 +1348,7 @@ pub fn divu( divisor, quotient, remainder, - Some(std::u32::MAX), + Some(u32::MAX), false, ) } @@ -1366,6 +1366,7 @@ pub fn remu( ) } +#[allow(clippy::too_many_arguments)] pub fn division_and_remainder_signed( stack: &mut StackTracker, tables: &StackTables, @@ -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, ) } @@ -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); @@ -1548,7 +1549,7 @@ pub fn get_selected_vars( 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); @@ -1558,9 +1559,7 @@ pub fn get_selected_vars( stack .end_if(chose_var_1, chose_var_2, consumes, output, 0) - .try_into() - .ok() - .expect("Vec length does not match expected array size") + .try_into().expect("Vec length does not match expected array size") } pub fn address_in_range(stack: &mut StackTracker, range: &(u32, u32), address: &StackVariable) { diff --git a/definitions/src/challenge.rs b/definitions/src/challenge.rs index 3c65921..bf94a03 100644 --- a/definitions/src/challenge.rs +++ b/definitions/src/challenge.rs @@ -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> { @@ -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(), )), @@ -268,7 +269,7 @@ impl EmulatorResultType { pub fn as_verifier_check(&self) -> Result, EmulatorResultError> { match self { - EmulatorResultType::VerifierCheckExecutionResult { step } => Ok(step.clone()), + EmulatorResultType::VerifierCheckExecutionResult { step } => Ok(*step), _ => Err(EmulatorResultError::GenericError( "Expected VerifierCheckExecutionResult".to_string(), )), @@ -278,7 +279,7 @@ impl EmulatorResultType { pub fn as_prover_hashes(&self) -> Result<(Vec, u8), EmulatorResultError> { match self { EmulatorResultType::ProverGetHashesForRoundResult { hashes, round } => { - Ok((hashes.clone(), round.clone())) + Ok((hashes.clone(), *round)) } _ => Err(EmulatorResultError::GenericError( "Expected ProverGetHashesForRoundResult".to_string(), @@ -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(), diff --git a/definitions/src/memory.rs b/definitions/src/memory.rs index 7ac209e..c90eff0 100644 --- a/definitions/src/memory.rs +++ b/definitions/src/memory.rs @@ -18,9 +18,9 @@ pub enum MemoryAccessType { Unused, } -impl Into for MemoryAccessType { - fn into(self) -> u8 { - match self { +impl From 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, diff --git a/definitions/src/trace.rs b/definitions/src/trace.rs index 80b537b..7fdd4b5 100644 --- a/definitions/src/trace.rs +++ b/definitions/src/trace.rs @@ -98,7 +98,7 @@ impl TraceStep { ) -> TraceStep { TraceStep { write_1: TraceWrite::new(write_address, write_value), - write_pc: ProgramCounter::new(program_counter as u32, micro), + write_pc: ProgramCounter::new(program_counter, micro), } } @@ -198,7 +198,7 @@ impl FromStr for TraceRWStep { pub fn compute_step_hash( hasher: &mut Hasher, previous_hash: &[u8; 20], - write_trace: &Vec, + write_trace: &[u8], ) -> [u8; 20] { // Compute the Blake3 hash hasher.reset(); diff --git a/emulator/src/decision/challenge.rs b/emulator/src/decision/challenge.rs index 5a26957..7572a9f 100644 --- a/emulator/src/decision/challenge.rs +++ b/emulator/src/decision/challenge.rs @@ -53,7 +53,7 @@ pub fn prover_execute( ); // TODO: Enable this in production to avoid commiting a failed claim if !force { - return Err(result)?; + return Err(result.into()); } error!("Execution with force. The claim will be commited on-chain."); } @@ -123,6 +123,7 @@ pub fn prover_get_hashes_for_round( Ok(hashes) } +#[allow(clippy::too_many_arguments)] pub fn verifier_check_execution( program_definition_file: &str, input: Vec, @@ -369,7 +370,7 @@ pub fn prover_get_hashes_and_step( pub fn get_hashes( mapping: &HashMap, - hashes: &Vec>, + hashes: &[Vec], challenge_step: u64, ) -> (String, String) { let next_step = challenge_step + 1; @@ -429,6 +430,7 @@ fn find_chunk_index(chunks: &[Chunk], address: u32) -> Option { }) } +#[allow(clippy::too_many_arguments)] pub fn verifier_choose_challenge( program_definition_file: &str, input_checkpoint_path: &str, @@ -717,8 +719,8 @@ pub fn verifier_choose_challenge( let value = program.read_mem(conflict_address, false)?; return Ok(ChallengeType::InputData { - prover_read_1: prover_read_1, - prover_read_2: prover_read_2, + prover_read_1, + prover_read_2, address: conflict_address, input_for_address: value, }); @@ -799,6 +801,7 @@ pub fn verifier_choose_challenge( Ok(ChallengeType::No) } +#[allow(clippy::too_many_arguments)] pub fn verifier_choose_challenge_for_read_challenge( program_definition_file: &str, input_checkpoint_path: &str, diff --git a/emulator/src/decision/execution_log.rs b/emulator/src/decision/execution_log.rs index 8110487..735f945 100644 --- a/emulator/src/decision/execution_log.rs +++ b/emulator/src/decision/execution_log.rs @@ -139,12 +139,12 @@ pub fn deserialize_challenge_log Deserialize<'a>>( ) -> Result { let fname = format!("{}/challenge_log.json", path); let serialized = std::fs::read(&fname).map_err(|e| { - EmulatorError::ChallengeError(format!("Error loading file: {} {}", e.to_string(), fname)) + EmulatorError::ChallengeError(format!("Error loading file: {} {}", e, fname)) })?; let serialized_str = std::str::from_utf8(&serialized).map_err(|e| { - EmulatorError::ChallengeError(format!("Error parsing file: {}", e.to_string())) + EmulatorError::ChallengeError(format!("Error parsing file: {}", e)) })?; - Ok(serde_json::from_str(serialized_str).map_err(|e| { - EmulatorError::ChallengeError(format!("Error deserializing file: {}", e.to_string())) - })?) + serde_json::from_str(serialized_str).map_err(|e| { + EmulatorError::ChallengeError(format!("Error deserializing file: {}", e)) + }) } diff --git a/emulator/src/decision/nary_search.rs b/emulator/src/decision/nary_search.rs index 51085e7..cfa2ac7 100644 --- a/emulator/src/decision/nary_search.rs +++ b/emulator/src/decision/nary_search.rs @@ -10,11 +10,11 @@ pub enum NArySearchType { ConflictStep, ReadValueChallenge, } -impl ToString for NArySearchType { - fn to_string(&self) -> String { +impl std::fmt::Display for NArySearchType { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - NArySearchType::ConflictStep => "conflict-step".to_string(), - NArySearchType::ReadValueChallenge => "read-value-challenge".to_string(), + NArySearchType::ConflictStep => write!(f, "conflict-step"), + NArySearchType::ReadValueChallenge => write!(f, "read-value-challenge"), } } } @@ -129,7 +129,7 @@ impl NArySearchDefinition { } } - pub fn step_mapping(&self, bits: &Vec) -> HashMap { + pub fn step_mapping(&self, bits: &[u32]) -> HashMap { assert_eq!(bits.len(), self.total_rounds() as usize); let mut base = 0; let mut mapping: HashMap = HashMap::new(); @@ -147,7 +147,7 @@ impl NArySearchDefinition { mapping } - pub fn step_from_decision_bits(&self, decision_bits: &Vec) -> u64 { + pub fn step_from_decision_bits(&self, decision_bits: &[u32]) -> u64 { decision_bits .iter() .enumerate() @@ -180,13 +180,14 @@ impl ExecutionHashes { } } -impl Into for Vec> { - fn into(self) -> ExecutionHashes { - ExecutionHashes::new(self) +impl From>> for ExecutionHashes { + fn from(hashes: Vec>) -> Self { + ExecutionHashes::new(hashes) } } // we assume that the previous hash to the list provided is agreed by both parties +#[allow(clippy::too_many_arguments)] pub fn choose_segment( nary_defs: &NArySearchDefinition, base_step: u64, diff --git a/emulator/src/executor/fetcher.rs b/emulator/src/executor/fetcher.rs index 74ef978..8750b67 100644 --- a/emulator/src/executor/fetcher.rs +++ b/emulator/src/executor/fetcher.rs @@ -16,6 +16,7 @@ use tracing::{error, info}; pub type TraceStepResult = (TraceRWStep, String); pub type FullTrace = Vec; +#[allow(clippy::too_many_arguments)] pub fn execute_program( program: &mut Program, input: Vec, @@ -123,13 +124,13 @@ pub fn execute_program( } } - if trace.is_ok() { + if let Ok(trace) = trace.as_mut() { if let Some(fr) = &fail_config.fail_reads { - fr.patch_trace_reads(trace.as_mut().unwrap(), should_patch); // patches trace reads only at the right step + fr.patch_trace_reads(trace, should_patch); // patches trace reads only at the right step } if let Some(fw) = &fail_config.fail_write { - fw.patch_trace_write(trace.as_mut().unwrap(), should_patch_write); + fw.patch_trace_write(trace, should_patch_write); } } @@ -157,48 +158,50 @@ pub fn execute_program( let limit_step_reached = limit_step.is_some_and(|limit_step| limit_step == program.step); - if print_trace || trace.is_err() || program.halt || limit_step_reached { - if trace_set.is_none() || trace_set.as_ref().unwrap().contains(&program.step) { - let hash_hex = hash_to_string(&program.hash); - traces.push(( - trace - .as_ref() - .unwrap_or(&TraceRWStep::from_step(program.step)) - .clone(), - hash_hex.clone(), - )); - if debug { - info!( - "{};{}", - trace.as_ref().unwrap_or(&TraceRWStep::default()).to_csv(), - hash_hex - ); - } + if (print_trace || trace.is_err() || program.halt || limit_step_reached) + && (trace_set.is_none() || trace_set.as_ref().unwrap().contains(&program.step)) + { + let hash_hex = hash_to_string(&program.hash); + traces.push(( + trace + .as_ref() + .unwrap_or(&TraceRWStep::from_step(program.step)) + .clone(), + hash_hex.clone(), + )); + if debug { + info!( + "{};{}", + trace.as_ref().unwrap_or(&TraceRWStep::default()).to_csv(), + hash_hex + ); } } if let Some(path) = &checkpoint_path { - if program.step % CHECKPOINT_SIZE == 0 + if program.step.is_multiple_of(CHECKPOINT_SIZE) || ((trace.is_err() || program.halt) && save_non_checkpoint_steps) { program.serialize_to_file(path); } } - if trace.is_ok() && verify_on_chain { - let validation_result = verify_script( - trace.as_ref().unwrap(), - program.registers.get_base_address(), - &instruction_mapping, - ); - if validation_result.is_err() { - break validation_result.unwrap_err(); + if verify_on_chain { + if let Ok(trace) = trace.as_ref() { + let validation_result = verify_script( + trace, + program.registers.get_base_address(), + &instruction_mapping, + ); + if let Err(err) = validation_result { + break err; + } + count += 1; } - count += 1; } - if trace.is_err() { - break trace.unwrap_err(); + if let Err(err) = trace { + break err; } if program.halt { @@ -321,7 +324,7 @@ pub fn execute_step( }; let new_pc = program.pc.get_address(); - if !fail_config.fail_memory_protection && new_pc % 4 != 0 { + if !fail_config.fail_memory_protection && !new_pc.is_multiple_of(4) { return Err(ExecutionResult::UnalignedJump(new_pc)); } @@ -534,22 +537,16 @@ pub fn op_arithmetic( let witness = match instruction { Rem(_) => Some(match (value_1 as i32, value_2 as i32) { - (_, 0) => (-1 as i32) as u32, - (std::i32::MIN, -1) => std::i32::MIN as u32, + (_, 0) => -1_i32 as u32, + (i32::MIN, -1) => i32::MIN as u32, _ => (value_1 as i32 / value_2 as i32) as u32, }), Div(_) => Some(match (value_1 as i32, value_2 as i32) { (_, 0) => value_1, - (std::i32::MIN, -1) => 0, + (i32::MIN, -1) => 0, _ => (value_1 as i32 % value_2 as i32) as u32, }), - Remu(_) => Some({ - if value_2 == 0 { - std::u32::MAX - } else { - value_1 / value_2 - } - }), + Remu(_) => Some(value_1.checked_div(value_2).unwrap_or(u32::MAX)), Divu(_) => Some({ if value_2 == 0 { value_1 @@ -578,20 +575,14 @@ pub fn op_arithmetic( (result >> 32) as u32 // High 32 bits } Div(_) => match (value_1 as i32, value_2 as i32) { - (_, 0) => (-1 as i32) as u32, - (std::i32::MIN, -1) => std::i32::MIN as u32, + (_, 0) => -1_i32 as u32, + (i32::MIN, -1) => i32::MIN as u32, _ => (value_1 as i32 / value_2 as i32) as u32, }, - Divu(_) => { - if value_2 == 0 { - std::u32::MAX - } else { - value_1 / value_2 - } - } + Divu(_) => value_1.checked_div(value_2).unwrap_or(u32::MAX), Rem(_) => match (value_1 as i32, value_2 as i32) { (_, 0) => value_1, - (std::i32::MIN, -1) => 0, + (i32::MIN, -1) => 0, _ => (value_1 as i32 % value_2 as i32) as u32, }, Remu(_) => { diff --git a/emulator/src/executor/utils.rs b/emulator/src/executor/utils.rs index 6273a85..3c3a549 100644 --- a/emulator/src/executor/utils.rs +++ b/emulator/src/executor/utils.rs @@ -18,8 +18,8 @@ where T: std::fmt::Debug, ::Err: std::fmt::Debug, { - if value.starts_with("0x") { - T::from_str_radix(&value[2..], 16).unwrap_or_else(|_| panic!("Invalid hexadecimal value")) + if let Some(hex) = value.strip_prefix("0x") { + T::from_str_radix(hex, 16).unwrap_or_else(|_| panic!("Invalid hexadecimal value")) } else { value.parse::().expect("Invalid decimal value") } @@ -44,9 +44,8 @@ impl FailRead { T: std::fmt::Debug, ::Err: std::fmt::Debug, { - if value.starts_with("0x") { - T::from_str_radix(&value[2..], 16) - .unwrap_or_else(|_| panic!("Invalid hexadecimal value")) + if let Some(hex) = value.strip_prefix("0x") { + T::from_str_radix(hex, 16).unwrap_or_else(|_| panic!("Invalid hexadecimal value")) } else { value.parse::().expect("Invalid decimal value") } @@ -92,7 +91,6 @@ impl FailRead { program .write_mem(self.address_original, self.value) .unwrap(); - return; } } } @@ -150,7 +148,7 @@ pub struct FailWrite { } impl FailWrite { - pub fn new(args: &Vec) -> Self { + pub fn new(args: &[String]) -> Self { Self { step: parse_value::(&args[0]), address_original: parse_value::(&args[1]), @@ -193,7 +191,7 @@ pub struct FailExecute { } impl FailExecute { - pub fn new(args: &Vec) -> Self { + pub fn new(args: &[String]) -> Self { Self { step: parse_value::(&args[0]) - 1, fake_trace: TraceRWStep::from_str(&args[1]).unwrap(), @@ -208,7 +206,7 @@ pub struct FailOpcode { } impl FailOpcode { - pub fn new(args: &Vec) -> Self { + pub fn new(args: &[String]) -> Self { Self { step: parse_value(&args[0]), opcode: parse_value(&args[1]), @@ -344,9 +342,11 @@ impl FromStr for FailConfiguration { } } -impl ToString for FailConfiguration { - fn to_string(&self) -> String { - serde_json::to_string(self).unwrap_or_else(|_| "Failed to serialize".to_string()) +impl std::fmt::Display for FailConfiguration { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let serialized = + serde_json::to_string(self).unwrap_or_else(|_| "Failed to serialize".to_string()); + write!(f, "{}", serialized) } } diff --git a/emulator/src/executor/verifier.rs b/emulator/src/executor/verifier.rs index 79d27b5..049f4bc 100644 --- a/emulator/src/executor/verifier.rs +++ b/emulator/src/executor/verifier.rs @@ -9,7 +9,7 @@ pub fn verify_script( instruction_mapping: &Option, ) -> Result<(), ExecutionResult> { let program = ProgramSpec::new(base_register_address); - let result = verify(instruction_mapping, program, trace)?; + verify(instruction_mapping, program, trace)?; - Ok(result) + Ok(()) } diff --git a/emulator/src/loader/program.rs b/emulator/src/loader/program.rs index 80609e2..8172b90 100644 --- a/emulator/src/loader/program.rs +++ b/emulator/src/loader/program.rs @@ -514,7 +514,7 @@ impl Program { if cfg!(target_endian = "big") { panic!("Big endian machine not supported"); } - if address % 4 != 0 { + if !address.is_multiple_of(4) { return Err(ExecutionResult::UnalignedRead(address)); } let section = self.find_section(address)?; @@ -534,7 +534,7 @@ impl Program { } pub fn write_mem(&mut self, address: u32, value: u32) -> Result<(), ExecutionResult> { - if address % 4 != 0 { + if !address.is_multiple_of(4) { return Err(ExecutionResult::UnalignedWrite(address)); } @@ -594,7 +594,7 @@ impl Program { .ranges .iter() .any(|&(start, end)| start <= address && address <= end - 3) - && address % 4 == 0 + && address.is_multiple_of(4) } pub fn is_valid_mem( @@ -841,10 +841,12 @@ pub fn generate_rom_commitment(program: &Program) -> Result Result Result<(), EmulatorError> { None => None, }; - let fail_execute = fail_execute_args.as_ref().map(FailExecute::new); + let fail_execute = fail_execute_args.as_deref().map(FailExecute::new); let fail_reads = if fail_read_1_args.is_some() || fail_read_2_args.is_some() { Some(FailReads::new( @@ -539,8 +539,8 @@ fn main() -> Result<(), EmulatorError> { None }; - let fail_write = fail_write_args.as_ref().map(FailWrite::new); - let fail_opcode = fail_opcode_args.as_ref().map(FailOpcode::new); + let fail_write = fail_write_args.as_deref().map(FailWrite::new); + let fail_opcode = fail_opcode_args.as_deref().map(FailOpcode::new); let debugvar = *debug; let fail_config = FailConfiguration { @@ -564,7 +564,7 @@ fn main() -> Result<(), EmulatorError> { input, &input_section.clone().unwrap_or(".input".to_string()), *input_as_little, - &checkpoint_output_path, + checkpoint_output_path, *limit, *trace, *verify, @@ -610,7 +610,7 @@ fn main() -> Result<(), EmulatorError> { let result = EmulatorResultType::ProverExecuteResult { last_step: result.1, last_hash: result.2, - halt: halt, + halt, } .to_value()?; @@ -702,7 +702,7 @@ fn main() -> Result<(), EmulatorError> { info!("Verifier choose segment: {:?}", result); let result = EmulatorResultType::VerifierChooseSegmentResult { - v_decision: result.clone(), + v_decision: result, round: *round_number, } .to_value()?; @@ -805,7 +805,7 @@ fn main() -> Result<(), EmulatorError> { }) => { let prover_hashes_and_step = prover_get_hashes_and_step( pdf, - &checkpoint_prover_path, + checkpoint_prover_path, NArySearchType::ReadValueChallenge, Some(*v_decision), fail_config_prover.clone(), From 8817d6ce59a3d588864a1044a374c80a32a3b763 Mon Sep 17 00:00:00 2001 From: Kevin Wahle <62912263+KevinWahle@users.noreply.github.com> Date: Mon, 31 Aug 2026 16:40:30 -0300 Subject: [PATCH 2/6] apply fmt --- bitcoin-script-riscv/src/riscv/script_utils.rs | 3 ++- emulator/src/decision/execution_log.rs | 10 ++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/bitcoin-script-riscv/src/riscv/script_utils.rs b/bitcoin-script-riscv/src/riscv/script_utils.rs index d917e91..8c1cdc1 100644 --- a/bitcoin-script-riscv/src/riscv/script_utils.rs +++ b/bitcoin-script-riscv/src/riscv/script_utils.rs @@ -1559,7 +1559,8 @@ pub fn get_selected_vars( stack .end_if(chose_var_1, chose_var_2, consumes, output, 0) - .try_into().expect("Vec length does not match expected array size") + .try_into() + .expect("Vec length does not match expected array size") } pub fn address_in_range(stack: &mut StackTracker, range: &(u32, u32), address: &StackVariable) { diff --git a/emulator/src/decision/execution_log.rs b/emulator/src/decision/execution_log.rs index 735f945..9ae4e6d 100644 --- a/emulator/src/decision/execution_log.rs +++ b/emulator/src/decision/execution_log.rs @@ -141,10 +141,8 @@ pub fn deserialize_challenge_log Deserialize<'a>>( let serialized = std::fs::read(&fname).map_err(|e| { EmulatorError::ChallengeError(format!("Error loading file: {} {}", e, fname)) })?; - let serialized_str = std::str::from_utf8(&serialized).map_err(|e| { - EmulatorError::ChallengeError(format!("Error parsing file: {}", e)) - })?; - serde_json::from_str(serialized_str).map_err(|e| { - EmulatorError::ChallengeError(format!("Error deserializing file: {}", e)) - }) + let serialized_str = std::str::from_utf8(&serialized) + .map_err(|e| EmulatorError::ChallengeError(format!("Error parsing file: {}", e)))?; + serde_json::from_str(serialized_str) + .map_err(|e| EmulatorError::ChallengeError(format!("Error deserializing file: {}", e))) } From 674ff002db0831334ca2329101e1fb2913b7f41c Mon Sep 17 00:00:00 2001 From: Martin Jonas Date: Mon, 31 Aug 2026 17:12:45 -0300 Subject: [PATCH 3/6] Change Clippy linting to fail on warnings --- .github/workflows/rust.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index a4075b7..a148015 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -41,7 +41,7 @@ jobs: run: cargo fmt --all -- --check - name: Lint with Clippy - continue-on-error: true + continue-on-error: false working-directory: ${{ inputs.submodule_path }} run: cargo clippy --all-targets --all-features -- -D warnings From d9b9ded26d4756a3390c5cc13657ef82f5c81bf5 Mon Sep 17 00:00:00 2001 From: Martin Jonas Date: Mon, 31 Aug 2026 17:18:05 -0300 Subject: [PATCH 4/6] Fix Clippy command by removing redundant option --- .github/workflows/rust.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index a148015..a1d24ff 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -43,7 +43,7 @@ jobs: - name: Lint with Clippy continue-on-error: false working-directory: ${{ inputs.submodule_path }} - run: cargo clippy --all-targets --all-features -- -D warnings + run: cargo clippy --all-features -- -D warnings - name: Build project run: cargo build --verbose From 459b8bf99667e8831a5cd80163a55cf5d22ec141 Mon Sep 17 00:00:00 2001 From: Martin Jonas Date: Mon, 31 Aug 2026 19:48:17 -0300 Subject: [PATCH 5/6] replace ci --- .github/workflows/rust.yml | 93 -------------------------------------- .github/workflows/test.yml | 31 +++++++++++++ 2 files changed, 31 insertions(+), 93 deletions(-) delete mode 100644 .github/workflows/rust.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml deleted file mode 100644 index a1d24ff..0000000 --- a/.github/workflows/rust.yml +++ /dev/null @@ -1,93 +0,0 @@ -name: 'Test action' - -on: - push: - branches: [ "main", "dev" ] - pull_request: - branches: [ "main", "dev" ] - -env: - CARGO_TERM_COLOR: always - -concurrency: - group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}' - cancel-in-progress: true - -jobs: - test: - if: ${{ !contains(github.event.pull_request.title, '[cov]') }} - runs-on: ubuntu-latest - defaults: - run: - working-directory: ./emulator - steps: - - name: Checkout repository - uses: actions/checkout@v7 - with: - submodules: 'true' - - - name: Install cargo-audit - uses: taiki-e/install-action@v2 - with: - tool: cargo-audit - - - name: Audit dependencies - working-directory: ${{ inputs.submodule_path }} - run: cargo audit - - - name: Lint with rustfmt - continue-on-error: true - working-directory: ${{ inputs.submodule_path }} - run: cargo fmt --all -- --check - - - name: Lint with Clippy - continue-on-error: false - working-directory: ${{ inputs.submodule_path }} - run: cargo clippy --all-features -- -D warnings - - - name: Build project - run: cargo build --verbose - - - name: Run tests - run: cargo test --verbose - - test-with-coverage: - if: contains(github.event.pull_request.title, '[cov]') - runs-on: ubuntu-latest - - permissions: - contents: write - pull-requests: write - repository-projects: write - - defaults: - run: - working-directory: ./emulator - - steps: - - name: Checkout repository - uses: actions/checkout@v7 - - - name: Build project - run: cargo build --verbose - - - name: Run cargo-tarpaulin - uses: actions-rs/tarpaulin@v0.1 - with: - version: '0.15.0' - args: '--out Xml --output-dir resources --no-fail-fast' - - - name: Code Coverage Summary Report - uses: irongut/CodeCoverageSummary@v1.3.0 - with: - filename: 'resources/cobertura.xml' - badge: true - format: 'markdown' - output: 'both' - - - name: Add Coverage PR Comment - uses: marocchino/sticky-pull-request-comment@v3 - if: github.event_name == 'pull_request' - with: - recreate: true - path: code-coverage-results.md diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..d85819e --- /dev/null +++ b/.github/workflows/test.yml @@ -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/rust-bitvmx-workspace' + submodule_path: 'rust-bitvmx-settings' + cargo_lock_path: 'rust-bitvmx-settings/Cargo.lock' + target_path: 'rust-bitvmx-settings/target' + clippy: true + secrets: inherit From 9c24c76c5d3a8e7a2cc2fca45c47cfb6483e6c52 Mon Sep 17 00:00:00 2001 From: Martin Jonas Date: Mon, 31 Aug 2026 20:11:17 -0300 Subject: [PATCH 6/6] fix ci --- .github/workflows/test.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d85819e..a5c2035 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,9 +23,9 @@ jobs: test: uses: FairgateLabs/BitVMX-CI/.github/workflows/ci_local_template.yml@main with: - repo: 'FairgateLabs/rust-bitvmx-workspace' - submodule_path: 'rust-bitvmx-settings' - cargo_lock_path: 'rust-bitvmx-settings/Cargo.lock' - target_path: 'rust-bitvmx-settings/target' + repo: 'FairgateLabs/BitVMX-CPU' + submodule_path: 'BitVMX-CPU' + cargo_lock_path: 'BitVMX-CPU/Cargo.lock' + target_path: 'BitVMX-CPU/target' clippy: true secrets: inherit