diff --git a/soroban-env-common/src/checked_env.rs b/soroban-env-common/src/checked_env.rs index d7d7baee9..3d6ea9dd6 100644 --- a/soroban-env-common/src/checked_env.rs +++ b/soroban-env-common/src/checked_env.rs @@ -1,5 +1,5 @@ use crate::call_macro_with_all_host_functions; -use crate::{EnvBase, Object, RawVal, Symbol}; +use crate::{EnvBase, Object, RawVal, Status, Symbol}; use core::fmt::Debug; /// The CheckedEnv trait is similar to the Env trait -- it provides all the diff --git a/soroban-env-common/src/env.rs b/soroban-env-common/src/env.rs index eab44e192..434ab2449 100644 --- a/soroban-env-common/src/env.rs +++ b/soroban-env-common/src/env.rs @@ -1,5 +1,5 @@ use super::Symbol; -use super::{Object, RawVal}; +use super::{Object, RawVal, Status}; use core::any; /// Base trait extended by the [Env](crate::Env) trait, providing various special-case @@ -168,6 +168,10 @@ macro_rules! call_macro_with_all_host_functions { /// vector contains the contract id as Hash, and a function as /// a Symbol. {"8", fn get_current_call_stack() -> Object } + /// Causes the currently executing contract to fail immediately + /// with a provided status code, which must be of error-type + /// `ScStatusType::ContractError`. Does not actually return. + {"9", fn fail_with_status(status:Status) -> RawVal } } mod u64 "u" { diff --git a/soroban-env-common/src/meta.rs b/soroban-env-common/src/meta.rs index 55493c5d9..6389103c8 100644 --- a/soroban-env-common/src/meta.rs +++ b/soroban-env-common/src/meta.rs @@ -56,5 +56,5 @@ // implementations over a long period of time. soroban_env_macros::generate_env_meta_consts!( - interface_version: 13, + interface_version: 14, ); diff --git a/soroban-env-common/src/unimplemented_env.rs b/soroban-env-common/src/unimplemented_env.rs index 65c54901b..e06503cad 100644 --- a/soroban-env-common/src/unimplemented_env.rs +++ b/soroban-env-common/src/unimplemented_env.rs @@ -1,4 +1,4 @@ -use super::{call_macro_with_all_host_functions, Env, EnvBase, Object, RawVal, Symbol}; +use super::{call_macro_with_all_host_functions, Env, EnvBase, Object, RawVal, Status, Symbol}; use core::any; /// A dummy implementation of the [Env] trait that fails with `unimplemented!()` in diff --git a/soroban-env-common/src/vmcaller_checked_env.rs b/soroban-env-common/src/vmcaller_checked_env.rs index ed609cfd6..9a1f2623e 100644 --- a/soroban-env-common/src/vmcaller_checked_env.rs +++ b/soroban-env-common/src/vmcaller_checked_env.rs @@ -2,7 +2,7 @@ use crate::xdr::ScHostContextErrorCode; use crate::call_macro_with_all_host_functions; -use crate::{Object, RawVal, Symbol}; +use crate::{Object, RawVal, Status, Symbol}; use core::fmt::Debug; #[cfg(not(feature = "vm"))] use core::marker::PhantomData; diff --git a/soroban-env-guest/src/guest.rs b/soroban-env-guest/src/guest.rs index a589f35f3..4867e3a9a 100644 --- a/soroban-env-guest/src/guest.rs +++ b/soroban-env-guest/src/guest.rs @@ -3,7 +3,7 @@ use soroban_env_common::call_macro_with_all_host_functions; -use super::{Env, EnvBase, Object, RawVal, Symbol}; +use super::{Env, EnvBase, Object, RawVal, Status, Symbol}; #[cfg(target_family = "wasm")] use static_assertions as sa; @@ -270,7 +270,7 @@ macro_rules! generate_extern_modules { $(#[$mod_attr])* mod $mod_id { #[allow(unused_imports)] - use crate::{RawVal,Object,Symbol}; + use crate::{RawVal,Object,Symbol,Status}; #[link(wasm_import_module = $mod_str)] extern "C" { $( diff --git a/soroban-env-host/src/host.rs b/soroban-env-host/src/host.rs index 6c3d7e0d4..62ebf861d 100644 --- a/soroban-env-host/src/host.rs +++ b/soroban-env-host/src/host.rs @@ -13,7 +13,7 @@ use soroban_env_common::{ use soroban_env_common::xdr::{ AccountId, ContractEvent, ContractEventBody, ContractEventType, ContractEventV0, - ExtensionPoint, Hash, PublicKey, ReadXdr, ThresholdIndexes, WriteXdr, + ExtensionPoint, Hash, PublicKey, ReadXdr, ScStatusType, ThresholdIndexes, WriteXdr, }; use crate::budget::{Budget, CostType}; @@ -2520,4 +2520,19 @@ impl VmCallerCheckedEnv for Host { let res = HostVec::from_vec(self.0.budget.clone(), outer)?; Ok(self.add_host_object(res)?.into()) } + + fn fail_with_status( + &self, + vmcaller: &mut VmCaller, + status: Status, + ) -> Result { + if status.is_type(ScStatusType::ContractError) { + Err(self.err_status_msg(status, "failing with contract error status code")) + } else { + Err(self.err_status_msg( + ScHostValErrorCode::UnexpectedValType, + "contract attempted to fail with non-ContractError status code", + )) + } + } } diff --git a/soroban-env-host/src/vm/dispatch.rs b/soroban-env-host/src/vm/dispatch.rs index 58332bb35..2a37c131d 100644 --- a/soroban-env-host/src/vm/dispatch.rs +++ b/soroban-env-host/src/vm/dispatch.rs @@ -1,4 +1,4 @@ -use crate::{budget::CostType, Host, Object, RawVal, Symbol, VmCaller, VmCallerCheckedEnv}; +use crate::{budget::CostType, Host, Object, RawVal, Status, Symbol, VmCaller, VmCallerCheckedEnv}; use soroban_env_common::call_macro_with_all_host_functions; use wasmi::core::{FromValue, Trap, TrapCode::UnexpectedSignature, Value}; diff --git a/soroban-env-host/src/weak_host.rs b/soroban-env-host/src/weak_host.rs index a89888daf..8b23e56d6 100644 --- a/soroban-env-host/src/weak_host.rs +++ b/soroban-env-host/src/weak_host.rs @@ -1,6 +1,6 @@ use soroban_env_common::call_macro_with_all_host_functions; -use crate::{host::HostImpl, Env, EnvBase, Host, Object, RawVal, Symbol}; +use crate::{host::HostImpl, Env, EnvBase, Host, Object, RawVal, Status, Symbol}; use core::fmt::Debug; use std::rc::Weak; diff --git a/soroban-test-wasms/wasm-workspace/Cargo.lock b/soroban-test-wasms/wasm-workspace/Cargo.lock index ddf3e4c4d..567ceb443 100644 --- a/soroban-test-wasms/wasm-workspace/Cargo.lock +++ b/soroban-test-wasms/wasm-workspace/Cargo.lock @@ -79,9 +79,9 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "bytes-lit" -version = "0.0.3" +version = "0.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3a949b8abd1d84c29a91f4c8480dac1b426d53cebc9a31a8424a5cbe5be32f6" +checksum = "1c181bca161a49348b90fa75f9a54fe11b7138098eed90d841a1055d574b4250" dependencies = [ "num-bigint", "proc-macro2", @@ -345,6 +345,12 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "indexmap-nostd" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e04e2fd2b8188ea827b32ef11de88377086d690286ab35747ef7f9bf3ccb590" + [[package]] name = "itertools" version = "0.10.3" @@ -630,7 +636,7 @@ dependencies = [ [[package]] name = "soroban-env-common" -version = "0.0.4" +version = "0.0.5" dependencies = [ "soroban-env-macros", "soroban-wasmi", @@ -640,7 +646,7 @@ dependencies = [ [[package]] name = "soroban-env-guest" -version = "0.0.4" +version = "0.0.5" dependencies = [ "soroban-env-common", "static_assertions", @@ -648,7 +654,7 @@ dependencies = [ [[package]] name = "soroban-env-host" -version = "0.0.4" +version = "0.0.5" dependencies = [ "backtrace", "dyn-fmt", @@ -670,7 +676,7 @@ dependencies = [ [[package]] name = "soroban-env-macros" -version = "0.0.4" +version = "0.0.5" dependencies = [ "itertools", "proc-macro2", @@ -681,7 +687,7 @@ dependencies = [ [[package]] name = "soroban-native-sdk-macros" -version = "0.0.4" +version = "0.0.5" dependencies = [ "itertools", "proc-macro2", @@ -692,7 +698,7 @@ dependencies = [ [[package]] name = "soroban-sdk" version = "0.0.4" -source = "git+https://github.com/sisuresh/rs-stellar-contract-sdk?rev=39a886b#39a886b2d423bde3db4aec27abea02f665c26547" +source = "git+https://github.com/stellar/rs-soroban-sdk?rev=8c35444b52ce5b59edde69415ff4cb7f9127b983#8c35444b52ce5b59edde69415ff4cb7f9127b983" dependencies = [ "bytes-lit", "ed25519-dalek", @@ -704,7 +710,7 @@ dependencies = [ [[package]] name = "soroban-sdk-macros" version = "0.0.4" -source = "git+https://github.com/sisuresh/rs-stellar-contract-sdk?rev=39a886b#39a886b2d423bde3db4aec27abea02f665c26547" +source = "git+https://github.com/stellar/rs-soroban-sdk?rev=8c35444b52ce5b59edde69415ff4cb7f9127b983#8c35444b52ce5b59edde69415ff4cb7f9127b983" dependencies = [ "darling", "itertools", @@ -720,8 +726,7 @@ dependencies = [ [[package]] name = "soroban-spec" version = "0.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81c656e53b7b18e559f86d2657e051948f670d89404074c1e7f6094e9546c205" +source = "git+https://github.com/stellar/rs-soroban-sdk?rev=8c35444b52ce5b59edde69415ff4cb7f9127b983#8c35444b52ce5b59edde69415ff4cb7f9127b983" dependencies = [ "base64", "darling", @@ -741,35 +746,32 @@ dependencies = [ [[package]] name = "soroban-wasmi" -version = "0.11.0" -source = "git+https://github.com/stellar/wasmi?rev=7b1f2355#7b1f2355ba26d09daf0241f953eb16f7afe16057" +version = "0.16.0" +source = "git+https://github.com/stellar/wasmi?rev=a61b6df#a61b6dffa0a13aca70b046fc11e379a3fde31147" dependencies = [ - "parity-wasm", - "soroban-wasmi-validation", "soroban-wasmi_core", -] - -[[package]] -name = "soroban-wasmi-validation" -version = "0.4.1" -source = "git+https://github.com/stellar/wasmi?rev=7b1f2355#7b1f2355ba26d09daf0241f953eb16f7afe16057" -dependencies = [ - "parity-wasm", + "spin", + "wasmparser-nostd", ] [[package]] name = "soroban-wasmi_core" -version = "0.1.0" -source = "git+https://github.com/stellar/wasmi?rev=7b1f2355#7b1f2355ba26d09daf0241f953eb16f7afe16057" +version = "0.2.0" +source = "git+https://github.com/stellar/wasmi?rev=a61b6df#a61b6dffa0a13aca70b046fc11e379a3fde31147" dependencies = [ "downcast-rs", "libm", "memory_units", "num-rational", "num-traits", - "parity-wasm", ] +[[package]] +name = "spin" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f6002a767bff9e83f8eeecf883ecb8011875a21ae8da43bffb817a57e78cc09" + [[package]] name = "static_assertions" version = "1.1.0" @@ -779,7 +781,7 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "stellar-xdr" version = "0.0.2" -source = "git+https://github.com/stellar/rs-stellar-xdr?rev=fee9a436#fee9a436be1af3a0c99c2f967758f39f958e5ff4" +source = "git+https://github.com/stellar/rs-stellar-xdr?rev=fb78a6b8#fb78a6b84c807fd2641cf257818060e1d7d26c62" dependencies = [ "base64", "serde", @@ -894,6 +896,15 @@ dependencies = [ "indexmap", ] +[[package]] +name = "wasmparser-nostd" +version = "0.90.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92a94fbf4c521b038f41382df2056cf47099d3b7a0faa5a6e46f7771fd7c84a6" +dependencies = [ + "indexmap-nostd", +] + [[package]] name = "zeroize" version = "1.3.0" diff --git a/soroban-test-wasms/wasm-workspace/Cargo.toml b/soroban-test-wasms/wasm-workspace/Cargo.toml index 9c480a0b1..0654139aa 100644 --- a/soroban-test-wasms/wasm-workspace/Cargo.toml +++ b/soroban-test-wasms/wasm-workspace/Cargo.toml @@ -34,11 +34,11 @@ soroban-native-sdk-macros = { path = "../../soroban-native-sdk-macros" } # You should update this rev to the XDR rev used by the outer workspace # anytime you're going to recompile this workspace. -stellar-xdr = { git = "https://github.com/stellar/rs-stellar-xdr", rev = "fee9a436" } +stellar-xdr = { git = "https://github.com/stellar/rs-stellar-xdr", rev = "fb78a6b8" } # You should actually be able to set this to be any existing version of wasmi because we are # not building the SDK in host mode, so the "vm" feature is off. -wasmi = { package = "soroban-wasmi", git = "https://github.com/stellar/wasmi", rev = "3bda8032" } +wasmi = { package = "soroban-wasmi", git = "https://github.com/stellar/wasmi", rev = "a61b6df" } # The following SDK patch lines must denote an SDK version that is _compatible_ # with the current version of soroban-env-guest and soroban-env-common, as found @@ -93,8 +93,13 @@ wasmi = { package = "soroban-wasmi", git = "https://github.com/stellar/wasmi", r # when you change the Env trait itself, and whatever change you make to Env may # well cause recompilation to fail. Again, you will know if it doesn't compile! -soroban-sdk = { git = "https://github.com/stellar/rs-soroban-sdk", rev = "e10f13cbe3c5c2dc3d7a3d0bc3616467352181b0" } -soroban-sdk-macros = { git = "https://github.com/stellar/rs-soroban-sdk", rev = "e10f13cbe3c5c2dc3d7a3d0bc3616467352181b0" } +soroban-sdk = { git = "https://github.com/stellar/rs-soroban-sdk", rev = "8c35444b52ce5b59edde69415ff4cb7f9127b983" } +soroban-sdk-macros = { git = "https://github.com/stellar/rs-soroban-sdk", rev = "8c35444b52ce5b59edde69415ff4cb7f9127b983" } +soroban-spec = { git = "https://github.com/stellar/rs-soroban-sdk", rev = "8c35444b52ce5b59edde69415ff4cb7f9127b983" } + +# soroban-auth is currently not-used by these examples, but is in the SDK repo +# and must be patched in lock-step with the others if it's ever used here. +# soroban-auth = { git = "https://github.com/stellar/rs-soroban-sdk", rev = "8c35444b52ce5b59edde69415ff4cb7f9127b983" } [profile.release] opt-level = "z" diff --git a/soroban-test-wasms/wasm-workspace/invoke_contract/src/lib.rs b/soroban-test-wasms/wasm-workspace/invoke_contract/src/lib.rs index fd1bcddc8..1cc6bee3d 100644 --- a/soroban-test-wasms/wasm-workspace/invoke_contract/src/lib.rs +++ b/soroban-test-wasms/wasm-workspace/invoke_contract/src/lib.rs @@ -9,7 +9,7 @@ impl Contract { env.invoke_contract( &contract_id, &Symbol::from_str("add"), - vec![&env, x.into_env_val(&env), y.into_env_val(&env)], + vec![&env, x.into_val(&env), y.into_val(&env)], ) } } diff --git a/soroban-test-wasms/wasm-workspace/opt/example_add_i32.wasm b/soroban-test-wasms/wasm-workspace/opt/example_add_i32.wasm index 5fc3a261b..04cbca859 100644 Binary files a/soroban-test-wasms/wasm-workspace/opt/example_add_i32.wasm and b/soroban-test-wasms/wasm-workspace/opt/example_add_i32.wasm differ diff --git a/soroban-test-wasms/wasm-workspace/opt/example_contract_data.wasm b/soroban-test-wasms/wasm-workspace/opt/example_contract_data.wasm index 6ecef044a..70f7c53a1 100644 Binary files a/soroban-test-wasms/wasm-workspace/opt/example_contract_data.wasm and b/soroban-test-wasms/wasm-workspace/opt/example_contract_data.wasm differ diff --git a/soroban-test-wasms/wasm-workspace/opt/example_create_contract.wasm b/soroban-test-wasms/wasm-workspace/opt/example_create_contract.wasm index 31b9916a6..d490a6f17 100644 Binary files a/soroban-test-wasms/wasm-workspace/opt/example_create_contract.wasm and b/soroban-test-wasms/wasm-workspace/opt/example_create_contract.wasm differ diff --git a/soroban-test-wasms/wasm-workspace/opt/example_invoke_contract.wasm b/soroban-test-wasms/wasm-workspace/opt/example_invoke_contract.wasm index 692bda021..305961c96 100644 Binary files a/soroban-test-wasms/wasm-workspace/opt/example_invoke_contract.wasm and b/soroban-test-wasms/wasm-workspace/opt/example_invoke_contract.wasm differ diff --git a/soroban-test-wasms/wasm-workspace/opt/example_linear_memory.wasm b/soroban-test-wasms/wasm-workspace/opt/example_linear_memory.wasm index 87f83b06c..c4db97eb6 100644 Binary files a/soroban-test-wasms/wasm-workspace/opt/example_linear_memory.wasm and b/soroban-test-wasms/wasm-workspace/opt/example_linear_memory.wasm differ diff --git a/soroban-test-wasms/wasm-workspace/opt/example_vec.wasm b/soroban-test-wasms/wasm-workspace/opt/example_vec.wasm index 782e0449a..a76a0e980 100644 Binary files a/soroban-test-wasms/wasm-workspace/opt/example_vec.wasm and b/soroban-test-wasms/wasm-workspace/opt/example_vec.wasm differ