diff --git a/clar2wasm/src/error_mapping.rs b/clar2wasm/src/error_mapping.rs index e0901ff1..22ee4a69 100644 --- a/clar2wasm/src/error_mapping.rs +++ b/clar2wasm/src/error_mapping.rs @@ -5,7 +5,7 @@ use clarity::vm::{ClarityVersion, Value}; use wasmtime::{AsContextMut, Instance, Trap}; use crate::wasm_utils::{ - read_from_wasm_indirect, read_identifier_from_wasm, signature_from_string, + read_bytes_from_wasm, read_from_wasm_indirect, read_identifier_from_wasm, signature_from_string, }; const LOG2_ERROR_MESSAGE: &str = "log2 must be passed a positive integer"; @@ -315,14 +315,12 @@ fn get_global_i32(instance: &Instance, store: &mut impl AsContextMut, name: &str /// A tuple `(expected, got)` where: /// - `expected` is the number of arguments expected. /// - `got` is the number of arguments actually received. -fn extract_expected_and_got(arg_lengths: &str) -> (usize, usize) { - let bytes = arg_lengths.as_bytes(); - +fn extract_expected_and_got(bytes: &[u8]) -> (usize, usize) { // Assuming the first 4 bytes represent the expected value let expected = u32::from_le_bytes([bytes[0], bytes[1], bytes[2], bytes[3]]) as usize; // Assuming the next 4 bytes represent the got value - let got = u32::from_le_bytes([bytes[16], bytes[17], bytes[18], bytes[19]]) as usize; + let got = u32::from_le_bytes([bytes[4], bytes[5], bytes[6], bytes[7]]) as usize; (expected, got) } @@ -379,7 +377,7 @@ fn get_runtime_error_arg_lengths( let memory = instance .get_memory(&mut *store, "memory") .unwrap_or_else(|| panic!("Could not find wasm instance memory")); - let arg_lengths = read_identifier_from_wasm( + let arg_lengths = read_bytes_from_wasm( memory, store, runtime_error_arg_offset, diff --git a/clar2wasm/src/wasm_utils.rs b/clar2wasm/src/wasm_utils.rs index 0aa7131b..b4de7726 100644 --- a/clar2wasm/src/wasm_utils.rs +++ b/clar2wasm/src/wasm_utils.rs @@ -1674,11 +1674,12 @@ pub fn check_argument_count( actual: usize, check: ArgumentCountCheck, ) -> Result<(), GeneratorError> { + let expected = expected as u32; + let actual = actual as u32; let mut handle_mismatch = |error_map: ErrorMap| -> Result<(), GeneratorError> { let (arg_name_offset_start, arg_name_len_expected) = - generator.add_literal(&clarity::vm::Value::UInt(expected as u128))?; - let (_, arg_name_len_got) = - generator.add_literal(&clarity::vm::Value::UInt(actual as u128))?; + generator.add_bytes_literal(&expected.to_le_bytes())?; + let (_, arg_name_len_got) = generator.add_bytes_literal(&actual.to_le_bytes())?; builder .i32_const(arg_name_offset_start as i32) .global_set(get_global(&generator.module, "runtime-error-arg-offset")?)