Skip to content

Commit

Permalink
v0.8.0 Release Candidate (#218)
Browse files Browse the repository at this point in the history
* update versions

* bug fixes in the rc

* fix up export of stylus test

* test in dev deps

* add testing dep
  • Loading branch information
rauljordan authored Feb 12, 2025
1 parent e6f04f9 commit eeccda9
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 51 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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" }
4 changes: 3 additions & 1 deletion stylus-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
7 changes: 3 additions & 4 deletions stylus-sdk/src/call/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ pub use self::{

pub(crate) use raw::CachePolicy;

use crate::host::WasmVM;
#[cfg(feature = "reentrant")]
use crate::storage::Storage;

Expand Down Expand Up @@ -59,7 +58,7 @@ pub fn static_call(
Storage::flush(); // flush storage to persist changes, but don't invalidate the cache

unsafe_reentrant! {{
RawCall::<WasmVM>::new_static()
RawCall::new_static()
.gas(context.gas())
.call(to, data)
.map_err(Error::Revert)
Expand All @@ -86,7 +85,7 @@ pub unsafe fn delegate_call(
#[cfg(feature = "reentrant")]
Storage::clear(); // clear the storage to persist changes, invalidating the cache

RawCall::<WasmVM>::new_delegate()
RawCall::new_delegate()
.gas(context.gas())
.call(to, data)
.map_err(Error::Revert)
Expand All @@ -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::<WasmVM>::new_with_value(context.value())
RawCall::new_with_value(context.value())
.gas(context.gas())
.call(to, data)
.map_err(Error::Revert)
Expand Down
44 changes: 18 additions & 26 deletions stylus-sdk/src/call/raw.rs
Original file line number Diff line number Diff line change
@@ -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)*) => {
Expand All @@ -25,16 +30,12 @@ macro_rules! unsafe_reentrant {
/// For safe calls, see [`Call`](super::Call).
#[derive(Clone, Default)]
#[must_use]
pub struct RawCall<H = WasmVM>
where
H: Host + Default,
{
pub struct RawCall {
kind: CallKind,
callvalue: U256,
gas: Option<u64>,
offset: usize,
size: Option<usize>,
host: H,
#[allow(unused)]
cache_policy: CachePolicy,
}
Expand Down Expand Up @@ -76,10 +77,8 @@ impl Default for RustVec {
}
}

impl<H> RawCall<H>
where
H: Host + Default,
{
#[allow(deprecated)]
impl RawCall {
/// Begin configuring the raw call, similar to how [`std::fs::OpenOptions`][OpenOptions] works.
///
/// ```no_run
Expand All @@ -91,7 +90,7 @@ where
/// let calldata = &hex::decode("eddecf107b5740cef7f5a01e3ea7e287665c4e75").unwrap();
///
/// unsafe {
/// let result = RawCall::<WasmVM>::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`)
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down Expand Up @@ -204,27 +196,27 @@ 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(),
value.as_ptr(),
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(),
Expand All @@ -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),
Expand Down
5 changes: 2 additions & 3 deletions stylus-sdk/src/call/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -32,7 +31,7 @@ pub fn transfer_eth(
) -> Result<(), Vec<u8>> {
Storage::clear(); // clear the storage to persist changes, invalidating the cache
unsafe {
RawCall::<WasmVM>::new_with_value(amount)
RawCall::new_with_value(amount)
.skip_return_data()
.call(to, &[])?;
}
Expand Down Expand Up @@ -62,7 +61,7 @@ pub fn transfer_eth(
)]
#[allow(dead_code, deprecated)]
pub fn transfer_eth(to: Address, amount: U256) -> Result<(), Vec<u8>> {
RawCall::<WasmVM>::new_with_value(amount)
RawCall::new_with_value(amount)
.skip_return_data()
.call(to, &[])?;
Ok(())
Expand Down
10 changes: 5 additions & 5 deletions stylus-sdk/src/host/calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl CallAccess for WasmVM {
}

unsafe_reentrant! {{
RawCall::<WasmVM>::new_with_value(context.value())
RawCall::new_with_value(context.value())
.gas(context.gas())
.call(to, data)
.map_err(Error::Revert)
Expand All @@ -63,7 +63,7 @@ impl CallAccess for WasmVM {
self.flush_cache(true); // clear the storage to persist changes, invalidating the cache
}

RawCall::<WasmVM>::new_delegate()
RawCall::new_delegate()
.gas(context.gas())
.call(to, data)
.map_err(Error::Revert)
Expand All @@ -82,7 +82,7 @@ impl CallAccess for WasmVM {
}

unsafe_reentrant! {{
RawCall::<WasmVM>::new_static()
RawCall::new_static()
.gas(context.gas())
.call(to, data)
.map_err(Error::Revert)
Expand All @@ -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::<WasmVM>::new_with_value(amount)
RawCall::new_with_value(amount)
.skip_return_data()
.call(to, &[])?;
}
Expand All @@ -134,7 +134,7 @@ impl ValueTransfer for WasmVM {
/// ```
#[cfg(not(feature = "reentrant"))]
fn transfer_eth(&self, to: Address, amount: U256) -> Result<(), Vec<u8>> {
RawCall::<WasmVM>::new_with_value(amount)
RawCall::new_with_value(amount)
.skip_return_data()
.call(to, &[])?;
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion stylus-sdk/src/host/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ cfg_if::cfg_if! {
to: Address,
amount: U256,
) -> Result<(), Vec<u8>> {
self.0.transfer_eth(to, storage, amount)
self.0.transfer_eth(storage, to, amount)
}
#[inline]
#[cfg(not(feature = "reentrant"))]
Expand Down
2 changes: 1 addition & 1 deletion stylus-sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion stylus-test/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
//! #[cfg(test)]
//! mod test {
//! use super::*;
//! use stylus_sdk::testing::*;
//! use stylus_test::*;
//!
//! #[test]
//! fn test_my_contract() {
Expand Down

0 comments on commit eeccda9

Please sign in to comment.