nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: CosmWasm/cosmwasm
Pull request #1194 (2021-12-23 08:50:08)

Remove stacktrace from VmError::RuntimeErr (0.16)


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8c2a75507..b35b41d89 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,11 @@ and this project adheres to
 
 ## [Unreleased]
 
+### Fixed
+
+- cosmwasm-vm: Remove system-dependent stacktrace from `VmError::RuntimeErr`
+  (fixes CWA-2021-003).
+
 ## [0.16.2] - 2021-09-07
 
 ### Added
diff --git a/packages/vm/src/errors/vm_error.rs b/packages/vm/src/errors/vm_error.rs
index 80d969328..ba0698278 100644
--- a/packages/vm/src/errors/vm_error.rs
+++ b/packages/vm/src/errors/vm_error.rs
@@ -267,7 +267,10 @@ impl VmError {
         }
     }
 
-    pub(crate) fn runtime_err(msg: impl Into<String>) -> Self {
+    // Creates a runtime error with the given message.
+    // This is private since it is only needed when converting wasmer::RuntimeError
+    // to VmError.
+    fn runtime_err(msg: impl Into<String>) -> Self {
         VmError::RuntimeErr {
             msg: msg.into(),
             #[cfg(feature = "backtraces")]
@@ -334,7 +337,19 @@ impl From<wasmer::DeserializeError> for VmError {
 
 impl From<wasmer::RuntimeError> for VmError {
     fn from(original: wasmer::RuntimeError) -> Self {
-        VmError::runtime_err(format!("Wasmer runtime error: {}", original))
+        // Do not use the Display implementation or to_string() of `RuntimeError`
+        // because it can contain a system specific stack trace, which can
+        // lead to non-deterministic execution.
+        //
+        // Implementation follows https://github.com/wasmerio/wasmer/blob/2.0.0/lib/engine/src/trap/error.rs#L215
+        let message = format!("RuntimeError: {}", original.message());
+        debug_assert!(
+            original.to_string().starts_with(&message),
+            "The error message we created is not a prefix of the error message from Wasmer. Our message: '{}'. Wasmer messsage: '{}'",
+            &message,
+            original.to_string()
+        );
+        VmError::runtime_err(format!("Wasmer runtime error: {}", &message))
     }
 }
 


Test patch:
diff --git a/contracts/hackatom/tests/integration.rs b/contracts/hackatom/tests/integration.rs
index 7f13e484e..7187258b5 100644
--- a/contracts/hackatom/tests/integration.rs
+++ b/contracts/hackatom/tests/integration.rs
@@ -453,7 +453,9 @@ fn execute_panic() {
         &to_vec(&ExecuteMsg::Panic {}).unwrap(),
     );
     match execute_res.unwrap_err() {
-        VmError::RuntimeErr { .. } => {}
+        VmError::RuntimeErr { msg, .. } => {
+            assert_eq!(msg, "Wasmer runtime error: RuntimeError: unreachable")
+        }
         err => panic!("Unexpected error: {:?}", err),
     }
 }
Repository: CosmWasm/cosmwasm
Pull request #1212 (2022-02-05 19:08:42)

Add integration test for floaty
To make `./devtools/check_contracts_full.sh` work again


Patch:
diff --git a/.circleci/config.yml b/.circleci/config.yml
index 045143632..923b5f0ae 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -546,6 +546,9 @@ jobs:
       - run:
           name: Unit tests
           command: cargo unit-test --locked
+      - run:
+          name: Integration tests (singlepass backend)
+          command: cargo integration-test --locked --no-default-features
       - run:
           name: Build and run schema generator
           command: cargo schema --locked
diff --git a/contracts/floaty/Cargo.toml b/contracts/floaty/Cargo.toml
index 0ef1a58be..66ae2e52a 100644
--- a/contracts/floaty/Cargo.toml
+++ b/contracts/floaty/Cargo.toml
@@ -39,4 +39,4 @@ thiserror = "1.0"
 [dev-dependencies]
 cosmwasm-schema = { path = "../../packages/schema" }
 cosmwasm-storage = { path = "../../packages/storage" }
-cosmwasm-vm = { path = "../../packages/vm", default-features = false }
+cosmwasm-vm = { path = "../../packages/vm", default-features = false, features = ["iterator"] }


Test patch:
diff --git a/contracts/floaty/tests/integration.rs b/contracts/floaty/tests/integration.rs
new file mode 100644
index 000000000..5d3de04e5
--- /dev/null
+++ b/contracts/floaty/tests/integration.rs
@@ -0,0 +1,12 @@
+use cosmwasm_vm::testing::mock_instance;
+
+// This line will test the output of cargo wasm
+static WASM: &[u8] = include_bytes!("../target/wasm32-unknown-unknown/release/floaty.wasm");
+// You can uncomment this line instead to test productionified build from rust-optimizer
+// static WASM: &[u8] = include_bytes!("../contract.wasm");
+
+#[test]
+#[should_panic(expected = "Float operator detected")]
+fn instantiate_fails() {
+    let mut _deps = mock_instance(WASM, &[]);
+}