diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 6125e6e9b..453036ebc 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -83,9 +83,9 @@ jobs: with: name: cargo-hack version: 0.5.16 - - run: cargo hack --feature-powerset clippy --locked --target ${{ matrix.sys.target }} + - run: cargo hack --each-feature clippy --locked --target ${{ matrix.sys.target }} - if: matrix.sys.test - run: cargo hack --feature-powerset test --locked --target ${{ matrix.sys.target }} + run: cargo hack --each-feature test --locked --target ${{ matrix.sys.target }} publish-dry-run: if: github.event_name == 'push' || startsWith(github.head_ref, 'release/') diff --git a/Makefile b/Makefile index 1a1df864b..1373ea10c 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,10 @@ all: build test test: - cargo hack --feature-powerset test + cargo hack --each-feature test build: - cargo hack --feature-powerset clippy + cargo hack --each-feature clippy watch: cargo watch --clear --watch-when-idle --shell '$(MAKE)' diff --git a/publish-dry-run.sh b/publish-dry-run.sh index 4e3784230..bab1040e7 100755 --- a/publish-dry-run.sh +++ b/publish-dry-run.sh @@ -15,7 +15,7 @@ mv Cargo.toml.bak Cargo.toml # Package the crates that will be published. Verification is disabled because # we aren't ready to verify yet. -cargo-hack hack --ignore-private package --no-verify --feature-powerset +cargo-hack hack --ignore-private package --no-verify --each-feature # Add each crate that was packaged to the vendor/ directory. for crate in target/package/*.crate diff --git a/soroban-env-host/src/events/system_events.rs b/soroban-env-host/src/events/system_events.rs index d208adb88..bbd54347a 100644 --- a/soroban-env-host/src/events/system_events.rs +++ b/soroban-env-host/src/events/system_events.rs @@ -9,10 +9,10 @@ impl Host { Ok(()) } - // Emits a system event for updating the contract executable. - // The only event topic is "executable_update" and the data contains - // a vector of [old_executable, new_executable] encoded as contract types - // (`ContractExecutable` above). + // Emits a system event for updating the contract executable. The topic + // vector contains the symbol "executable_update" followed by the + // old_executable and new_executable, encoded as contract types + // (`ContractExecutable` above). The event data is empty. pub(crate) fn emit_update_contract_event( &self, old_executable: &xdr::ContractExecutable, diff --git a/soroban-env-host/src/host.rs b/soroban-env-host/src/host.rs index b0747e02e..625e955c4 100644 --- a/soroban-env-host/src/host.rs +++ b/soroban-env-host/src/host.rs @@ -1,6 +1,3 @@ -#![allow(unused_variables)] -#![allow(dead_code)] - use core::{cell::RefCell, cmp::Ordering, fmt::Debug}; use std::rc::Rc; @@ -9,22 +6,22 @@ use crate::{ budget::{AsBudget, Budget}, events::{diagnostic::DiagnosticLevel, Events, InternalEventsBuffer}, host_object::{HostMap, HostObject, HostObjectType, HostVec}, - impl_bignum_host_fns_rhs_u32, impl_wrapping_obj_from_num, impl_wrapping_obj_to_num, + impl_bignum_host_fns, impl_bignum_host_fns_rhs_u32, impl_wrapping_obj_from_num, + impl_wrapping_obj_to_num, num::*, storage::Storage, xdr::{ int128_helpers, AccountId, Asset, ContractCostType, ContractEventType, ContractExecutable, - CreateContractArgs, Duration, Hash, LedgerEntryData, PublicKey, ScAddress, ScBytes, - ScErrorType, ScString, ScSymbol, ScVal, TimePoint, + ContractIdPreimage, ContractIdPreimageFromAddress, CreateContractArgs, Duration, Hash, + LedgerEntryData, PublicKey, ScAddress, ScBytes, ScErrorCode, ScErrorType, ScString, + ScSymbol, ScVal, TimePoint, Uint256, }, - AddressObject, Bool, BytesObject, ConversionError, Error, I128Object, I256Object, MapObject, - StorageType, StringObject, SymbolObject, SymbolSmall, SymbolStr, TryFromVal, U128Object, - U256Object, U32Val, U64Val, VecObject, VmCaller, VmCallerEnv, Void, I256, U256, + AddressObject, Bool, BytesObject, Compare, ConversionError, EnvBase, Error, I128Object, + I256Object, MapObject, Object, StorageType, StringObject, Symbol, SymbolObject, SymbolSmall, + TryFromVal, U128Object, U256Object, U32Val, U64Val, Val, VecObject, Vm, VmCaller, VmCallerEnv, + Void, I256, U256, }; -use crate::Vm; -use crate::{EnvBase, Object, Symbol, Val}; - mod comparison; mod conversion; pub(crate) mod crypto; @@ -41,23 +38,18 @@ pub(crate) mod metered_vector; pub(crate) mod metered_xdr; mod num; mod prng; -pub use prng::{Seed, SEED_BYTES}; mod validity; + pub use error::HostError; -use soroban_env_common::xdr::{ - ContractIdPreimage, ContractIdPreimageFromAddress, ScErrorCode, Uint256, -}; +pub use prng::{Seed, SEED_BYTES}; use self::{ frame::{Context, ContractReentryMode}, - prng::Prng, -}; -use self::{ metered_clone::{MeteredClone, MeteredContainer}, metered_xdr::metered_write_xdr, + prng::Prng, }; -use crate::impl_bignum_host_fns; -use crate::Compare; + #[cfg(any(test, feature = "testutils"))] pub use frame::ContractFunctionSet; pub(crate) use frame::Frame; @@ -144,6 +136,7 @@ impl Default for Host { macro_rules! impl_checked_borrow_helpers { ($field:ident, $t:ty, $borrow:ident, $borrow_mut:ident) => { impl Host { + #[allow(dead_code)] pub(crate) fn $borrow(&self) -> Result, HostError> { use crate::host::error::TryBorrowOrErr; self.0.$field.try_borrow_or_err_with( @@ -151,6 +144,7 @@ macro_rules! impl_checked_borrow_helpers { concat!("host.0.", stringify!($field), ".try_borrow failed"), ) } + #[allow(dead_code)] pub(crate) fn $borrow_mut(&self) -> Result, HostError> { use crate::host::error::TryBorrowOrErr; self.0.$field.try_borrow_mut_or_err_with( @@ -350,16 +344,6 @@ impl Host { self.with_ledger_info(|li| Ok(li.protocol_version)) } - /// Helper for mutating the [`Budget`] held in this [`Host`], either to - /// allocate it on contract creation or to deplete it on callbacks from - /// the VM or host functions. - pub(crate) fn with_budget(&self, f: F) -> Result - where - F: FnOnce(Budget) -> Result, - { - f(self.0.budget.clone()) - } - pub(crate) fn budget_ref(&self) -> &Budget { &self.0.budget } @@ -369,7 +353,7 @@ impl Host { } pub fn charge_budget(&self, ty: ContractCostType, input: Option) -> Result<(), HostError> { - self.0.budget.clone().charge(ty, input) + self.0.budget.charge(ty, input) } /// Accept a _unique_ (refcount = 1) host reference and destroy the @@ -386,43 +370,6 @@ impl Host { Error::from_type_and_code(ScErrorType::Context, ScErrorCode::InternalError).into() }) } - - // Testing interface to create values directly for later use via Env functions. - // It needs to be a `pub` method because benches are considered a separate crate. - #[cfg(any(test, feature = "testutils"))] - pub fn inject_val(&self, v: &ScVal) -> Result { - self.to_host_val(v).map(Into::into) - } - - fn symbol_matches(&self, s: &[u8], sym: Symbol) -> Result { - if let Ok(ss) = SymbolSmall::try_from(sym) { - let sstr: SymbolStr = ss.into(); - let slice: &[u8] = sstr.as_ref(); - self.as_budget() - .compare(&slice, &s) - .map(|c| c == Ordering::Equal) - } else { - let sobj: SymbolObject = sym.try_into()?; - self.visit_obj(sobj, |scsym: &ScSymbol| { - self.as_budget() - .compare(&scsym.as_slice(), &s) - .map(|c| c == Ordering::Equal) - }) - } - } - - fn check_symbol_matches(&self, s: &[u8], sym: Symbol) -> Result<(), HostError> { - if self.symbol_matches(s, sym)? { - Ok(()) - } else { - Err(self.err( - ScErrorType::Value, - ScErrorCode::InvalidInput, - "symbol mismatch", - &[sym.to_val()], - )) - } - } } // Notes on metering: these are called from the guest and thus charged on the VM instructions. @@ -1245,7 +1192,7 @@ impl VmCallerEnv for Host { &vm, keys_pos, len as usize, - |n, slice| { + |_n, slice| { self.charge_budget(ContractCostType::VmMemRead, Some(slice.len() as u64))?; let scsym = ScSymbol(slice.try_into()?); let sym = Symbol::try_from(self.to_host_val(&ScVal::Symbol(scsym))?)?; @@ -1292,6 +1239,14 @@ impl VmCallerEnv for Host { len, } = self.decode_vmslice(keys_pos, len)?; self.visit_obj(map, |mapobj: &HostMap| { + if mapobj.len() != len as usize { + return Err(self.err( + ScErrorType::Object, + ScErrorCode::UnexpectedSize, + "differing host map and output slice lengths when unpacking map to linear memory", + &[], + )); + } // Step 1: check all key symbols. self.metered_vm_scan_slices_in_linear_memory( vmcaller, @@ -1571,10 +1526,18 @@ impl VmCallerEnv for Host { ) -> Result { let VmSlice { vm, pos, len } = self.decode_vmslice(vals_pos, len)?; self.visit_obj(vec, |vecobj: &HostVec| { + if vecobj.len() != len as usize { + return Err(self.err( + ScErrorType::Object, + ScErrorCode::UnexpectedSize, + "differing host vector and output vector lengths when unpacking vec to linear memory", + &[], + )); + } self.metered_vm_write_vals_to_linear_memory( vmcaller, &vm, - vals_pos.into(), + pos, vecobj.as_slice(), |x| { Ok(u64::to_le_bytes( @@ -2618,6 +2581,26 @@ impl VmCallerEnv for Host { // endregion "prng" module functions } +#[cfg(any(test, feature = "testutils"))] +impl Host { + // Testing interface to create values directly for later use via Env functions. + // It needs to be a `pub` method because benches are considered a separate crate. + pub fn inject_val(&self, v: &ScVal) -> Result { + self.to_host_val(v).map(Into::into) + } + + /// Helper for mutating the [`Budget`] held in this [`Host`], either to + /// allocate it on contract creation or to deplete it on callbacks from + /// the VM or host functions. + #[allow(dead_code)] + pub(crate) fn with_budget(&self, f: F) -> Result + where + F: FnOnce(Budget) -> Result, + { + f(self.0.budget.clone()) + } +} + #[cfg(any(test, feature = "testutils"))] pub(crate) mod testutils { use std::cell::Cell; diff --git a/soroban-env-host/src/host/conversion.rs b/soroban-env-host/src/host/conversion.rs index 54be959c2..39e7de433 100644 --- a/soroban-env-host/src/host/conversion.rs +++ b/soroban-env-host/src/host/conversion.rs @@ -40,32 +40,6 @@ impl Host { self.usize_to_u32(u).map(|v| v.into()) } - // Notes on metering: free - pub(crate) fn usize_from_rawval_u32_input( - &self, - name: &'static str, - r: Val, - ) -> Result { - self.u32_from_rawval_input(name, r).map(|u| u as usize) - } - - // Notes on metering: free - pub(crate) fn u32_from_rawval_input( - &self, - name: &'static str, - r: Val, - ) -> Result { - match u32::try_from(r) { - Ok(v) => Ok(v), - Err(cvt) => Err(self.err( - ScErrorType::Value, - ScErrorCode::UnexpectedType, - "expecting U32Val", - &[r], - )), - } - } - pub(crate) fn u256_from_account(&self, account_id: &AccountId) -> Result { let crate::xdr::PublicKey::PublicKeyTypeEd25519(ed25519) = account_id.metered_clone(self)?.0; @@ -81,11 +55,11 @@ impl Host { let u: u32 = r.into(); match u8::try_from(u) { Ok(v) => Ok(v), - Err(cvt) => Err(self.err( + Err(_) => Err(self.err( ScErrorType::Value, ScErrorCode::InvalidInput, "expecting U32Val less than 256", - &[r.to_val()], + &[r.to_val(), name.try_into_val(self)?], )), } } @@ -119,7 +93,7 @@ impl Host { self.charge_budget(ContractCostType::HostMemCpy, Some(N as u64))?; Ok(arr.into()) } - Err(cvt) => Err(err!( + Err(_) => Err(err!( self, (ScErrorType::Object, ScErrorCode::UnexpectedSize), "expected fixed-length bytes slice, got slice with different size", diff --git a/soroban-env-host/src/host/crypto.rs b/soroban-env-host/src/host/crypto.rs index 07bb42325..c88ed4a29 100644 --- a/soroban-env-host/src/host/crypto.rs +++ b/soroban-env-host/src/host/crypto.rs @@ -11,15 +11,6 @@ use sha3::Keccak256; impl Host { // Ed25519 functions - - pub(crate) fn ed25519_signature_from_bytes( - &self, - name: &'static str, - bytes: &[u8], - ) -> Result { - self.fixed_length_bytes_from_slice::(name, bytes) - } - pub(crate) fn ed25519_signature_from_bytesobj_input( &self, name: &'static str, @@ -83,6 +74,10 @@ impl Host { // ECDSA secp256k1 functions + #[cfg(any(test, feature = "testutils"))] + // FIXME: this operation is dead code besides the code that claibrates it; + // the interface we settled on doesn't involve users converting bytes to + // public keys. see https://github.com/stellar/rs-soroban-env/issues/1087 pub(crate) fn secp256k1_pub_key_from_bytes( &self, bytes: &[u8], @@ -98,15 +93,6 @@ impl Host { }) } - pub(crate) fn secp256k1_pub_key_from_bytesobj_input( - &self, - k: BytesObject, - ) -> Result { - self.visit_obj(k, |bytes: &ScBytes| { - self.secp256k1_pub_key_from_bytes(bytes.as_slice()) - }) - } - pub(crate) fn secp256k1_signature_from_bytes( &self, bytes: &[u8], diff --git a/soroban-env-host/src/host/error.rs b/soroban-env-host/src/host/error.rs index cb670cd96..e4d6998c6 100644 --- a/soroban-env-host/src/host/error.rs +++ b/soroban-env-host/src/host/error.rs @@ -256,7 +256,7 @@ impl Host { .with_free_budget(|| events_ref.externalize(self)) { Ok(events) => events, - Err(e) => return None, + Err(_) => return None, }; let backtrace = Backtrace::new_unresolved(); return Some(Box::new(DebugInfo { backtrace, events })); @@ -295,15 +295,6 @@ impl Host { } } - pub(crate) fn err_wasmi_fuel_metering_disabled(&self) -> HostError { - self.err( - ScErrorType::WasmVm, - ScErrorCode::InternalError, - "wasmi fuel metering is disabled", - &[], - ) - } - /// Given a result carrying some error type that can be converted to an /// [Error] and supports [core::fmt::Debug], calls [Host::error] with the /// error when there's an error, also passing the result of @@ -455,7 +446,7 @@ pub(crate) trait DebugArg { fn debug_arg(host: &Host, arg: &Self) -> Val { // We similarly guard against double-faulting here by try-acquiring the event buffer, // which will fail if we're re-entering error reporting _while_ forming a debug argument. - if let Ok(guard) = host.0.events.try_borrow_mut() { + if let Ok(_guard) = host.0.events.try_borrow_mut() { host.as_budget() .with_free_budget(|| Self::debug_arg_maybe_expensive_or_fallible(host, arg)) .unwrap_or( @@ -492,7 +483,7 @@ impl DebugArg for str { } impl DebugArg for usize { - fn debug_arg_maybe_expensive_or_fallible(host: &Host, arg: &Self) -> Result { + fn debug_arg_maybe_expensive_or_fallible(_host: &Host, arg: &Self) -> Result { u32::try_from(*arg) .map(|x| U32Val::from(x).into()) .map_err(|_| HostError::from(ConversionError)) diff --git a/soroban-env-host/src/host/frame.rs b/soroban-env-host/src/host/frame.rs index f5b7266b6..0983495fd 100644 --- a/soroban-env-host/src/host/frame.rs +++ b/soroban-env-host/src/host/frame.rs @@ -33,6 +33,7 @@ pub(crate) enum ContractReentryMode { /// possible for a contract to do a self-call via host). SelfAllowed, /// Re-entry is fully allowed. + #[allow(dead_code)] Allowed, } @@ -639,7 +640,7 @@ impl Host { match &res { Ok(res) => self.fn_return_diagnostics(id, &func, res)?, - Err(err) => {} + Err(_err) => {} } res diff --git a/soroban-env-host/src/host/mem_helper.rs b/soroban-env-host/src/host/mem_helper.rs index a98d5e8e2..d898f459f 100644 --- a/soroban-env-host/src/host/mem_helper.rs +++ b/soroban-env-host/src/host/mem_helper.rs @@ -1,17 +1,13 @@ -use soroban_env_common::{ - xdr::{ScErrorCode, ScErrorType}, - U32Val, -}; - -use crate::{host_object::MemHostObjectType, xdr::ContractCostType, Host, HostError, VmCaller}; - -use std::rc::Rc; - use crate::{ + budget::AsBudget, host::{Frame, VmSlice}, - Vm, + host_object::MemHostObjectType, + xdr::{ContractCostType, ScErrorCode, ScErrorType, ScSymbol}, + Compare, Host, HostError, Symbol, SymbolObject, SymbolSmall, SymbolStr, U32Val, Vm, VmCaller, }; +use std::{cmp::Ordering, rc::Rc}; + impl Host { // Notes on metering: free pub(crate) fn decode_vmslice(&self, pos: U32Val, len: U32Val) -> Result { @@ -362,6 +358,36 @@ impl Host { self.add_host_object::(vnew.try_into()?) } + pub(crate) fn symbol_matches(&self, s: &[u8], sym: Symbol) -> Result { + if let Ok(ss) = SymbolSmall::try_from(sym) { + let sstr: SymbolStr = ss.into(); + let slice: &[u8] = sstr.as_ref(); + self.as_budget() + .compare(&slice, &s) + .map(|c| c == Ordering::Equal) + } else { + let sobj: SymbolObject = sym.try_into()?; + self.visit_obj(sobj, |scsym: &ScSymbol| { + self.as_budget() + .compare(&scsym.as_slice(), &s) + .map(|c| c == Ordering::Equal) + }) + } + } + + pub(crate) fn check_symbol_matches(&self, s: &[u8], sym: Symbol) -> Result<(), HostError> { + if self.symbol_matches(s, sym)? { + Ok(()) + } else { + Err(self.err( + ScErrorType::Value, + ScErrorCode::InvalidInput, + "symbol mismatch", + &[sym.to_val()], + )) + } + } + // Test function for calibration purpose. The caller needs to ensure `src` and `dest` has // the same length or else it panics. #[cfg(any(test, feature = "testutils"))] diff --git a/soroban-env-host/src/host/metered_clone.rs b/soroban-env-host/src/host/metered_clone.rs index c514aa584..ccfb8ce4c 100644 --- a/soroban-env-host/src/host/metered_clone.rs +++ b/soroban-env-host/src/host/metered_clone.rs @@ -159,7 +159,7 @@ pub trait MeteredClone: Clone + DeclaredSizeForMetering { // Self::IS_SHALLOW and set it to false, you should override this method also (it will actually // Err if you don't). This charge does not include shallow copying of `Self` because that // should be taken care of by the caller beforehand, e.g. in `metered_clone`. - fn charge_for_substructure(&self, budget: impl AsBudget) -> Result<(), HostError> { + fn charge_for_substructure(&self, _budget: impl AsBudget) -> Result<(), HostError> { if Self::IS_SHALLOW { Ok(()) } else { diff --git a/soroban-env-host/src/host/metered_xdr.rs b/soroban-env-host/src/host/metered_xdr.rs index 264cd2c7a..eab29fd85 100644 --- a/soroban-env-host/src/host/metered_xdr.rs +++ b/soroban-env-host/src/host/metered_xdr.rs @@ -1,15 +1,14 @@ use crate::{ budget::Budget, - xdr::ContractCostType, - xdr::{ReadXdr, ScBytes, WriteXdr}, + xdr::{ + ContractCostType, DepthLimitedWrite, ReadXdr, ScBytes, ScErrorCode, ScErrorType, WriteXdr, + DEFAULT_XDR_RW_DEPTH_LIMIT, + }, BytesObject, Host, HostError, }; use std::io::Write; use sha2::{Digest, Sha256}; -use soroban_env_common::xdr::{ - DepthLimitedWrite, ScErrorCode, ScErrorType, DEFAULT_XDR_RW_DEPTH_LIMIT, -}; struct MeteredWrite<'a, W: Write> { budget: &'a Budget, diff --git a/soroban-env-host/src/host/validity.rs b/soroban-env-host/src/host/validity.rs index 40d397931..2cccbcdf7 100644 --- a/soroban-env-host/src/host/validity.rs +++ b/soroban-env-host/src/host/validity.rs @@ -58,16 +58,10 @@ impl Host { a: usize, b: usize, ) -> Result { - let lim = u32::MAX as usize; - if a > lim || b > lim || a > (lim - b) { - Err(self.err( - ScErrorType::Value, - ScErrorCode::ExceededLimit, - "sum of sizes exceeds u32::MAX", - &[], - )) - } else { - Ok(a + b) - } + let a = u32::try_from(a).map_err(|_| self.err_arith_overflow())?; + let b = u32::try_from(b).map_err(|_| self.err_arith_overflow())?; + a.checked_add(b) + .ok_or_else(|| self.err_arith_overflow()) + .map(|u| u as usize) } } diff --git a/soroban-env-host/src/lib.rs b/soroban-env-host/src/lib.rs index 83c97588b..ecd3245e7 100644 --- a/soroban-env-host/src/lib.rs +++ b/soroban-env-host/src/lib.rs @@ -6,13 +6,9 @@ //! crate for use by host (or contract local-testing) code. Most of the type and //! module definitions visible here are actually defined in the common crate. //! -//! It may seem unusual to configure a contract host _without_ a VM, but this -//! configuration makes more sense when considering that Soroban supports a -//! "local testing" configuration where host and guest code are _both compiled -//! natively_ and linked together for a faster and richer debugging and testing -//! experience. When testing this way, developers may also wish to enable the -//! `"testutils"` feature, which enables an interface on [Host] for registering -//! other test contracts by ID. +//! When unit-testing contracts natively (not using wasm), developers may also +//! wish to enable the `"testutils"` feature, which enables an interface on +//! [Host] for registering other test contracts by ID. //! //! The [Host] type provides some facilities above and beyond just the [Env] //! trait, including: @@ -55,6 +51,7 @@ pub mod auth; pub mod vm; pub use vm::Vm; #[cfg(any(test, feature = "testutils"))] +#[doc(hidden)] pub mod cost_runner; pub mod storage; #[cfg(test)] diff --git a/soroban-env-host/src/test/vec.rs b/soroban-env-host/src/test/vec.rs index 701bba517..b21929b4b 100644 --- a/soroban-env-host/src/test/vec.rs +++ b/soroban-env-host/src/test/vec.rs @@ -1,6 +1,7 @@ use core::cmp::Ordering; -use soroban_env_common::{xdr::ScVal, Compare, Tag, U32Val}; +use soroban_env_common::{xdr::ScVal, Compare, Symbol, Tag, TryFromVal, U32Val}; +use soroban_test_wasms::LINEAR_MEMORY; use crate::{ xdr::{ScErrorCode, ScErrorType}, @@ -336,3 +337,34 @@ fn vec_build_bad_element_integrity() -> Result<(), HostError> { Ok(()) } + +#[test] +fn linear_memory_operations() -> Result<(), HostError> { + let host = Host::test_host_with_recording_footprint(); + let id_obj = host.register_test_contract_wasm(LINEAR_MEMORY); + + // Tests vec_unpack_to_linear_memory works when given correct input + { + let args = host.vec_new()?; + let res = host.call( + id_obj, + Symbol::try_from_val(&host, &"vec_mem_ok").unwrap(), + args, + ); + + assert!(res.is_ok()); + } + + // Tests vec_unpack_to_linear_memory fails when given incorrect input + { + let args = host.vec_new()?; + let res = host.call( + id_obj, + Symbol::try_from_val(&host, &"vec_mem_bad").unwrap(), + args, + ); + assert!(res.is_err()); + assert!(res.unwrap_err().error.is_code(ScErrorCode::UnexpectedSize)); + } + Ok(()) +} diff --git a/soroban-test-wasms/wasm-workspace/linear_memory/src/lib.rs b/soroban-test-wasms/wasm-workspace/linear_memory/src/lib.rs index f16647365..641ce3945 100644 --- a/soroban-test-wasms/wasm-workspace/linear_memory/src/lib.rs +++ b/soroban-test-wasms/wasm-workspace/linear_memory/src/lib.rs @@ -1,5 +1,6 @@ #![no_std] use soroban_sdk::{contract, contractimpl, Bytes, Env}; +use soroban_env_common::{VecObject, Val, EnvBase, Error}; #[contract] pub struct Contract; @@ -27,4 +28,27 @@ impl Contract { } Bytes::from_slice(&e, &buf) } + + // Bounce a vector of vals off the host, successfully + pub fn vec_mem_ok(e: Env) -> Result<(), Error> { + let in_buf: [Val; 3] = [Val::from(1), Val::from(2), Val::from(3)]; + let mut out_buf: [Val; 3] = [Val::from(0); 3]; + let vec: VecObject = e.vec_new_from_slice(&in_buf)?; + e.vec_unpack_to_slice(vec, &mut out_buf)?; + assert!(in_buf[0].shallow_eq(&out_buf[0])); + assert!(in_buf[1].shallow_eq(&out_buf[1])); + assert!(in_buf[2].shallow_eq(&out_buf[2])); + Ok(()) + } + + // Same but with a length mismatch + pub fn vec_mem_bad(e: Env) -> Result<(), Error> { + let in_buf: [Val; 3] = [Val::from(1), Val::from(2), Val::from(3)]; + let mut long_buf: [Val; 4] = [Val::from(0); 4]; + let mut short_buf: [Val; 2] = [Val::from(0); 2]; + let vec: VecObject = e.vec_new_from_slice(&in_buf)?; + assert!(e.vec_unpack_to_slice(vec, &mut short_buf).is_err()); + assert!(e.vec_unpack_to_slice(vec, &mut long_buf).is_err()); + Ok(()) + } } diff --git a/soroban-test-wasms/wasm-workspace/opt/curr/auth_test_contract.wasm b/soroban-test-wasms/wasm-workspace/opt/curr/auth_test_contract.wasm index 2be561a6d..f63ee3b5e 100644 Binary files a/soroban-test-wasms/wasm-workspace/opt/curr/auth_test_contract.wasm and b/soroban-test-wasms/wasm-workspace/opt/curr/auth_test_contract.wasm differ diff --git a/soroban-test-wasms/wasm-workspace/opt/curr/example_add_f32.wasm b/soroban-test-wasms/wasm-workspace/opt/curr/example_add_f32.wasm index dbabd570f..c059f0f48 100644 Binary files a/soroban-test-wasms/wasm-workspace/opt/curr/example_add_f32.wasm and b/soroban-test-wasms/wasm-workspace/opt/curr/example_add_f32.wasm differ diff --git a/soroban-test-wasms/wasm-workspace/opt/curr/example_add_i32.wasm b/soroban-test-wasms/wasm-workspace/opt/curr/example_add_i32.wasm index eef79589d..20a7f9495 100644 Binary files a/soroban-test-wasms/wasm-workspace/opt/curr/example_add_i32.wasm and b/soroban-test-wasms/wasm-workspace/opt/curr/example_add_i32.wasm differ diff --git a/soroban-test-wasms/wasm-workspace/opt/curr/example_alloc.wasm b/soroban-test-wasms/wasm-workspace/opt/curr/example_alloc.wasm index 1018ec193..506576cb7 100644 Binary files a/soroban-test-wasms/wasm-workspace/opt/curr/example_alloc.wasm and b/soroban-test-wasms/wasm-workspace/opt/curr/example_alloc.wasm differ diff --git a/soroban-test-wasms/wasm-workspace/opt/curr/example_complex.wasm b/soroban-test-wasms/wasm-workspace/opt/curr/example_complex.wasm index 273de9611..286f04984 100644 Binary files a/soroban-test-wasms/wasm-workspace/opt/curr/example_complex.wasm and b/soroban-test-wasms/wasm-workspace/opt/curr/example_complex.wasm differ diff --git a/soroban-test-wasms/wasm-workspace/opt/curr/example_contract_data.wasm b/soroban-test-wasms/wasm-workspace/opt/curr/example_contract_data.wasm index 0e2b43115..1c34044e9 100644 Binary files a/soroban-test-wasms/wasm-workspace/opt/curr/example_contract_data.wasm and b/soroban-test-wasms/wasm-workspace/opt/curr/example_contract_data.wasm differ diff --git a/soroban-test-wasms/wasm-workspace/opt/curr/example_create_contract.wasm b/soroban-test-wasms/wasm-workspace/opt/curr/example_create_contract.wasm index 235a209a5..3a3a4076c 100644 Binary files a/soroban-test-wasms/wasm-workspace/opt/curr/example_create_contract.wasm and b/soroban-test-wasms/wasm-workspace/opt/curr/example_create_contract.wasm differ diff --git a/soroban-test-wasms/wasm-workspace/opt/curr/example_err.wasm b/soroban-test-wasms/wasm-workspace/opt/curr/example_err.wasm index 346e59f96..ee3704912 100644 Binary files a/soroban-test-wasms/wasm-workspace/opt/curr/example_err.wasm and b/soroban-test-wasms/wasm-workspace/opt/curr/example_err.wasm differ diff --git a/soroban-test-wasms/wasm-workspace/opt/curr/example_fannkuch.wasm b/soroban-test-wasms/wasm-workspace/opt/curr/example_fannkuch.wasm index e7f38dab5..cb523d49b 100644 Binary files a/soroban-test-wasms/wasm-workspace/opt/curr/example_fannkuch.wasm and b/soroban-test-wasms/wasm-workspace/opt/curr/example_fannkuch.wasm differ diff --git a/soroban-test-wasms/wasm-workspace/opt/curr/example_fib.wasm b/soroban-test-wasms/wasm-workspace/opt/curr/example_fib.wasm index f1edbd8b4..f59d90ced 100644 Binary files a/soroban-test-wasms/wasm-workspace/opt/curr/example_fib.wasm and b/soroban-test-wasms/wasm-workspace/opt/curr/example_fib.wasm differ diff --git a/soroban-test-wasms/wasm-workspace/opt/curr/example_hostile.wasm b/soroban-test-wasms/wasm-workspace/opt/curr/example_hostile.wasm index 9534824e3..fe237a79f 100644 Binary files a/soroban-test-wasms/wasm-workspace/opt/curr/example_hostile.wasm and b/soroban-test-wasms/wasm-workspace/opt/curr/example_hostile.wasm differ diff --git a/soroban-test-wasms/wasm-workspace/opt/curr/example_invoke_contract.wasm b/soroban-test-wasms/wasm-workspace/opt/curr/example_invoke_contract.wasm index 0b4ae0610..e48807e2d 100644 Binary files a/soroban-test-wasms/wasm-workspace/opt/curr/example_invoke_contract.wasm and b/soroban-test-wasms/wasm-workspace/opt/curr/example_invoke_contract.wasm differ diff --git a/soroban-test-wasms/wasm-workspace/opt/curr/example_linear_memory.wasm b/soroban-test-wasms/wasm-workspace/opt/curr/example_linear_memory.wasm index 3ec5f8204..d552553f0 100644 Binary files a/soroban-test-wasms/wasm-workspace/opt/curr/example_linear_memory.wasm and b/soroban-test-wasms/wasm-workspace/opt/curr/example_linear_memory.wasm differ diff --git a/soroban-test-wasms/wasm-workspace/opt/curr/example_simple_account.wasm b/soroban-test-wasms/wasm-workspace/opt/curr/example_simple_account.wasm index 49190dd99..bc3494770 100644 Binary files a/soroban-test-wasms/wasm-workspace/opt/curr/example_simple_account.wasm and b/soroban-test-wasms/wasm-workspace/opt/curr/example_simple_account.wasm differ diff --git a/soroban-test-wasms/wasm-workspace/opt/curr/example_updateable_contract.wasm b/soroban-test-wasms/wasm-workspace/opt/curr/example_updateable_contract.wasm index e916d0fc7..61e70a276 100644 Binary files a/soroban-test-wasms/wasm-workspace/opt/curr/example_updateable_contract.wasm and b/soroban-test-wasms/wasm-workspace/opt/curr/example_updateable_contract.wasm differ diff --git a/soroban-test-wasms/wasm-workspace/opt/curr/example_vec.wasm b/soroban-test-wasms/wasm-workspace/opt/curr/example_vec.wasm index 98c311d2e..190e26fab 100644 Binary files a/soroban-test-wasms/wasm-workspace/opt/curr/example_vec.wasm and b/soroban-test-wasms/wasm-workspace/opt/curr/example_vec.wasm differ diff --git a/soroban-test-wasms/wasm-workspace/opt/curr/soroban_write_upgrade_bytes_contract.wasm b/soroban-test-wasms/wasm-workspace/opt/curr/soroban_write_upgrade_bytes_contract.wasm index 049661886..429256c5d 100644 Binary files a/soroban-test-wasms/wasm-workspace/opt/curr/soroban_write_upgrade_bytes_contract.wasm and b/soroban-test-wasms/wasm-workspace/opt/curr/soroban_write_upgrade_bytes_contract.wasm differ diff --git a/soroban-test-wasms/wasm-workspace/opt/curr/test_delegated_account.wasm b/soroban-test-wasms/wasm-workspace/opt/curr/test_delegated_account.wasm index c44b4064c..379a621dc 100644 Binary files a/soroban-test-wasms/wasm-workspace/opt/curr/test_delegated_account.wasm and b/soroban-test-wasms/wasm-workspace/opt/curr/test_delegated_account.wasm differ diff --git a/soroban-test-wasms/wasm-workspace/opt/next/auth_test_contract.wasm b/soroban-test-wasms/wasm-workspace/opt/next/auth_test_contract.wasm index 3d9f12b92..a981aa30d 100644 Binary files a/soroban-test-wasms/wasm-workspace/opt/next/auth_test_contract.wasm and b/soroban-test-wasms/wasm-workspace/opt/next/auth_test_contract.wasm differ diff --git a/soroban-test-wasms/wasm-workspace/opt/next/example_add_f32.wasm b/soroban-test-wasms/wasm-workspace/opt/next/example_add_f32.wasm index 8bbcc8252..c3e374ced 100644 Binary files a/soroban-test-wasms/wasm-workspace/opt/next/example_add_f32.wasm and b/soroban-test-wasms/wasm-workspace/opt/next/example_add_f32.wasm differ diff --git a/soroban-test-wasms/wasm-workspace/opt/next/example_add_i32.wasm b/soroban-test-wasms/wasm-workspace/opt/next/example_add_i32.wasm index ca570c926..d0540b01d 100644 Binary files a/soroban-test-wasms/wasm-workspace/opt/next/example_add_i32.wasm and b/soroban-test-wasms/wasm-workspace/opt/next/example_add_i32.wasm differ diff --git a/soroban-test-wasms/wasm-workspace/opt/next/example_alloc.wasm b/soroban-test-wasms/wasm-workspace/opt/next/example_alloc.wasm index 16eed98f7..338086dd9 100644 Binary files a/soroban-test-wasms/wasm-workspace/opt/next/example_alloc.wasm and b/soroban-test-wasms/wasm-workspace/opt/next/example_alloc.wasm differ diff --git a/soroban-test-wasms/wasm-workspace/opt/next/example_complex.wasm b/soroban-test-wasms/wasm-workspace/opt/next/example_complex.wasm index 5f87556d9..8f30fa8b3 100644 Binary files a/soroban-test-wasms/wasm-workspace/opt/next/example_complex.wasm and b/soroban-test-wasms/wasm-workspace/opt/next/example_complex.wasm differ diff --git a/soroban-test-wasms/wasm-workspace/opt/next/example_contract_data.wasm b/soroban-test-wasms/wasm-workspace/opt/next/example_contract_data.wasm index ad8cdf4f5..4d33d8b43 100644 Binary files a/soroban-test-wasms/wasm-workspace/opt/next/example_contract_data.wasm and b/soroban-test-wasms/wasm-workspace/opt/next/example_contract_data.wasm differ diff --git a/soroban-test-wasms/wasm-workspace/opt/next/example_create_contract.wasm b/soroban-test-wasms/wasm-workspace/opt/next/example_create_contract.wasm index 29e6fa74d..aaa4d6bb5 100644 Binary files a/soroban-test-wasms/wasm-workspace/opt/next/example_create_contract.wasm and b/soroban-test-wasms/wasm-workspace/opt/next/example_create_contract.wasm differ diff --git a/soroban-test-wasms/wasm-workspace/opt/next/example_err.wasm b/soroban-test-wasms/wasm-workspace/opt/next/example_err.wasm index 3691f0aef..5e329294d 100644 Binary files a/soroban-test-wasms/wasm-workspace/opt/next/example_err.wasm and b/soroban-test-wasms/wasm-workspace/opt/next/example_err.wasm differ diff --git a/soroban-test-wasms/wasm-workspace/opt/next/example_fannkuch.wasm b/soroban-test-wasms/wasm-workspace/opt/next/example_fannkuch.wasm index 27250c0ef..113132cfd 100644 Binary files a/soroban-test-wasms/wasm-workspace/opt/next/example_fannkuch.wasm and b/soroban-test-wasms/wasm-workspace/opt/next/example_fannkuch.wasm differ diff --git a/soroban-test-wasms/wasm-workspace/opt/next/example_fib.wasm b/soroban-test-wasms/wasm-workspace/opt/next/example_fib.wasm index f462b1f4d..5ec2fbd77 100644 Binary files a/soroban-test-wasms/wasm-workspace/opt/next/example_fib.wasm and b/soroban-test-wasms/wasm-workspace/opt/next/example_fib.wasm differ diff --git a/soroban-test-wasms/wasm-workspace/opt/next/example_hostile.wasm b/soroban-test-wasms/wasm-workspace/opt/next/example_hostile.wasm index a49915cd2..c4f8bd0b8 100644 Binary files a/soroban-test-wasms/wasm-workspace/opt/next/example_hostile.wasm and b/soroban-test-wasms/wasm-workspace/opt/next/example_hostile.wasm differ diff --git a/soroban-test-wasms/wasm-workspace/opt/next/example_invoke_contract.wasm b/soroban-test-wasms/wasm-workspace/opt/next/example_invoke_contract.wasm index adef6f878..43b9c1171 100644 Binary files a/soroban-test-wasms/wasm-workspace/opt/next/example_invoke_contract.wasm and b/soroban-test-wasms/wasm-workspace/opt/next/example_invoke_contract.wasm differ diff --git a/soroban-test-wasms/wasm-workspace/opt/next/example_linear_memory.wasm b/soroban-test-wasms/wasm-workspace/opt/next/example_linear_memory.wasm index 36773d652..5361d0b4a 100644 Binary files a/soroban-test-wasms/wasm-workspace/opt/next/example_linear_memory.wasm and b/soroban-test-wasms/wasm-workspace/opt/next/example_linear_memory.wasm differ diff --git a/soroban-test-wasms/wasm-workspace/opt/next/example_simple_account.wasm b/soroban-test-wasms/wasm-workspace/opt/next/example_simple_account.wasm index b32ad7f0d..526fa95cf 100644 Binary files a/soroban-test-wasms/wasm-workspace/opt/next/example_simple_account.wasm and b/soroban-test-wasms/wasm-workspace/opt/next/example_simple_account.wasm differ diff --git a/soroban-test-wasms/wasm-workspace/opt/next/example_updateable_contract.wasm b/soroban-test-wasms/wasm-workspace/opt/next/example_updateable_contract.wasm index 95a6ae196..95f653370 100644 Binary files a/soroban-test-wasms/wasm-workspace/opt/next/example_updateable_contract.wasm and b/soroban-test-wasms/wasm-workspace/opt/next/example_updateable_contract.wasm differ diff --git a/soroban-test-wasms/wasm-workspace/opt/next/example_vec.wasm b/soroban-test-wasms/wasm-workspace/opt/next/example_vec.wasm index da669daf7..d764506a9 100644 Binary files a/soroban-test-wasms/wasm-workspace/opt/next/example_vec.wasm and b/soroban-test-wasms/wasm-workspace/opt/next/example_vec.wasm differ diff --git a/soroban-test-wasms/wasm-workspace/opt/next/soroban_write_upgrade_bytes_contract.wasm b/soroban-test-wasms/wasm-workspace/opt/next/soroban_write_upgrade_bytes_contract.wasm index 75fa80f44..b0ee47bd9 100644 Binary files a/soroban-test-wasms/wasm-workspace/opt/next/soroban_write_upgrade_bytes_contract.wasm and b/soroban-test-wasms/wasm-workspace/opt/next/soroban_write_upgrade_bytes_contract.wasm differ diff --git a/soroban-test-wasms/wasm-workspace/opt/next/test_delegated_account.wasm b/soroban-test-wasms/wasm-workspace/opt/next/test_delegated_account.wasm index 1a3bc5fc7..b88a9fd03 100644 Binary files a/soroban-test-wasms/wasm-workspace/opt/next/test_delegated_account.wasm and b/soroban-test-wasms/wasm-workspace/opt/next/test_delegated_account.wasm differ