From eeccda99581299704a41d6d2cef333e6426adc0a Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Wed, 12 Feb 2025 12:49:56 -0600 Subject: [PATCH] v0.8.0 Release Candidate (#218) * update versions * bug fixes in the rc * fix up export of stylus test * test in dev deps * add testing dep --- Cargo.lock | 10 ++++---- Cargo.toml | 8 +++--- stylus-sdk/Cargo.toml | 4 ++- stylus-sdk/src/call/mod.rs | 7 +++--- stylus-sdk/src/call/raw.rs | 44 ++++++++++++++------------------- stylus-sdk/src/call/transfer.rs | 5 ++-- stylus-sdk/src/host/calls.rs | 10 ++++---- stylus-sdk/src/host/mod.rs | 2 +- stylus-sdk/src/lib.rs | 2 +- stylus-test/src/vm.rs | 2 +- 10 files changed, 43 insertions(+), 51 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1205fe8..ac05967 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1752,7 +1752,7 @@ checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" [[package]] name = "mini-alloc" -version = "0.7.0" +version = "0.8.0" dependencies = [ "cfg-if", "wasm-bindgen-test", @@ -2734,7 +2734,7 @@ dependencies = [ [[package]] name = "stylus-core" -version = "0.7.0" +version = "0.8.0" dependencies = [ "alloy-primitives", "alloy-sol-types", @@ -2744,7 +2744,7 @@ dependencies = [ [[package]] name = "stylus-proc" -version = "0.7.0" +version = "0.8.0" dependencies = [ "alloy-primitives", "alloy-sol-types", @@ -2768,7 +2768,7 @@ dependencies = [ [[package]] name = "stylus-sdk" -version = "0.7.0" +version = "0.8.0" dependencies = [ "alloy-primitives", "alloy-sol-types", @@ -2789,7 +2789,7 @@ dependencies = [ [[package]] name = "stylus-test" -version = "0.7.0" +version = "0.8.0" dependencies = [ "alloy-primitives", "alloy-provider", diff --git a/Cargo.toml b/Cargo.toml index f10dbed..42b7c88 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ members = ["stylus-sdk", "stylus-proc", "stylus-test", "mini-alloc", "stylus-cor resolver = "2" [workspace.package] -version = "0.7.0" +version = "0.8.0" edition = "2021" authors = ["Offchain Labs"] license = "MIT OR Apache-2.0" @@ -39,8 +39,8 @@ prettyplease = "0.2.22" trybuild = "1.0" # members -mini-alloc = { path = "mini-alloc", version = "0.7.0-rc.1" } +mini-alloc = { path = "mini-alloc", version = "0.8.0" } stylus-sdk = { path = "stylus-sdk" } stylus-core = { path = "stylus-core" } -stylus-test = { path = "stylus-test" } -stylus-proc = { path = "stylus-proc", version = "0.7.0-rc.1" } +stylus-test = { path = "stylus-test", version = "0.8.0" } +stylus-proc = { path = "stylus-proc", version = "0.8.0" } diff --git a/stylus-sdk/Cargo.toml b/stylus-sdk/Cargo.toml index 1615ba9..08de453 100644 --- a/stylus-sdk/Cargo.toml +++ b/stylus-sdk/Cargo.toml @@ -27,12 +27,14 @@ mini-alloc = { workspace = true, optional = true } stylus-proc.workspace = true stylus-core.workspace = true +[target.'cfg(not(target_arch = "wasm32"))'.dependencies] +stylus-test.workspace = true + [dev-dependencies] paste.workspace = true sha3.workspace = true alloy-primitives = { workspace = true, default-features = false, features=["tiny-keccak"] } rclite.workspace = true -stylus-test.workspace = true [package.metadata.docs.rs] features = ["default", "docs", "debug", "export-abi"] diff --git a/stylus-sdk/src/call/mod.rs b/stylus-sdk/src/call/mod.rs index d41d820..9f46488 100644 --- a/stylus-sdk/src/call/mod.rs +++ b/stylus-sdk/src/call/mod.rs @@ -22,7 +22,6 @@ pub use self::{ pub(crate) use raw::CachePolicy; -use crate::host::WasmVM; #[cfg(feature = "reentrant")] use crate::storage::Storage; @@ -59,7 +58,7 @@ pub fn static_call( Storage::flush(); // flush storage to persist changes, but don't invalidate the cache unsafe_reentrant! {{ - RawCall::::new_static() + RawCall::new_static() .gas(context.gas()) .call(to, data) .map_err(Error::Revert) @@ -86,7 +85,7 @@ pub unsafe fn delegate_call( #[cfg(feature = "reentrant")] Storage::clear(); // clear the storage to persist changes, invalidating the cache - RawCall::::new_delegate() + RawCall::new_delegate() .gas(context.gas()) .call(to, data) .map_err(Error::Revert) @@ -103,7 +102,7 @@ pub fn call(context: impl MutatingCallContext, to: Address, data: &[u8]) -> Resu Storage::clear(); // clear the storage to persist changes, invalidating the cache unsafe_reentrant! {{ - RawCall::::new_with_value(context.value()) + RawCall::new_with_value(context.value()) .gas(context.gas()) .call(to, data) .map_err(Error::Revert) diff --git a/stylus-sdk/src/call/raw.rs b/stylus-sdk/src/call/raw.rs index 3bba10d..4929177 100644 --- a/stylus-sdk/src/call/raw.rs +++ b/stylus-sdk/src/call/raw.rs @@ -1,10 +1,15 @@ // Copyright 2023-2024, Offchain Labs, Inc. // For licensing, see https://github.com/OffchainLabs/stylus-sdk-rs/blob/main/licenses/COPYRIGHT.md -use crate::{host::WasmVM, ArbResult}; +use crate::{ + hostio::{call_contract, delegate_call_contract, static_call_contract}, + ArbResult, +}; use alloy_primitives::{Address, B256, U256}; use cfg_if::cfg_if; -use stylus_core::Host; + +#[cfg(feature = "reentrant")] +use crate::storage::StorageCache; macro_rules! unsafe_reentrant { ($(#[$meta:meta])* pub fn $name:ident $($rest:tt)*) => { @@ -25,16 +30,12 @@ macro_rules! unsafe_reentrant { /// For safe calls, see [`Call`](super::Call). #[derive(Clone, Default)] #[must_use] -pub struct RawCall -where - H: Host + Default, -{ +pub struct RawCall { kind: CallKind, callvalue: U256, gas: Option, offset: usize, size: Option, - host: H, #[allow(unused)] cache_policy: CachePolicy, } @@ -76,10 +77,8 @@ impl Default for RustVec { } } -impl RawCall -where - H: Host + Default, -{ +#[allow(deprecated)] +impl RawCall { /// Begin configuring the raw call, similar to how [`std::fs::OpenOptions`][OpenOptions] works. /// /// ```no_run @@ -91,7 +90,7 @@ where /// let calldata = &hex::decode("eddecf107b5740cef7f5a01e3ea7e287665c4e75").unwrap(); /// /// unsafe { - /// let result = RawCall::::new() // configure a call + /// let result = RawCall::new() // configure a call /// .gas(2100) // supply 2100 gas /// .limit_return_data(0, 32) // only read the first 32 bytes back /// // .flush_storage_cache() // flush the storage cache before the call (available in `reentrant`) @@ -132,13 +131,6 @@ where } } - /// Sets the host VM environment for the call, overriding - /// the default value. - pub fn vm(mut self, vm: H) -> Self { - self.host = vm; - self - } - /// Configures the amount of gas to supply. /// Note: large values are clipped to the amount of gas remaining. pub fn gas(mut self, gas: u64) -> Self { @@ -152,7 +144,7 @@ where /// /// [`Ink and Gas`]: https://docs.arbitrum.io/stylus/concepts/gas-metering pub fn ink(mut self, ink: u64) -> Self { - self.gas = Some(self.host.ink_to_gas(ink)); + self.gas = Some(crate::tx::ink_to_gas(ink)); self } @@ -204,12 +196,12 @@ where let status = unsafe { #[cfg(feature = "reentrant")] match self.cache_policy { - CachePolicy::Clear => self.host.flush_cache(true /* clear */), - CachePolicy::Flush => self.host.flush_cache(false /* do not clear */), + CachePolicy::Clear => StorageCache::clear(), + CachePolicy::Flush => StorageCache::flush(), CachePolicy::DoNothing => {} } match self.kind { - CallKind::Basic => self.host.call_contract( + CallKind::Basic => call_contract( contract.as_ptr(), calldata.as_ptr(), calldata.len(), @@ -217,14 +209,14 @@ where gas, &mut outs_len, ), - CallKind::Delegate => self.host.delegate_call_contract( + CallKind::Delegate => delegate_call_contract( contract.as_ptr(), calldata.as_ptr(), calldata.len(), gas, &mut outs_len, ), - CallKind::Static => self.host.static_call_contract( + CallKind::Static => static_call_contract( contract.as_ptr(), calldata.as_ptr(), calldata.len(), @@ -240,7 +232,7 @@ where } } - let outs = self.host.read_return_data(self.offset, self.size); + let outs = crate::contract::read_return_data(self.offset, self.size); match status { 0 => Ok(outs), _ => Err(outs), diff --git a/stylus-sdk/src/call/transfer.rs b/stylus-sdk/src/call/transfer.rs index 51a8b90..24b1555 100644 --- a/stylus-sdk/src/call/transfer.rs +++ b/stylus-sdk/src/call/transfer.rs @@ -2,7 +2,6 @@ // For licensing, see https://github.com/OffchainLabs/stylus-sdk-rs/blob/main/licenses/COPYRIGHT.md use crate::call::RawCall; -use crate::host::WasmVM; use alloc::vec::Vec; use alloy_primitives::{Address, U256}; @@ -32,7 +31,7 @@ pub fn transfer_eth( ) -> Result<(), Vec> { Storage::clear(); // clear the storage to persist changes, invalidating the cache unsafe { - RawCall::::new_with_value(amount) + RawCall::new_with_value(amount) .skip_return_data() .call(to, &[])?; } @@ -62,7 +61,7 @@ pub fn transfer_eth( )] #[allow(dead_code, deprecated)] pub fn transfer_eth(to: Address, amount: U256) -> Result<(), Vec> { - RawCall::::new_with_value(amount) + RawCall::new_with_value(amount) .skip_return_data() .call(to, &[])?; Ok(()) diff --git a/stylus-sdk/src/host/calls.rs b/stylus-sdk/src/host/calls.rs index 2f4dbfb..7dfa127 100644 --- a/stylus-sdk/src/host/calls.rs +++ b/stylus-sdk/src/host/calls.rs @@ -38,7 +38,7 @@ impl CallAccess for WasmVM { } unsafe_reentrant! {{ - RawCall::::new_with_value(context.value()) + RawCall::new_with_value(context.value()) .gas(context.gas()) .call(to, data) .map_err(Error::Revert) @@ -63,7 +63,7 @@ impl CallAccess for WasmVM { self.flush_cache(true); // clear the storage to persist changes, invalidating the cache } - RawCall::::new_delegate() + RawCall::new_delegate() .gas(context.gas()) .call(to, data) .map_err(Error::Revert) @@ -82,7 +82,7 @@ impl CallAccess for WasmVM { } unsafe_reentrant! {{ - RawCall::::new_static() + RawCall::new_static() .gas(context.gas()) .call(to, data) .map_err(Error::Revert) @@ -108,7 +108,7 @@ impl ValueTransfer for WasmVM { use stylus_core::host::StorageAccess; self.flush_cache(true); // clear the storage to persist changes, invalidating the cache unsafe { - RawCall::::new_with_value(amount) + RawCall::new_with_value(amount) .skip_return_data() .call(to, &[])?; } @@ -134,7 +134,7 @@ impl ValueTransfer for WasmVM { /// ``` #[cfg(not(feature = "reentrant"))] fn transfer_eth(&self, to: Address, amount: U256) -> Result<(), Vec> { - RawCall::::new_with_value(amount) + RawCall::new_with_value(amount) .skip_return_data() .call(to, &[])?; Ok(()) diff --git a/stylus-sdk/src/host/mod.rs b/stylus-sdk/src/host/mod.rs index cdb4d0f..f1f9da4 100644 --- a/stylus-sdk/src/host/mod.rs +++ b/stylus-sdk/src/host/mod.rs @@ -278,7 +278,7 @@ cfg_if::cfg_if! { to: Address, amount: U256, ) -> Result<(), Vec> { - self.0.transfer_eth(to, storage, amount) + self.0.transfer_eth(storage, to, amount) } #[inline] #[cfg(not(feature = "reentrant"))] diff --git a/stylus-sdk/src/lib.rs b/stylus-sdk/src/lib.rs index c242fed..bb33d56 100644 --- a/stylus-sdk/src/lib.rs +++ b/stylus-sdk/src/lib.rs @@ -48,7 +48,7 @@ pub use stylus_proc; // for Stylus SDK consumers, to be used as a test framework. #[cfg(all(not(target_arch = "wasm32"), test))] pub use rclite as rc; -#[cfg(all(not(target_arch = "wasm32"), test))] +#[cfg(not(target_arch = "wasm32"))] pub use stylus_test as testing; #[macro_use] diff --git a/stylus-test/src/vm.rs b/stylus-test/src/vm.rs index 5aaa1c6..0df00f6 100644 --- a/stylus-test/src/vm.rs +++ b/stylus-test/src/vm.rs @@ -22,7 +22,7 @@ //! #[cfg(test)] //! mod test { //! use super::*; -//! use stylus_sdk::testing::*; +//! use stylus_test::*; //! //! #[test] //! fn test_my_contract() {