From 077499c1ade274c28bd723d681463cd11ab5e181 Mon Sep 17 00:00:00 2001 From: Chris Guimaraes Date: Thu, 10 Jul 2025 19:16:56 +0100 Subject: [PATCH 1/2] fix rollback handling in case of a runtime error This change needs to be reverted, as it adds an additional call to global_context.rollback(), which in turn disrupts the function call context. --- clarity/src/vm/clarity_wasm.rs | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/clarity/src/vm/clarity_wasm.rs b/clarity/src/vm/clarity_wasm.rs index 2fd1ed9af8..acc072fa2c 100644 --- a/clarity/src/vm/clarity_wasm.rs +++ b/clarity/src/vm/clarity_wasm.rs @@ -428,28 +428,11 @@ pub fn initialize_contract( results.push(placeholder_for_type(result_ty)); } - let top_level_result = top_level.call(&mut store, &[], results.as_mut_slice()); - match top_level_result { - Ok(_) => {} - Err(e) => { - // Before propagating the error, attempt to roll back the function context. - // If the rollback fails, immediately return a rollback-specific error. - if store.data_mut().global_context.roll_back().is_err() { - return Err(Error::Wasm(WasmError::Expect( - "Expected entry to rollback".into(), - ))); - } - - // Rollback succeeded, so resolve and return the original runtime error. - return Err(error_mapping::resolve_error( - e, - instance, - &mut store, - &epoch, - &clarity_version, - )); - } - } + top_level + .call(&mut store, &[], results.as_mut_slice()) + .map_err(|e| { + error_mapping::resolve_error(e, instance, &mut store, &epoch, &clarity_version) + })?; // Save the compiled Wasm module into the contract context store.data_mut().contract_context_mut()?.set_wasm_module( From b299de5e38bfce3de0062bb9cf8dba29f194b714 Mon Sep 17 00:00:00 2001 From: Chris Guimaraes Date: Fri, 11 Jul 2025 10:58:31 +0100 Subject: [PATCH 2/2] chore: update Cargo.lock --- Cargo.lock | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6383d00b81..5f881dc54f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -668,7 +668,7 @@ checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" [[package]] name = "clar2wasm" version = "0.1.0" -source = "git+https://github.com/stacks-network/clarity-wasm.git?branch=main#9d1b83cbc4b6e69680a63663b2c292097ba5ba77" +source = "git+https://github.com/stacks-network/clarity-wasm.git?branch=main#906af4986ec9f3726f7e7301fd8c02f792bc2f4d" dependencies = [ "chrono", "clap", @@ -720,7 +720,7 @@ version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fde0e0ec90c9dfb3b4b1a0891a7dcd0e2bffde2f7efed5fe7c9bb00e5bfb915e" dependencies = [ - "windows-sys 0.59.0", + "windows-sys 0.52.0", ] [[package]] @@ -1172,7 +1172,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "976dd42dc7e85965fe702eb8164f21f450704bdde31faefd6471dba214cb594e" dependencies = [ "libc", - "windows-sys 0.59.0", + "windows-sys 0.52.0", ] [[package]] @@ -2129,7 +2129,7 @@ checksum = "e04d7f318608d35d4b61ddd75cbdaee86b023ebe2bd5a66ee0915f0bf93095a9" dependencies = [ "hermit-abi 0.5.0", "libc", - "windows-sys 0.59.0", + "windows-sys 0.52.0", ] [[package]] @@ -3404,7 +3404,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys 0.4.15", - "windows-sys 0.59.0", + "windows-sys 0.52.0", ] [[package]] @@ -3417,7 +3417,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys 0.9.4", - "windows-sys 0.59.0", + "windows-sys 0.52.0", ] [[package]] @@ -3864,7 +3864,7 @@ dependencies = [ "cfg-if 1.0.0", "libc", "psm", - "windows-sys 0.59.0", + "windows-sys 0.52.0", ] [[package]] @@ -4183,7 +4183,7 @@ dependencies = [ "getrandom 0.3.2", "once_cell", "rustix 1.0.5", - "windows-sys 0.59.0", + "windows-sys 0.52.0", ] [[package]]