From 64cb1ec8b03da5f1816864565b8698ecb54c0cb2 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Thu, 17 Oct 2024 15:51:47 +0400 Subject: [PATCH 01/57] add storage guard --- Cargo.lock | 31 ++++++++++++++++++- .../src/token/erc721/extensions/enumerable.rs | 10 +++--- lib/motsu-proc/src/test.rs | 6 ++-- lib/motsu/Cargo.toml | 1 + lib/motsu/src/context.rs | 15 +++++++-- 5 files changed, 52 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 953b3db07..cf79155e0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -256,7 +256,7 @@ dependencies = [ "cfg-if", "const-hex", "derive_arbitrary", - "derive_more", + "derive_more 0.99.18", "ethereum_ssz", "getrandom", "hex-literal", @@ -1379,6 +1379,28 @@ dependencies = [ "syn 2.0.68", ] +[[package]] +name = "derive_more" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a9b99b9cbbe49445b21764dc0625032a89b145a2642e67603e1c936f5458d05" +dependencies = [ + "derive_more-impl", +] + +[[package]] +name = "derive_more-impl" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb7330aeadfbe296029522e6c40f315320aba36fc43a5b3632f3795348f3bd22" +dependencies = [ + "convert_case 0.6.0", + "proc-macro2", + "quote", + "syn 2.0.68", + "unicode-xid", +] + [[package]] name = "digest" version = "0.9.0" @@ -2448,6 +2470,7 @@ version = "0.2.0" dependencies = [ "const-hex", "dashmap 6.1.0", + "derive_more 1.0.0", "motsu-proc", "once_cell", "stylus-sdk", @@ -3984,6 +4007,12 @@ version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + [[package]] name = "url" version = "2.5.2" diff --git a/contracts/src/token/erc721/extensions/enumerable.rs b/contracts/src/token/erc721/extensions/enumerable.rs index f35bc97c0..20a892efd 100644 --- a/contracts/src/token/erc721/extensions/enumerable.rs +++ b/contracts/src/token/erc721/extensions/enumerable.rs @@ -454,7 +454,7 @@ mod tests { assert_eq!(owner, alice); let res = - contract._add_token_to_owner_enumeration(alice, token_id, &erc721); + contract._add_token_to_owner_enumeration(alice, token_id, &*erc721); assert!(res.is_ok()); let test_token_id = contract @@ -483,7 +483,7 @@ mod tests { assert_eq!(owner, alice); let res = - contract._add_token_to_owner_enumeration(alice, token_id, &erc721); + contract._add_token_to_owner_enumeration(alice, token_id, &*erc721); assert!(res.is_ok()); let err = @@ -525,7 +525,7 @@ mod tests { assert_eq!(owner, alice); let res = - contract._add_token_to_owner_enumeration(alice, token_id, &erc721); + contract._add_token_to_owner_enumeration(alice, token_id, &*erc721); assert!(res.is_ok()); // Transfer the token from ALICE to BOB. @@ -538,11 +538,11 @@ mod tests { assert_eq!(owner, BOB); let res = contract - ._remove_token_from_owner_enumeration(alice, token_id, &erc721); + ._remove_token_from_owner_enumeration(alice, token_id, &*erc721); assert!(res.is_ok()); let res = - contract._add_token_to_owner_enumeration(BOB, token_id, &erc721); + contract._add_token_to_owner_enumeration(BOB, token_id, &*erc721); assert!(res.is_ok()); let test_token_id = contract diff --git a/lib/motsu-proc/src/test.rs b/lib/motsu-proc/src/test.rs index 2e2425d1e..ffef40d8f 100644 --- a/lib/motsu-proc/src/test.rs +++ b/lib/motsu-proc/src/test.rs @@ -12,7 +12,7 @@ pub(crate) fn test(_attr: &TokenStream, input: TokenStream) -> TokenStream { let sig = &item_fn.sig; let fn_name = &sig.ident; let fn_return_type = &sig.output; - let fn_block = &item_fn.block; + let fn_stmts = &item_fn.block.stmts; let fn_args = &sig.inputs; // Currently, more than one contract per unit test is not supported. @@ -45,7 +45,9 @@ pub(crate) fn test(_attr: &TokenStream, input: TokenStream) -> TokenStream { fn #fn_name() #fn_return_type { use ::motsu::prelude::DefaultStorage; #( #contract_declarations )* - let res = #fn_block; + let res = { + #( #fn_stmts )* + }; ::motsu::prelude::Context::current().reset_storage(); res } diff --git a/lib/motsu/Cargo.toml b/lib/motsu/Cargo.toml index 2bfa39776..f290b3190 100644 --- a/lib/motsu/Cargo.toml +++ b/lib/motsu/Cargo.toml @@ -15,6 +15,7 @@ tiny-keccak.workspace = true stylus-sdk.workspace = true motsu-proc.workspace = true dashmap.workspace = true +derive_more = { version = "1.0.0", features = ["full"] } [lints] workspace = true diff --git a/lib/motsu/src/context.rs b/lib/motsu/src/context.rs index 381d504b9..b55b5e1c4 100644 --- a/lib/motsu/src/context.rs +++ b/lib/motsu/src/context.rs @@ -4,7 +4,13 @@ use std::{collections::HashMap, ptr}; use dashmap::DashMap; use once_cell::sync::Lazy; -use stylus_sdk::{alloy_primitives::uint, prelude::StorageType}; +use stylus_sdk::{ + alloy_primitives::{ + private::derive_more::{Deref, DerefMut}, + uint, + }, + prelude::StorageType, +}; use crate::prelude::{Bytes32, WORD_BYTES}; @@ -101,9 +107,12 @@ pub trait DefaultStorage: StorageType { /// Initializes fields of contract storage and child contract storages with /// default values. #[must_use] - fn default() -> Self { - unsafe { Self::new(uint!(0_U256), 0) } + fn default() -> StorageGuard { + StorageGuard(unsafe { Self::new(uint!(0_U256), 0) }) } } impl DefaultStorage for ST {} + +#[derive(Deref, DerefMut)] +pub struct StorageGuard(ST); From e2fafe80475f99b741c50adbd89debfc586947f3 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Thu, 21 Nov 2024 17:49:11 +0400 Subject: [PATCH 02/57] comment non erc721 unit test --- contracts/src/access/control.rs | 3 ++- contracts/src/access/ownable.rs | 3 ++- contracts/src/access/ownable_two_step.rs | 3 ++- contracts/src/token/erc1155/mod.rs | 3 ++- contracts/src/token/erc20/extensions/burnable.rs | 3 ++- contracts/src/token/erc20/extensions/capped.rs | 3 ++- contracts/src/token/erc20/mod.rs | 3 ++- contracts/src/token/erc20/utils/safe_erc20.rs | 3 ++- contracts/src/token/erc721/extensions/burnable.rs | 3 ++- contracts/src/token/erc721/extensions/consecutive.rs | 3 ++- contracts/src/token/erc721/extensions/enumerable.rs | 3 ++- contracts/src/token/erc721/extensions/uri_storage.rs | 3 ++- contracts/src/utils/nonces.rs | 3 ++- contracts/src/utils/pausable.rs | 3 ++- contracts/src/utils/structs/bitmap.rs | 3 ++- contracts/src/utils/structs/checkpoints/mod.rs | 3 ++- 16 files changed, 32 insertions(+), 16 deletions(-) diff --git a/contracts/src/access/control.rs b/contracts/src/access/control.rs index 1ef997353..6b5f46c7f 100644 --- a/contracts/src/access/control.rs +++ b/contracts/src/access/control.rs @@ -365,7 +365,7 @@ impl AccessControl { } } } - +/* #[cfg(all(test, feature = "std"))] mod tests { use alloy_primitives::{address, Address}; @@ -593,3 +593,4 @@ mod tests { assert_eq!(role_revoked, false); } } +*/ diff --git a/contracts/src/access/ownable.rs b/contracts/src/access/ownable.rs index 50692973f..32e4a7907 100644 --- a/contracts/src/access/ownable.rs +++ b/contracts/src/access/ownable.rs @@ -191,7 +191,7 @@ impl Ownable { evm::log(OwnershipTransferred { previous_owner, new_owner }); } } - +/* #[cfg(all(test, feature = "std"))] mod tests { use alloy_primitives::{address, Address}; @@ -264,3 +264,4 @@ mod tests { assert_eq!(owner, ALICE); } } +*/ diff --git a/contracts/src/access/ownable_two_step.rs b/contracts/src/access/ownable_two_step.rs index f5d9a2be1..184f0fffb 100644 --- a/contracts/src/access/ownable_two_step.rs +++ b/contracts/src/access/ownable_two_step.rs @@ -208,7 +208,7 @@ impl Ownable2Step { self._ownable._transfer_ownership(new_owner); } } - +/* #[cfg(all(test, feature = "std"))] mod tests { use alloy_primitives::{address, Address}; @@ -351,3 +351,4 @@ mod tests { assert_eq!(contract.owner(), msg::sender()); } } +*/ diff --git a/contracts/src/token/erc1155/mod.rs b/contracts/src/token/erc1155/mod.rs index e128f6868..8edb516e0 100644 --- a/contracts/src/token/erc1155/mod.rs +++ b/contracts/src/token/erc1155/mod.rs @@ -1167,7 +1167,7 @@ enum Transfer { /// * `values` - Array of all amount of tokens being transferred. Batch { ids: Vec, values: Vec }, } - +/* #[cfg(all(test, feature = "std"))] mod tests { use alloy_primitives::{address, uint, Address, U256}; @@ -2193,3 +2193,4 @@ mod tests { assert_eq!(actual, expected); } } +*/ diff --git a/contracts/src/token/erc20/extensions/burnable.rs b/contracts/src/token/erc20/extensions/burnable.rs index fce7fe9a3..f2a583eed 100644 --- a/contracts/src/token/erc20/extensions/burnable.rs +++ b/contracts/src/token/erc20/extensions/burnable.rs @@ -76,7 +76,7 @@ impl IErc20Burnable for Erc20 { self._burn(account, value) } } - +/* #[cfg(all(test, feature = "std"))] mod tests { use alloy_primitives::{address, uint, Address, U256}; @@ -184,3 +184,4 @@ mod tests { assert!(matches!(result, Err(Error::InsufficientAllowance(_)))); } } +*/ diff --git a/contracts/src/token/erc20/extensions/capped.rs b/contracts/src/token/erc20/extensions/capped.rs index a971900b5..f37d579c7 100644 --- a/contracts/src/token/erc20/extensions/capped.rs +++ b/contracts/src/token/erc20/extensions/capped.rs @@ -50,7 +50,7 @@ impl Capped { self._cap.get() } } - +/* #[cfg(all(test, feature = "std"))] mod tests { use alloy_primitives::uint; @@ -68,3 +68,4 @@ mod tests { assert_eq!(contract.cap(), value); } } +*/ diff --git a/contracts/src/token/erc20/mod.rs b/contracts/src/token/erc20/mod.rs index 91399f425..ac8c294d6 100644 --- a/contracts/src/token/erc20/mod.rs +++ b/contracts/src/token/erc20/mod.rs @@ -573,7 +573,7 @@ impl Erc20 { Ok(()) } } - +/* #[cfg(all(test, feature = "std"))] mod tests { use alloy_primitives::{address, uint, Address, U256}; @@ -925,3 +925,4 @@ mod tests { assert_eq!(actual, expected); } } +*/ diff --git a/contracts/src/token/erc20/utils/safe_erc20.rs b/contracts/src/token/erc20/utils/safe_erc20.rs index 1669a69cd..7d0b54c4b 100644 --- a/contracts/src/token/erc20/utils/safe_erc20.rs +++ b/contracts/src/token/erc20/utils/safe_erc20.rs @@ -388,7 +388,7 @@ impl SafeErc20 { }) } } - +/* #[cfg(all(test, feature = "std"))] mod tests { use super::SafeErc20; @@ -431,3 +431,4 @@ mod tests { ); } } +*/ diff --git a/contracts/src/token/erc721/extensions/burnable.rs b/contracts/src/token/erc721/extensions/burnable.rs index 31d5701b8..b8e364398 100644 --- a/contracts/src/token/erc721/extensions/burnable.rs +++ b/contracts/src/token/erc721/extensions/burnable.rs @@ -51,7 +51,7 @@ impl IErc721Burnable for Erc721 { Ok(()) } } - +/* #[cfg(all(test, feature = "std"))] mod tests { use alloy_primitives::{address, uint, Address}; @@ -223,3 +223,4 @@ mod tests { )); } } +*/ diff --git a/contracts/src/token/erc721/extensions/consecutive.rs b/contracts/src/token/erc721/extensions/consecutive.rs index 302cb56f4..32576f71f 100644 --- a/contracts/src/token/erc721/extensions/consecutive.rs +++ b/contracts/src/token/erc721/extensions/consecutive.rs @@ -793,7 +793,7 @@ impl Erc721Consecutive { Ok(owner) } } - +/* #[cfg(all(test, feature = "std"))] mod tests { use alloy_primitives::{address, uint, Address, U256}; @@ -1333,3 +1333,4 @@ mod tests { )); } } +*/ diff --git a/contracts/src/token/erc721/extensions/enumerable.rs b/contracts/src/token/erc721/extensions/enumerable.rs index 20a892efd..1e41280aa 100644 --- a/contracts/src/token/erc721/extensions/enumerable.rs +++ b/contracts/src/token/erc721/extensions/enumerable.rs @@ -323,7 +323,7 @@ impl Erc721Enumerable { } } } - +/* #[cfg(all(test, feature = "std"))] mod tests { use alloy_primitives::{address, uint, Address, U256}; @@ -563,3 +563,4 @@ mod tests { assert_eq!(actual, expected); } } +*/ diff --git a/contracts/src/token/erc721/extensions/uri_storage.rs b/contracts/src/token/erc721/extensions/uri_storage.rs index 644a3dc22..f24ab3d59 100644 --- a/contracts/src/token/erc721/extensions/uri_storage.rs +++ b/contracts/src/token/erc721/extensions/uri_storage.rs @@ -102,7 +102,7 @@ impl Erc721UriStorage { Ok(uri) } } - +/* #[cfg(all(test, feature = "std"))] mod tests { use alloy_primitives::U256; @@ -181,3 +181,4 @@ mod tests { ); } } +*/ diff --git a/contracts/src/utils/nonces.rs b/contracts/src/utils/nonces.rs index 752565174..d5d08e598 100644 --- a/contracts/src/utils/nonces.rs +++ b/contracts/src/utils/nonces.rs @@ -106,7 +106,7 @@ impl Nonces { Ok(()) } } - +/* #[cfg(all(test, feature = "std"))] mod tests { use alloy_primitives::U256; @@ -153,3 +153,4 @@ mod tests { )); } } +*/ diff --git a/contracts/src/utils/pausable.rs b/contracts/src/utils/pausable.rs index 1a2ed5ae9..e154a70ec 100644 --- a/contracts/src/utils/pausable.rs +++ b/contracts/src/utils/pausable.rs @@ -146,7 +146,7 @@ impl Pausable { Ok(()) } } - +/* #[cfg(all(test, feature = "std"))] mod tests { use crate::utils::pausable::{Error, Pausable}; @@ -238,3 +238,4 @@ mod tests { assert_eq!(contract.paused(), false); } } +*/ diff --git a/contracts/src/utils/structs/bitmap.rs b/contracts/src/utils/structs/bitmap.rs index 8c9a8d188..3d3ba5af6 100644 --- a/contracts/src/utils/structs/bitmap.rs +++ b/contracts/src/utils/structs/bitmap.rs @@ -91,7 +91,7 @@ impl BitMap { index >> 8 } } - +/* #[cfg(all(test, feature = "std"))] mod tests { use alloy_primitives::{private::proptest::proptest, U256}; @@ -130,3 +130,4 @@ mod tests { }); } } +*/ diff --git a/contracts/src/utils/structs/checkpoints/mod.rs b/contracts/src/utils/structs/checkpoints/mod.rs index 88b1eb22c..55062b617 100644 --- a/contracts/src/utils/structs/checkpoints/mod.rs +++ b/contracts/src/utils/structs/checkpoints/mod.rs @@ -366,7 +366,7 @@ impl Trace { new_checkpoint._value.set(value); } } - +/* #[cfg(all(test, feature = "std"))] mod tests { use alloy_primitives::uint; @@ -526,3 +526,4 @@ mod tests { )); } } +*/ From 02d3468c77083ff79f2f57dc8bc26d3632abeebe Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Fri, 22 Nov 2024 10:18:20 +0400 Subject: [PATCH 03/57] ++ --- Cargo.lock | 1 + lib/motsu/Cargo.toml | 1 + lib/motsu/src/context.rs | 81 ++++++++++++++++++++++++++++++++++------ lib/motsu/src/prelude.rs | 2 +- 4 files changed, 73 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cf79155e0..87ce1d701 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2468,6 +2468,7 @@ checksum = "7843ec2de400bcbc6a6328c958dc38e5359da6e93e72e37bc5246bf1ae776389" name = "motsu" version = "0.2.0" dependencies = [ + "alloy-primitives", "const-hex", "dashmap 6.1.0", "derive_more 1.0.0", diff --git a/lib/motsu/Cargo.toml b/lib/motsu/Cargo.toml index f290b3190..dc4135112 100644 --- a/lib/motsu/Cargo.toml +++ b/lib/motsu/Cargo.toml @@ -16,6 +16,7 @@ stylus-sdk.workspace = true motsu-proc.workspace = true dashmap.workspace = true derive_more = { version = "1.0.0", features = ["full"] } +alloy-primitives = { workspace = true, features = ["arbitrary", "rand"] } [lints] workspace = true diff --git a/lib/motsu/src/context.rs b/lib/motsu/src/context.rs index b55b5e1c4..4c0ba38ad 100644 --- a/lib/motsu/src/context.rs +++ b/lib/motsu/src/context.rs @@ -2,15 +2,10 @@ use std::{collections::HashMap, ptr}; +use alloy_primitives::Address; use dashmap::DashMap; use once_cell::sync::Lazy; -use stylus_sdk::{ - alloy_primitives::{ - private::derive_more::{Deref, DerefMut}, - uint, - }, - prelude::StorageType, -}; +use stylus_sdk::{alloy_primitives::uint, prelude::StorageType}; use crate::prelude::{Bytes32, WORD_BYTES}; @@ -107,12 +102,76 @@ pub trait DefaultStorage: StorageType { /// Initializes fields of contract storage and child contract storages with /// default values. #[must_use] - fn default() -> StorageGuard { - StorageGuard(unsafe { Self::new(uint!(0_U256), 0) }) + fn default() -> Contract { + Contract::random() } } impl DefaultStorage for ST {} -#[derive(Deref, DerefMut)] -pub struct StorageGuard(ST); +pub struct ContractCall { + contract: ST, + caller: Address, +} + +impl ::core::ops::Deref for ContractCall { + type Target = ST; + + #[inline] + fn deref(&self) -> &Self::Target { + &self.contract + } +} + +impl ::core::ops::DerefMut for ContractCall { + #[inline] + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.contract + } +} + +pub struct Contract { + phantom: ::core::marker::PhantomData, + address: Address, +} + +impl Contract { + pub fn new(address: Address) -> Self { + // TODO#q: save contract instance to storage + Self { phantom: ::core::marker::PhantomData, address } + } + + pub fn random() -> Self { + Self::new(Address::random()) + } +} + +pub struct Account { + address: Address, +} + +impl Account { + pub const fn new(address: Address) -> Self { + Self { address } + } + + pub fn random() -> Self { + Self::new(Address::random()) + } + + // TODO#q: we also need an initializer + + pub fn deploys(&self) -> Contract { + Contract::random() + } + + pub fn uses( + &self, + contract: &mut Contract, + ) -> ContractCall { + ContractCall { + contract: unsafe { ST::new(uint!(0_U256), 0) }, + caller: self.address, + } + } +} diff --git a/lib/motsu/src/prelude.rs b/lib/motsu/src/prelude.rs index 5c8798297..5af1b5e21 100644 --- a/lib/motsu/src/prelude.rs +++ b/lib/motsu/src/prelude.rs @@ -1,5 +1,5 @@ //! Common imports for `motsu` tests. pub use crate::{ - context::{Context, DefaultStorage}, + context::{Account, Context, ContractCall, DefaultStorage}, shims::*, }; From d126f0e50d25e47aa3091d2f3b2fd02caadfe334 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Fri, 22 Nov 2024 10:55:12 +0400 Subject: [PATCH 04/57] ++ --- lib/motsu/src/context.rs | 21 +++++++++++++++++++-- lib/motsu/src/shims.rs | 5 +++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/motsu/src/context.rs b/lib/motsu/src/context.rs index 4c0ba38ad..e85777387 100644 --- a/lib/motsu/src/context.rs +++ b/lib/motsu/src/context.rs @@ -52,6 +52,16 @@ impl Context { pub fn reset_storage(self) { STORAGE.remove(&self.thread_name); } + + pub(crate) fn set_msg_sender(self, msg_sender: Address) { + let mut storage = STORAGE.entry(self.thread_name).or_default(); + let _ = storage.msg_sender.insert(msg_sender); + } + + pub(crate) fn get_msg_sender(self) -> Address { + let storage = STORAGE.entry(self.thread_name).or_default(); + storage.msg_sender.expect("msg_sender should be set") + } } /// Storage mock: A global mutable key-value store. @@ -80,6 +90,7 @@ impl ThreadName { /// Storage for unit test's mock data. #[derive(Default)] struct MockStorage { + msg_sender: Option
, /// Contract's mock data storage. contract_data: HashMap, } @@ -119,6 +130,7 @@ impl ::core::ops::Deref for ContractCall { #[inline] fn deref(&self) -> &Self::Target { + Context::current().set_msg_sender(self.caller); &self.contract } } @@ -126,6 +138,7 @@ impl ::core::ops::Deref for ContractCall { impl ::core::ops::DerefMut for ContractCall { #[inline] fn deref_mut(&mut self) -> &mut Self::Target { + Context::current().set_msg_sender(self.caller); &mut self.contract } } @@ -141,6 +154,8 @@ impl Contract { Self { phantom: ::core::marker::PhantomData, address } } + // TODO#q: probably we need generic initializer + pub fn random() -> Self { Self::new(Address::random()) } @@ -159,12 +174,14 @@ impl Account { Self::new(Address::random()) } - // TODO#q: we also need an initializer - pub fn deploys(&self) -> Contract { Contract::random() } + pub fn address(&self) -> Address { + self.address + } + pub fn uses( &self, contract: &mut Contract, diff --git a/lib/motsu/src/shims.rs b/lib/motsu/src/shims.rs index a20ebdfce..b5128e723 100644 --- a/lib/motsu/src/shims.rs +++ b/lib/motsu/src/shims.rs @@ -145,8 +145,9 @@ pub const EOA_CODEHASH: &[u8; 66] = /// May panic if fails to parse `MSG_SENDER` as an address. #[no_mangle] pub unsafe extern "C" fn msg_sender(sender: *mut u8) { - let addr = const_hex::const_decode_to_array::<20>(MSG_SENDER).unwrap(); - std::ptr::copy(addr.as_ptr(), sender, 20); + let msg_sender = Context::current().get_msg_sender(); + let x: &[u8; 20] = msg_sender.as_ref(); + std::ptr::copy(x.as_ptr(), sender, 20); } /// Gets the address of the current program. The semantics are equivalent to From ef905e50ebc127a134e7579c4110d8684c0a1b6d Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Fri, 22 Nov 2024 11:50:39 +0400 Subject: [PATCH 05/57] ++ --- lib/motsu/src/context.rs | 62 ++++++++++++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 12 deletions(-) diff --git a/lib/motsu/src/context.rs b/lib/motsu/src/context.rs index e85777387..15dcc42ba 100644 --- a/lib/motsu/src/context.rs +++ b/lib/motsu/src/context.rs @@ -25,7 +25,15 @@ impl Context { /// Get the value at `key` in storage. pub(crate) fn get_bytes(self, key: &Bytes32) -> Bytes32 { let storage = STORAGE.entry(self.thread_name).or_default(); - storage.contract_data.get(key).copied().unwrap_or_default() + let msg_receiver = + storage.msg_receiver.expect("msg_receiver should be set"); + storage + .contracts + .get(&msg_receiver) + .expect("contract receiver should have a storage initialised") + .get(key) + .copied() + .unwrap_or_default() } /// Get the raw value at `key` in storage and write it to `value`. @@ -38,7 +46,13 @@ impl Context { /// Set the value at `key` in storage to `value`. pub(crate) fn set_bytes(self, key: Bytes32, value: Bytes32) { let mut storage = STORAGE.entry(self.thread_name).or_default(); - storage.contract_data.insert(key, value); + let msg_receiver = + storage.msg_receiver.expect("msg_receiver should be set"); + storage + .contracts + .get_mut(&msg_receiver) + .expect("contract receiver should have a storage initialised") + .insert(key, value); } /// Set the raw value at `key` in storage to `value`. @@ -62,6 +76,24 @@ impl Context { let storage = STORAGE.entry(self.thread_name).or_default(); storage.msg_sender.expect("msg_sender should be set") } + + pub(crate) fn set_msg_receiver(self, msg_receiver: Address) { + let mut storage = STORAGE.entry(self.thread_name).or_default(); + let _ = storage.msg_receiver.insert(msg_receiver); + } + + pub(crate) fn get_msg_receiver(self) -> Address { + let storage = STORAGE.entry(self.thread_name).or_default(); + storage.msg_receiver.expect("msg_receiver should be set") + } + + pub(crate) fn init_contract(self, contract_address: Address) { + let mut storage = STORAGE.entry(self.thread_name).or_default(); + if storage.contracts.insert(contract_address, HashMap::new()).is_some() + { + panic!("contract storage already initialized - contract_address: {contract_address}"); + } + } } /// Storage mock: A global mutable key-value store. @@ -90,11 +122,16 @@ impl ThreadName { /// Storage for unit test's mock data. #[derive(Default)] struct MockStorage { + /// Address of the message sender. msg_sender: Option
, + /// Address of the contract that is currently receiving the message. + msg_receiver: Option
, /// Contract's mock data storage. - contract_data: HashMap, + contracts: HashMap, } +type ContractStorage = HashMap; + /// Read the word from location pointed by `ptr`. unsafe fn read_bytes32(ptr: *const u8) -> Bytes32 { let mut res = Bytes32::default(); @@ -122,7 +159,8 @@ impl DefaultStorage for ST {} pub struct ContractCall { contract: ST, - caller: Address, + caller_address: Address, + contract_address: Address, } impl ::core::ops::Deref for ContractCall { @@ -130,7 +168,8 @@ impl ::core::ops::Deref for ContractCall { #[inline] fn deref(&self) -> &Self::Target { - Context::current().set_msg_sender(self.caller); + Context::current().set_msg_sender(self.caller_address); + Context::current().set_msg_receiver(self.contract_address); &self.contract } } @@ -138,7 +177,8 @@ impl ::core::ops::Deref for ContractCall { impl ::core::ops::DerefMut for ContractCall { #[inline] fn deref_mut(&mut self) -> &mut Self::Target { - Context::current().set_msg_sender(self.caller); + Context::current().set_msg_sender(self.caller_address); + Context::current().set_msg_receiver(self.contract_address); &mut self.contract } } @@ -150,7 +190,8 @@ pub struct Contract { impl Contract { pub fn new(address: Address) -> Self { - // TODO#q: save contract instance to storage + Context::current().init_contract(address); + Self { phantom: ::core::marker::PhantomData, address } } @@ -174,10 +215,6 @@ impl Account { Self::new(Address::random()) } - pub fn deploys(&self) -> Contract { - Contract::random() - } - pub fn address(&self) -> Address { self.address } @@ -188,7 +225,8 @@ impl Account { ) -> ContractCall { ContractCall { contract: unsafe { ST::new(uint!(0_U256), 0) }, - caller: self.address, + caller_address: self.address, + contract_address: contract.address, } } } From 7883a6490555f7b8891cac02f540020e6e0666f2 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Fri, 22 Nov 2024 12:47:17 +0400 Subject: [PATCH 06/57] add ping pong test case --- Cargo.lock | 1 + lib/motsu-proc/src/test.rs | 5 -- lib/motsu/Cargo.toml | 1 + lib/motsu/src/context.rs | 10 ++++ lib/motsu/src/lib.rs | 95 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 107 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 87ce1d701..e7d6add19 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2469,6 +2469,7 @@ name = "motsu" version = "0.2.0" dependencies = [ "alloy-primitives", + "alloy-sol-types", "const-hex", "dashmap 6.1.0", "derive_more 1.0.0", diff --git a/lib/motsu-proc/src/test.rs b/lib/motsu-proc/src/test.rs index ffef40d8f..910ba4f25 100644 --- a/lib/motsu-proc/src/test.rs +++ b/lib/motsu-proc/src/test.rs @@ -15,11 +15,6 @@ pub(crate) fn test(_attr: &TokenStream, input: TokenStream) -> TokenStream { let fn_stmts = &item_fn.block.stmts; let fn_args = &sig.inputs; - // Currently, more than one contract per unit test is not supported. - if fn_args.len() > 1 { - error!(fn_args, "expected at most one contract in test signature"); - } - // Whether 1 or none contracts will be declared. let contract_declarations = fn_args.into_iter().map(|arg| { let FnArg::Typed(arg) = arg else { diff --git a/lib/motsu/Cargo.toml b/lib/motsu/Cargo.toml index dc4135112..5f54f0800 100644 --- a/lib/motsu/Cargo.toml +++ b/lib/motsu/Cargo.toml @@ -17,6 +17,7 @@ motsu-proc.workspace = true dashmap.workspace = true derive_more = { version = "1.0.0", features = ["full"] } alloy-primitives = { workspace = true, features = ["arbitrary", "rand"] } +alloy-sol-types.workspace = true [lints] workspace = true diff --git a/lib/motsu/src/context.rs b/lib/motsu/src/context.rs index 15dcc42ba..015f4b78a 100644 --- a/lib/motsu/src/context.rs +++ b/lib/motsu/src/context.rs @@ -163,6 +163,12 @@ pub struct ContractCall { contract_address: Address, } +impl ContractCall { + pub fn address(&self) -> Address { + self.contract_address + } +} + impl ::core::ops::Deref for ContractCall { type Target = ST; @@ -200,6 +206,10 @@ impl Contract { pub fn random() -> Self { Self::new(Address::random()) } + + pub fn address(&self) -> Address { + self.address + } } pub struct Account { diff --git a/lib/motsu/src/lib.rs b/lib/motsu/src/lib.rs index 88eb49707..f2dd0a423 100644 --- a/lib/motsu/src/lib.rs +++ b/lib/motsu/src/lib.rs @@ -48,3 +48,98 @@ pub mod prelude; mod shims; pub use motsu_proc::test; + +#[cfg(all(test))] +mod tests { + #![deny(rustdoc::broken_intra_doc_links)] + extern crate alloc; + + use alloy_primitives::uint; + use stylus_sdk::{ + alloy_primitives::{Address, U256}, + call::Call, + prelude::{public, sol_storage, TopLevelStorage}, + }; + + use crate::context::Account; + + sol_storage! { + pub struct PingContract { + uint256 _pings_count; + // TODO#q: add last pinged address. + } + } + + #[public] + impl PingContract { + fn ping(&mut self, to: Address, value: U256) -> Result> { + let receiver = receiver::PongContract::new(to); + let call = Call::new_in(self); + let value = + receiver.pong(call, value).expect("should pong successfully"); + + let pings_count = self._pings_count.get(); + self._pings_count.set(pings_count + uint!(1_U256)); + Ok(value) + } + + fn ping_count(&self) -> U256 { + self._pings_count.get() + } + } + + unsafe impl TopLevelStorage for PingContract {} + + mod receiver { + use super::alloc; + stylus_sdk::stylus_proc::sol_interface! { + interface PongContract { + #[allow(missing_docs)] + function pong(uint256 value) external returns (uint256); + } + } + } + + sol_storage! { + pub struct PongContract { + uint256 _pongs_count; + uint256 _value; + } + } + + #[public] + impl PongContract { + pub fn pong(&mut self, value: U256) -> Result> { + let pongs_count = self._pongs_count.get(); + self._pongs_count.set(pongs_count + uint!(1_U256)); + Ok(value + uint!(1_U256)) + } + + fn pong_count(&self) -> U256 { + self._pongs_count.get() + } + } + + unsafe impl TopLevelStorage for PongContract {} + + #[test] + fn ping_pong_works() { + use crate::prelude::DefaultStorage; + let mut ping = PingContract::default(); + let ping = &mut ping; + let mut pong = PongContract::default(); + let pong = &mut pong; + + let alice = Account::random(); + let mut ping = alice.uses(ping); + let mut pong = alice.uses(pong); + + let value = uint!(1_U256); + let ponged_value = + ping.ping(pong.address(), value).expect("should ping successfully"); + + assert_eq!(ponged_value, value + uint!(1_U256)); + assert_eq!(ping.ping_count(), uint!(1_U256)); + assert_eq!(pong.pong_count(), uint!(1_U256)); + } +} From f49daf55794635bbd6ec74b761a3d2b012613b9e Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Fri, 22 Nov 2024 14:30:47 +0400 Subject: [PATCH 07/57] add test router --- lib/motsu/src/context.rs | 85 ++++++++++++++++++++++++++++++---------- lib/motsu/src/lib.rs | 14 ++++++- 2 files changed, 76 insertions(+), 23 deletions(-) diff --git a/lib/motsu/src/context.rs b/lib/motsu/src/context.rs index 015f4b78a..988e39474 100644 --- a/lib/motsu/src/context.rs +++ b/lib/motsu/src/context.rs @@ -1,11 +1,16 @@ //! Unit-testing context for Stylus contracts. -use std::{collections::HashMap, ptr}; +use std::{borrow::BorrowMut, collections::HashMap, ptr, sync::Mutex}; use alloy_primitives::Address; use dashmap::DashMap; use once_cell::sync::Lazy; -use stylus_sdk::{alloy_primitives::uint, prelude::StorageType}; +use stylus_sdk::{ + abi::Router, + alloy_primitives::uint, + prelude::{StorageType, TopLevelStorage}, + ArbResult, +}; use crate::prelude::{Bytes32, WORD_BYTES}; @@ -28,7 +33,7 @@ impl Context { let msg_receiver = storage.msg_receiver.expect("msg_receiver should be set"); storage - .contracts + .contract_data .get(&msg_receiver) .expect("contract receiver should have a storage initialised") .get(key) @@ -49,7 +54,7 @@ impl Context { let msg_receiver = storage.msg_receiver.expect("msg_receiver should be set"); storage - .contracts + .contract_data .get_mut(&msg_receiver) .expect("contract receiver should have a storage initialised") .insert(key, value); @@ -87,15 +92,44 @@ impl Context { storage.msg_receiver.expect("msg_receiver should be set") } - pub(crate) fn init_contract(self, contract_address: Address) { + pub(crate) fn init_contract( + self, + contract_address: Address, + ) { let mut storage = STORAGE.entry(self.thread_name).or_default(); - if storage.contracts.insert(contract_address, HashMap::new()).is_some() + if storage + .contract_data + .insert(contract_address, HashMap::new()) + .is_some() + { + panic!("contract storage already initialized - contract_address: {contract_address}"); + } + + if storage + .contract_router + .insert( + contract_address, + Mutex::new(Box::new(unsafe { ST::new(uint!(0_U256), 0) })), + ) + .is_some() { panic!("contract storage already initialized - contract_address: {contract_address}"); } } } +/// Read the word from location pointed by `ptr`. +unsafe fn read_bytes32(ptr: *const u8) -> Bytes32 { + let mut res = Bytes32::default(); + ptr::copy(ptr, res.as_mut_ptr(), WORD_BYTES); + res +} + +/// Write the word `bytes` to the location pointed by `ptr`. +unsafe fn write_bytes32(ptr: *mut u8, bytes: Bytes32) { + ptr::copy(bytes.as_ptr(), ptr, WORD_BYTES); +} + /// Storage mock: A global mutable key-value store. /// Allows concurrent access. /// @@ -119,34 +153,40 @@ impl ThreadName { } } -/// Storage for unit test's mock data. +/// Storage for unit test's mock data.x #[derive(Default)] struct MockStorage { /// Address of the message sender. msg_sender: Option
, /// Address of the contract that is currently receiving the message. msg_receiver: Option
, - /// Contract's mock data storage. - contracts: HashMap, + /// Contract's address to mock data storage mapping. + contract_data: HashMap, + // Contract's address to router mapping. + // NOTE: Mutex is important since contract type is not `Sync`. + contract_router: HashMap>>, } type ContractStorage = HashMap; -/// Read the word from location pointed by `ptr`. -unsafe fn read_bytes32(ptr: *const u8) -> Bytes32 { - let mut res = Bytes32::default(); - ptr::copy(ptr, res.as_mut_ptr(), WORD_BYTES); - res +/// A trait for routing messages to the appropriate selector in tests. +pub trait TestRouter: Send { + /// Tries to find and execute a method for the given selector, returning + /// `None` if none is found. + fn route(&mut self, selector: u32, input: &[u8]) -> Option; } -/// Write the word `bytes` to the location pointed by `ptr`. -unsafe fn write_bytes32(ptr: *mut u8, bytes: Bytes32) { - ptr::copy(bytes.as_ptr(), ptr, WORD_BYTES); +impl + TopLevelStorage + BorrowMut + Send> TestRouter + for R +{ + fn route(&mut self, selector: u32, input: &[u8]) -> Option { + >::route(self, selector, input) + } } /// Initializes fields of contract storage and child contract storages with /// default values. -pub trait DefaultStorage: StorageType { +pub trait DefaultStorage: StorageType + TestRouter + 'static { /// Initializes fields of contract storage and child contract storages with /// default values. #[must_use] @@ -155,7 +195,7 @@ pub trait DefaultStorage: StorageType { } } -impl DefaultStorage for ST {} +impl DefaultStorage for ST {} pub struct ContractCall { contract: ST, @@ -194,9 +234,9 @@ pub struct Contract { address: Address, } -impl Contract { +impl Contract { pub fn new(address: Address) -> Self { - Context::current().init_contract(address); + Context::current().init_contract::(address); Self { phantom: ::core::marker::PhantomData, address } } @@ -217,14 +257,17 @@ pub struct Account { } impl Account { + #[must_use] pub const fn new(address: Address) -> Self { Self { address } } + #[must_use] pub fn random() -> Self { Self::new(Address::random()) } + #[must_use] pub fn address(&self) -> Address { self.address } diff --git a/lib/motsu/src/lib.rs b/lib/motsu/src/lib.rs index f2dd0a423..99df163d4 100644 --- a/lib/motsu/src/lib.rs +++ b/lib/motsu/src/lib.rs @@ -58,10 +58,10 @@ mod tests { use stylus_sdk::{ alloy_primitives::{Address, U256}, call::Call, - prelude::{public, sol_storage, TopLevelStorage}, + prelude::{public, sol_storage, StorageType, TopLevelStorage}, }; - use crate::context::Account; + use crate::context::{Account, TestRouter}; sol_storage! { pub struct PingContract { @@ -142,4 +142,14 @@ mod tests { assert_eq!(ping.ping_count(), uint!(1_U256)); assert_eq!(pong.pong_count(), uint!(1_U256)); } + + #[test] + fn smoke() { + let mut ping_contract = unsafe { PingContract::new(uint!(0_U256), 0) }; + ::route( + &mut ping_contract, + 0, + &[0, 0, 0, 0], + ); + } } From 1dc7519ee3eeea9ad40beb76f4a17a302ad8b928 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Fri, 22 Nov 2024 17:42:53 +0400 Subject: [PATCH 08/57] add call shim --- lib/motsu/src/context.rs | 79 +++++++++++++++++++++++++++++++++++++++- lib/motsu/src/shims.rs | 15 ++++---- 2 files changed, 85 insertions(+), 9 deletions(-) diff --git a/lib/motsu/src/context.rs b/lib/motsu/src/context.rs index 988e39474..cd88228a6 100644 --- a/lib/motsu/src/context.rs +++ b/lib/motsu/src/context.rs @@ -1,6 +1,6 @@ //! Unit-testing context for Stylus contracts. -use std::{borrow::BorrowMut, collections::HashMap, ptr, sync::Mutex}; +use std::{borrow::BorrowMut, collections::HashMap, ptr, slice, sync::Mutex}; use alloy_primitives::Address; use dashmap::DashMap; @@ -24,6 +24,7 @@ impl Context { /// Get test context associated with the current test thread. #[must_use] pub fn current() -> Self { + // TODO#q: STORAGE entry call here Self { thread_name: ThreadName::current() } } @@ -116,6 +117,80 @@ impl Context { panic!("contract storage already initialized - contract_address: {contract_address}"); } } + + pub(crate) unsafe fn call_contract_raw( + self, + address: *const u8, + calldata: *const u8, + calldata_len: usize, + return_data_len: *mut usize, + ) -> u8 { + let address_bytes = slice::from_raw_parts(address, 20); + let address = Address::from_slice(address_bytes); + + let input = slice::from_raw_parts(calldata, calldata_len); + let selector = + u32::from_be_bytes(TryInto::try_into(&input[..4]).unwrap()); + + match self.call_contract(address, selector, &input[4..]) { + Ok(res) => { + return_data_len.write(res.len()); + self.set_return_data(res); + 0 + } + Err(err) => { + return_data_len.write(err.len()); + self.set_return_data(err); + 1 + } + } + } + + pub(crate) fn set_return_data(&self, data: Vec) { + let _ = STORAGE + .entry(self.thread_name.clone()) + .or_default() + .call_output + .insert(data); + } + + pub(crate) fn call_contract( + &self, + contract_address: Address, + selector: u32, + input: &[u8], + ) -> ArbResult { + let storage = STORAGE.entry(self.thread_name.clone()).or_default(); + + let router = storage + .contract_router + .get(&contract_address) + .expect("contract router should be set"); + + let mut router = router.lock().expect("should lock test router"); + router.route(selector, input).unwrap_or_else(|| { + panic!("selector not found - selector: {selector}") + }) + } + + pub(crate) unsafe fn read_return_data_raw( + self, + dest: *mut u8, + size: usize, + ) -> usize { + let data = self.get_return_data(); + ptr::copy(data.as_ptr(), dest, size); + 0 + } + + pub(crate) fn get_return_data(&self) -> Vec { + STORAGE + .entry(self.thread_name.clone()) + .or_default() + .call_output + .take() + .expect("call_output should be set") + } } /// Read the word from location pointed by `ptr`. @@ -165,6 +240,8 @@ struct MockStorage { // Contract's address to router mapping. // NOTE: Mutex is important since contract type is not `Sync`. contract_router: HashMap>>, + // Output of a contract call. + call_output: Option>, } type ContractStorage = HashMap; diff --git a/lib/motsu/src/shims.rs b/lib/motsu/src/shims.rs index b5128e723..5dc478bb6 100644 --- a/lib/motsu/src/shims.rs +++ b/lib/motsu/src/shims.rs @@ -236,10 +236,7 @@ pub unsafe extern "C" fn read_return_data( _offset: usize, _size: usize, ) -> usize { - // TODO: #156 - // No-op: we do not use this function in our unit-tests, - // but the binary does include it. - 0 + Context::current().read_return_data_raw(_dest, _size) } /// Calls the contract at the given address with options for passing value and @@ -265,10 +262,12 @@ pub unsafe extern "C" fn call_contract( _gas: u64, _return_data_len: *mut usize, ) -> u8 { - // TODO: #156 - // No-op: we do not use this function in our unit-tests, - // but the binary does include it. - 0 + Context::current().call_contract_raw( + _contract, + _calldata, + _calldata_len, + _return_data_len, + ) } /// Static calls the contract at the given address, with the option to limit the From 092a370d69ec5cb67ec0466a57039da986396108 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Fri, 22 Nov 2024 18:55:52 +0400 Subject: [PATCH 09/57] ++ --- lib/motsu/src/context.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/motsu/src/context.rs b/lib/motsu/src/context.rs index cd88228a6..2009c7ef9 100644 --- a/lib/motsu/src/context.rs +++ b/lib/motsu/src/context.rs @@ -160,7 +160,11 @@ impl Context { selector: u32, input: &[u8], ) -> ArbResult { - let storage = STORAGE.entry(self.thread_name.clone()).or_default(); + let mut storage = STORAGE.entry(self.thread_name.clone()).or_default(); + + let previous_receiver = storage.msg_receiver.replace(contract_address); + let previous_sender = storage.msg_sender.take(); + storage.msg_sender = previous_receiver; // now the sender is current contract let router = storage .contract_router @@ -168,9 +172,15 @@ impl Context { .expect("contract router should be set"); let mut router = router.lock().expect("should lock test router"); - router.route(selector, input).unwrap_or_else(|| { + let result = router.route(selector, input).unwrap_or_else(|| { panic!("selector not found - selector: {selector}") - }) + }); + std::mem::drop(router); + + storage.msg_receiver = previous_receiver; + storage.msg_sender = previous_sender; + + result } pub(crate) unsafe fn read_return_data_raw( From e5028fcc1cc756c1feca0a243a3b6c5ebf5c40d3 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Fri, 22 Nov 2024 20:03:55 +0400 Subject: [PATCH 10/57] add msg::value --- lib/motsu/src/context.rs | 4 ++++ lib/motsu/src/shims.rs | 10 ++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/motsu/src/context.rs b/lib/motsu/src/context.rs index 2009c7ef9..5e280c8d9 100644 --- a/lib/motsu/src/context.rs +++ b/lib/motsu/src/context.rs @@ -30,6 +30,9 @@ impl Context { /// Get the value at `key` in storage. pub(crate) fn get_bytes(self, key: &Bytes32) -> Bytes32 { + // TODO#q: fix deadlock here. + // When contract is called from another contract, it access storage + // second time. Split STORAGE into two parts. let storage = STORAGE.entry(self.thread_name).or_default(); let msg_receiver = storage.msg_receiver.expect("msg_receiver should be set"); @@ -139,6 +142,7 @@ impl Context { 0 } Err(err) => { + // TODO#q: how should we process errors? return_data_len.write(err.len()); self.set_return_data(err); 1 diff --git a/lib/motsu/src/shims.rs b/lib/motsu/src/shims.rs index 5dc478bb6..89b7063b1 100644 --- a/lib/motsu/src/shims.rs +++ b/lib/motsu/src/shims.rs @@ -146,8 +146,14 @@ pub const EOA_CODEHASH: &[u8; 66] = #[no_mangle] pub unsafe extern "C" fn msg_sender(sender: *mut u8) { let msg_sender = Context::current().get_msg_sender(); - let x: &[u8; 20] = msg_sender.as_ref(); - std::ptr::copy(x.as_ptr(), sender, 20); + std::ptr::copy(msg_sender.as_ptr(), sender, 20); +} + +/// Get the ETH value (U256) in wei sent to the program. +#[no_mangle] +pub unsafe extern "C" fn msg_value(value: *mut u8) { + let dummy_msg_value: Bytes32 = Bytes32::default(); + std::ptr::copy(dummy_msg_value.as_ptr(), value, 32); } /// Gets the address of the current program. The semantics are equivalent to From c03429d57fd741fe968c511e34bbaa0a99c66362 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Fri, 22 Nov 2024 20:48:26 +0400 Subject: [PATCH 11/57] fix deadlock --- lib/motsu/src/context.rs | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/lib/motsu/src/context.rs b/lib/motsu/src/context.rs index 5e280c8d9..d142f5392 100644 --- a/lib/motsu/src/context.rs +++ b/lib/motsu/src/context.rs @@ -100,8 +100,9 @@ impl Context { self, contract_address: Address, ) { - let mut storage = STORAGE.entry(self.thread_name).or_default(); - if storage + if STORAGE + .entry(self.thread_name.clone()) + .or_default() .contract_data .insert(contract_address, HashMap::new()) .is_some() @@ -109,7 +110,9 @@ impl Context { panic!("contract storage already initialized - contract_address: {contract_address}"); } - if storage + if CALL_STORAGE + .entry(self.thread_name.clone()) + .or_default() .contract_router .insert( contract_address, @@ -151,7 +154,7 @@ impl Context { } pub(crate) fn set_return_data(&self, data: Vec) { - let _ = STORAGE + let _ = CALL_STORAGE .entry(self.thread_name.clone()) .or_default() .call_output @@ -165,22 +168,23 @@ impl Context { input: &[u8], ) -> ArbResult { let mut storage = STORAGE.entry(self.thread_name.clone()).or_default(); - let previous_receiver = storage.msg_receiver.replace(contract_address); let previous_sender = storage.msg_sender.take(); storage.msg_sender = previous_receiver; // now the sender is current contract + drop(storage); - let router = storage + let call_storage = + CALL_STORAGE.entry(self.thread_name.clone()).or_default(); + let router = call_storage .contract_router .get(&contract_address) .expect("contract router should be set"); - let mut router = router.lock().expect("should lock test router"); let result = router.route(selector, input).unwrap_or_else(|| { panic!("selector not found - selector: {selector}") }); - std::mem::drop(router); + let mut storage = STORAGE.entry(self.thread_name.clone()).or_default(); storage.msg_receiver = previous_receiver; storage.msg_sender = previous_sender; @@ -198,7 +202,7 @@ impl Context { } pub(crate) fn get_return_data(&self) -> Vec { - STORAGE + CALL_STORAGE .entry(self.thread_name.clone()) .or_default() .call_output @@ -251,6 +255,18 @@ struct MockStorage { msg_receiver: Option
, /// Contract's address to mock data storage mapping. contract_data: HashMap, +} + +type ContractStorage = HashMap; + +/// The key is the name of the test thread, and the value is external call +/// metadata. +static CALL_STORAGE: Lazy> = + Lazy::new(DashMap::new); + +/// Metadata related to call of external contract. +#[derive(Default)] +struct CallStorage { // Contract's address to router mapping. // NOTE: Mutex is important since contract type is not `Sync`. contract_router: HashMap>>, @@ -258,8 +274,6 @@ struct MockStorage { call_output: Option>, } -type ContractStorage = HashMap; - /// A trait for routing messages to the appropriate selector in tests. pub trait TestRouter: Send { /// Tries to find and execute a method for the given selector, returning From 0c5ac778d23f085f0d72466f64039c4d2f990c48 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Fri, 22 Nov 2024 20:57:42 +0400 Subject: [PATCH 12/57] ping pong works --- lib/motsu/src/context.rs | 42 +++++++++++++++++++++++++--------------- lib/motsu/src/shims.rs | 3 ++- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/lib/motsu/src/context.rs b/lib/motsu/src/context.rs index d142f5392..69e3e0b45 100644 --- a/lib/motsu/src/context.rs +++ b/lib/motsu/src/context.rs @@ -76,26 +76,35 @@ impl Context { STORAGE.remove(&self.thread_name); } - pub(crate) fn set_msg_sender(self, msg_sender: Address) { + /// Set the message sender account address. + pub(crate) fn set_msg_sender(self, msg_sender: Address) -> Option
{ let mut storage = STORAGE.entry(self.thread_name).or_default(); - let _ = storage.msg_sender.insert(msg_sender); + storage.msg_sender.replace(msg_sender) } - pub(crate) fn get_msg_sender(self) -> Address { + /// Get the message sender account address. + pub(crate) fn get_msg_sender(self) -> Option
{ let storage = STORAGE.entry(self.thread_name).or_default(); - storage.msg_sender.expect("msg_sender should be set") + storage.msg_sender } - pub(crate) fn set_msg_receiver(self, msg_receiver: Address) { + /// Set the address of the contract, that should be called. + pub(crate) fn set_msg_receiver( + self, + msg_receiver: Address, + ) -> Option
{ let mut storage = STORAGE.entry(self.thread_name).or_default(); - let _ = storage.msg_receiver.insert(msg_receiver); + storage.msg_receiver.replace(msg_receiver) } - pub(crate) fn get_msg_receiver(self) -> Address { + /// Get the address of the contract, that should be called. + pub(crate) fn get_msg_receiver(self) -> Option
{ let storage = STORAGE.entry(self.thread_name).or_default(); - storage.msg_receiver.expect("msg_receiver should be set") + storage.msg_receiver } + /// Initialise contract storage for the current test thread and + /// `contract_address`. pub(crate) fn init_contract( self, contract_address: Address, @@ -171,7 +180,7 @@ impl Context { let previous_receiver = storage.msg_receiver.replace(contract_address); let previous_sender = storage.msg_sender.take(); storage.msg_sender = previous_receiver; // now the sender is current contract - drop(storage); + drop(storage); // TODO#q: use msg_receiver setter (avoid a deadlock the other way) let call_storage = CALL_STORAGE.entry(self.thread_name.clone()).or_default(); @@ -198,7 +207,7 @@ impl Context { ) -> usize { let data = self.get_return_data(); ptr::copy(data.as_ptr(), dest, size); - 0 + data.len() } pub(crate) fn get_return_data(&self) -> Vec { @@ -281,8 +290,9 @@ pub trait TestRouter: Send { fn route(&mut self, selector: u32, input: &[u8]) -> Option; } -impl + TopLevelStorage + BorrowMut + Send> TestRouter - for R +impl TestRouter for R +where + R: Router + TopLevelStorage + BorrowMut + Send, { fn route(&mut self, selector: u32, input: &[u8]) -> Option { >::route(self, selector, input) @@ -319,8 +329,8 @@ impl ::core::ops::Deref for ContractCall { #[inline] fn deref(&self) -> &Self::Target { - Context::current().set_msg_sender(self.caller_address); - Context::current().set_msg_receiver(self.contract_address); + let _ = Context::current().set_msg_sender(self.caller_address); + let _ = Context::current().set_msg_receiver(self.contract_address); &self.contract } } @@ -328,8 +338,8 @@ impl ::core::ops::Deref for ContractCall { impl ::core::ops::DerefMut for ContractCall { #[inline] fn deref_mut(&mut self) -> &mut Self::Target { - Context::current().set_msg_sender(self.caller_address); - Context::current().set_msg_receiver(self.contract_address); + let _ = Context::current().set_msg_sender(self.caller_address); + let _ = Context::current().set_msg_receiver(self.contract_address); &mut self.contract } } diff --git a/lib/motsu/src/shims.rs b/lib/motsu/src/shims.rs index 89b7063b1..1d329e7fb 100644 --- a/lib/motsu/src/shims.rs +++ b/lib/motsu/src/shims.rs @@ -145,7 +145,8 @@ pub const EOA_CODEHASH: &[u8; 66] = /// May panic if fails to parse `MSG_SENDER` as an address. #[no_mangle] pub unsafe extern "C" fn msg_sender(sender: *mut u8) { - let msg_sender = Context::current().get_msg_sender(); + let msg_sender = + Context::current().get_msg_sender().expect("msg_sender should be set"); std::ptr::copy(msg_sender.as_ptr(), sender, 20); } From 924e72e3513084736fc583a8fbb7dd9cae01af63 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Fri, 22 Nov 2024 21:27:19 +0400 Subject: [PATCH 13/57] ++ --- lib/motsu/src/context.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/motsu/src/context.rs b/lib/motsu/src/context.rs index 69e3e0b45..cf4cd1dba 100644 --- a/lib/motsu/src/context.rs +++ b/lib/motsu/src/context.rs @@ -30,9 +30,6 @@ impl Context { /// Get the value at `key` in storage. pub(crate) fn get_bytes(self, key: &Bytes32) -> Bytes32 { - // TODO#q: fix deadlock here. - // When contract is called from another contract, it access storage - // second time. Split STORAGE into two parts. let storage = STORAGE.entry(self.thread_name).or_default(); let msg_receiver = storage.msg_receiver.expect("msg_receiver should be set"); From 59cc1a2788f72d77e40d0631ee54637e756d0af5 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Fri, 22 Nov 2024 21:49:56 +0400 Subject: [PATCH 14/57] ++ --- lib/motsu/src/context.rs | 78 +++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 36 deletions(-) diff --git a/lib/motsu/src/context.rs b/lib/motsu/src/context.rs index cf4cd1dba..0b6c9e3d3 100644 --- a/lib/motsu/src/context.rs +++ b/lib/motsu/src/context.rs @@ -3,7 +3,7 @@ use std::{borrow::BorrowMut, collections::HashMap, ptr, slice, sync::Mutex}; use alloy_primitives::Address; -use dashmap::DashMap; +use dashmap::{mapref::one::RefMut, DashMap}; use once_cell::sync::Lazy; use stylus_sdk::{ abi::Router, @@ -28,9 +28,16 @@ impl Context { Self { thread_name: ThreadName::current() } } + /// Get the raw value at `key` in storage and write it to `value`. + pub(crate) unsafe fn get_bytes_raw(self, key: *const u8, value: *mut u8) { + let key = read_bytes32(key); + + write_bytes32(value, self.get_bytes(&key)); + } + /// Get the value at `key` in storage. pub(crate) fn get_bytes(self, key: &Bytes32) -> Bytes32 { - let storage = STORAGE.entry(self.thread_name).or_default(); + let storage = self.get_storage(); let msg_receiver = storage.msg_receiver.expect("msg_receiver should be set"); storage @@ -42,16 +49,15 @@ impl Context { .unwrap_or_default() } - /// Get the raw value at `key` in storage and write it to `value`. - pub(crate) unsafe fn get_bytes_raw(self, key: *const u8, value: *mut u8) { - let key = read_bytes32(key); - - write_bytes32(value, self.get_bytes(&key)); + /// Set the raw value at `key` in storage to `value`. + pub(crate) unsafe fn set_bytes_raw(self, key: *const u8, value: *const u8) { + let (key, value) = (read_bytes32(key), read_bytes32(value)); + self.set_bytes(key, value); } /// Set the value at `key` in storage to `value`. pub(crate) fn set_bytes(self, key: Bytes32, value: Bytes32) { - let mut storage = STORAGE.entry(self.thread_name).or_default(); + let mut storage = self.get_storage(); let msg_receiver = storage.msg_receiver.expect("msg_receiver should be set"); storage @@ -61,43 +67,50 @@ impl Context { .insert(key, value); } - /// Set the raw value at `key` in storage to `value`. - pub(crate) unsafe fn set_bytes_raw(self, key: *const u8, value: *const u8) { - let (key, value) = (read_bytes32(key), read_bytes32(value)); - self.set_bytes(key, value); - } - /// Clears storage, removing all key-value pairs associated with the current /// test thread. pub fn reset_storage(self) { STORAGE.remove(&self.thread_name); } + /// Get reference to the storage for the current test thread. + fn get_storage(&self) -> RefMut<'static, ThreadName, MockStorage> { + STORAGE + .get_mut(&self.thread_name) + .expect("contract should be initialised first") + } + + /// Get reference to the call storage for the current test thread. + fn get_call_storage(&self) -> RefMut<'static, ThreadName, CallStorage> { + CALL_STORAGE + .get_mut(&self.thread_name.clone()) + .expect("contract should be initialised first") + } + /// Set the message sender account address. - pub(crate) fn set_msg_sender(self, msg_sender: Address) -> Option
{ - let mut storage = STORAGE.entry(self.thread_name).or_default(); - storage.msg_sender.replace(msg_sender) + pub(crate) fn set_msg_sender( + &self, + msg_sender: Address, + ) -> Option
{ + self.get_storage().msg_sender.replace(msg_sender) } /// Get the message sender account address. - pub(crate) fn get_msg_sender(self) -> Option
{ - let storage = STORAGE.entry(self.thread_name).or_default(); - storage.msg_sender + pub(crate) fn get_msg_sender(&self) -> Option
{ + self.get_storage().msg_sender } /// Set the address of the contract, that should be called. pub(crate) fn set_msg_receiver( - self, + &self, msg_receiver: Address, ) -> Option
{ - let mut storage = STORAGE.entry(self.thread_name).or_default(); - storage.msg_receiver.replace(msg_receiver) + self.get_storage().msg_receiver.replace(msg_receiver) } /// Get the address of the contract, that should be called. - pub(crate) fn get_msg_receiver(self) -> Option
{ - let storage = STORAGE.entry(self.thread_name).or_default(); - storage.msg_receiver + pub(crate) fn get_msg_receiver(&self) -> Option
{ + self.get_storage().msg_receiver } /// Initialise contract storage for the current test thread and @@ -117,7 +130,7 @@ impl Context { } if CALL_STORAGE - .entry(self.thread_name.clone()) + .entry(self.thread_name) .or_default() .contract_router .insert( @@ -151,7 +164,6 @@ impl Context { 0 } Err(err) => { - // TODO#q: how should we process errors? return_data_len.write(err.len()); self.set_return_data(err); 1 @@ -160,11 +172,7 @@ impl Context { } pub(crate) fn set_return_data(&self, data: Vec) { - let _ = CALL_STORAGE - .entry(self.thread_name.clone()) - .or_default() - .call_output - .insert(data); + let _ = self.get_call_storage().call_output.insert(data); } pub(crate) fn call_contract( @@ -208,9 +216,7 @@ impl Context { } pub(crate) fn get_return_data(&self) -> Vec { - CALL_STORAGE - .entry(self.thread_name.clone()) - .or_default() + self.get_call_storage() .call_output .take() .expect("call_output should be set") From 110d340badbb1e9aed4b62edb3cb02eab6bcdab6 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Fri, 22 Nov 2024 21:55:45 +0400 Subject: [PATCH 15/57] ++ --- lib/motsu/src/context.rs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/lib/motsu/src/context.rs b/lib/motsu/src/context.rs index 0b6c9e3d3..27c0eb79c 100644 --- a/lib/motsu/src/context.rs +++ b/lib/motsu/src/context.rs @@ -181,14 +181,12 @@ impl Context { selector: u32, input: &[u8], ) -> ArbResult { - let mut storage = STORAGE.entry(self.thread_name.clone()).or_default(); - let previous_receiver = storage.msg_receiver.replace(contract_address); - let previous_sender = storage.msg_sender.take(); - storage.msg_sender = previous_receiver; // now the sender is current contract - drop(storage); // TODO#q: use msg_receiver setter (avoid a deadlock the other way) - - let call_storage = - CALL_STORAGE.entry(self.thread_name.clone()).or_default(); + let previous_receiver = self.set_msg_receiver(contract_address); + let previous_msg_sender = self.set_msg_sender( + previous_receiver.expect("msg_receiver should be set"), + ); + + let call_storage = self.get_call_storage(); let router = call_storage .contract_router .get(&contract_address) @@ -198,9 +196,9 @@ impl Context { panic!("selector not found - selector: {selector}") }); - let mut storage = STORAGE.entry(self.thread_name.clone()).or_default(); + let mut storage = self.get_storage(); storage.msg_receiver = previous_receiver; - storage.msg_sender = previous_sender; + storage.msg_sender = previous_msg_sender; result } @@ -258,7 +256,7 @@ impl ThreadName { } } -/// Storage for unit test's mock data.x +/// Storage for unit test's mock data. #[derive(Default)] struct MockStorage { /// Address of the message sender. From aa577f26048d538aafe7060c03496e153b368457 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Fri, 22 Nov 2024 22:06:57 +0400 Subject: [PATCH 16/57] ++ --- lib/motsu/src/context.rs | 16 ++++++++-------- lib/motsu/src/lib.rs | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/motsu/src/context.rs b/lib/motsu/src/context.rs index 27c0eb79c..3b9d0ccf5 100644 --- a/lib/motsu/src/context.rs +++ b/lib/motsu/src/context.rs @@ -24,7 +24,6 @@ impl Context { /// Get test context associated with the current test thread. #[must_use] pub fn current() -> Self { - // TODO#q: STORAGE entry call here Self { thread_name: ThreadName::current() } } @@ -181,10 +180,12 @@ impl Context { selector: u32, input: &[u8], ) -> ArbResult { - let previous_receiver = self.set_msg_receiver(contract_address); - let previous_msg_sender = self.set_msg_sender( - previous_receiver.expect("msg_receiver should be set"), - ); + let previous_receiver = self + .set_msg_receiver(contract_address) + .expect("previous msg_receiver should be set"); + let previous_msg_sender = self + .set_msg_sender(previous_receiver) + .expect("previous msg_sender should be set"); let call_storage = self.get_call_storage(); let router = call_storage @@ -196,9 +197,8 @@ impl Context { panic!("selector not found - selector: {selector}") }); - let mut storage = self.get_storage(); - storage.msg_receiver = previous_receiver; - storage.msg_sender = previous_msg_sender; + let _ = self.set_msg_receiver(previous_receiver); + let _ = self.set_msg_sender(previous_msg_sender); result } diff --git a/lib/motsu/src/lib.rs b/lib/motsu/src/lib.rs index 99df163d4..b509a74e9 100644 --- a/lib/motsu/src/lib.rs +++ b/lib/motsu/src/lib.rs @@ -134,7 +134,7 @@ mod tests { let mut ping = alice.uses(ping); let mut pong = alice.uses(pong); - let value = uint!(1_U256); + let value = uint!(10_U256); let ponged_value = ping.ping(pong.address(), value).expect("should ping successfully"); From 01401e84467dd3dd4f71173bf4ea2203700c1755 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Sat, 23 Nov 2024 09:57:18 +0400 Subject: [PATCH 17/57] comment erc721 tests --- contracts/src/token/erc721/mod.rs | 2 ++ lib/motsu/src/lib.rs | 10 ---------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/contracts/src/token/erc721/mod.rs b/contracts/src/token/erc721/mod.rs index 5f6fb886d..2120387a9 100644 --- a/contracts/src/token/erc721/mod.rs +++ b/contracts/src/token/erc721/mod.rs @@ -1175,6 +1175,7 @@ mod tests { U256::from(num) } + /* #[motsu::test] fn error_when_checking_balance_of_invalid_owner(contract: Erc721) { let invalid_owner = Address::ZERO; @@ -2505,4 +2506,5 @@ mod tests { let expected = 0x01ffc9a7; assert_eq!(actual, expected); } + */ } diff --git a/lib/motsu/src/lib.rs b/lib/motsu/src/lib.rs index b509a74e9..d87dbd7d1 100644 --- a/lib/motsu/src/lib.rs +++ b/lib/motsu/src/lib.rs @@ -142,14 +142,4 @@ mod tests { assert_eq!(ping.ping_count(), uint!(1_U256)); assert_eq!(pong.pong_count(), uint!(1_U256)); } - - #[test] - fn smoke() { - let mut ping_contract = unsafe { PingContract::new(uint!(0_U256), 0) }; - ::route( - &mut ping_contract, - 0, - &[0, 0, 0, 0], - ); - } } From 0cd42999ab6db57f6f8b2ba62eb1400feb3ccd3c Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Sat, 23 Nov 2024 11:21:10 +0400 Subject: [PATCH 18/57] add erc721 receiver test --- contracts/src/token/erc721/mod.rs | 52 ++++++++++++++++++- lib/motsu/src/context.rs | 83 ++++++++++++++++++------------- lib/motsu/src/shims.rs | 17 +++++-- 3 files changed, 112 insertions(+), 40 deletions(-) diff --git a/contracts/src/token/erc721/mod.rs b/contracts/src/token/erc721/mod.rs index 2120387a9..99752cd84 100644 --- a/contracts/src/token/erc721/mod.rs +++ b/contracts/src/token/erc721/mod.rs @@ -1156,8 +1156,15 @@ impl Erc721 { #[cfg(all(test, feature = "std"))] mod tests { - use alloy_primitives::{address, uint, Address, U256}; - use stylus_sdk::msg; + use alloy_primitives::{ + address, fixed_bytes, uint, Address, FixedBytes, U256, + }; + use motsu::prelude::Account; + use stylus_sdk::{ + abi::Bytes, + msg, + prelude::{public, sol_storage, TopLevelStorage}, + }; use super::{ ERC721IncorrectOwner, ERC721InsufficientApproval, @@ -2507,4 +2514,45 @@ mod tests { assert_eq!(actual, expected); } */ + + sol_storage! { + pub struct Erc721ReceiverMock { + uint256 _received_token_id; + } + } + + #[public] + impl Erc721ReceiverMock { + #[selector(name = "onERC721Received")] + fn on_erc721_received( + &mut self, + operator: Address, + from: Address, + token_id: U256, + data: Bytes, + ) -> FixedBytes<4> { + self._received_token_id.set(token_id); + fixed_bytes!("150b7a02") + } + + fn received_token_id(&self) -> U256 { + self._received_token_id.get() + } + } + + unsafe impl TopLevelStorage for Erc721ReceiverMock {} + + #[motsu::test] + fn on_erc721_received(erc721: Erc721, receiver: Erc721ReceiverMock) { + let alice = Account::random(); + let token_id = random_token_id(); + alice + .uses(erc721) + ._safe_mint(receiver.address(), token_id, vec![0, 1, 2, 3].into()) + .unwrap(); + + let received_token_id = alice.uses(receiver).received_token_id(); + + assert_eq!(received_token_id, token_id); + } } diff --git a/lib/motsu/src/context.rs b/lib/motsu/src/context.rs index 3b9d0ccf5..618b9d3cb 100644 --- a/lib/motsu/src/context.rs +++ b/lib/motsu/src/context.rs @@ -35,7 +35,7 @@ impl Context { } /// Get the value at `key` in storage. - pub(crate) fn get_bytes(self, key: &Bytes32) -> Bytes32 { + fn get_bytes(self, key: &Bytes32) -> Bytes32 { let storage = self.get_storage(); let msg_receiver = storage.msg_receiver.expect("msg_receiver should be set"); @@ -55,7 +55,7 @@ impl Context { } /// Set the value at `key` in storage to `value`. - pub(crate) fn set_bytes(self, key: Bytes32, value: Bytes32) { + fn set_bytes(self, key: Bytes32, value: Bytes32) { let mut storage = self.get_storage(); let msg_receiver = storage.msg_receiver.expect("msg_receiver should be set"); @@ -72,25 +72,8 @@ impl Context { STORAGE.remove(&self.thread_name); } - /// Get reference to the storage for the current test thread. - fn get_storage(&self) -> RefMut<'static, ThreadName, MockStorage> { - STORAGE - .get_mut(&self.thread_name) - .expect("contract should be initialised first") - } - - /// Get reference to the call storage for the current test thread. - fn get_call_storage(&self) -> RefMut<'static, ThreadName, CallStorage> { - CALL_STORAGE - .get_mut(&self.thread_name.clone()) - .expect("contract should be initialised first") - } - /// Set the message sender account address. - pub(crate) fn set_msg_sender( - &self, - msg_sender: Address, - ) -> Option
{ + fn set_msg_sender(&self, msg_sender: Address) -> Option
{ self.get_storage().msg_sender.replace(msg_sender) } @@ -100,21 +83,18 @@ impl Context { } /// Set the address of the contract, that should be called. - pub(crate) fn set_msg_receiver( - &self, - msg_receiver: Address, - ) -> Option
{ + fn set_msg_receiver(&self, msg_receiver: Address) -> Option
{ self.get_storage().msg_receiver.replace(msg_receiver) } /// Get the address of the contract, that should be called. - pub(crate) fn get_msg_receiver(&self) -> Option
{ + fn get_msg_receiver(&self) -> Option
{ self.get_storage().msg_receiver } /// Initialise contract storage for the current test thread and /// `contract_address`. - pub(crate) fn init_contract( + fn init_contract( self, contract_address: Address, ) { @@ -142,6 +122,7 @@ impl Context { } } + /// Call the contract at raw `address` with the given raw `calldata`. pub(crate) unsafe fn call_contract_raw( self, address: *const u8, @@ -170,23 +151,22 @@ impl Context { } } - pub(crate) fn set_return_data(&self, data: Vec) { - let _ = self.get_call_storage().call_output.insert(data); - } - - pub(crate) fn call_contract( + fn call_contract( &self, contract_address: Address, selector: u32, input: &[u8], ) -> ArbResult { + // Set the current contract as message sender and callee contract as + // receiver. let previous_receiver = self .set_msg_receiver(contract_address) - .expect("previous msg_receiver should be set"); + .expect("msg_receiver should be set"); let previous_msg_sender = self .set_msg_sender(previous_receiver) - .expect("previous msg_sender should be set"); + .expect("msg_sender should be set"); + // Call external contract. let call_storage = self.get_call_storage(); let router = call_storage .contract_router @@ -197,12 +177,17 @@ impl Context { panic!("selector not found - selector: {selector}") }); + // Set the previous message sender and receiver back. let _ = self.set_msg_receiver(previous_receiver); let _ = self.set_msg_sender(previous_msg_sender); result } + fn set_return_data(&self, data: Vec) { + let _ = self.get_call_storage().call_output.insert(data); + } + pub(crate) unsafe fn read_return_data_raw( self, dest: *mut u8, @@ -213,12 +198,40 @@ impl Context { data.len() } - pub(crate) fn get_return_data(&self) -> Vec { + fn get_return_data(&self) -> Vec { self.get_call_storage() .call_output .take() .expect("call_output should be set") } + + /// Check if the contract at raw `address` has code. + pub(crate) unsafe fn has_code_raw(self, address: *const u8) -> bool { + let address_bytes = slice::from_raw_parts(address, 20); + let address = Address::from_slice(address_bytes); + self.has_code(address) + } + + /// Check if the contract at `address` has code. + #[must_use] + fn has_code(&self, address: Address) -> bool { + let call_storage = self.get_call_storage(); + call_storage.contract_router.contains_key(&address) + } + + /// Get reference to the storage for the current test thread. + fn get_storage(&self) -> RefMut<'static, ThreadName, MockStorage> { + STORAGE + .get_mut(&self.thread_name) + .expect("contract should be initialised first") + } + + /// Get reference to the call storage for the current test thread. + fn get_call_storage(&self) -> RefMut<'static, ThreadName, CallStorage> { + CALL_STORAGE + .get_mut(&self.thread_name.clone()) + .expect("contract should be initialised first") + } } /// Read the word from location pointed by `ptr`. @@ -279,7 +292,7 @@ static CALL_STORAGE: Lazy> = struct CallStorage { // Contract's address to router mapping. // NOTE: Mutex is important since contract type is not `Sync`. - contract_router: HashMap>>, + contract_router: HashMap>>, // Output of a contract call. call_output: Option>, } diff --git a/lib/motsu/src/shims.rs b/lib/motsu/src/shims.rs index 1d329e7fb..56d22dea7 100644 --- a/lib/motsu/src/shims.rs +++ b/lib/motsu/src/shims.rs @@ -124,10 +124,15 @@ pub const CONTRACT_ADDRESS: &[u8; 42] = /// Arbitrum's CHAID ID. pub const CHAIN_ID: u64 = 42161; -/// Externally Owned Account (EOA) code hash. +/// Externally Owned Account (EOA) code hash (wallet account). pub const EOA_CODEHASH: &[u8; 66] = b"0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"; +/// Contract Account (CA) code hash (smart contract code). +/// NOTE: can be any 256-bit value to pass `has_code` check. +pub const CA_CODEHASH: &[u8; 66] = + b"0x1111111111111111111111111111111111111111111111111111111111111111"; + /// Gets the address of the account that called the program. For normal /// L2-to-L2 transactions the semantics are equivalent to that of the EVM's /// [`CALLER`] opcode, including in cases arising from [`DELEGATE_CALL`]. @@ -209,9 +214,15 @@ pub unsafe extern "C" fn emit_log(_: *const u8, _: usize, _: usize) { /// /// May panic if fails to parse `ACCOUNT_CODEHASH` as a keccack hash. #[no_mangle] -pub unsafe extern "C" fn account_codehash(_address: *const u8, dest: *mut u8) { +pub unsafe extern "C" fn account_codehash(address: *const u8, dest: *mut u8) { + let code_hash = if Context::current().has_code_raw(address) { + CA_CODEHASH + } else { + EOA_CODEHASH + }; + let account_codehash = - const_hex::const_decode_to_array::<32>(EOA_CODEHASH).unwrap(); + const_hex::const_decode_to_array::<32>(code_hash).unwrap(); std::ptr::copy(account_codehash.as_ptr(), dest, 32); } From 2b944ce6854a17842c1a01c0ce203161bfa1f8b4 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Thu, 28 Nov 2024 07:06:43 +0400 Subject: [PATCH 19/57] use contract wrapper in motsu params --- contracts/src/token/erc721/mod.rs | 13 ++++++++----- lib/motsu-proc/src/test.rs | 1 - lib/motsu/src/context.rs | 31 +++++++++++-------------------- lib/motsu/src/lib.rs | 19 +++++++++---------- lib/motsu/src/prelude.rs | 2 +- 5 files changed, 29 insertions(+), 37 deletions(-) diff --git a/contracts/src/token/erc721/mod.rs b/contracts/src/token/erc721/mod.rs index 99752cd84..566055ed0 100644 --- a/contracts/src/token/erc721/mod.rs +++ b/contracts/src/token/erc721/mod.rs @@ -1159,7 +1159,7 @@ mod tests { use alloy_primitives::{ address, fixed_bytes, uint, Address, FixedBytes, U256, }; - use motsu::prelude::Account; + use motsu::prelude::{Account, Contract}; use stylus_sdk::{ abi::Bytes, msg, @@ -2543,15 +2543,18 @@ mod tests { unsafe impl TopLevelStorage for Erc721ReceiverMock {} #[motsu::test] - fn on_erc721_received(erc721: Erc721, receiver: Erc721ReceiverMock) { + fn on_erc721_received( + erc721: Contract, + receiver: Contract, + ) { let alice = Account::random(); let token_id = random_token_id(); - alice - .uses(erc721) + erc721 + .sender(alice) ._safe_mint(receiver.address(), token_id, vec![0, 1, 2, 3].into()) .unwrap(); - let received_token_id = alice.uses(receiver).received_token_id(); + let received_token_id = receiver.sender(alice).received_token_id(); assert_eq!(received_token_id, token_id); } diff --git a/lib/motsu-proc/src/test.rs b/lib/motsu-proc/src/test.rs index 910ba4f25..05aa9f5c2 100644 --- a/lib/motsu-proc/src/test.rs +++ b/lib/motsu-proc/src/test.rs @@ -38,7 +38,6 @@ pub(crate) fn test(_attr: &TokenStream, input: TokenStream) -> TokenStream { #( #attrs )* #[test] fn #fn_name() #fn_return_type { - use ::motsu::prelude::DefaultStorage; #( #contract_declarations )* let res = { #( #fn_stmts )* diff --git a/lib/motsu/src/context.rs b/lib/motsu/src/context.rs index 618b9d3cb..7736e41c9 100644 --- a/lib/motsu/src/context.rs +++ b/lib/motsu/src/context.rs @@ -313,19 +313,12 @@ where } } -/// Initializes fields of contract storage and child contract storages with -/// default values. -pub trait DefaultStorage: StorageType + TestRouter + 'static { - /// Initializes fields of contract storage and child contract storages with - /// default values. - #[must_use] - fn default() -> Contract { +impl Default for Contract { + fn default() -> Self { Contract::random() } } -impl DefaultStorage for ST {} - pub struct ContractCall { contract: ST, caller_address: Address, @@ -379,8 +372,17 @@ impl Contract { pub fn address(&self) -> Address { self.address } + + pub fn sender(&self, account: Account) -> ContractCall { + ContractCall { + contract: unsafe { ST::new(uint!(0_U256), 0) }, + caller_address: account.address, + contract_address: self.address, + } + } } +#[derive(Clone, Copy)] pub struct Account { address: Address, } @@ -400,15 +402,4 @@ impl Account { pub fn address(&self) -> Address { self.address } - - pub fn uses( - &self, - contract: &mut Contract, - ) -> ContractCall { - ContractCall { - contract: unsafe { ST::new(uint!(0_U256), 0) }, - caller_address: self.address, - contract_address: contract.address, - } - } } diff --git a/lib/motsu/src/lib.rs b/lib/motsu/src/lib.rs index d87dbd7d1..47632130a 100644 --- a/lib/motsu/src/lib.rs +++ b/lib/motsu/src/lib.rs @@ -61,7 +61,7 @@ mod tests { prelude::{public, sol_storage, StorageType, TopLevelStorage}, }; - use crate::context::{Account, TestRouter}; + use crate::context::{Account, Contract, TestRouter}; sol_storage! { pub struct PingContract { @@ -124,22 +124,21 @@ mod tests { #[test] fn ping_pong_works() { - use crate::prelude::DefaultStorage; - let mut ping = PingContract::default(); + let mut ping = Contract::::default(); let ping = &mut ping; - let mut pong = PongContract::default(); + let mut pong = Contract::::default(); let pong = &mut pong; let alice = Account::random(); - let mut ping = alice.uses(ping); - let mut pong = alice.uses(pong); let value = uint!(10_U256); - let ponged_value = - ping.ping(pong.address(), value).expect("should ping successfully"); + let ponged_value = ping + .sender(alice) + .ping(pong.address(), value) + .expect("should ping successfully"); assert_eq!(ponged_value, value + uint!(1_U256)); - assert_eq!(ping.ping_count(), uint!(1_U256)); - assert_eq!(pong.pong_count(), uint!(1_U256)); + assert_eq!(ping.sender(alice).ping_count(), uint!(1_U256)); + assert_eq!(pong.sender(alice).pong_count(), uint!(1_U256)); } } diff --git a/lib/motsu/src/prelude.rs b/lib/motsu/src/prelude.rs index 5af1b5e21..a881a05fb 100644 --- a/lib/motsu/src/prelude.rs +++ b/lib/motsu/src/prelude.rs @@ -1,5 +1,5 @@ //! Common imports for `motsu` tests. pub use crate::{ - context::{Account, Context, ContractCall, DefaultStorage}, + context::{Account, Context, Contract, ContractCall}, shims::*, }; From 0aaa81e65f1ae38f8ae9bc22c27b3f5732eb1634 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Thu, 28 Nov 2024 09:42:58 +0400 Subject: [PATCH 20/57] add msg sender mock --- contracts/src/token/erc721/mod.rs | 18 ++++++++++-------- contracts/src/utils/context.rs | 17 +++++++++++++++++ contracts/src/utils/mod.rs | 1 + lib/motsu/src/context.rs | 2 +- lib/motsu/src/lib.rs | 24 ++++++++++++++++++++++-- 5 files changed, 51 insertions(+), 11 deletions(-) create mode 100644 contracts/src/utils/context.rs diff --git a/contracts/src/token/erc721/mod.rs b/contracts/src/token/erc721/mod.rs index 566055ed0..a32174b20 100644 --- a/contracts/src/token/erc721/mod.rs +++ b/contracts/src/token/erc721/mod.rs @@ -7,11 +7,12 @@ use stylus_sdk::{ abi::Bytes, alloy_sol_types::sol, call::{self, Call, MethodError}, - evm, msg, + evm, prelude::*, }; use crate::utils::{ + context::msg_sender, introspection::erc165::{Erc165, IErc165}, math::storage::{AddAssignUnchecked, SubAssignUnchecked}, }; @@ -161,6 +162,7 @@ impl MethodError for Error { } pub use receiver::IERC721Receiver; + #[allow(missing_docs)] mod receiver { stylus_sdk::stylus_proc::sol_interface! { @@ -505,7 +507,7 @@ impl IErc721 for Erc721 { data: Bytes, ) -> Result<(), Error> { self.transfer_from(from, to, token_id)?; - self._check_on_erc721_received(msg::sender(), from, to, token_id, data) + self._check_on_erc721_received(msg_sender(), from, to, token_id, data) } fn transfer_from( @@ -523,7 +525,7 @@ impl IErc721 for Erc721 { // Setting an "auth" argument enables the `_is_authorized` check which // verifies that the token exists (`from != 0`). Therefore, it is // not needed to verify that the return value is not 0 here. - let previous_owner = self._update(to, token_id, msg::sender())?; + let previous_owner = self._update(to, token_id, msg_sender())?; if previous_owner != from { return Err(ERC721IncorrectOwner { sender: from, @@ -536,7 +538,7 @@ impl IErc721 for Erc721 { } fn approve(&mut self, to: Address, token_id: U256) -> Result<(), Error> { - self._approve(to, token_id, msg::sender(), true) + self._approve(to, token_id, msg_sender(), true) } fn set_approval_for_all( @@ -544,7 +546,7 @@ impl IErc721 for Erc721 { operator: Address, approved: bool, ) -> Result<(), Error> { - self._set_approval_for_all(msg::sender(), operator, approved) + self._set_approval_for_all(msg_sender(), operator, approved) } fn get_approved(&self, token_id: U256) -> Result { @@ -822,7 +824,7 @@ impl Erc721 { ) -> Result<(), Error> { self._mint(to, token_id)?; self._check_on_erc721_received( - msg::sender(), + msg_sender(), Address::ZERO, to, token_id, @@ -967,7 +969,7 @@ impl Erc721 { data: Bytes, ) -> Result<(), Error> { self._transfer(from, to, token_id)?; - self._check_on_erc721_received(msg::sender(), from, to, token_id, data) + self._check_on_erc721_received(msg_sender(), from, to, token_id, data) } /// Approve `to` to operate on `token_id`. @@ -1085,7 +1087,7 @@ impl Erc721 { /// Performs an acceptance check for the provided `operator` by calling /// [`IERC721Receiver::on_erc_721_received`] on the `to` address. The /// `operator` is generally the address that initiated the token transfer - /// (i.e. `msg::sender()`). + /// (i.e. `msg_sender()`). /// /// The acceptance call is not executed and treated as a no-op if the /// target address doesn't contain code (i.e. an EOA). Otherwise, the diff --git a/contracts/src/utils/context.rs b/contracts/src/utils/context.rs new file mode 100644 index 000000000..9f66d44b5 --- /dev/null +++ b/contracts/src/utils/context.rs @@ -0,0 +1,17 @@ +//! Context functions used for mocking unit tests. + +use stylus_sdk::{alloy_primitives::Address, msg}; + +/// Returns the address of the message sender. +#[cfg(test)] +pub fn msg_sender() -> Address { + motsu::prelude::Context::current() + .get_msg_sender() + .expect("msg_sender should be set") +} + +/// Returns the address of the message sender. +#[cfg(not(test))] +pub fn msg_sender() -> Address { + msg::sender() +} diff --git a/contracts/src/utils/mod.rs b/contracts/src/utils/mod.rs index b8f56cef7..4746849b1 100644 --- a/contracts/src/utils/mod.rs +++ b/contracts/src/utils/mod.rs @@ -1,4 +1,5 @@ //! Common Smart Contracts utilities. +pub mod context; pub mod cryptography; pub mod introspection; pub mod math; diff --git a/lib/motsu/src/context.rs b/lib/motsu/src/context.rs index 7736e41c9..631c76e8c 100644 --- a/lib/motsu/src/context.rs +++ b/lib/motsu/src/context.rs @@ -78,7 +78,7 @@ impl Context { } /// Get the message sender account address. - pub(crate) fn get_msg_sender(&self) -> Option
{ + pub fn get_msg_sender(&self) -> Option
{ self.get_storage().msg_sender } diff --git a/lib/motsu/src/lib.rs b/lib/motsu/src/lib.rs index 47632130a..1a62db177 100644 --- a/lib/motsu/src/lib.rs +++ b/lib/motsu/src/lib.rs @@ -63,10 +63,17 @@ mod tests { use crate::context::{Account, Contract, TestRouter}; + /// Message sender that mocks `msg::sender()` in tests. + pub fn msg_sender() -> Address { + crate::prelude::Context::current() + .get_msg_sender() + .expect("msg_sender should be set") + } + sol_storage! { pub struct PingContract { uint256 _pings_count; - // TODO#q: add last pinged address. + address _pinged_from; } } @@ -80,12 +87,17 @@ mod tests { let pings_count = self._pings_count.get(); self._pings_count.set(pings_count + uint!(1_U256)); + self._pinged_from.set(msg_sender()); Ok(value) } fn ping_count(&self) -> U256 { self._pings_count.get() } + + fn pinged_from(&self) -> Address { + self._pinged_from.get() + } } unsafe impl TopLevelStorage for PingContract {} @@ -103,7 +115,7 @@ mod tests { sol_storage! { pub struct PongContract { uint256 _pongs_count; - uint256 _value; + address _ponged_from; } } @@ -112,12 +124,17 @@ mod tests { pub fn pong(&mut self, value: U256) -> Result> { let pongs_count = self._pongs_count.get(); self._pongs_count.set(pongs_count + uint!(1_U256)); + self._ponged_from.set(msg_sender()); Ok(value + uint!(1_U256)) } fn pong_count(&self) -> U256 { self._pongs_count.get() } + + fn ponged_from(&self) -> Address { + self._ponged_from.get() + } } unsafe impl TopLevelStorage for PongContract {} @@ -140,5 +157,8 @@ mod tests { assert_eq!(ponged_value, value + uint!(1_U256)); assert_eq!(ping.sender(alice).ping_count(), uint!(1_U256)); assert_eq!(pong.sender(alice).pong_count(), uint!(1_U256)); + + assert_eq!(ping.sender(alice).pinged_from(), alice.address()); + assert_eq!(pong.sender(alice).ponged_from(), ping.address()); } } From 33454f626a259bf4c97a1e2f68bfd88bdba4822d Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Thu, 28 Nov 2024 10:32:31 +0400 Subject: [PATCH 21/57] ++ --- Cargo.lock | 32 +------------------------------- lib/motsu/Cargo.toml | 3 +-- 2 files changed, 2 insertions(+), 33 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e7d6add19..c04a6556f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -256,7 +256,7 @@ dependencies = [ "cfg-if", "const-hex", "derive_arbitrary", - "derive_more 0.99.18", + "derive_more", "ethereum_ssz", "getrandom", "hex-literal", @@ -1379,28 +1379,6 @@ dependencies = [ "syn 2.0.68", ] -[[package]] -name = "derive_more" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a9b99b9cbbe49445b21764dc0625032a89b145a2642e67603e1c936f5458d05" -dependencies = [ - "derive_more-impl", -] - -[[package]] -name = "derive_more-impl" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb7330aeadfbe296029522e6c40f315320aba36fc43a5b3632f3795348f3bd22" -dependencies = [ - "convert_case 0.6.0", - "proc-macro2", - "quote", - "syn 2.0.68", - "unicode-xid", -] - [[package]] name = "digest" version = "0.9.0" @@ -2469,10 +2447,8 @@ name = "motsu" version = "0.2.0" dependencies = [ "alloy-primitives", - "alloy-sol-types", "const-hex", "dashmap 6.1.0", - "derive_more 1.0.0", "motsu-proc", "once_cell", "stylus-sdk", @@ -4009,12 +3985,6 @@ version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" -[[package]] -name = "unicode-xid" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" - [[package]] name = "url" version = "2.5.2" diff --git a/lib/motsu/Cargo.toml b/lib/motsu/Cargo.toml index 5f54f0800..478376c30 100644 --- a/lib/motsu/Cargo.toml +++ b/lib/motsu/Cargo.toml @@ -15,9 +15,8 @@ tiny-keccak.workspace = true stylus-sdk.workspace = true motsu-proc.workspace = true dashmap.workspace = true -derive_more = { version = "1.0.0", features = ["full"] } alloy-primitives = { workspace = true, features = ["arbitrary", "rand"] } -alloy-sol-types.workspace = true + [lints] workspace = true From 299ecc4bcf5ad13d6b633d58c77af146d12fe40b Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Fri, 29 Nov 2024 10:05:43 +0400 Subject: [PATCH 22/57] ++ --- Cargo.lock | 1 + lib/motsu/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index c04a6556f..d92e01c18 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2447,6 +2447,7 @@ name = "motsu" version = "0.2.0" dependencies = [ "alloy-primitives", + "alloy-sol-types", "const-hex", "dashmap 6.1.0", "motsu-proc", diff --git a/lib/motsu/Cargo.toml b/lib/motsu/Cargo.toml index 478376c30..2376089a2 100644 --- a/lib/motsu/Cargo.toml +++ b/lib/motsu/Cargo.toml @@ -16,7 +16,7 @@ stylus-sdk.workspace = true motsu-proc.workspace = true dashmap.workspace = true alloy-primitives = { workspace = true, features = ["arbitrary", "rand"] } - +alloy-sol-types.workspace = true [lints] workspace = true From 4a747f1a36bb7b7dae57ad8473d3f5ecb0f80b20 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Mon, 2 Dec 2024 16:04:11 +0400 Subject: [PATCH 23/57] comment test not ported test cases --- contracts/src/finance/vesting_wallet.rs | 4 ++-- contracts/src/token/erc1155/extensions/burnable.rs | 2 ++ contracts/src/token/erc1155/extensions/metadata_uri.rs | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/contracts/src/finance/vesting_wallet.rs b/contracts/src/finance/vesting_wallet.rs index 24b0e2a89..9b5043a25 100644 --- a/contracts/src/finance/vesting_wallet.rs +++ b/contracts/src/finance/vesting_wallet.rs @@ -511,7 +511,7 @@ impl VestingWallet { #[cfg(all(test, feature = "std"))] mod tests { - use alloy_primitives::{address, uint, Address, U256, U64}; + /*use alloy_primitives::{address, uint, Address, U256, U64}; use stylus_sdk::block; use super::{IVestingWallet, VestingWallet}; @@ -607,5 +607,5 @@ mod tests { ); assert_eq!(two, contract.vesting_schedule(two, start)); assert_eq!(two, contract.vesting_schedule(two, start + U64::from(1))); - } + }*/ } diff --git a/contracts/src/token/erc1155/extensions/burnable.rs b/contracts/src/token/erc1155/extensions/burnable.rs index bae3789f6..111061dec 100644 --- a/contracts/src/token/erc1155/extensions/burnable.rs +++ b/contracts/src/token/erc1155/extensions/burnable.rs @@ -110,6 +110,7 @@ impl Erc1155 { #[cfg(all(test, feature = "std"))] mod tests { + /* use alloy_primitives::{address, Address, U256}; use stylus_sdk::msg; @@ -348,4 +349,5 @@ mod tests { }) if sender == alice && balance == values[0] && needed == to_burn[0] && token_id == token_ids[0] )); } + */ } diff --git a/contracts/src/token/erc1155/extensions/metadata_uri.rs b/contracts/src/token/erc1155/extensions/metadata_uri.rs index 6f822a7df..4a2c12839 100644 --- a/contracts/src/token/erc1155/extensions/metadata_uri.rs +++ b/contracts/src/token/erc1155/extensions/metadata_uri.rs @@ -68,7 +68,7 @@ impl IErc165 for Erc1155MetadataUri { #[cfg(all(test, feature = "std"))] mod tests { - use alloy_primitives::U256; + /*use alloy_primitives::U256; use super::{Erc1155MetadataUri, IErc1155MetadataUri, IErc165}; @@ -98,5 +98,5 @@ mod tests { let actual = ::INTERFACE_ID; let expected = 0x01ffc9a7; assert_eq!(actual, expected); - } + }*/ } From 73c5792dc01f6b64d1e73829fa177d272c888ed3 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Mon, 2 Dec 2024 16:10:18 +0400 Subject: [PATCH 24/57] remove motsu from default members, since we're going to split this library anyway --- Cargo.toml | 2 -- 1 file changed, 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cf26be1b5..e4cfdffcc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,8 +28,6 @@ default-members = [ "contracts", "contracts-proc", "lib/crypto", - "lib/motsu", - "lib/motsu-proc", "lib/e2e-proc", "examples/erc20", "examples/erc20-permit", From abfbbb935f22c30506f696d3226990107eb7195f Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Mon, 2 Dec 2024 16:32:52 +0400 Subject: [PATCH 25/57] have cargo hack just for contracts --- .github/workflows/check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 71c35acf0..0c96dc55d 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -118,7 +118,7 @@ jobs: # target in this context means one of `--lib`, `--bin`, etc, and not the # target triple. - name: Cargo hack - run: cargo hack check --feature-powerset --depth 2 --release --target wasm32-unknown-unknown --skip std --workspace --exclude e2e --exclude basic-example-script --exclude benches + run: cargo hack check --feature-powerset --depth 2 --release --target wasm32-unknown-unknown --skip std --package openzeppelin-stylus typos: runs-on: ubuntu-latest name: ubuntu / stable / typos From f4a74c54aa714052bafa49685c636652557495da Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Mon, 2 Dec 2024 16:33:35 +0400 Subject: [PATCH 26/57] ++ --- lib/motsu/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/motsu/src/lib.rs b/lib/motsu/src/lib.rs index 1a62db177..317b60f9a 100644 --- a/lib/motsu/src/lib.rs +++ b/lib/motsu/src/lib.rs @@ -64,6 +64,7 @@ mod tests { use crate::context::{Account, Contract, TestRouter}; /// Message sender that mocks `msg::sender()` in tests. + #[must_use] pub fn msg_sender() -> Address { crate::prelude::Context::current() .get_msg_sender() From 2b688ce000a41386589e5be00477fb28c3940d47 Mon Sep 17 00:00:00 2001 From: Daniel Bigos Date: Fri, 29 Nov 2024 17:33:10 +0100 Subject: [PATCH 27/57] build: bump Stylus SDK and alloy versions (cherry picked from commit e539ee931812135f0c1295754140b0bf01417e4f) --- Cargo.lock | 1186 ++++++++++++++++++++------ Cargo.toml | 16 +- examples/erc1155/src/constructor.sol | 4 +- 3 files changed, 925 insertions(+), 281 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5043d0fc0..95c68d77a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6,8 +6,8 @@ version = 4 name = "access-control-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy", - "alloy-primitives", + "alloy 0.7.2", + "alloy-primitives 0.8.13", "e2e", "eyre", "openzeppelin-stylus", @@ -59,6 +59,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" dependencies = [ "cfg-if", + "getrandom", "once_cell", "version_check", "zerocopy", @@ -85,20 +86,42 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ba1c79677c9ce51c8d45e20845b05e6fb070ea2c863fba03ad6af2c778474bd" dependencies = [ - "alloy-consensus", - "alloy-contract", - "alloy-core", - "alloy-eips", - "alloy-genesis", - "alloy-network", - "alloy-provider", - "alloy-rpc-client", - "alloy-rpc-types", - "alloy-serde", - "alloy-signer", - "alloy-signer-local", - "alloy-transport", - "alloy-transport-http", + "alloy-consensus 0.1.3", + "alloy-contract 0.1.3", + "alloy-core 0.7.6", + "alloy-eips 0.1.3", + "alloy-genesis 0.1.3", + "alloy-network 0.1.3", + "alloy-provider 0.1.3", + "alloy-rpc-client 0.1.3", + "alloy-rpc-types 0.1.3", + "alloy-serde 0.1.3", + "alloy-signer 0.1.3", + "alloy-signer-local 0.1.3", + "alloy-transport 0.1.3", + "alloy-transport-http 0.1.3", +] + +[[package]] +name = "alloy" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44ab65cb6104c389b46df77b7990cab08780f57e41b412b46d6d12baf7e8c716" +dependencies = [ + "alloy-consensus 0.7.0", + "alloy-contract 0.7.0", + "alloy-core 0.8.13", + "alloy-eips 0.7.0", + "alloy-genesis 0.7.0", + "alloy-network 0.7.0", + "alloy-provider 0.7.0", + "alloy-rpc-client 0.7.0", + "alloy-rpc-types 0.7.0", + "alloy-serde 0.7.0", + "alloy-signer 0.7.0", + "alloy-signer-local 0.7.0", + "alloy-transport 0.7.0", + "alloy-transport-http 0.7.0", ] [[package]] @@ -117,11 +140,42 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f63a6c9eb45684a5468536bc55379a2af0f45ffa5d756e4e4964532737e1836" dependencies = [ - "alloy-eips", - "alloy-primitives", + "alloy-eips 0.1.3", + "alloy-primitives 0.7.6", + "alloy-rlp", + "alloy-serde 0.1.3", + "c-kzg", + "serde", +] + +[[package]] +name = "alloy-consensus" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a1ff8439834ab71a4b0ecd1a8ff80b3921c87615f158940c3364f399c732786" +dependencies = [ + "alloy-eips 0.7.0", + "alloy-primitives 0.8.13", "alloy-rlp", - "alloy-serde", + "alloy-serde 0.7.0", + "alloy-trie", + "auto_impl", "c-kzg", + "derive_more 1.0.0", + "serde", +] + +[[package]] +name = "alloy-consensus-any" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "519a86faaa6729464365a90c04eba68539b6d3a30f426edb4b3dafd78920d42f" +dependencies = [ + "alloy-consensus 0.7.0", + "alloy-eips 0.7.0", + "alloy-primitives 0.8.13", + "alloy-rlp", + "alloy-serde 0.7.0", "serde", ] @@ -131,14 +185,34 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c26b7d34cb76f826558e9409a010e25257f7bfb5aa5e3dd0042c564664ae159" dependencies = [ - "alloy-dyn-abi", - "alloy-json-abi", - "alloy-network", - "alloy-primitives", - "alloy-provider", - "alloy-rpc-types-eth", - "alloy-sol-types", - "alloy-transport", + "alloy-dyn-abi 0.7.6", + "alloy-json-abi 0.7.6", + "alloy-network 0.1.3", + "alloy-primitives 0.7.6", + "alloy-provider 0.1.3", + "alloy-rpc-types-eth 0.1.3", + "alloy-sol-types 0.7.6", + "alloy-transport 0.1.3", + "futures", + "futures-util", + "thiserror", +] + +[[package]] +name = "alloy-contract" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cca2b353d8b7f160dc930dfa174557acefece6deab5ecd7e6230d38858579eea" +dependencies = [ + "alloy-dyn-abi 0.8.13", + "alloy-json-abi 0.8.13", + "alloy-network 0.7.0", + "alloy-network-primitives", + "alloy-primitives 0.8.13", + "alloy-provider 0.7.0", + "alloy-rpc-types-eth 0.7.0", + "alloy-sol-types 0.8.13", + "alloy-transport 0.7.0", "futures", "futures-util", "thiserror", @@ -150,10 +224,23 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5af3faff14c12c8b11037e0a093dd157c3702becb8435577a2408534d0758315" dependencies = [ - "alloy-dyn-abi", - "alloy-json-abi", - "alloy-primitives", - "alloy-sol-types", + "alloy-dyn-abi 0.7.6", + "alloy-json-abi 0.7.6", + "alloy-primitives 0.7.6", + "alloy-sol-types 0.7.6", +] + +[[package]] +name = "alloy-core" +version = "0.8.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d22df68fa7d9744be0b1a9be3260e9aa089fbf41903ab182328333061ed186" +dependencies = [ + "alloy-dyn-abi 0.8.13", + "alloy-json-abi 0.8.13", + "alloy-primitives 0.8.13", + "alloy-rlp", + "alloy-sol-types 0.8.13", ] [[package]] @@ -162,10 +249,27 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb6e6436a9530f25010d13653e206fab4c9feddacf21a54de8d7311b275bc56b" dependencies = [ - "alloy-json-abi", - "alloy-primitives", - "alloy-sol-type-parser", - "alloy-sol-types", + "alloy-json-abi 0.7.6", + "alloy-primitives 0.7.6", + "alloy-sol-type-parser 0.7.6", + "alloy-sol-types 0.7.6", + "const-hex", + "itoa", + "serde", + "serde_json", + "winnow 0.6.13", +] + +[[package]] +name = "alloy-dyn-abi" +version = "0.8.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cf633ae9a1f0c82fdb9e559ed2be1c8e415c3e48fc47e1feaf32c6078ec0cdd" +dependencies = [ + "alloy-json-abi 0.8.13", + "alloy-primitives 0.8.13", + "alloy-sol-type-parser 0.8.14", + "alloy-sol-types 0.8.13", "const-hex", "itoa", "serde", @@ -173,29 +277,81 @@ dependencies = [ "winnow 0.6.13", ] +[[package]] +name = "alloy-eip2930" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0069cf0642457f87a01a014f6dc29d5d893cd4fd8fddf0c3cdfad1bb3ebafc41" +dependencies = [ + "alloy-primitives 0.8.13", + "alloy-rlp", + "serde", +] + +[[package]] +name = "alloy-eip7702" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c986539255fb839d1533c128e190e557e52ff652c9ef62939e233a81dd93f7e" +dependencies = [ + "alloy-primitives 0.8.13", + "alloy-rlp", + "derive_more 1.0.0", + "serde", +] + [[package]] name = "alloy-eips" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aa4b0fc6a572ef2eebda0a31a5e393d451abda703fec917c75d9615d8c978cf2" dependencies = [ - "alloy-primitives", + "alloy-primitives 0.7.6", "alloy-rlp", - "alloy-serde", + "alloy-serde 0.1.3", "c-kzg", "once_cell", "serde", "sha2", ] +[[package]] +name = "alloy-eips" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8dedb328c2114284f767e075589ca9de8d5e9c8a91333402f4804a584ed71a38" +dependencies = [ + "alloy-eip2930", + "alloy-eip7702", + "alloy-primitives 0.8.13", + "alloy-rlp", + "alloy-serde 0.7.0", + "c-kzg", + "derive_more 1.0.0", + "once_cell", + "serde", + "sha2", +] + [[package]] name = "alloy-genesis" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48450f9c6f0821c1eee00ed912942492ed4f11dd69532825833de23ecc7a2256" dependencies = [ - "alloy-primitives", - "alloy-serde", + "alloy-primitives 0.7.6", + "alloy-serde 0.1.3", + "serde", +] + +[[package]] +name = "alloy-genesis" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4841e8dd4e0f53d76b501fd4c6bc21d95d688bc8ebf0ea359fc6c7ab65b48742" +dependencies = [ + "alloy-primitives 0.8.13", + "alloy-serde 0.7.0", "serde", ] @@ -205,8 +361,20 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aaeaccd50238126e3a0ff9387c7c568837726ad4f4e399b528ca88104d6c25ef" dependencies = [ - "alloy-primitives", - "alloy-sol-type-parser", + "alloy-primitives 0.7.6", + "alloy-sol-type-parser 0.7.6", + "serde", + "serde_json", +] + +[[package]] +name = "alloy-json-abi" +version = "0.8.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a500037938085feed8a20dbfc8fce58c599db68c948cfae711147175dee392c" +dependencies = [ + "alloy-primitives 0.8.13", + "alloy-sol-type-parser 0.8.14", "serde", "serde_json", ] @@ -217,7 +385,21 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d484c2a934d0a4d86f8ad4db8113cb1d607707a6c54f6e78f4f1b4451b47aa70" dependencies = [ - "alloy-primitives", + "alloy-primitives 0.7.6", + "serde", + "serde_json", + "thiserror", + "tracing", +] + +[[package]] +name = "alloy-json-rpc" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "254f770918f96dc4ec88a15e6e2e243358e1719d66b40ef814428e7697079d25" +dependencies = [ + "alloy-primitives 0.8.13", + "alloy-sol-types 0.8.13", "serde", "serde_json", "thiserror", @@ -230,25 +412,86 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a20eba9bc551037f0626d6d29e191888638d979943fa4e842e9e6fc72bf0565" dependencies = [ - "alloy-consensus", - "alloy-eips", - "alloy-json-rpc", - "alloy-primitives", - "alloy-rpc-types-eth", - "alloy-serde", - "alloy-signer", - "alloy-sol-types", + "alloy-consensus 0.1.3", + "alloy-eips 0.1.3", + "alloy-json-rpc 0.1.3", + "alloy-primitives 0.7.6", + "alloy-rpc-types-eth 0.1.3", + "alloy-serde 0.1.3", + "alloy-signer 0.1.3", + "alloy-sol-types 0.7.6", + "async-trait", + "auto_impl", + "futures-utils-wasm", + "thiserror", +] + +[[package]] +name = "alloy-network" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "931dd176c6e33355f3dc0170ec69cf5b951f4d73870b276e2c837ab35f9c5136" +dependencies = [ + "alloy-consensus 0.7.0", + "alloy-consensus-any", + "alloy-eips 0.7.0", + "alloy-json-rpc 0.7.0", + "alloy-network-primitives", + "alloy-primitives 0.8.13", + "alloy-rpc-types-any", + "alloy-rpc-types-eth 0.7.0", + "alloy-serde 0.7.0", + "alloy-signer 0.7.0", + "alloy-sol-types 0.8.13", "async-trait", "auto_impl", "futures-utils-wasm", + "serde", + "serde_json", "thiserror", ] +[[package]] +name = "alloy-network-primitives" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa6ec0f23be233e851e31c5e4badfedfa9c7bc177bc37f4e03616072cd40a806" +dependencies = [ + "alloy-consensus 0.7.0", + "alloy-eips 0.7.0", + "alloy-primitives 0.8.13", + "alloy-serde 0.7.0", + "serde", +] + [[package]] name = "alloy-primitives" version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f783611babedbbe90db3478c120fb5f5daacceffc210b39adc0af4fe0da70bad" +dependencies = [ + "alloy-rlp", + "bytes", + "cfg-if", + "const-hex", + "derive_more 0.99.18", + "getrandom", + "hex-literal", + "itoa", + "k256", + "keccak-asm", + "proptest", + "rand", + "ruint", + "serde", + "tiny-keccak", +] + +[[package]] +name = "alloy-primitives" +version = "0.8.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3aeeb5825c2fc8c2662167058347cd0cafc3cb15bcb5cdb1758a63c2dca0409e" dependencies = [ "alloy-rlp", "arbitrary", @@ -256,18 +499,23 @@ dependencies = [ "cfg-if", "const-hex", "derive_arbitrary", - "derive_more", - "ethereum_ssz", + "derive_more 1.0.0", + "foldhash", "getrandom", + "hashbrown 0.15.2", "hex-literal", + "indexmap 2.6.0", "itoa", "k256", "keccak-asm", + "paste", "proptest", "proptest-derive", "rand", "ruint", + "rustc-hash", "serde", + "sha3", "tiny-keccak", ] @@ -278,15 +526,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ad5d89acb7339fad13bc69e7b925232f242835bfd91c82fcb9326b36481bd0f0" dependencies = [ "alloy-chains", - "alloy-consensus", - "alloy-eips", - "alloy-json-rpc", - "alloy-network", - "alloy-primitives", - "alloy-rpc-client", - "alloy-rpc-types-eth", - "alloy-transport", - "alloy-transport-http", + "alloy-consensus 0.1.3", + "alloy-eips 0.1.3", + "alloy-json-rpc 0.1.3", + "alloy-network 0.1.3", + "alloy-primitives 0.7.6", + "alloy-rpc-client 0.1.3", + "alloy-rpc-types-eth 0.1.3", + "alloy-transport 0.1.3", + "alloy-transport-http 0.1.3", "async-stream", "async-trait", "auto_impl", @@ -303,11 +551,48 @@ dependencies = [ "url", ] +[[package]] +name = "alloy-provider" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5545e2cbf2f8f24c68bb887ba0294fa12a2f816b9e72c4f226cd137b77d0e294" +dependencies = [ + "alloy-chains", + "alloy-consensus 0.7.0", + "alloy-eips 0.7.0", + "alloy-json-rpc 0.7.0", + "alloy-network 0.7.0", + "alloy-network-primitives", + "alloy-primitives 0.8.13", + "alloy-rpc-client 0.7.0", + "alloy-rpc-types-eth 0.7.0", + "alloy-transport 0.7.0", + "alloy-transport-http 0.7.0", + "async-stream", + "async-trait", + "auto_impl", + "dashmap 6.1.0", + "futures", + "futures-utils-wasm", + "lru", + "parking_lot", + "pin-project", + "reqwest", + "schnellru", + "serde", + "serde_json", + "thiserror", + "tokio", + "tracing", + "url", + "wasmtimer", +] + [[package]] name = "alloy-rlp" -version = "0.3.7" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a43b18702501396fa9bcdeecd533bc85fac75150d308fc0f6800a01e6234a003" +checksum = "da0822426598f95e45dd1ea32a738dac057529a709ee645fcc516ffa4cbde08f" dependencies = [ "alloy-rlp-derive", "arrayvec", @@ -316,13 +601,13 @@ dependencies = [ [[package]] name = "alloy-rlp-derive" -version = "0.3.7" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d83524c1f6162fcb5b0decf775498a125066c86dda6066ed609531b0e912f85a" +checksum = "2b09cae092c27b6f1bde952653a22708691802e57bfef4a2973b80bea21efd3f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", ] [[package]] @@ -331,9 +616,9 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "479ce003e8c74bbbc7d4235131c1d6b7eaf14a533ae850295b90d240340989cb" dependencies = [ - "alloy-json-rpc", - "alloy-transport", - "alloy-transport-http", + "alloy-json-rpc 0.1.3", + "alloy-transport 0.1.3", + "alloy-transport-http 0.1.3", "futures", "pin-project", "reqwest", @@ -341,19 +626,66 @@ dependencies = [ "serde_json", "tokio", "tokio-stream", - "tower", + "tower 0.4.13", "tracing", "url", ] +[[package]] +name = "alloy-rpc-client" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aed9e40c2a73265ebf70f1e48303ee55920282e1ea5971e832873fb2d32cea74" +dependencies = [ + "alloy-json-rpc 0.7.0", + "alloy-primitives 0.8.13", + "alloy-transport 0.7.0", + "alloy-transport-http 0.7.0", + "futures", + "pin-project", + "reqwest", + "serde", + "serde_json", + "tokio", + "tokio-stream", + "tower 0.5.1", + "tracing", + "url", + "wasmtimer", +] + [[package]] name = "alloy-rpc-types" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0dfa1dd3e0bc3a3d89744fba8d1511216e83257160da2cd028a18b7d9c026030" dependencies = [ - "alloy-rpc-types-eth", - "alloy-serde", + "alloy-rpc-types-eth 0.1.3", + "alloy-serde 0.1.3", +] + +[[package]] +name = "alloy-rpc-types" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42dea20fa715a6f39ec7adc735cfd9567342870737270ac67795d55896527772" +dependencies = [ + "alloy-primitives 0.8.13", + "alloy-rpc-types-eth 0.7.0", + "alloy-serde 0.7.0", + "serde", +] + +[[package]] +name = "alloy-rpc-types-any" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79d7620e22d6ed7c58451dd303d0501ade5a8bec9dc8daef0fbc48ceffabbae1" +dependencies = [ + "alloy-consensus 0.7.0", + "alloy-consensus-any", + "alloy-rpc-types-eth 0.7.0", + "alloy-serde 0.7.0", ] [[package]] @@ -362,25 +694,56 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13bd7aa9ff9e67f1ba7ee0dd8cebfc95831d1649b0e4eeefae940dc3681079fa" dependencies = [ - "alloy-consensus", - "alloy-eips", - "alloy-primitives", + "alloy-consensus 0.1.3", + "alloy-eips 0.1.3", + "alloy-primitives 0.7.6", "alloy-rlp", - "alloy-serde", - "alloy-sol-types", + "alloy-serde 0.1.3", + "alloy-sol-types 0.7.6", "itertools 0.13.0", "serde", "serde_json", "thiserror", ] +[[package]] +name = "alloy-rpc-types-eth" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df34b88df4deeac9ecfc80ad7cbb26a33e57437b9db8be5b952792feef6134bc" +dependencies = [ + "alloy-consensus 0.7.0", + "alloy-consensus-any", + "alloy-eips 0.7.0", + "alloy-network-primitives", + "alloy-primitives 0.8.13", + "alloy-rlp", + "alloy-serde 0.7.0", + "alloy-sol-types 0.8.13", + "derive_more 1.0.0", + "itertools 0.13.0", + "serde", + "serde_json", +] + [[package]] name = "alloy-serde" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8913f9e825068d77c516188c221c44f78fd814fce8effe550a783295a2757d19" dependencies = [ - "alloy-primitives", + "alloy-primitives 0.7.6", + "serde", + "serde_json", +] + +[[package]] +name = "alloy-serde" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43a89fd4cc3f96b3c5c0dd1cebeb63323e4659bbdc837117fa3fd5ac168df7d9" +dependencies = [ + "alloy-primitives 0.8.13", "serde", "serde_json", ] @@ -391,7 +754,21 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f740e13eb4c6a0e4d0e49738f1e86f31ad2d7ef93be499539f492805000f7237" dependencies = [ - "alloy-primitives", + "alloy-primitives 0.7.6", + "async-trait", + "auto_impl", + "elliptic-curve", + "k256", + "thiserror", +] + +[[package]] +name = "alloy-signer" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "532010243a96d1f8593c2246ec3971bc52303884fa1e43ca0a776798ba178910" +dependencies = [ + "alloy-primitives 0.8.13", "async-trait", "auto_impl", "elliptic-curve", @@ -405,10 +782,10 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "87db68d926887393a1d0f9c43833b44446ea29d603291e7b20e5d115f31aa4e3" dependencies = [ - "alloy-consensus", - "alloy-network", - "alloy-primitives", - "alloy-signer", + "alloy-consensus 0.1.3", + "alloy-network 0.1.3", + "alloy-primitives 0.7.6", + "alloy-signer 0.1.3", "async-trait", "elliptic-curve", "eth-keystore", @@ -417,54 +794,120 @@ dependencies = [ "thiserror", ] +[[package]] +name = "alloy-signer-local" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8080c0ab2dc729b0cbb183843d08e78d2a1629140c9fc16234d2272abb483bd" +dependencies = [ + "alloy-consensus 0.7.0", + "alloy-network 0.7.0", + "alloy-primitives 0.8.13", + "alloy-signer 0.7.0", + "async-trait", + "k256", + "rand", + "thiserror", +] + [[package]] name = "alloy-sol-macro" version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4bad41a7c19498e3f6079f7744656328699f8ea3e783bdd10d85788cd439f572" dependencies = [ - "alloy-sol-macro-expander", - "alloy-sol-macro-input", + "alloy-sol-macro-expander 0.7.6", + "alloy-sol-macro-input 0.7.6", "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", +] + +[[package]] +name = "alloy-sol-macro" +version = "0.8.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c0279d09463a4695788a3622fd95443625f7be307422deba4b55dd491a9c7a1" +dependencies = [ + "alloy-sol-macro-expander 0.8.13", + "alloy-sol-macro-input 0.8.13", + "proc-macro-error2", + "proc-macro2", + "quote", + "syn 2.0.89", +] + +[[package]] +name = "alloy-sol-macro-expander" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd9899da7d011b4fe4c406a524ed3e3f963797dbc93b45479d60341d3a27b252" +dependencies = [ + "alloy-json-abi 0.7.6", + "alloy-sol-macro-input 0.7.6", + "const-hex", + "heck", + "indexmap 2.6.0", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 2.0.89", + "syn-solidity 0.7.6", + "tiny-keccak", +] + +[[package]] +name = "alloy-sol-macro-expander" +version = "0.8.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4feea540fc8233df2ad1156efd744b2075372f43a8f942a68b3b19c8a00e2c12" +dependencies = [ + "alloy-json-abi 0.8.13", + "alloy-sol-macro-input 0.8.13", + "const-hex", + "heck", + "indexmap 2.6.0", + "proc-macro-error2", + "proc-macro2", + "quote", + "syn 2.0.89", + "syn-solidity 0.8.14", + "tiny-keccak", ] [[package]] -name = "alloy-sol-macro-expander" +name = "alloy-sol-macro-input" version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd9899da7d011b4fe4c406a524ed3e3f963797dbc93b45479d60341d3a27b252" +checksum = "d32d595768fdc61331a132b6f65db41afae41b9b97d36c21eb1b955c422a7e60" dependencies = [ - "alloy-json-abi", - "alloy-sol-macro-input", + "alloy-json-abi 0.7.6", "const-hex", + "dunce", "heck", - "indexmap 2.2.6", - "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.68", - "syn-solidity", - "tiny-keccak", + "serde_json", + "syn 2.0.89", + "syn-solidity 0.7.6", ] [[package]] name = "alloy-sol-macro-input" -version = "0.7.6" +version = "0.8.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d32d595768fdc61331a132b6f65db41afae41b9b97d36c21eb1b955c422a7e60" +checksum = "2a0ad281f3d1b613af814b66977ee698e443d4644a1510962d0241f26e0e53ae" dependencies = [ - "alloy-json-abi", + "alloy-json-abi 0.8.13", "const-hex", "dunce", "heck", "proc-macro2", "quote", "serde_json", - "syn 2.0.68", - "syn-solidity", + "syn 2.0.89", + "syn-solidity 0.8.14", ] [[package]] @@ -476,15 +919,38 @@ dependencies = [ "winnow 0.6.13", ] +[[package]] +name = "alloy-sol-type-parser" +version = "0.8.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac17c6e89a50fb4a758012e4b409d9a0ba575228e69b539fe37d7a1bd507ca4a" +dependencies = [ + "serde", + "winnow 0.6.13", +] + [[package]] name = "alloy-sol-types" version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a49042c6d3b66a9fe6b2b5a8bf0d39fc2ae1ee0310a2a26ffedd79fb097878dd" dependencies = [ - "alloy-json-abi", - "alloy-primitives", - "alloy-sol-macro", + "alloy-json-abi 0.7.6", + "alloy-primitives 0.7.6", + "alloy-sol-macro 0.7.6", + "const-hex", + "serde", +] + +[[package]] +name = "alloy-sol-types" +version = "0.8.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cff34e0682d6665da243a3e81da96f07a2dd50f7e64073e382b1a141f5a2a2f6" +dependencies = [ + "alloy-json-abi 0.8.13", + "alloy-primitives 0.8.13", + "alloy-sol-macro 0.8.13", "const-hex", "serde", ] @@ -495,7 +961,25 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd9773e4ec6832346171605c776315544bd06e40f803e7b5b7824b325d5442ca" dependencies = [ - "alloy-json-rpc", + "alloy-json-rpc 0.1.3", + "base64", + "futures-util", + "futures-utils-wasm", + "serde", + "serde_json", + "thiserror", + "tokio", + "tower 0.4.13", + "url", +] + +[[package]] +name = "alloy-transport" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6f295f4b745fb9e4e663d70bc57aed991288912c7aaaf25767def921050ee43" +dependencies = [ + "alloy-json-rpc 0.7.0", "base64", "futures-util", "futures-utils-wasm", @@ -503,8 +987,10 @@ dependencies = [ "serde_json", "thiserror", "tokio", - "tower", + "tower 0.5.1", + "tracing", "url", + "wasmtimer", ] [[package]] @@ -513,15 +999,45 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff8ef947b901c0d4e97370f9fa25844cf8b63b1a58fd4011ee82342dc8a9fc6b" dependencies = [ - "alloy-json-rpc", - "alloy-transport", + "alloy-json-rpc 0.1.3", + "alloy-transport 0.1.3", + "reqwest", + "serde_json", + "tower 0.4.13", + "tracing", + "url", +] + +[[package]] +name = "alloy-transport-http" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39139015a5ec127d9c895b49b484608e27fe4538544f84cdf5eae0bd36339bc6" +dependencies = [ + "alloy-json-rpc 0.7.0", + "alloy-transport 0.7.0", "reqwest", "serde_json", - "tower", + "tower 0.5.1", "tracing", "url", ] +[[package]] +name = "alloy-trie" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6b2e366c0debf0af77766c23694a3f863b02633050e71e096e257ffbd395e50" +dependencies = [ + "alloy-primitives 0.8.13", + "alloy-rlp", + "arrayvec", + "derive_more 1.0.0", + "nybbles", + "smallvec", + "tracing", +] + [[package]] name = "anstream" version = "0.6.14" @@ -726,7 +1242,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", ] [[package]] @@ -737,7 +1253,7 @@ checksum = "6e0c28dcc82d7c8ead5cb13beb15405b57b8546e93215673ff8ca0349a028107" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", ] [[package]] @@ -748,7 +1264,7 @@ checksum = "3c87f3f15e7794432337fc718554eaa4dc8f04c9677a950ffe366f20a162ae42" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", ] [[package]] @@ -794,7 +1310,7 @@ checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" name = "basic-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy-primitives", + "alloy-primitives 0.8.13", "openzeppelin-stylus", "stylus-sdk", ] @@ -803,8 +1319,8 @@ dependencies = [ name = "basic-example-script" version = "0.2.0-alpha.1" dependencies = [ - "alloy", - "alloy-primitives", + "alloy 0.7.2", + "alloy-primitives 0.8.13", "basic-example", "koba", "tokio", @@ -814,8 +1330,8 @@ dependencies = [ name = "benches" version = "0.2.0-alpha.1" dependencies = [ - "alloy", - "alloy-primitives", + "alloy 0.7.2", + "alloy-primitives 0.8.13", "e2e", "eyre", "futures", @@ -1029,7 +1545,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", ] [[package]] @@ -1256,8 +1772,8 @@ dependencies = [ name = "cryptography-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy", - "alloy-primitives", + "alloy 0.7.2", + "alloy-primitives 0.8.13", "e2e", "eyre", "openzeppelin-stylus", @@ -1294,7 +1810,7 @@ dependencies = [ "ident_case", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", ] [[package]] @@ -1305,7 +1821,7 @@ checksum = "733cabb43482b1a1b53eee8583c2b9e8684d592215ea83efd305dd31bc2f0178" dependencies = [ "darling_core", "quote", - "syn 2.0.68", + "syn 2.0.89", ] [[package]] @@ -1364,7 +1880,7 @@ checksum = "67e77553c4162a157adbf834ebae5b415acbecbeafc7a74b0e886657506a7611" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", ] [[package]] @@ -1377,7 +1893,28 @@ dependencies = [ "proc-macro2", "quote", "rustc_version 0.4.0", - "syn 2.0.68", + "syn 2.0.89", +] + +[[package]] +name = "derive_more" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a9b99b9cbbe49445b21764dc0625032a89b145a2642e67603e1c936f5458d05" +dependencies = [ + "derive_more-impl", +] + +[[package]] +name = "derive_more-impl" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb7330aeadfbe296029522e6c40f315320aba36fc43a5b3632f3795348f3bd22" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.89", + "unicode-xid", ] [[package]] @@ -1411,7 +1948,7 @@ checksum = "56ce8c6da7551ec6c462cbaf3bfbc75131ebbfa1c944aeaa9dab51ca1c5f0c3b" name = "e2e" version = "0.1.0" dependencies = [ - "alloy", + "alloy 0.7.2", "e2e-proc", "eyre", "koba", @@ -1427,7 +1964,7 @@ version = "0.1.0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", ] [[package]] @@ -1453,7 +1990,7 @@ dependencies = [ "enum-ordinalize", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", ] [[package]] @@ -1518,7 +2055,7 @@ checksum = "0d28318a75d4aead5c4db25382e8ef717932d0346600cacae6357eb5941bc5ff" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", ] [[package]] @@ -1539,7 +2076,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", ] [[package]] @@ -1552,8 +2089,8 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" name = "erc1155-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy", - "alloy-primitives", + "alloy 0.7.2", + "alloy-primitives 0.8.13", "e2e", "eyre", "openzeppelin-stylus", @@ -1565,8 +2102,8 @@ dependencies = [ name = "erc20-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy", - "alloy-primitives", + "alloy 0.7.2", + "alloy-primitives 0.8.13", "e2e", "eyre", "openzeppelin-stylus", @@ -1578,8 +2115,8 @@ dependencies = [ name = "erc20-permit-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy", - "alloy-primitives", + "alloy 0.7.2", + "alloy-primitives 0.8.13", "e2e", "eyre", "openzeppelin-stylus", @@ -1591,9 +2128,9 @@ dependencies = [ name = "erc721-consecutive-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy", - "alloy-primitives", - "alloy-sol-types", + "alloy 0.7.2", + "alloy-primitives 0.8.13", + "alloy-sol-types 0.8.13", "e2e", "eyre", "openzeppelin-stylus", @@ -1606,8 +2143,8 @@ dependencies = [ name = "erc721-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy", - "alloy-primitives", + "alloy 0.7.2", + "alloy-primitives 0.8.13", "e2e", "eyre", "openzeppelin-stylus", @@ -1620,8 +2157,8 @@ dependencies = [ name = "erc721-metadata-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy", - "alloy-primitives", + "alloy 0.7.2", + "alloy-primitives 0.8.13", "e2e", "eyre", "openzeppelin-stylus", @@ -1662,44 +2199,6 @@ dependencies = [ "uuid 0.8.2", ] -[[package]] -name = "ethbloom" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c22d4b5885b6aa2fe5e8b9329fb8d232bf739e434e6b87347c63bdd00c120f60" -dependencies = [ - "crunchy", - "fixed-hash", - "impl-rlp", - "impl-serde", - "tiny-keccak", -] - -[[package]] -name = "ethereum-types" -version = "0.14.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02d215cbf040552efcbe99a38372fe80ab9d00268e20012b79fcd0f073edd8ee" -dependencies = [ - "ethbloom", - "fixed-hash", - "impl-rlp", - "impl-serde", - "primitive-types", - "uint", -] - -[[package]] -name = "ethereum_ssz" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d3627f83d8b87b432a5fad9934b4565260722a141a2c40f371f8080adec9425" -dependencies = [ - "ethereum-types", - "itertools 0.10.5", - "smallvec", -] - [[package]] name = "eyre" version = "0.6.12" @@ -1749,7 +2248,6 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "835c052cb0c08c1acf6ffd71c022172e18723949c8282f2b9f27efbc51e64534" dependencies = [ - "arbitrary", "byteorder", "rand", "rustc-hex", @@ -1762,6 +2260,12 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foldhash" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2" + [[package]] name = "foreign-types" version = "0.3.2" @@ -1848,7 +2352,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", ] [[package]] @@ -1961,6 +2465,12 @@ dependencies = [ "ahash 0.7.8", ] +[[package]] +name = "hashbrown" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" + [[package]] name = "hashbrown" version = "0.14.5" @@ -1971,6 +2481,16 @@ dependencies = [ "allocator-api2", ] +[[package]] +name = "hashbrown" +version = "0.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" +dependencies = [ + "foldhash", + "serde", +] + [[package]] name = "heck" version = "0.5.0" @@ -2097,7 +2617,7 @@ dependencies = [ "pin-project-lite", "socket2", "tokio", - "tower", + "tower 0.4.13", "tower-service", "tracing", ] @@ -2127,24 +2647,6 @@ dependencies = [ "parity-scale-codec", ] -[[package]] -name = "impl-rlp" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f28220f89297a075ddc7245cd538076ee98b01f2a9c23a53a4f1105d5a322808" -dependencies = [ - "rlp", -] - -[[package]] -name = "impl-serde" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebc88fc67028ae3db0c853baa36269d398d5f45b6982f95549ff5def78c935cd" -dependencies = [ - "serde", -] - [[package]] name = "impl-trait-for-tuples" version = "0.2.2" @@ -2174,12 +2676,14 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.2.6" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ + "arbitrary", "equivalent", - "hashbrown 0.14.5", + "hashbrown 0.15.2", + "serde", ] [[package]] @@ -2280,7 +2784,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "80e92e1148d087df999396266311bece9e5311c352821872cccaf5dc67117cfc" dependencies = [ - "alloy", + "alloy 0.1.4", "brotli2", "bytesize", "clap", @@ -2395,8 +2899,8 @@ dependencies = [ name = "merkle-proofs-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy-primitives", - "alloy-sol-types", + "alloy-primitives 0.8.13", + "alloy-sol-types 0.8.13", "openzeppelin-crypto", "stylus-sdk", ] @@ -2409,9 +2913,9 @@ checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" [[package]] name = "mini-alloc" -version = "0.6.0" +version = "0.7.0-beta.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14eacc4bfcf10da9b6d5185ef51b2dc75434afac34b4d8aabe40f6b141ee071c" +checksum = "6d79b46612e3fc76138ed930cd2e4bbd26ada11954a6d312e3affe4b56df0081" dependencies = [ "cfg-if", ] @@ -2458,13 +2962,13 @@ dependencies = [ name = "motsu-proc" version = "0.2.0" dependencies = [ - "alloy-primitives", - "alloy-sol-types", + "alloy-primitives 0.8.13", + "alloy-sol-types 0.8.13", "motsu", "proc-macro2", "quote", "stylus-sdk", - "syn 2.0.68", + "syn 2.0.89", ] [[package]] @@ -2540,7 +3044,17 @@ checksum = "681030a937600a36906c185595136d26abfebb4aa9c65701cefcaf8578bb982b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", +] + +[[package]] +name = "nybbles" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95f06be0417d97f81fe4e5c86d7d01b392655a9cac9c19a848aa033e18937b23" +dependencies = [ + "const-hex", + "smallvec", ] [[package]] @@ -2581,7 +3095,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", ] [[package]] @@ -2620,11 +3134,11 @@ dependencies = [ name = "openzeppelin-stylus" version = "0.2.0-alpha.1" dependencies = [ - "alloy-primitives", - "alloy-sol-macro", - "alloy-sol-macro-expander", - "alloy-sol-macro-input", - "alloy-sol-types", + "alloy-primitives 0.8.13", + "alloy-sol-macro 0.8.13", + "alloy-sol-macro-expander 0.8.13", + "alloy-sol-macro-input 0.8.13", + "alloy-sol-types 0.8.13", "keccak-const", "motsu", "openzeppelin-stylus-proc", @@ -2639,15 +3153,15 @@ dependencies = [ "convert_case 0.6.0", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", ] [[package]] name = "ownable-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy", - "alloy-primitives", + "alloy 0.7.2", + "alloy-primitives 0.8.13", "e2e", "eyre", "openzeppelin-stylus", @@ -2659,8 +3173,8 @@ dependencies = [ name = "ownable-two-step" version = "0.2.0-alpha.1" dependencies = [ - "alloy", - "alloy-primitives", + "alloy 0.7.2", + "alloy-primitives 0.8.13", "e2e", "eyre", "openzeppelin-stylus", @@ -2772,7 +3286,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", ] [[package]] @@ -2817,8 +3331,6 @@ checksum = "0b34d9fd68ae0b74a41b21c03c2f62847aa0ffea044eee893b4c140b37e244e2" dependencies = [ "fixed-hash", "impl-codec", - "impl-rlp", - "impl-serde", "uint", ] @@ -2855,11 +3367,33 @@ dependencies = [ "version_check", ] +[[package]] +name = "proc-macro-error-attr2" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96de42df36bb9bba5542fe9f1a054b8cc87e172759a1868aa05c1f3acc89dfc5" +dependencies = [ + "proc-macro2", + "quote", +] + +[[package]] +name = "proc-macro-error2" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11ec05c52be0a07b08061f7dd003e7d7092e0472bc731b4af7bb1ef876109802" +dependencies = [ + "proc-macro-error-attr2", + "proc-macro2", + "quote", + "syn 2.0.89", +] + [[package]] name = "proc-macro2" -version = "1.0.86" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" dependencies = [ "unicode-ident", ] @@ -2886,13 +3420,13 @@ dependencies = [ [[package]] name = "proptest-derive" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cf16337405ca084e9c78985114633b6827711d22b9e6ef6c6c0d665eb3f0b6e" +checksum = "6ff7ff745a347b87471d859a377a9a404361e7efc2a971d73424a6d183c0fc77" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.89", ] [[package]] @@ -2945,6 +3479,7 @@ dependencies = [ "libc", "rand_chacha", "rand_core", + "serde", ] [[package]] @@ -3018,9 +3553,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.5" +version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" dependencies = [ "aho-corasick", "memchr", @@ -3030,9 +3565,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.7" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" dependencies = [ "aho-corasick", "memchr", @@ -3041,9 +3576,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "region" @@ -3094,7 +3629,7 @@ dependencies = [ "serde", "serde_json", "serde_urlencoded", - "sync_wrapper", + "sync_wrapper 1.0.1", "tokio", "tokio-native-tls", "tower-service", @@ -3192,6 +3727,12 @@ version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +[[package]] +name = "rustc-hash" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" + [[package]] name = "rustc-hex" version = "2.1.0" @@ -3273,8 +3814,8 @@ checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" name = "safe-erc20-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy", - "alloy-primitives", + "alloy 0.7.2", + "alloy-primitives 0.8.13", "e2e", "eyre", "openzeppelin-stylus", @@ -3300,6 +3841,17 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "schnellru" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9a8ef13a93c54d20580de1e5c413e624e53121d42fc7e2c11d10ef7f8b02367" +dependencies = [ + "ahash 0.8.11", + "cfg-if", + "hashbrown 0.13.2", +] + [[package]] name = "scopeguard" version = "1.2.0" @@ -3413,7 +3965,7 @@ checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", ] [[package]] @@ -3582,36 +4134,38 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.68", + "syn 2.0.89", ] [[package]] name = "stylus-proc" -version = "0.6.0" +version = "0.7.0-beta.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fd02e91dffe7b73df84a861c992494d6b72054bc9a17fe73e147e34e9a64ef3" +checksum = "8abd5d2cb3a10a36101b3d9243eda29daa58aad89b93979afe77c4be89068413" dependencies = [ - "alloy-primitives", - "alloy-sol-types", + "alloy-primitives 0.8.13", + "alloy-sol-types 0.8.13", "cfg-if", "convert_case 0.6.0", "lazy_static", + "proc-macro-error", "proc-macro2", "quote", "regex", "sha3", - "syn 1.0.109", - "syn-solidity", + "syn 2.0.89", + "syn-solidity 0.8.14", + "trybuild", ] [[package]] name = "stylus-sdk" -version = "0.6.0" +version = "0.7.0-beta.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26042693706e29fb7e3cf3d71c99534ac97fca98b6f81ba77ab658022ab2e210" +checksum = "caa33222d37101b3ba7064f1099ae38c7e388eaeac422e58260b7d00346a5267" dependencies = [ - "alloy-primitives", - "alloy-sol-types", + "alloy-primitives 0.8.13", + "alloy-sol-types 0.8.13", "cfg-if", "derivative", "hex", @@ -3640,9 +4194,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.68" +version = "2.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "901fa70d88b9d6c98022e23b4136f9f3e54e4662c3bc1bd1d84a42a9a0f0c1e9" +checksum = "44d46482f1c1c87acd84dea20c1bf5ebff4c757009ed6bf19cfd36fb10e92c4e" dependencies = [ "proc-macro2", "quote", @@ -3658,9 +4212,27 @@ dependencies = [ "paste", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", +] + +[[package]] +name = "syn-solidity" +version = "0.8.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da0523f59468a2696391f2a772edc089342aacd53c3caa2ac3264e598edf119b" +dependencies = [ + "paste", + "proc-macro2", + "quote", + "syn 2.0.89", ] +[[package]] +name = "sync_wrapper" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" + [[package]] name = "sync_wrapper" version = "1.0.1" @@ -3679,6 +4251,12 @@ version = "0.12.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e1fc403891a21bcfb7c37834ba66a547a8f402146eba7265b5a6d88059c9ff2f" +[[package]] +name = "target-triple" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42a4d50cdb458045afc8131fd91b64904da29548bcb63c7236e0844936c13078" + [[package]] name = "tempfile" version = "3.10.1" @@ -3691,6 +4269,15 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + [[package]] name = "thiserror" version = "1.0.61" @@ -3708,7 +4295,7 @@ checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", ] [[package]] @@ -3771,7 +4358,7 @@ checksum = "5f5ae998a069d4b5aba8ee9dad856af7d520c3699e6159b185c2acd48155d39a" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", ] [[package]] @@ -3836,7 +4423,7 @@ version = "0.21.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1" dependencies = [ - "indexmap 2.2.6", + "indexmap 2.6.0", "toml_datetime", "winnow 0.5.40", ] @@ -3847,7 +4434,7 @@ version = "0.22.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f21c7aaf97f1bd9ca9d4f9e73b0a6c74bd5afef56f2bc931943a6e1c37e04e38" dependencies = [ - "indexmap 2.2.6", + "indexmap 2.6.0", "serde", "serde_spanned", "toml_datetime", @@ -3870,17 +4457,31 @@ dependencies = [ "tracing", ] +[[package]] +name = "tower" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2873938d487c3cfb9aed7546dc9f2711d867c9f90c46b889989a2cb84eba6b4f" +dependencies = [ + "futures-core", + "futures-util", + "pin-project-lite", + "sync_wrapper 0.1.2", + "tower-layer", + "tower-service", +] + [[package]] name = "tower-layer" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" [[package]] name = "tower-service" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" [[package]] name = "tracing" @@ -3902,7 +4503,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", ] [[package]] @@ -3920,6 +4521,21 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" +[[package]] +name = "trybuild" +version = "1.0.101" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8dcd332a5496c026f1e14b7f3d2b7bd98e509660c04239c58b0ba38a12daded4" +dependencies = [ + "glob", + "serde", + "serde_derive", + "serde_json", + "target-triple", + "termcolor", + "toml", +] + [[package]] name = "typenum" version = "1.17.0" @@ -3938,7 +4554,6 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "76f64bba2c53b04fcab63c01a7d7427eadc821e3bc48c34dc9ba29c501164b52" dependencies = [ - "arbitrary", "byteorder", "crunchy", "hex", @@ -3984,6 +4599,12 @@ version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + [[package]] name = "url" version = "2.5.2" @@ -4039,8 +4660,8 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" name = "vesting-wallet-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy", - "alloy-primitives", + "alloy 0.7.2", + "alloy-primitives 0.8.13", "e2e", "eyre", "openzeppelin-stylus", @@ -4093,7 +4714,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", "wasm-bindgen-shared", ] @@ -4150,7 +4771,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -4305,6 +4926,20 @@ dependencies = [ "url", ] +[[package]] +name = "wasmtimer" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0048ad49a55b9deb3953841fa1fc5858f0efbcb7a18868c899a360269fac1b23" +dependencies = [ + "futures", + "js-sys", + "parking_lot", + "pin-utils", + "slab", + "wasm-bindgen", +] + [[package]] name = "wast" version = "212.0.0" @@ -4353,6 +4988,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" +dependencies = [ + "windows-sys 0.52.0", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" @@ -4595,7 +5239,7 @@ checksum = "15e934569e47891f7d9411f1a451d947a60e000ab3bd24fbb970f000387d1b3b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", ] [[package]] @@ -4615,5 +5259,5 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", ] diff --git a/Cargo.toml b/Cargo.toml index cf26be1b5..841770e5d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -69,10 +69,10 @@ pedantic = "warn" all = "warn" [workspace.dependencies] -# stylus-related -stylus-sdk = "0.6.0" +# Stylus SDK related +stylus-sdk = "0.7.0-beta.1" -alloy = { version = "=0.1.4", features = [ +alloy = { version = "=0.7.2", features = [ "contract", "network", "providers", @@ -85,11 +85,11 @@ alloy = { version = "=0.1.4", features = [ # Even though `alloy` includes `alloy-primitives` and `alloy-sol-types` we need # to keep both versions for compatibility with the Stylus SDK. Once they start # using `alloy` we can remove these. -alloy-primitives = { version = "=0.7.6", default-features = false } -alloy-sol-types = { version = "=0.7.6", default-features = false } -alloy-sol-macro = { version = "=0.7.6", default-features = false } -alloy-sol-macro-expander = { version = "=0.7.6", default-features = false } -alloy-sol-macro-input = { version = "=0.7.6", default-features = false } +alloy-primitives = { version = "=0.8.13", default-features = false } +alloy-sol-types = { version = "=0.8.13", default-features = false } +alloy-sol-macro = { version = "=0.8.13", default-features = false } +alloy-sol-macro-expander = { version = "=0.8.13", default-features = false } +alloy-sol-macro-input = { version = "=0.8.13", default-features = false } const-hex = { version = "1.11.1", default-features = false } eyre = "0.6.8" diff --git a/examples/erc1155/src/constructor.sol b/examples/erc1155/src/constructor.sol index 08dd31f1a..cfb15ceb0 100644 --- a/examples/erc1155/src/constructor.sol +++ b/examples/erc1155/src/constructor.sol @@ -4,9 +4,9 @@ pragma solidity ^0.8.24; contract Erc1155Example { mapping(address => mapping(uint256 => uint256)) private _balanceOf; mapping(address => mapping(address => bool)) private _isApprovedForAll; - + string private _uri; - + constructor(string memory uri_) { _uri = uri_; } From ddef560cbb5307529d21c5536392bf1417136d71 Mon Sep 17 00:00:00 2001 From: Daniel Bigos Date: Fri, 29 Nov 2024 18:30:06 +0100 Subject: [PATCH 28/57] fix: move const value in AccessControl (cherry picked from commit 0cab5f9063c101611b6bfd7b5bd14489ebd35db8) --- contracts/src/access/control.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contracts/src/access/control.rs b/contracts/src/access/control.rs index 1ef997353..c4895ba1e 100644 --- a/contracts/src/access/control.rs +++ b/contracts/src/access/control.rs @@ -116,9 +116,6 @@ sol_storage! { #[public] impl AccessControl { - /// The default admin role. `[0; 32]` by default. - pub const DEFAULT_ADMIN_ROLE: [u8; 32] = [0; 32]; - /// Returns `true` if `account` has been granted `role`. /// /// # Arguments @@ -270,6 +267,9 @@ impl AccessControl { } impl AccessControl { + /// The default admin role. `[0; 32]` by default. + pub const DEFAULT_ADMIN_ROLE: [u8; 32] = [0; 32]; + /// Sets `admin_role` as `role`'s admin role. /// /// # Arguments From 1d27f6cfeefe42e6415e4f8b37b35a95b2f1659e Mon Sep 17 00:00:00 2001 From: Daniel Bigos Date: Mon, 2 Dec 2024 17:56:23 +0100 Subject: [PATCH 29/57] ref: move interfaces to base modules (cherry picked from commit e84084857ac7af4ae3be599e7ab7e14a6faa55f9) --- contracts/src/finance/vesting_wallet.rs | 15 +++---- contracts/src/token/erc1155/mod.rs | 59 +++++++++++++++++++++++-- contracts/src/token/erc1155/receiver.rs | 59 ------------------------- contracts/src/token/erc721/mod.rs | 42 +++++++++--------- 4 files changed, 82 insertions(+), 93 deletions(-) delete mode 100644 contracts/src/token/erc1155/receiver.rs diff --git a/contracts/src/finance/vesting_wallet.rs b/contracts/src/finance/vesting_wallet.rs index 24b0e2a89..6fd5ce987 100644 --- a/contracts/src/finance/vesting_wallet.rs +++ b/contracts/src/finance/vesting_wallet.rs @@ -30,7 +30,7 @@ use stylus_sdk::{ call::{self, call, Call}, contract, evm, function_selector, storage::TopLevelStorage, - stylus_proc::{public, sol_storage, SolidityError}, + stylus_proc::{public, sol_interface, sol_storage, SolidityError}, }; use crate::{ @@ -80,14 +80,11 @@ pub enum Error { InvalidToken(InvalidToken), } -pub use token::IErc20; -#[allow(missing_docs)] -mod token { - stylus_sdk::stylus_proc::sol_interface! { - /// Interface of the ERC-20 token. - interface IErc20 { - function balanceOf(address account) external view returns (uint256); - } +sol_interface! { + /// Interface of the ERC-20 token. + #[allow(missing_docs)] + interface IErc20 { + function balanceOf(address account) external view returns (uint256); } } diff --git a/contracts/src/token/erc1155/mod.rs b/contracts/src/token/erc1155/mod.rs index 1bd927744..ba7df6f09 100644 --- a/contracts/src/token/erc1155/mod.rs +++ b/contracts/src/token/erc1155/mod.rs @@ -10,6 +10,7 @@ use stylus_sdk::{ evm, function_selector, msg, prelude::{public, sol_storage, AddressVM, SolidityError}, storage::TopLevelStorage, + stylus_proc::sol_interface, }; use crate::utils::{ @@ -19,9 +20,6 @@ use crate::utils::{ pub mod extensions; -mod receiver; -pub use receiver::IERC1155Receiver; - const SINGLE_TRANSFER_FN_SELECTOR: [u8; 4] = function_selector!( "onERC1155Received", Address, @@ -179,6 +177,61 @@ impl MethodError for Error { } } +sol_interface! { + /// Interface that must be implemented by smart contracts + /// in order to receive ERC-1155 token transfers. + #[allow(missing_docs)] + interface IERC1155Receiver { + /// Handles the receipt of a single ERC-1155 token type. + /// This function is called at the end of a + /// [`IErc1155::safe_batch_transfer_from`] + /// after the balance has been updated. + /// + /// NOTE: To accept the transfer, + /// this must return [`SINGLE_TRANSFER_FN_SELECTOR`], + /// or its own function selector. + /// + /// * `operator` - The address which initiated the transfer. + /// * `from` - The address which previously owned the token. + /// * `id` - The ID of the token being transferred. + /// * `value` - The amount of tokens being transferred. + /// * `data` - Additional data with no specified format. + #[allow(missing_docs)] + function onERC1155Received( + address operator, + address from, + uint256 id, + uint256 value, + bytes calldata data + ) external returns (bytes4); + + /// Handles the receipt of multiple ERC-1155 token types. + /// This function is called at the end of a + /// [`IErc1155::safe_batch_transfer_from`] + /// after the balances have been updated. + /// + /// NOTE: To accept the transfer(s), + /// this must return [`BATCH_TRANSFER_FN_SELECTOR`], + /// or its own function selector. + /// + /// * `operator` - The address which initiated the batch transfer. + /// * `from` - The address which previously owned the token. + /// * `ids` - An array containing ids of each token being transferred + /// (order and length must match values array). + /// * `values` - An array containing amounts of each token + /// being transferred (order and length must match ids array). + /// * `data` - Additional data with no specified format. + #[allow(missing_docs)] + function onERC1155BatchReceived( + address operator, + address from, + uint256[] calldata ids, + uint256[] calldata values, + bytes calldata data + ) external returns (bytes4); + } +} + sol_storage! { /// State of an [`Erc1155`] token. pub struct Erc1155 { diff --git a/contracts/src/token/erc1155/receiver.rs b/contracts/src/token/erc1155/receiver.rs deleted file mode 100644 index 49da4798f..000000000 --- a/contracts/src/token/erc1155/receiver.rs +++ /dev/null @@ -1,59 +0,0 @@ -#![allow(missing_docs)] -//! Module with an interface required for smart contract -//! in order to receive ERC-1155 token transfers. - -use stylus_sdk::stylus_proc::sol_interface; - -sol_interface! { - /// Interface that must be implemented by smart contracts - /// in order to receive ERC-1155 token transfers. - interface IERC1155Receiver { - /// Handles the receipt of a single ERC-1155 token type. - /// This function is called at the end of a - /// [`IErc1155::safe_batch_transfer_from`] - /// after the balance has been updated. - /// - /// NOTE: To accept the transfer, - /// this must return [`SINGLE_TRANSFER_FN_SELECTOR`], - /// or its own function selector. - /// - /// * `operator` - The address which initiated the transfer. - /// * `from` - The address which previously owned the token. - /// * `id` - The ID of the token being transferred. - /// * `value` - The amount of tokens being transferred. - /// * `data` - Additional data with no specified format. - #[allow(missing_docs)] - function onERC1155Received( - address operator, - address from, - uint256 id, - uint256 value, - bytes calldata data - ) external returns (bytes4); - - /// Handles the receipt of multiple ERC-1155 token types. - /// This function is called at the end of a - /// [`IErc1155::safe_batch_transfer_from`] - /// after the balances have been updated. - /// - /// NOTE: To accept the transfer(s), - /// this must return [`BATCH_TRANSFER_FN_SELECTOR`], - /// or its own function selector. - /// - /// * `operator` - The address which initiated the batch transfer. - /// * `from` - The address which previously owned the token. - /// * `ids` - An array containing ids of each token being transferred - /// (order and length must match values array). - /// * `values` - An array containing amounts of each token - /// being transferred (order and length must match ids array). - /// * `data` - Additional data with no specified format. - #[allow(missing_docs)] - function onERC1155BatchReceived( - address operator, - address from, - uint256[] calldata ids, - uint256[] calldata values, - bytes calldata data - ) external returns (bytes4); - } -} diff --git a/contracts/src/token/erc721/mod.rs b/contracts/src/token/erc721/mod.rs index 5f6fb886d..1a3fe8e4f 100644 --- a/contracts/src/token/erc721/mod.rs +++ b/contracts/src/token/erc721/mod.rs @@ -9,6 +9,7 @@ use stylus_sdk::{ call::{self, Call, MethodError}, evm, msg, prelude::*, + stylus_proc::sol_interface, }; use crate::utils::{ @@ -160,29 +161,26 @@ impl MethodError for Error { } } -pub use receiver::IERC721Receiver; -#[allow(missing_docs)] -mod receiver { - stylus_sdk::stylus_proc::sol_interface! { - /// [`Erc721`] token receiver interface. +sol_interface! { + /// [`Erc721`] token receiver interface. + /// + /// Interface for any contract that wants to support `safe_transfers` + /// from [`Erc721`] asset contracts. + #[allow(missing_docs)] + interface IERC721Receiver { + /// Whenever an [`Erc721`] `token_id` token is transferred + /// to this contract via [`Erc721::safe_transfer_from`]. /// - /// Interface for any contract that wants to support `safe_transfers` - /// from [`Erc721`] asset contracts. - interface IERC721Receiver { - /// Whenever an [`Erc721`] `token_id` token is transferred - /// to this contract via [`Erc721::safe_transfer_from`]. - /// - /// It must return its function selector to confirm the token transfer. - /// If any other value is returned or the interface is not implemented - /// by the recipient, the transfer will be reverted. - #[allow(missing_docs)] - function onERC721Received( - address operator, - address from, - uint256 token_id, - bytes calldata data - ) external returns (bytes4); - } + /// It must return its function selector to confirm the token transfer. + /// If any other value is returned or the interface is not implemented + /// by the recipient, the transfer will be reverted. + #[allow(missing_docs)] + function onERC721Received( + address operator, + address from, + uint256 token_id, + bytes calldata data + ) external returns (bytes4); } } From c3cc640c02b7f497fca8c3d5e8329328505a79dc Mon Sep 17 00:00:00 2001 From: Daniel Bigos Date: Mon, 2 Dec 2024 18:01:59 +0100 Subject: [PATCH 30/57] ref: fix AccessControl example (cherry picked from commit 431b7063d87e1e86581feaf397ed81420cc04eb9) --- examples/access-control/src/lib.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/access-control/src/lib.rs b/examples/access-control/src/lib.rs index 0b4590d1f..af489be33 100644 --- a/examples/access-control/src/lib.rs +++ b/examples/access-control/src/lib.rs @@ -29,8 +29,6 @@ pub const TRANSFER_ROLE: [u8; 32] = [ #[public] #[inherit(Erc20, AccessControl)] impl AccessControlExample { - pub const TRANSFER_ROLE: [u8; 32] = TRANSFER_ROLE; - pub fn make_admin(&mut self, account: Address) -> Result<(), Vec> { self.access.only_role(AccessControl::DEFAULT_ADMIN_ROLE.into())?; self.access @@ -55,3 +53,7 @@ impl AccessControlExample { self.access._set_role_admin(role, new_admin_role) } } + +impl AccessControlExample { + pub const TRANSFER_ROLE: [u8; 32] = TRANSFER_ROLE; +} From e0e71ba87b11e334835a7fc5d5bcfafdd1f3015b Mon Sep 17 00:00:00 2001 From: Daniel Bigos Date: Mon, 2 Dec 2024 18:12:34 +0100 Subject: [PATCH 31/57] fix: add missing Vec imports (cherry picked from commit f921f1be673c48d4a993029d9f49145de715756d) --- contracts/src/access/control.rs | 2 ++ contracts/src/access/ownable.rs | 2 ++ contracts/src/access/ownable_two_step.rs | 2 ++ contracts/src/finance/vesting_wallet.rs | 2 ++ contracts/src/token/erc20/extensions/capped.rs | 3 ++- contracts/src/token/erc20/extensions/metadata.rs | 3 ++- contracts/src/token/erc20/extensions/permit.rs | 2 ++ contracts/src/token/erc20/mod.rs | 2 ++ contracts/src/token/erc20/utils/safe_erc20.rs | 2 ++ contracts/src/token/erc721/extensions/consecutive.rs | 2 +- contracts/src/token/erc721/extensions/enumerable.rs | 3 ++- contracts/src/token/erc721/extensions/metadata.rs | 5 ++++- contracts/src/token/erc721/mod.rs | 3 ++- contracts/src/utils/metadata.rs | 3 +-- contracts/src/utils/nonces.rs | 2 ++ contracts/src/utils/pausable.rs | 2 ++ 16 files changed, 32 insertions(+), 8 deletions(-) diff --git a/contracts/src/access/control.rs b/contracts/src/access/control.rs index c4895ba1e..53515c556 100644 --- a/contracts/src/access/control.rs +++ b/contracts/src/access/control.rs @@ -40,6 +40,8 @@ //! accounts that have been granted it. We recommend using //! `AccessControlDefaultAdminRules` to enforce additional security measures for //! this role. +use alloc::vec::Vec; + use alloy_primitives::{Address, B256}; use alloy_sol_types::sol; use stylus_sdk::{ diff --git a/contracts/src/access/ownable.rs b/contracts/src/access/ownable.rs index 50692973f..89fa892d9 100644 --- a/contracts/src/access/ownable.rs +++ b/contracts/src/access/ownable.rs @@ -8,6 +8,8 @@ //! This module is used through inheritance. It will make available the //! [`Ownable::only_owner`] function, which can be called to restrict operations //! to the owner. +use alloc::vec::Vec; + use alloy_primitives::Address; use alloy_sol_types::sol; use openzeppelin_stylus_proc::interface_id; diff --git a/contracts/src/access/ownable_two_step.rs b/contracts/src/access/ownable_two_step.rs index f5d9a2be1..f244c0dee 100644 --- a/contracts/src/access/ownable_two_step.rs +++ b/contracts/src/access/ownable_two_step.rs @@ -16,6 +16,8 @@ //! This module uses [`Ownable`] as a member, and makes all its public functions //! available. +use alloc::vec::Vec; + use alloy_primitives::Address; use alloy_sol_types::sol; use stylus_sdk::{ diff --git a/contracts/src/finance/vesting_wallet.rs b/contracts/src/finance/vesting_wallet.rs index 6fd5ce987..a1b442425 100644 --- a/contracts/src/finance/vesting_wallet.rs +++ b/contracts/src/finance/vesting_wallet.rs @@ -22,6 +22,8 @@ //! adjustment in the vesting schedule to ensure the vested amount is as //! intended. +use alloc::{vec, vec::Vec}; + use alloy_primitives::{Address, U256, U64}; use alloy_sol_types::sol; use openzeppelin_stylus_proc::interface_id; diff --git a/contracts/src/token/erc20/extensions/capped.rs b/contracts/src/token/erc20/extensions/capped.rs index a971900b5..c4b9ad341 100644 --- a/contracts/src/token/erc20/extensions/capped.rs +++ b/contracts/src/token/erc20/extensions/capped.rs @@ -5,10 +5,11 @@ //! Note that they will not be capped by simply including this module, //! but only once the checks are put in place. +use alloc::vec::Vec; + use alloy_primitives::U256; use alloy_sol_types::sol; use stylus_sdk::stylus_proc::{public, sol_storage, SolidityError}; - sol! { /// Indicates an error related to the operation that failed /// because `total_supply` exceeded the `_cap`. diff --git a/contracts/src/token/erc20/extensions/metadata.rs b/contracts/src/token/erc20/extensions/metadata.rs index 6cc10141f..a333d3865 100644 --- a/contracts/src/token/erc20/extensions/metadata.rs +++ b/contracts/src/token/erc20/extensions/metadata.rs @@ -11,8 +11,9 @@ use crate::utils::introspection::erc165::IErc165; /// Number of decimals used by default on implementors of [`Metadata`]. pub const DEFAULT_DECIMALS: u8 = 18; -use crate::utils::Metadata; +use alloc::vec::Vec; +use crate::utils::Metadata; sol_storage! { /// Metadata of the [`super::super::Erc20`] token. /// diff --git a/contracts/src/token/erc20/extensions/permit.rs b/contracts/src/token/erc20/extensions/permit.rs index 1b58e948d..311b5d7c7 100644 --- a/contracts/src/token/erc20/extensions/permit.rs +++ b/contracts/src/token/erc20/extensions/permit.rs @@ -9,6 +9,8 @@ //! By not relying on [`crate::token::erc20::IErc20::approve`], //! the token holder account doesn’t need to send a transaction, //! and thus is not required to hold Ether at all. +use alloc::vec::Vec; + use alloy_primitives::{b256, keccak256, Address, B256, U256}; use alloy_sol_types::{sol, SolType}; use stylus_sdk::{ diff --git a/contracts/src/token/erc20/mod.rs b/contracts/src/token/erc20/mod.rs index 91399f425..d0f51c421 100644 --- a/contracts/src/token/erc20/mod.rs +++ b/contracts/src/token/erc20/mod.rs @@ -4,6 +4,8 @@ //! revert instead of returning `false` on failure. This behavior is //! nonetheless conventional and does not conflict with the expectations of //! [`Erc20`] applications. +use alloc::vec::Vec; + use alloy_primitives::{Address, FixedBytes, U256}; use alloy_sol_types::sol; use openzeppelin_stylus_proc::interface_id; diff --git a/contracts/src/token/erc20/utils/safe_erc20.rs b/contracts/src/token/erc20/utils/safe_erc20.rs index 28115e227..ba3f7bfe8 100644 --- a/contracts/src/token/erc20/utils/safe_erc20.rs +++ b/contracts/src/token/erc20/utils/safe_erc20.rs @@ -7,6 +7,8 @@ //! your contract, which allows you to call the safe operations as //! `contract.safe_transfer(token_addr, ...)`, etc. +use alloc::vec::Vec; + use alloy_primitives::{Address, U256}; use alloy_sol_types::{sol, SolCall}; use stylus_sdk::{ diff --git a/contracts/src/token/erc721/extensions/consecutive.rs b/contracts/src/token/erc721/extensions/consecutive.rs index 302cb56f4..1f793802b 100644 --- a/contracts/src/token/erc721/extensions/consecutive.rs +++ b/contracts/src/token/erc721/extensions/consecutive.rs @@ -22,7 +22,7 @@ //! restriction on the [`Erc721Consecutive::_update`] function call since it is //! not possible to call a Rust function from the Solidity constructor. -use alloc::vec; +use alloc::{vec, vec::Vec}; use alloy_primitives::{uint, Address, U256}; use alloy_sol_types::sol; diff --git a/contracts/src/token/erc721/extensions/enumerable.rs b/contracts/src/token/erc721/extensions/enumerable.rs index f35bc97c0..70e60bbaf 100644 --- a/contracts/src/token/erc721/extensions/enumerable.rs +++ b/contracts/src/token/erc721/extensions/enumerable.rs @@ -9,6 +9,8 @@ //! interfere with enumerability and should not be used together with //! [`Erc721Enumerable`]. +use alloc::vec::Vec; + use alloy_primitives::{uint, Address, FixedBytes, U256}; use alloy_sol_types::sol; use openzeppelin_stylus_proc::interface_id; @@ -18,7 +20,6 @@ use crate::{ token::{erc721, erc721::IErc721}, utils::introspection::erc165::IErc165, }; - sol! { /// Indicates an error when an `owner`'s token query /// was out of bounds for `index`. diff --git a/contracts/src/token/erc721/extensions/metadata.rs b/contracts/src/token/erc721/extensions/metadata.rs index c1e95e078..d37c83371 100644 --- a/contracts/src/token/erc721/extensions/metadata.rs +++ b/contracts/src/token/erc721/extensions/metadata.rs @@ -1,6 +1,9 @@ //! Optional Metadata of the ERC-721 standard. -use alloc::string::{String, ToString}; +use alloc::{ + string::{String, ToString}, + vec::Vec, +}; use alloy_primitives::{FixedBytes, U256}; use openzeppelin_stylus_proc::interface_id; diff --git a/contracts/src/token/erc721/mod.rs b/contracts/src/token/erc721/mod.rs index 1a3fe8e4f..527c3716d 100644 --- a/contracts/src/token/erc721/mod.rs +++ b/contracts/src/token/erc721/mod.rs @@ -1,5 +1,4 @@ //! Implementation of the [`Erc721`] token standard. -use alloc::vec; use alloy_primitives::{fixed_bytes, uint, Address, FixedBytes, U128, U256}; use openzeppelin_stylus_proc::interface_id; @@ -19,6 +18,8 @@ use crate::utils::{ pub mod extensions; +use alloc::{vec, vec::Vec}; + sol! { /// Emitted when the `token_id` token is transferred from `from` to `to`. /// diff --git a/contracts/src/utils/metadata.rs b/contracts/src/utils/metadata.rs index 7d904dbb0..b4410d12c 100644 --- a/contracts/src/utils/metadata.rs +++ b/contracts/src/utils/metadata.rs @@ -1,8 +1,7 @@ //! Common Metadata Smart Contract. -use alloc::string::String; +use alloc::{string::String, vec, vec::Vec}; use stylus_sdk::stylus_proc::{public, sol_storage}; - sol_storage! { /// Metadata of the token. pub struct Metadata { diff --git a/contracts/src/utils/nonces.rs b/contracts/src/utils/nonces.rs index 13678fcc3..0e55134f5 100644 --- a/contracts/src/utils/nonces.rs +++ b/contracts/src/utils/nonces.rs @@ -2,6 +2,8 @@ //! //! Nonces will only increment. +use alloc::vec::Vec; + use alloy_primitives::{uint, Address, U256}; use alloy_sol_types::sol; use stylus_sdk::stylus_proc::{public, sol_storage, SolidityError}; diff --git a/contracts/src/utils/pausable.rs b/contracts/src/utils/pausable.rs index 1a2ed5ae9..d072c3a38 100644 --- a/contracts/src/utils/pausable.rs +++ b/contracts/src/utils/pausable.rs @@ -14,6 +14,8 @@ //! exposed by default. //! You should expose them manually in your contract's abi. +use alloc::vec::Vec; + use alloy_sol_types::sol; use stylus_sdk::{ evm, msg, From b24bcdf4e869a3794ea3142cff637f3d523baa82 Mon Sep 17 00:00:00 2001 From: Daniel Bigos Date: Wed, 4 Dec 2024 16:36:58 +0100 Subject: [PATCH 32/57] build: use koba with updated alloy --- Cargo.lock | 758 +++++++++++------------------------------------------ Cargo.toml | 2 +- 2 files changed, 160 insertions(+), 600 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 95c68d77a..3119e815c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6,8 +6,8 @@ version = 4 name = "access-control-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy 0.7.2", - "alloy-primitives 0.8.13", + "alloy", + "alloy-primitives", "e2e", "eyre", "openzeppelin-stylus", @@ -80,48 +80,26 @@ version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" -[[package]] -name = "alloy" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ba1c79677c9ce51c8d45e20845b05e6fb070ea2c863fba03ad6af2c778474bd" -dependencies = [ - "alloy-consensus 0.1.3", - "alloy-contract 0.1.3", - "alloy-core 0.7.6", - "alloy-eips 0.1.3", - "alloy-genesis 0.1.3", - "alloy-network 0.1.3", - "alloy-provider 0.1.3", - "alloy-rpc-client 0.1.3", - "alloy-rpc-types 0.1.3", - "alloy-serde 0.1.3", - "alloy-signer 0.1.3", - "alloy-signer-local 0.1.3", - "alloy-transport 0.1.3", - "alloy-transport-http 0.1.3", -] - [[package]] name = "alloy" version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44ab65cb6104c389b46df77b7990cab08780f57e41b412b46d6d12baf7e8c716" dependencies = [ - "alloy-consensus 0.7.0", - "alloy-contract 0.7.0", - "alloy-core 0.8.13", - "alloy-eips 0.7.0", - "alloy-genesis 0.7.0", - "alloy-network 0.7.0", - "alloy-provider 0.7.0", - "alloy-rpc-client 0.7.0", - "alloy-rpc-types 0.7.0", - "alloy-serde 0.7.0", - "alloy-signer 0.7.0", - "alloy-signer-local 0.7.0", - "alloy-transport 0.7.0", - "alloy-transport-http 0.7.0", + "alloy-consensus", + "alloy-contract", + "alloy-core", + "alloy-eips", + "alloy-genesis", + "alloy-network", + "alloy-provider", + "alloy-rpc-client", + "alloy-rpc-types", + "alloy-serde", + "alloy-signer", + "alloy-signer-local", + "alloy-transport", + "alloy-transport-http", ] [[package]] @@ -134,34 +112,20 @@ dependencies = [ "strum", ] -[[package]] -name = "alloy-consensus" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f63a6c9eb45684a5468536bc55379a2af0f45ffa5d756e4e4964532737e1836" -dependencies = [ - "alloy-eips 0.1.3", - "alloy-primitives 0.7.6", - "alloy-rlp", - "alloy-serde 0.1.3", - "c-kzg", - "serde", -] - [[package]] name = "alloy-consensus" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3a1ff8439834ab71a4b0ecd1a8ff80b3921c87615f158940c3364f399c732786" dependencies = [ - "alloy-eips 0.7.0", - "alloy-primitives 0.8.13", + "alloy-eips", + "alloy-primitives", "alloy-rlp", - "alloy-serde 0.7.0", + "alloy-serde", "alloy-trie", "auto_impl", "c-kzg", - "derive_more 1.0.0", + "derive_more", "serde", ] @@ -171,93 +135,45 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "519a86faaa6729464365a90c04eba68539b6d3a30f426edb4b3dafd78920d42f" dependencies = [ - "alloy-consensus 0.7.0", - "alloy-eips 0.7.0", - "alloy-primitives 0.8.13", + "alloy-consensus", + "alloy-eips", + "alloy-primitives", "alloy-rlp", - "alloy-serde 0.7.0", + "alloy-serde", "serde", ] -[[package]] -name = "alloy-contract" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c26b7d34cb76f826558e9409a010e25257f7bfb5aa5e3dd0042c564664ae159" -dependencies = [ - "alloy-dyn-abi 0.7.6", - "alloy-json-abi 0.7.6", - "alloy-network 0.1.3", - "alloy-primitives 0.7.6", - "alloy-provider 0.1.3", - "alloy-rpc-types-eth 0.1.3", - "alloy-sol-types 0.7.6", - "alloy-transport 0.1.3", - "futures", - "futures-util", - "thiserror", -] - [[package]] name = "alloy-contract" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cca2b353d8b7f160dc930dfa174557acefece6deab5ecd7e6230d38858579eea" dependencies = [ - "alloy-dyn-abi 0.8.13", - "alloy-json-abi 0.8.13", - "alloy-network 0.7.0", + "alloy-dyn-abi", + "alloy-json-abi", + "alloy-network", "alloy-network-primitives", - "alloy-primitives 0.8.13", - "alloy-provider 0.7.0", - "alloy-rpc-types-eth 0.7.0", - "alloy-sol-types 0.8.13", - "alloy-transport 0.7.0", + "alloy-primitives", + "alloy-provider", + "alloy-rpc-types-eth", + "alloy-sol-types", + "alloy-transport", "futures", "futures-util", "thiserror", ] -[[package]] -name = "alloy-core" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5af3faff14c12c8b11037e0a093dd157c3702becb8435577a2408534d0758315" -dependencies = [ - "alloy-dyn-abi 0.7.6", - "alloy-json-abi 0.7.6", - "alloy-primitives 0.7.6", - "alloy-sol-types 0.7.6", -] - [[package]] name = "alloy-core" version = "0.8.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8d22df68fa7d9744be0b1a9be3260e9aa089fbf41903ab182328333061ed186" dependencies = [ - "alloy-dyn-abi 0.8.13", - "alloy-json-abi 0.8.13", - "alloy-primitives 0.8.13", + "alloy-dyn-abi", + "alloy-json-abi", + "alloy-primitives", "alloy-rlp", - "alloy-sol-types 0.8.13", -] - -[[package]] -name = "alloy-dyn-abi" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb6e6436a9530f25010d13653e206fab4c9feddacf21a54de8d7311b275bc56b" -dependencies = [ - "alloy-json-abi 0.7.6", - "alloy-primitives 0.7.6", - "alloy-sol-type-parser 0.7.6", - "alloy-sol-types 0.7.6", - "const-hex", - "itoa", - "serde", - "serde_json", - "winnow 0.6.13", + "alloy-sol-types", ] [[package]] @@ -266,10 +182,10 @@ version = "0.8.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1cf633ae9a1f0c82fdb9e559ed2be1c8e415c3e48fc47e1feaf32c6078ec0cdd" dependencies = [ - "alloy-json-abi 0.8.13", - "alloy-primitives 0.8.13", - "alloy-sol-type-parser 0.8.14", - "alloy-sol-types 0.8.13", + "alloy-json-abi", + "alloy-primitives", + "alloy-sol-type-parser", + "alloy-sol-types", "const-hex", "itoa", "serde", @@ -283,7 +199,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0069cf0642457f87a01a014f6dc29d5d893cd4fd8fddf0c3cdfad1bb3ebafc41" dependencies = [ - "alloy-primitives 0.8.13", + "alloy-primitives", "alloy-rlp", "serde", ] @@ -294,25 +210,10 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c986539255fb839d1533c128e190e557e52ff652c9ef62939e233a81dd93f7e" dependencies = [ - "alloy-primitives 0.8.13", - "alloy-rlp", - "derive_more 1.0.0", - "serde", -] - -[[package]] -name = "alloy-eips" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa4b0fc6a572ef2eebda0a31a5e393d451abda703fec917c75d9615d8c978cf2" -dependencies = [ - "alloy-primitives 0.7.6", + "alloy-primitives", "alloy-rlp", - "alloy-serde 0.1.3", - "c-kzg", - "once_cell", + "derive_more", "serde", - "sha2", ] [[package]] @@ -323,73 +224,37 @@ checksum = "8dedb328c2114284f767e075589ca9de8d5e9c8a91333402f4804a584ed71a38" dependencies = [ "alloy-eip2930", "alloy-eip7702", - "alloy-primitives 0.8.13", + "alloy-primitives", "alloy-rlp", - "alloy-serde 0.7.0", + "alloy-serde", "c-kzg", - "derive_more 1.0.0", + "derive_more", "once_cell", "serde", "sha2", ] -[[package]] -name = "alloy-genesis" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48450f9c6f0821c1eee00ed912942492ed4f11dd69532825833de23ecc7a2256" -dependencies = [ - "alloy-primitives 0.7.6", - "alloy-serde 0.1.3", - "serde", -] - [[package]] name = "alloy-genesis" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4841e8dd4e0f53d76b501fd4c6bc21d95d688bc8ebf0ea359fc6c7ab65b48742" dependencies = [ - "alloy-primitives 0.8.13", - "alloy-serde 0.7.0", + "alloy-primitives", + "alloy-serde", "serde", ] -[[package]] -name = "alloy-json-abi" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aaeaccd50238126e3a0ff9387c7c568837726ad4f4e399b528ca88104d6c25ef" -dependencies = [ - "alloy-primitives 0.7.6", - "alloy-sol-type-parser 0.7.6", - "serde", - "serde_json", -] - [[package]] name = "alloy-json-abi" version = "0.8.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a500037938085feed8a20dbfc8fce58c599db68c948cfae711147175dee392c" dependencies = [ - "alloy-primitives 0.8.13", - "alloy-sol-type-parser 0.8.14", - "serde", - "serde_json", -] - -[[package]] -name = "alloy-json-rpc" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d484c2a934d0a4d86f8ad4db8113cb1d607707a6c54f6e78f4f1b4451b47aa70" -dependencies = [ - "alloy-primitives 0.7.6", + "alloy-primitives", + "alloy-sol-type-parser", "serde", "serde_json", - "thiserror", - "tracing", ] [[package]] @@ -398,51 +263,31 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "254f770918f96dc4ec88a15e6e2e243358e1719d66b40ef814428e7697079d25" dependencies = [ - "alloy-primitives 0.8.13", - "alloy-sol-types 0.8.13", + "alloy-primitives", + "alloy-sol-types", "serde", "serde_json", "thiserror", "tracing", ] -[[package]] -name = "alloy-network" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a20eba9bc551037f0626d6d29e191888638d979943fa4e842e9e6fc72bf0565" -dependencies = [ - "alloy-consensus 0.1.3", - "alloy-eips 0.1.3", - "alloy-json-rpc 0.1.3", - "alloy-primitives 0.7.6", - "alloy-rpc-types-eth 0.1.3", - "alloy-serde 0.1.3", - "alloy-signer 0.1.3", - "alloy-sol-types 0.7.6", - "async-trait", - "auto_impl", - "futures-utils-wasm", - "thiserror", -] - [[package]] name = "alloy-network" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "931dd176c6e33355f3dc0170ec69cf5b951f4d73870b276e2c837ab35f9c5136" dependencies = [ - "alloy-consensus 0.7.0", + "alloy-consensus", "alloy-consensus-any", - "alloy-eips 0.7.0", - "alloy-json-rpc 0.7.0", + "alloy-eips", + "alloy-json-rpc", "alloy-network-primitives", - "alloy-primitives 0.8.13", + "alloy-primitives", "alloy-rpc-types-any", - "alloy-rpc-types-eth 0.7.0", - "alloy-serde 0.7.0", - "alloy-signer 0.7.0", - "alloy-sol-types 0.8.13", + "alloy-rpc-types-eth", + "alloy-serde", + "alloy-signer", + "alloy-sol-types", "async-trait", "auto_impl", "futures-utils-wasm", @@ -457,34 +302,11 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa6ec0f23be233e851e31c5e4badfedfa9c7bc177bc37f4e03616072cd40a806" dependencies = [ - "alloy-consensus 0.7.0", - "alloy-eips 0.7.0", - "alloy-primitives 0.8.13", - "alloy-serde 0.7.0", - "serde", -] - -[[package]] -name = "alloy-primitives" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f783611babedbbe90db3478c120fb5f5daacceffc210b39adc0af4fe0da70bad" -dependencies = [ - "alloy-rlp", - "bytes", - "cfg-if", - "const-hex", - "derive_more 0.99.18", - "getrandom", - "hex-literal", - "itoa", - "k256", - "keccak-asm", - "proptest", - "rand", - "ruint", + "alloy-consensus", + "alloy-eips", + "alloy-primitives", + "alloy-serde", "serde", - "tiny-keccak", ] [[package]] @@ -499,7 +321,7 @@ dependencies = [ "cfg-if", "const-hex", "derive_arbitrary", - "derive_more 1.0.0", + "derive_more", "foldhash", "getrandom", "hashbrown 0.15.2", @@ -519,38 +341,6 @@ dependencies = [ "tiny-keccak", ] -[[package]] -name = "alloy-provider" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad5d89acb7339fad13bc69e7b925232f242835bfd91c82fcb9326b36481bd0f0" -dependencies = [ - "alloy-chains", - "alloy-consensus 0.1.3", - "alloy-eips 0.1.3", - "alloy-json-rpc 0.1.3", - "alloy-network 0.1.3", - "alloy-primitives 0.7.6", - "alloy-rpc-client 0.1.3", - "alloy-rpc-types-eth 0.1.3", - "alloy-transport 0.1.3", - "alloy-transport-http 0.1.3", - "async-stream", - "async-trait", - "auto_impl", - "dashmap 5.5.3", - "futures", - "futures-utils-wasm", - "lru", - "pin-project", - "reqwest", - "serde", - "serde_json", - "tokio", - "tracing", - "url", -] - [[package]] name = "alloy-provider" version = "0.7.0" @@ -558,16 +348,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5545e2cbf2f8f24c68bb887ba0294fa12a2f816b9e72c4f226cd137b77d0e294" dependencies = [ "alloy-chains", - "alloy-consensus 0.7.0", - "alloy-eips 0.7.0", - "alloy-json-rpc 0.7.0", - "alloy-network 0.7.0", + "alloy-consensus", + "alloy-eips", + "alloy-json-rpc", + "alloy-network", "alloy-network-primitives", - "alloy-primitives 0.8.13", - "alloy-rpc-client 0.7.0", - "alloy-rpc-types-eth 0.7.0", - "alloy-transport 0.7.0", - "alloy-transport-http 0.7.0", + "alloy-primitives", + "alloy-rpc-client", + "alloy-rpc-types-eth", + "alloy-transport", + "alloy-transport-http", "async-stream", "async-trait", "auto_impl", @@ -610,37 +400,16 @@ dependencies = [ "syn 2.0.89", ] -[[package]] -name = "alloy-rpc-client" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "479ce003e8c74bbbc7d4235131c1d6b7eaf14a533ae850295b90d240340989cb" -dependencies = [ - "alloy-json-rpc 0.1.3", - "alloy-transport 0.1.3", - "alloy-transport-http 0.1.3", - "futures", - "pin-project", - "reqwest", - "serde", - "serde_json", - "tokio", - "tokio-stream", - "tower 0.4.13", - "tracing", - "url", -] - [[package]] name = "alloy-rpc-client" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aed9e40c2a73265ebf70f1e48303ee55920282e1ea5971e832873fb2d32cea74" dependencies = [ - "alloy-json-rpc 0.7.0", - "alloy-primitives 0.8.13", - "alloy-transport 0.7.0", - "alloy-transport-http 0.7.0", + "alloy-json-rpc", + "alloy-primitives", + "alloy-transport", + "alloy-transport-http", "futures", "pin-project", "reqwest", @@ -654,25 +423,15 @@ dependencies = [ "wasmtimer", ] -[[package]] -name = "alloy-rpc-types" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dfa1dd3e0bc3a3d89744fba8d1511216e83257160da2cd028a18b7d9c026030" -dependencies = [ - "alloy-rpc-types-eth 0.1.3", - "alloy-serde 0.1.3", -] - [[package]] name = "alloy-rpc-types" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42dea20fa715a6f39ec7adc735cfd9567342870737270ac67795d55896527772" dependencies = [ - "alloy-primitives 0.8.13", - "alloy-rpc-types-eth 0.7.0", - "alloy-serde 0.7.0", + "alloy-primitives", + "alloy-rpc-types-eth", + "alloy-serde", "serde", ] @@ -682,28 +441,10 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "79d7620e22d6ed7c58451dd303d0501ade5a8bec9dc8daef0fbc48ceffabbae1" dependencies = [ - "alloy-consensus 0.7.0", + "alloy-consensus", "alloy-consensus-any", - "alloy-rpc-types-eth 0.7.0", - "alloy-serde 0.7.0", -] - -[[package]] -name = "alloy-rpc-types-eth" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13bd7aa9ff9e67f1ba7ee0dd8cebfc95831d1649b0e4eeefae940dc3681079fa" -dependencies = [ - "alloy-consensus 0.1.3", - "alloy-eips 0.1.3", - "alloy-primitives 0.7.6", - "alloy-rlp", - "alloy-serde 0.1.3", - "alloy-sol-types 0.7.6", - "itertools 0.13.0", - "serde", - "serde_json", - "thiserror", + "alloy-rpc-types-eth", + "alloy-serde", ] [[package]] @@ -712,63 +453,38 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df34b88df4deeac9ecfc80ad7cbb26a33e57437b9db8be5b952792feef6134bc" dependencies = [ - "alloy-consensus 0.7.0", + "alloy-consensus", "alloy-consensus-any", - "alloy-eips 0.7.0", + "alloy-eips", "alloy-network-primitives", - "alloy-primitives 0.8.13", + "alloy-primitives", "alloy-rlp", - "alloy-serde 0.7.0", - "alloy-sol-types 0.8.13", - "derive_more 1.0.0", + "alloy-serde", + "alloy-sol-types", + "derive_more", "itertools 0.13.0", "serde", "serde_json", ] -[[package]] -name = "alloy-serde" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8913f9e825068d77c516188c221c44f78fd814fce8effe550a783295a2757d19" -dependencies = [ - "alloy-primitives 0.7.6", - "serde", - "serde_json", -] - [[package]] name = "alloy-serde" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "43a89fd4cc3f96b3c5c0dd1cebeb63323e4659bbdc837117fa3fd5ac168df7d9" dependencies = [ - "alloy-primitives 0.8.13", + "alloy-primitives", "serde", "serde_json", ] -[[package]] -name = "alloy-signer" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f740e13eb4c6a0e4d0e49738f1e86f31ad2d7ef93be499539f492805000f7237" -dependencies = [ - "alloy-primitives 0.7.6", - "async-trait", - "auto_impl", - "elliptic-curve", - "k256", - "thiserror", -] - [[package]] name = "alloy-signer" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "532010243a96d1f8593c2246ec3971bc52303884fa1e43ca0a776798ba178910" dependencies = [ - "alloy-primitives 0.8.13", + "alloy-primitives", "async-trait", "auto_impl", "elliptic-curve", @@ -776,95 +492,45 @@ dependencies = [ "thiserror", ] -[[package]] -name = "alloy-signer-local" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87db68d926887393a1d0f9c43833b44446ea29d603291e7b20e5d115f31aa4e3" -dependencies = [ - "alloy-consensus 0.1.3", - "alloy-network 0.1.3", - "alloy-primitives 0.7.6", - "alloy-signer 0.1.3", - "async-trait", - "elliptic-curve", - "eth-keystore", - "k256", - "rand", - "thiserror", -] - [[package]] name = "alloy-signer-local" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8080c0ab2dc729b0cbb183843d08e78d2a1629140c9fc16234d2272abb483bd" dependencies = [ - "alloy-consensus 0.7.0", - "alloy-network 0.7.0", - "alloy-primitives 0.8.13", - "alloy-signer 0.7.0", + "alloy-consensus", + "alloy-network", + "alloy-primitives", + "alloy-signer", "async-trait", + "eth-keystore", "k256", "rand", "thiserror", ] -[[package]] -name = "alloy-sol-macro" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bad41a7c19498e3f6079f7744656328699f8ea3e783bdd10d85788cd439f572" -dependencies = [ - "alloy-sol-macro-expander 0.7.6", - "alloy-sol-macro-input 0.7.6", - "proc-macro-error", - "proc-macro2", - "quote", - "syn 2.0.89", -] - [[package]] name = "alloy-sol-macro" version = "0.8.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c0279d09463a4695788a3622fd95443625f7be307422deba4b55dd491a9c7a1" dependencies = [ - "alloy-sol-macro-expander 0.8.13", - "alloy-sol-macro-input 0.8.13", + "alloy-sol-macro-expander", + "alloy-sol-macro-input", "proc-macro-error2", "proc-macro2", "quote", "syn 2.0.89", ] -[[package]] -name = "alloy-sol-macro-expander" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd9899da7d011b4fe4c406a524ed3e3f963797dbc93b45479d60341d3a27b252" -dependencies = [ - "alloy-json-abi 0.7.6", - "alloy-sol-macro-input 0.7.6", - "const-hex", - "heck", - "indexmap 2.6.0", - "proc-macro-error", - "proc-macro2", - "quote", - "syn 2.0.89", - "syn-solidity 0.7.6", - "tiny-keccak", -] - [[package]] name = "alloy-sol-macro-expander" version = "0.8.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4feea540fc8233df2ad1156efd744b2075372f43a8f942a68b3b19c8a00e2c12" dependencies = [ - "alloy-json-abi 0.8.13", - "alloy-sol-macro-input 0.8.13", + "alloy-json-abi", + "alloy-sol-macro-input", "const-hex", "heck", "indexmap 2.6.0", @@ -872,34 +538,17 @@ dependencies = [ "proc-macro2", "quote", "syn 2.0.89", - "syn-solidity 0.8.14", + "syn-solidity", "tiny-keccak", ] -[[package]] -name = "alloy-sol-macro-input" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d32d595768fdc61331a132b6f65db41afae41b9b97d36c21eb1b955c422a7e60" -dependencies = [ - "alloy-json-abi 0.7.6", - "const-hex", - "dunce", - "heck", - "proc-macro2", - "quote", - "serde_json", - "syn 2.0.89", - "syn-solidity 0.7.6", -] - [[package]] name = "alloy-sol-macro-input" version = "0.8.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a0ad281f3d1b613af814b66977ee698e443d4644a1510962d0241f26e0e53ae" dependencies = [ - "alloy-json-abi 0.8.13", + "alloy-json-abi", "const-hex", "dunce", "heck", @@ -907,16 +556,7 @@ dependencies = [ "quote", "serde_json", "syn 2.0.89", - "syn-solidity 0.8.14", -] - -[[package]] -name = "alloy-sol-type-parser" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baa2fbd22d353d8685bd9fee11ba2d8b5c3b1d11e56adb3265fcf1f32bfdf404" -dependencies = [ - "winnow 0.6.13", + "syn-solidity", ] [[package]] @@ -929,57 +569,26 @@ dependencies = [ "winnow 0.6.13", ] -[[package]] -name = "alloy-sol-types" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a49042c6d3b66a9fe6b2b5a8bf0d39fc2ae1ee0310a2a26ffedd79fb097878dd" -dependencies = [ - "alloy-json-abi 0.7.6", - "alloy-primitives 0.7.6", - "alloy-sol-macro 0.7.6", - "const-hex", - "serde", -] - [[package]] name = "alloy-sol-types" version = "0.8.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cff34e0682d6665da243a3e81da96f07a2dd50f7e64073e382b1a141f5a2a2f6" dependencies = [ - "alloy-json-abi 0.8.13", - "alloy-primitives 0.8.13", - "alloy-sol-macro 0.8.13", + "alloy-json-abi", + "alloy-primitives", + "alloy-sol-macro", "const-hex", "serde", ] -[[package]] -name = "alloy-transport" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd9773e4ec6832346171605c776315544bd06e40f803e7b5b7824b325d5442ca" -dependencies = [ - "alloy-json-rpc 0.1.3", - "base64", - "futures-util", - "futures-utils-wasm", - "serde", - "serde_json", - "thiserror", - "tokio", - "tower 0.4.13", - "url", -] - [[package]] name = "alloy-transport" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6f295f4b745fb9e4e663d70bc57aed991288912c7aaaf25767def921050ee43" dependencies = [ - "alloy-json-rpc 0.7.0", + "alloy-json-rpc", "base64", "futures-util", "futures-utils-wasm", @@ -993,29 +602,14 @@ dependencies = [ "wasmtimer", ] -[[package]] -name = "alloy-transport-http" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff8ef947b901c0d4e97370f9fa25844cf8b63b1a58fd4011ee82342dc8a9fc6b" -dependencies = [ - "alloy-json-rpc 0.1.3", - "alloy-transport 0.1.3", - "reqwest", - "serde_json", - "tower 0.4.13", - "tracing", - "url", -] - [[package]] name = "alloy-transport-http" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39139015a5ec127d9c895b49b484608e27fe4538544f84cdf5eae0bd36339bc6" dependencies = [ - "alloy-json-rpc 0.7.0", - "alloy-transport 0.7.0", + "alloy-json-rpc", + "alloy-transport", "reqwest", "serde_json", "tower 0.5.1", @@ -1029,10 +623,10 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6b2e366c0debf0af77766c23694a3f863b02633050e71e096e257ffbd395e50" dependencies = [ - "alloy-primitives 0.8.13", + "alloy-primitives", "alloy-rlp", "arrayvec", - "derive_more 1.0.0", + "derive_more", "nybbles", "smallvec", "tracing", @@ -1310,7 +904,7 @@ checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" name = "basic-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy-primitives 0.8.13", + "alloy-primitives", "openzeppelin-stylus", "stylus-sdk", ] @@ -1319,8 +913,8 @@ dependencies = [ name = "basic-example-script" version = "0.2.0-alpha.1" dependencies = [ - "alloy 0.7.2", - "alloy-primitives 0.8.13", + "alloy", + "alloy-primitives", "basic-example", "koba", "tokio", @@ -1330,8 +924,8 @@ dependencies = [ name = "benches" version = "0.2.0-alpha.1" dependencies = [ - "alloy 0.7.2", - "alloy-primitives 0.8.13", + "alloy", + "alloy-primitives", "e2e", "eyre", "futures", @@ -1579,12 +1173,6 @@ version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" -[[package]] -name = "convert_case" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" - [[package]] name = "convert_case" version = "0.6.0" @@ -1772,8 +1360,8 @@ dependencies = [ name = "cryptography-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy 0.7.2", - "alloy-primitives 0.8.13", + "alloy", + "alloy-primitives", "e2e", "eyre", "openzeppelin-stylus", @@ -1883,19 +1471,6 @@ dependencies = [ "syn 2.0.89", ] -[[package]] -name = "derive_more" -version = "0.99.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" -dependencies = [ - "convert_case 0.4.0", - "proc-macro2", - "quote", - "rustc_version 0.4.0", - "syn 2.0.89", -] - [[package]] name = "derive_more" version = "1.0.0" @@ -1948,7 +1523,7 @@ checksum = "56ce8c6da7551ec6c462cbaf3bfbc75131ebbfa1c944aeaa9dab51ca1c5f0c3b" name = "e2e" version = "0.1.0" dependencies = [ - "alloy 0.7.2", + "alloy", "e2e-proc", "eyre", "koba", @@ -2089,8 +1664,8 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" name = "erc1155-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy 0.7.2", - "alloy-primitives 0.8.13", + "alloy", + "alloy-primitives", "e2e", "eyre", "openzeppelin-stylus", @@ -2102,8 +1677,8 @@ dependencies = [ name = "erc20-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy 0.7.2", - "alloy-primitives 0.8.13", + "alloy", + "alloy-primitives", "e2e", "eyre", "openzeppelin-stylus", @@ -2115,8 +1690,8 @@ dependencies = [ name = "erc20-permit-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy 0.7.2", - "alloy-primitives 0.8.13", + "alloy", + "alloy-primitives", "e2e", "eyre", "openzeppelin-stylus", @@ -2128,9 +1703,9 @@ dependencies = [ name = "erc721-consecutive-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy 0.7.2", - "alloy-primitives 0.8.13", - "alloy-sol-types 0.8.13", + "alloy", + "alloy-primitives", + "alloy-sol-types", "e2e", "eyre", "openzeppelin-stylus", @@ -2143,8 +1718,8 @@ dependencies = [ name = "erc721-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy 0.7.2", - "alloy-primitives 0.8.13", + "alloy", + "alloy-primitives", "e2e", "eyre", "openzeppelin-stylus", @@ -2157,8 +1732,8 @@ dependencies = [ name = "erc721-metadata-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy 0.7.2", - "alloy-primitives 0.8.13", + "alloy", + "alloy-primitives", "e2e", "eyre", "openzeppelin-stylus", @@ -2781,10 +2356,9 @@ checksum = "57d8d8ce877200136358e0bbff3a77965875db3af755a11e1fa6b1b3e2df13ea" [[package]] name = "koba" version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80e92e1148d087df999396266311bece9e5311c352821872cccaf5dc67117cfc" +source = "git+https://github.com/OpenZeppelin/koba?branch=build%2Fbump-alloy#9f5fc33853088f7c265571c1f90728eb56c5051f" dependencies = [ - "alloy 0.1.4", + "alloy", "brotli2", "bytesize", "clap", @@ -2899,8 +2473,8 @@ dependencies = [ name = "merkle-proofs-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy-primitives 0.8.13", - "alloy-sol-types 0.8.13", + "alloy-primitives", + "alloy-sol-types", "openzeppelin-crypto", "stylus-sdk", ] @@ -2962,8 +2536,8 @@ dependencies = [ name = "motsu-proc" version = "0.2.0" dependencies = [ - "alloy-primitives 0.8.13", - "alloy-sol-types 0.8.13", + "alloy-primitives", + "alloy-sol-types", "motsu", "proc-macro2", "quote", @@ -3134,11 +2708,11 @@ dependencies = [ name = "openzeppelin-stylus" version = "0.2.0-alpha.1" dependencies = [ - "alloy-primitives 0.8.13", - "alloy-sol-macro 0.8.13", - "alloy-sol-macro-expander 0.8.13", - "alloy-sol-macro-input 0.8.13", - "alloy-sol-types 0.8.13", + "alloy-primitives", + "alloy-sol-macro", + "alloy-sol-macro-expander", + "alloy-sol-macro-input", + "alloy-sol-types", "keccak-const", "motsu", "openzeppelin-stylus-proc", @@ -3150,7 +2724,7 @@ dependencies = [ name = "openzeppelin-stylus-proc" version = "0.1.0" dependencies = [ - "convert_case 0.6.0", + "convert_case", "proc-macro2", "quote", "syn 2.0.89", @@ -3160,8 +2734,8 @@ dependencies = [ name = "ownable-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy 0.7.2", - "alloy-primitives 0.8.13", + "alloy", + "alloy-primitives", "e2e", "eyre", "openzeppelin-stylus", @@ -3173,8 +2747,8 @@ dependencies = [ name = "ownable-two-step" version = "0.2.0-alpha.1" dependencies = [ - "alloy 0.7.2", - "alloy-primitives 0.8.13", + "alloy", + "alloy-primitives", "e2e", "eyre", "openzeppelin-stylus", @@ -3814,8 +3388,8 @@ checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" name = "safe-erc20-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy 0.7.2", - "alloy-primitives 0.8.13", + "alloy", + "alloy-primitives", "e2e", "eyre", "openzeppelin-stylus", @@ -4143,10 +3717,10 @@ version = "0.7.0-beta.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8abd5d2cb3a10a36101b3d9243eda29daa58aad89b93979afe77c4be89068413" dependencies = [ - "alloy-primitives 0.8.13", - "alloy-sol-types 0.8.13", + "alloy-primitives", + "alloy-sol-types", "cfg-if", - "convert_case 0.6.0", + "convert_case", "lazy_static", "proc-macro-error", "proc-macro2", @@ -4154,7 +3728,7 @@ dependencies = [ "regex", "sha3", "syn 2.0.89", - "syn-solidity 0.8.14", + "syn-solidity", "trybuild", ] @@ -4164,8 +3738,8 @@ version = "0.7.0-beta.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "caa33222d37101b3ba7064f1099ae38c7e388eaeac422e58260b7d00346a5267" dependencies = [ - "alloy-primitives 0.8.13", - "alloy-sol-types 0.8.13", + "alloy-primitives", + "alloy-sol-types", "cfg-if", "derivative", "hex", @@ -4203,18 +3777,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "syn-solidity" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d71e19bca02c807c9faa67b5a47673ff231b6e7449b251695188522f1dc44b2" -dependencies = [ - "paste", - "proc-macro2", - "quote", - "syn 2.0.89", -] - [[package]] name = "syn-solidity" version = "0.8.14" @@ -4454,7 +4016,6 @@ dependencies = [ "tokio", "tower-layer", "tower-service", - "tracing", ] [[package]] @@ -4489,7 +4050,6 @@ version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ - "log", "pin-project-lite", "tracing-attributes", "tracing-core", @@ -4660,8 +4220,8 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" name = "vesting-wallet-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy 0.7.2", - "alloy-primitives 0.8.13", + "alloy", + "alloy-primitives", "e2e", "eyre", "openzeppelin-stylus", diff --git a/Cargo.toml b/Cargo.toml index 841770e5d..54a663b4e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -94,7 +94,7 @@ alloy-sol-macro-input = { version = "=0.8.13", default-features = false } const-hex = { version = "1.11.1", default-features = false } eyre = "0.6.8" keccak-const = "0.2.0" -koba = "0.2.0" +koba = { git = "https://github.com/OpenZeppelin/koba", branch = "build/bump-alloy" } once_cell = "1.19.0" rand = "0.8.5" regex = "1.10.4" From 0f40dc46bde2744e332c40ea3655c633137f9e6a Mon Sep 17 00:00:00 2001 From: Daniel Bigos Date: Tue, 3 Dec 2024 09:21:30 +0100 Subject: [PATCH 33/57] build: update E2E crate with new alloy (cherry picked from commit 91a0e8edc06df3ed4e3f6dfd8fcccb7fc063b2c7) --- Cargo.lock | 2 +- lib/e2e/Cargo.toml | 2 +- lib/e2e/src/system.rs | 18 ++++++++++++------ 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3119e815c..2c0d6a37d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1521,7 +1521,7 @@ checksum = "56ce8c6da7551ec6c462cbaf3bfbc75131ebbfa1c944aeaa9dab51ca1c5f0c3b" [[package]] name = "e2e" -version = "0.1.0" +version = "0.2.0" dependencies = [ "alloy", "e2e-proc", diff --git a/lib/e2e/Cargo.toml b/lib/e2e/Cargo.toml index 84a9c6df0..fc8b8ab51 100644 --- a/lib/e2e/Cargo.toml +++ b/lib/e2e/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "e2e" description = "End-to-end Testing for Stylus" -version = "0.1.0" +version = "0.2.0" categories = ["development-tools::testing", "cryptography::cryptocurrencies"] keywords = ["arbitrum", "ethereum", "stylus", "integration-testing", "tests"] authors.workspace = true diff --git a/lib/e2e/src/system.rs b/lib/e2e/src/system.rs index 5d90cd8be..9f622cd24 100644 --- a/lib/e2e/src/system.rs +++ b/lib/e2e/src/system.rs @@ -3,8 +3,8 @@ use alloy::{ primitives::Address, providers::{ fillers::{ - ChainIdFiller, FillProvider, GasFiller, JoinFill, NonceFiller, - WalletFiller, + BlobGasFiller, ChainIdFiller, FillProvider, GasFiller, JoinFill, + NonceFiller, WalletFiller, }, Identity, ProviderBuilder, RootProvider, }, @@ -20,8 +20,11 @@ pub(crate) const RPC_URL_ENV_VAR_NAME: &str = "RPC_URL"; pub type Wallet = FillProvider< JoinFill< JoinFill< - JoinFill, NonceFiller>, - ChainIdFiller, + Identity, + JoinFill< + GasFiller, + JoinFill>, + >, >, WalletFiller, >, @@ -33,8 +36,11 @@ pub type Wallet = FillProvider< /// Convenience type alias that represents an alloy provider. pub type Provider = FillProvider< JoinFill< - JoinFill, NonceFiller>, - ChainIdFiller, + Identity, + JoinFill< + GasFiller, + JoinFill>, + >, >, RootProvider>, Http, From 3c909bf38e3ab7ba757e169060792159e260c7de Mon Sep 17 00:00:00 2001 From: Daniel Bigos Date: Tue, 3 Dec 2024 09:52:56 +0100 Subject: [PATCH 34/57] ref: extract v as u8 from Signature (cherry picked from commit 25d400c9122af0840d51049b3c40ed4c0e464ce3) --- examples/ecdsa/tests/ecdsa.rs | 16 ++++++---------- examples/erc20-permit/tests/erc20permit.rs | 19 ++++++++++++------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/examples/ecdsa/tests/ecdsa.rs b/examples/ecdsa/tests/ecdsa.rs index 9380fd9bb..1673a6c90 100644 --- a/examples/ecdsa/tests/ecdsa.rs +++ b/examples/ecdsa/tests/ecdsa.rs @@ -1,7 +1,7 @@ #![cfg(feature = "e2e")] use abi::ECDSA; -use alloy::primitives::{address, b256, uint, Address, B256}; +use alloy::primitives::{address, b256, uint, Address, Parity, B256}; use e2e::{Account, ReceiptExt, Revert}; use eyre::Result; use openzeppelin_stylus::utils::cryptography::ecdsa::SIGNATURE_S_UPPER_BOUND; @@ -108,17 +108,13 @@ async fn recovers_from_v_r_s(alice: Account) -> Result<()> { let contract = ECDSA::new(contract_addr, &alice.wallet); let signature = alice.sign_hash(&HASH).await; + let parity: Parity = signature.v().into(); + let v_byte = parity + .y_parity_byte_non_eip155() + .expect("should be non-EIP155 signature"); let ECDSA::recoverReturn { recovered } = contract - .recover( - HASH, - signature - .v() - .y_parity_byte_non_eip155() - .expect("should be non-EIP155 signature"), - signature.r().into(), - signature.s().into(), - ) + .recover(HASH, v_byte, signature.r().into(), signature.s().into()) .call() .await?; diff --git a/examples/erc20-permit/tests/erc20permit.rs b/examples/erc20-permit/tests/erc20permit.rs index d831c3f43..ab0e155a5 100644 --- a/examples/erc20-permit/tests/erc20permit.rs +++ b/examples/erc20-permit/tests/erc20permit.rs @@ -2,14 +2,14 @@ use abi::Erc20Permit; use alloy::{ - primitives::{b256, keccak256, Address, B256, U256}, + primitives::{b256, keccak256, Address, Parity, B256, U256}, + signers::Signature, sol, sol_types::SolType, }; use alloy_primitives::uint; use e2e::{receipt, send, watch, Account, EventExt, ReceiptExt, Revert}; use eyre::Result; - mod abi; // Saturday, 1 January 2000 00:00:00 @@ -65,6 +65,11 @@ fn permit_struct_hash( ))) } +fn extract_signature_v(signature: &Signature) -> u8 { + let parity: Parity = signature.v().into(); + parity.y_parity_byte_non_eip155().expect("should be non-EIP155 signature") +} + // ============================================================================ // Integration Tests: ERC-20 Permit Extension // ============================================================================ @@ -103,7 +108,7 @@ async fn error_when_expired_deadline_for_permit( bob_addr, balance, EXPIRED_DEADLINE, - signature.v().y_parity_byte_non_eip155().unwrap(), + extract_signature_v(&signature), signature.r().into(), signature.s().into() )) @@ -152,7 +157,7 @@ async fn permit_works(alice: Account, bob: Account) -> Result<()> { bob_addr, balance, FAIR_DEADLINE, - signature.v().y_parity_byte_non_eip155().unwrap(), + extract_signature_v(&signature), signature.r().into(), signature.s().into() ))?; @@ -237,7 +242,7 @@ async fn permit_rejects_reused_signature( bob_addr, balance, FAIR_DEADLINE, - signature.v().y_parity_byte_non_eip155().unwrap(), + extract_signature_v(&signature), signature.r().into(), signature.s().into() ))?; @@ -247,7 +252,7 @@ async fn permit_rejects_reused_signature( bob_addr, balance, FAIR_DEADLINE, - signature.v().y_parity_byte_non_eip155().unwrap(), + extract_signature_v(&signature), signature.r().into(), signature.s().into() )) @@ -312,7 +317,7 @@ async fn permit_rejects_invalid_signature( bob_addr, balance, FAIR_DEADLINE, - signature.v().y_parity_byte_non_eip155().unwrap(), + extract_signature_v(&signature), signature.r().into(), signature.s().into() )) From 1acaa4c1b8fba808cfa5b5b45e4cdc7ee54ebc88 Mon Sep 17 00:00:00 2001 From: Daniel Bigos Date: Tue, 3 Dec 2024 10:09:38 +0100 Subject: [PATCH 35/57] fix: use proper data type for U96 (cherry picked from commit 0596f0c17d2c3b6fa3a116e62fba470f4d3ecd1e) --- examples/erc721-consecutive/tests/erc721-consecutive.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/erc721-consecutive/tests/erc721-consecutive.rs b/examples/erc721-consecutive/tests/erc721-consecutive.rs index 1f50f78c5..ed572ea52 100644 --- a/examples/erc721-consecutive/tests/erc721-consecutive.rs +++ b/examples/erc721-consecutive/tests/erc721-consecutive.rs @@ -4,7 +4,7 @@ use alloy::{ primitives::{Address, U256}, sol, }; -use alloy_primitives::uint; +use alloy_primitives::{uint, aliases::U96}; use e2e::{receipt, watch, Account, EventExt, ReceiptExt, Revert}; use crate::{abi::Erc721, Erc721ConsecutiveExample::constructorCall}; @@ -24,9 +24,9 @@ fn random_token_id() -> U256 { fn ctr(receivers: Vec
, amounts: Vec) -> constructorCall { constructorCall { receivers, - amounts, - firstConsecutiveId: FIRST_CONSECUTIVE_ID, - maxBatchSize: MAX_BATCH_SIZE, + amounts: amounts.iter().map(|v| U96::from(*v)).collect(), + firstConsecutiveId: U96::from(FIRST_CONSECUTIVE_ID), + maxBatchSize: U96::from(MAX_BATCH_SIZE), } } From fa476f146652ca0a6e1178518b7b7f5cde852acc Mon Sep 17 00:00:00 2001 From: Daniel Bigos Date: Tue, 3 Dec 2024 11:50:40 +0100 Subject: [PATCH 36/57] fix: benches (cherry picked from commit 65a0c6ed24b1400a91688a20f32d0b3c3ad87b8c) --- benches/src/lib.rs | 4 ++-- examples/erc721-consecutive/tests/erc721-consecutive.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/benches/src/lib.rs b/benches/src/lib.rs index f6f39d9a2..dfbb657f6 100644 --- a/benches/src/lib.rs +++ b/benches/src/lib.rs @@ -3,7 +3,7 @@ use std::process::Command; use alloy::{ primitives::Address, rpc::types::{ - serde_helpers::WithOtherFields, AnyReceiptEnvelope, Log, + serde_helpers::WithOtherFields, AnyReceiptEnvelope, Log, Receipt, TransactionReceipt, }, }; @@ -40,7 +40,7 @@ pub enum CacheOpt { } type ArbTxReceipt = - WithOtherFields>>; + WithOtherFields>>>; async fn deploy( account: &Account, diff --git a/examples/erc721-consecutive/tests/erc721-consecutive.rs b/examples/erc721-consecutive/tests/erc721-consecutive.rs index ed572ea52..740779a42 100644 --- a/examples/erc721-consecutive/tests/erc721-consecutive.rs +++ b/examples/erc721-consecutive/tests/erc721-consecutive.rs @@ -4,7 +4,7 @@ use alloy::{ primitives::{Address, U256}, sol, }; -use alloy_primitives::{uint, aliases::U96}; +use alloy_primitives::{aliases::U96, uint}; use e2e::{receipt, watch, Account, EventExt, ReceiptExt, Revert}; use crate::{abi::Erc721, Erc721ConsecutiveExample::constructorCall}; From 1078a12fd0e6090c4979d27fadf8ec33549bf776 Mon Sep 17 00:00:00 2001 From: Daniel Bigos Date: Wed, 4 Dec 2024 21:10:54 +0100 Subject: [PATCH 37/57] fix: constrain storage ints --- .../src/token/erc1155/extensions/metadata_uri.rs | 2 +- contracts/src/utils/math/storage.rs | 13 +++++++++---- contracts/src/utils/metadata.rs | 2 +- .../src/utils/structs/checkpoints/generic_size.rs | 3 +++ 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/contracts/src/token/erc1155/extensions/metadata_uri.rs b/contracts/src/token/erc1155/extensions/metadata_uri.rs index 6f822a7df..8e7c8debd 100644 --- a/contracts/src/token/erc1155/extensions/metadata_uri.rs +++ b/contracts/src/token/erc1155/extensions/metadata_uri.rs @@ -3,7 +3,7 @@ //! //! [ERC]: https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions -use alloc::string::String; +use alloc::{string::String, vec::Vec}; use alloy_primitives::{FixedBytes, U256}; use alloy_sol_macro::sol; diff --git a/contracts/src/utils/math/storage.rs b/contracts/src/utils/math/storage.rs index 31193c47b..51d891a3b 100644 --- a/contracts/src/utils/math/storage.rs +++ b/contracts/src/utils/math/storage.rs @@ -1,5 +1,6 @@ //! Simple math operations missing in `stylus_sdk::storage`. use alloy_primitives::Uint; +use alloy_sol_types::sol_data::{IntBitCount, SupportedInt}; use stylus_sdk::storage::{StorageGuardMut, StorageUint}; pub(crate) trait AddAssignUnchecked { @@ -8,10 +9,12 @@ pub(crate) trait AddAssignUnchecked { impl<'a, const B: usize, const L: usize> AddAssignUnchecked> for StorageGuardMut<'a, StorageUint> +where + IntBitCount: SupportedInt, { fn add_assign_unchecked(&mut self, rhs: Uint) { - let new_balance = self.get() + rhs; - self.set(new_balance); + let new_value = self.get() + rhs; + self.set(new_value); } } @@ -21,9 +24,11 @@ pub(crate) trait SubAssignUnchecked { impl<'a, const B: usize, const L: usize> SubAssignUnchecked> for StorageGuardMut<'a, StorageUint> +where + IntBitCount: SupportedInt, { fn sub_assign_unchecked(&mut self, rhs: Uint) { - let new_balance = self.get() - rhs; - self.set(new_balance); + let new_value = self.get() - rhs; + self.set(new_value); } } diff --git a/contracts/src/utils/metadata.rs b/contracts/src/utils/metadata.rs index b4410d12c..e668bca34 100644 --- a/contracts/src/utils/metadata.rs +++ b/contracts/src/utils/metadata.rs @@ -1,5 +1,5 @@ //! Common Metadata Smart Contract. -use alloc::{string::String, vec, vec::Vec}; +use alloc::{string::String, vec::Vec}; use stylus_sdk::stylus_proc::{public, sol_storage}; sol_storage! { diff --git a/contracts/src/utils/structs/checkpoints/generic_size.rs b/contracts/src/utils/structs/checkpoints/generic_size.rs index 033700c66..aee10a65e 100644 --- a/contracts/src/utils/structs/checkpoints/generic_size.rs +++ b/contracts/src/utils/structs/checkpoints/generic_size.rs @@ -2,6 +2,7 @@ use core::ops::{Add, Div, Mul, Sub}; +use alloy_sol_types::sol_data::{IntBitCount, SupportedInt}; use stylus_sdk::{alloy_primitives::Uint, prelude::*}; /// Trait that associates types of specific size for checkpoints key and value. @@ -87,6 +88,8 @@ pub trait Accessor { impl Accessor for stylus_sdk::storage::StorageUint +where + IntBitCount: SupportedInt, { type Wraps = Uint; From a9c3fbed98776fdaeb53d9317747f8d3d065b55a Mon Sep 17 00:00:00 2001 From: Daniel Bigos Date: Thu, 5 Dec 2024 15:24:56 +0100 Subject: [PATCH 38/57] build: update koba to v0.3.0 --- Cargo.lock | 5 +++-- Cargo.toml | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2c0d6a37d..4b966c4ba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2355,8 +2355,9 @@ checksum = "57d8d8ce877200136358e0bbff3a77965875db3af755a11e1fa6b1b3e2df13ea" [[package]] name = "koba" -version = "0.2.0" -source = "git+https://github.com/OpenZeppelin/koba?branch=build%2Fbump-alloy#9f5fc33853088f7c265571c1f90728eb56c5051f" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "648bf93c7aff36defcf825c5a42d32503eb617c85f057a989f34ebfebed99f45" dependencies = [ "alloy", "brotli2", diff --git a/Cargo.toml b/Cargo.toml index 54a663b4e..aeaad6ac9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -94,7 +94,7 @@ alloy-sol-macro-input = { version = "=0.8.13", default-features = false } const-hex = { version = "1.11.1", default-features = false } eyre = "0.6.8" keccak-const = "0.2.0" -koba = { git = "https://github.com/OpenZeppelin/koba", branch = "build/bump-alloy" } +koba = "0.3.0" once_cell = "1.19.0" rand = "0.8.5" regex = "1.10.4" From 94cb034c5f59ea0ffd46c644adc193e13bef4b4d Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Fri, 6 Dec 2024 11:55:40 +0400 Subject: [PATCH 39/57] remove not used Provider --- lib/e2e/src/lib.rs | 2 +- lib/e2e/src/system.rs | 30 +----------------------------- 2 files changed, 2 insertions(+), 30 deletions(-) diff --git a/lib/e2e/src/lib.rs b/lib/e2e/src/lib.rs index 539f71aa7..13c2c4dea 100644 --- a/lib/e2e/src/lib.rs +++ b/lib/e2e/src/lib.rs @@ -13,7 +13,7 @@ pub use e2e_proc::test; pub use error::{Panic, PanicCode, Revert}; pub use event::EventExt; pub use receipt::ReceiptExt; -pub use system::{fund_account, provider, Provider, Wallet}; +pub use system::{fund_account, Wallet}; /// This macro provides a shorthand for broadcasting the transaction to the /// network. diff --git a/lib/e2e/src/system.rs b/lib/e2e/src/system.rs index 9f622cd24..1c0613e4a 100644 --- a/lib/e2e/src/system.rs +++ b/lib/e2e/src/system.rs @@ -6,7 +6,7 @@ use alloy::{ BlobGasFiller, ChainIdFiller, FillProvider, GasFiller, JoinFill, NonceFiller, WalletFiller, }, - Identity, ProviderBuilder, RootProvider, + Identity, RootProvider, }, transports::http::{Client, Http}, }; @@ -33,39 +33,11 @@ pub type Wallet = FillProvider< Ethereum, >; -/// Convenience type alias that represents an alloy provider. -pub type Provider = FillProvider< - JoinFill< - Identity, - JoinFill< - GasFiller, - JoinFill>, - >, - >, - RootProvider>, - Http, - Ethereum, ->; - /// Load the `name` environment variable. fn env(name: &str) -> eyre::Result { std::env::var(name).wrap_err(format!("failed to load {name}")) } -/// Returns an alloy provider connected to the `RPC_URL` rpc endpoint. -/// -/// # Panics -/// -/// May panic if unable to load the `RPC_URL` environment variable. -#[must_use] -pub fn provider() -> Provider { - let rpc_url = env(RPC_URL_ENV_VAR_NAME) - .expect("failed to load RPC_URL var from env") - .parse() - .expect("failed to parse RPC_URL string into a URL"); - ProviderBuilder::new().with_recommended_fillers().on_http(rpc_url) -} - /// Send `amount` eth to `address` in the nitro-tesnode. pub fn fund_account(address: Address, amount: u32) -> eyre::Result<()> { let node_script = get_node_path()?.join("test-node.bash"); From 06945d6230c2fc735bcffcc22e059633c5fc07d4 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Fri, 6 Dec 2024 14:43:21 +0400 Subject: [PATCH 40/57] add stylus-sdk patch for external calls --- Cargo.lock | 9 +++------ Cargo.toml | 9 +++++++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4b966c4ba..746da475d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2489,8 +2489,7 @@ checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" [[package]] name = "mini-alloc" version = "0.7.0-beta.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d79b46612e3fc76138ed930cd2e4bbd26ada11954a6d312e3affe4b56df0081" +source = "git+https://github.com/qalisander/stylus-sdk-rs?branch=fix-encoding-in-sol-interface#a31d36a883f8b3d30835f05779997b793444e532" dependencies = [ "cfg-if", ] @@ -3715,8 +3714,7 @@ dependencies = [ [[package]] name = "stylus-proc" version = "0.7.0-beta.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8abd5d2cb3a10a36101b3d9243eda29daa58aad89b93979afe77c4be89068413" +source = "git+https://github.com/qalisander/stylus-sdk-rs?branch=fix-encoding-in-sol-interface#a31d36a883f8b3d30835f05779997b793444e532" dependencies = [ "alloy-primitives", "alloy-sol-types", @@ -3736,8 +3734,7 @@ dependencies = [ [[package]] name = "stylus-sdk" version = "0.7.0-beta.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "caa33222d37101b3ba7064f1099ae38c7e388eaeac422e58260b7d00346a5267" +source = "git+https://github.com/qalisander/stylus-sdk-rs?branch=fix-encoding-in-sol-interface#a31d36a883f8b3d30835f05779997b793444e532" dependencies = [ "alloy-primitives", "alloy-sol-types", diff --git a/Cargo.toml b/Cargo.toml index aeaad6ac9..3748f50e5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -136,3 +136,12 @@ incremental = false [profile.dev] panic = "abort" + +# TODO#q: remove this once the fix is released +[patch.crates-io.stylus-sdk] +git = "https://github.com/qalisander/stylus-sdk-rs" +branch = "fix-encoding-in-sol-interface" + +[patch.crates-io.stylus-proc] +git = "https://github.com/qalisander/stylus-sdk-rs" +branch = "fix-encoding-in-sol-interface" From 3a6e6bd3ffec2f428c7c4fc7b8cc4f37440ff076 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Sat, 7 Dec 2024 19:08:45 +0400 Subject: [PATCH 41/57] retrieve tx hashes for block timestamp --- examples/vesting-wallet/tests/vesting-wallet.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/vesting-wallet/tests/vesting-wallet.rs b/examples/vesting-wallet/tests/vesting-wallet.rs index 50f0b48e8..d75ba49c1 100644 --- a/examples/vesting-wallet/tests/vesting-wallet.rs +++ b/examples/vesting-wallet/tests/vesting-wallet.rs @@ -39,7 +39,7 @@ fn ctr( async fn block_timestamp(account: &Account) -> eyre::Result { let timestamp = account .wallet - .get_block(BlockId::latest(), BlockTransactionsKind::Full) + .get_block(BlockId::latest(), BlockTransactionsKind::Hashes) .await? .expect("latest block should exist") .header From d33bdc3d303322263e93907524cba1cf490df771 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Sat, 7 Dec 2024 19:55:29 +0400 Subject: [PATCH 42/57] fix run_check_release test for vesting_wallet --- examples/vesting-wallet/tests/vesting-wallet.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/vesting-wallet/tests/vesting-wallet.rs b/examples/vesting-wallet/tests/vesting-wallet.rs index d75ba49c1..d292b8b7f 100644 --- a/examples/vesting-wallet/tests/vesting-wallet.rs +++ b/examples/vesting-wallet/tests/vesting-wallet.rs @@ -311,9 +311,10 @@ mod erc20_vesting { assert_in_delta(old_alice_balance + released, alice_balance); assert_in_delta(old_contract_balance - released, contract_balance); - assert!( - receipt.emits(VestingWallet::EtherReleased { amount: released }) - ); + assert!(receipt.emits(VestingWallet::ERC20Released { + token: erc20_address, + amount: released + })); Ok(()) } From eb5cc951a3215c15944866995181ef7ae99566e1 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Mon, 9 Dec 2024 17:08:30 +0400 Subject: [PATCH 43/57] update alloy to 0.8.14 --- Cargo.lock | 34 +++++++++++++++++----------------- Cargo.toml | 10 +++++----- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4c813e09e..650e87f1d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -247,9 +247,9 @@ dependencies = [ [[package]] name = "alloy-json-abi" -version = "0.8.13" +version = "0.8.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a500037938085feed8a20dbfc8fce58c599db68c948cfae711147175dee392c" +checksum = "ac4b22b3e51cac09fd2adfcc73b55f447b4df669f983c13f7894ec82b607c63f" dependencies = [ "alloy-primitives", "alloy-sol-type-parser", @@ -311,9 +311,9 @@ dependencies = [ [[package]] name = "alloy-primitives" -version = "0.8.13" +version = "0.8.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3aeeb5825c2fc8c2662167058347cd0cafc3cb15bcb5cdb1758a63c2dca0409e" +checksum = "9db948902dfbae96a73c2fbf1f7abec62af034ab883e4c777c3fd29702bd6e2c" dependencies = [ "alloy-rlp", "arbitrary", @@ -511,9 +511,9 @@ dependencies = [ [[package]] name = "alloy-sol-macro" -version = "0.8.13" +version = "0.8.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c0279d09463a4695788a3622fd95443625f7be307422deba4b55dd491a9c7a1" +checksum = "3bfd7853b65a2b4f49629ec975fee274faf6dff15ab8894c620943398ef283c0" dependencies = [ "alloy-sol-macro-expander", "alloy-sol-macro-input", @@ -525,9 +525,9 @@ dependencies = [ [[package]] name = "alloy-sol-macro-expander" -version = "0.8.13" +version = "0.8.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4feea540fc8233df2ad1156efd744b2075372f43a8f942a68b3b19c8a00e2c12" +checksum = "82ec42f342d9a9261699f8078e57a7a4fda8aaa73c1a212ed3987080e6a9cd13" dependencies = [ "alloy-json-abi", "alloy-sol-macro-input", @@ -544,9 +544,9 @@ dependencies = [ [[package]] name = "alloy-sol-macro-input" -version = "0.8.13" +version = "0.8.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a0ad281f3d1b613af814b66977ee698e443d4644a1510962d0241f26e0e53ae" +checksum = "ed2c50e6a62ee2b4f7ab3c6d0366e5770a21cad426e109c2f40335a1b3aff3df" dependencies = [ "alloy-json-abi", "const-hex", @@ -571,9 +571,9 @@ dependencies = [ [[package]] name = "alloy-sol-types" -version = "0.8.13" +version = "0.8.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cff34e0682d6665da243a3e81da96f07a2dd50f7e64073e382b1a141f5a2a2f6" +checksum = "c9dc0fffe397aa17628160e16b89f704098bf3c9d74d5d369ebc239575936de5" dependencies = [ "alloy-json-abi", "alloy-primitives", @@ -1156,9 +1156,9 @@ checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" [[package]] name = "const-hex" -version = "1.12.0" +version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94fb8a24a26d37e1ffd45343323dc9fe6654ceea44c12f2fcb3d7ac29e610bc6" +checksum = "4b0485bab839b018a8f1723fc5391819fea5f8f0f32288ef8a735fd096b6160c" dependencies = [ "cfg-if", "cpufeatures", @@ -2502,7 +2502,7 @@ checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" [[package]] name = "mini-alloc" version = "0.7.0-beta.1" -source = "git+https://github.com/qalisander/stylus-sdk-rs?branch=fix-encoding-in-sol-interface#a31d36a883f8b3d30835f05779997b793444e532" +source = "git+https://github.com/qalisander/stylus-sdk-rs?branch=fix-encoding-in-sol-interface#2af4d8e232fc90c464eed29d0c0396f330f183ea" dependencies = [ "cfg-if", ] @@ -3727,7 +3727,7 @@ dependencies = [ [[package]] name = "stylus-proc" version = "0.7.0-beta.1" -source = "git+https://github.com/qalisander/stylus-sdk-rs?branch=fix-encoding-in-sol-interface#a31d36a883f8b3d30835f05779997b793444e532" +source = "git+https://github.com/qalisander/stylus-sdk-rs?branch=fix-encoding-in-sol-interface#2af4d8e232fc90c464eed29d0c0396f330f183ea" dependencies = [ "alloy-primitives", "alloy-sol-types", @@ -3747,7 +3747,7 @@ dependencies = [ [[package]] name = "stylus-sdk" version = "0.7.0-beta.1" -source = "git+https://github.com/qalisander/stylus-sdk-rs?branch=fix-encoding-in-sol-interface#a31d36a883f8b3d30835f05779997b793444e532" +source = "git+https://github.com/qalisander/stylus-sdk-rs?branch=fix-encoding-in-sol-interface#2af4d8e232fc90c464eed29d0c0396f330f183ea" dependencies = [ "alloy-primitives", "alloy-sol-types", diff --git a/Cargo.toml b/Cargo.toml index cdfde278f..06f56207c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -87,11 +87,11 @@ alloy = { version = "=0.7.2", features = [ # Even though `alloy` includes `alloy-primitives` and `alloy-sol-types` we need # to keep both versions for compatibility with the Stylus SDK. Once they start # using `alloy` we can remove these. -alloy-primitives = { version = "=0.8.13", default-features = false } -alloy-sol-types = { version = "=0.8.13", default-features = false } -alloy-sol-macro = { version = "=0.8.13", default-features = false } -alloy-sol-macro-expander = { version = "=0.8.13", default-features = false } -alloy-sol-macro-input = { version = "=0.8.13", default-features = false } +alloy-primitives = { version = "=0.8.14", default-features = false } +alloy-sol-types = { version = "=0.8.14", default-features = false } +alloy-sol-macro = { version = "=0.8.14", default-features = false } +alloy-sol-macro-expander = { version = "=0.8.14", default-features = false } +alloy-sol-macro-input = { version = "=0.8.14", default-features = false } const-hex = { version = "1.11.1", default-features = false } eyre = "0.6.8" From c255a90371d7a72c723792105ed1764ec21368dc Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Wed, 11 Dec 2024 16:17:50 +0400 Subject: [PATCH 44/57] ++ --- contracts/src/utils/math/storage.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/contracts/src/utils/math/storage.rs b/contracts/src/utils/math/storage.rs index 7d5a07c34..5e709c002 100644 --- a/contracts/src/utils/math/storage.rs +++ b/contracts/src/utils/math/storage.rs @@ -1,5 +1,6 @@ //! Simple math operations missing in `stylus_sdk::storage`. use alloy_primitives::Uint; +use alloy_sol_types::sol_data::{IntBitCount, SupportedInt}; use stylus_sdk::storage::StorageUint; /// Adds value and assign the result to `self`, ignoring overflow. From f8b76459b21c8863e7df48a57e7f8b0c9c9a2857 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Wed, 11 Dec 2024 16:28:40 +0400 Subject: [PATCH 45/57] import alloc::vec::Vec for permit --- contracts/src/token/erc20/extensions/permit.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/contracts/src/token/erc20/extensions/permit.rs b/contracts/src/token/erc20/extensions/permit.rs index 64af6492a..089184048 100644 --- a/contracts/src/token/erc20/extensions/permit.rs +++ b/contracts/src/token/erc20/extensions/permit.rs @@ -12,6 +12,8 @@ //! //! [ERC]: https://eips.ethereum.org/EIPS/eip-2612 +use alloc::vec::Vec; + use alloy_primitives::{b256, keccak256, Address, B256, U256}; use alloy_sol_types::{sol, SolType}; use stylus_sdk::{ From 0f2a246697ce9de751b44f2a138c5b20ea271a7f Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Wed, 11 Dec 2024 16:28:59 +0400 Subject: [PATCH 46/57] remove unused code --- lib/e2e/src/lib.rs | 2 +- lib/e2e/src/system.rs | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/e2e/src/lib.rs b/lib/e2e/src/lib.rs index 8c35d7e62..8878ee197 100644 --- a/lib/e2e/src/lib.rs +++ b/lib/e2e/src/lib.rs @@ -13,7 +13,7 @@ pub use e2e_proc::test; pub use error::{Panic, PanicCode, Revert}; pub use event::Ext as EventExt; pub use receipt::Ext as ReceiptExt; -pub use system::{fund_account, provider, Provider, Wallet}; +pub use system::{fund_account, Wallet}; /// This macro provides a shorthand for broadcasting the transaction to the /// network. diff --git a/lib/e2e/src/system.rs b/lib/e2e/src/system.rs index 1ab09c66b..f58591e53 100644 --- a/lib/e2e/src/system.rs +++ b/lib/e2e/src/system.rs @@ -33,11 +33,6 @@ pub type Wallet = FillProvider< Ethereum, >; -/// Load the `name` environment variable. -fn env(name: &str) -> eyre::Result { - std::env::var(name).wrap_err(format!("failed to load {name}")) -} - /// Send `amount` eth to `address` in the nitro-tesnode. /// /// # Errors From f27aed9f42f9949d1124d1f447b451befa317ec7 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Thu, 12 Dec 2024 00:20:12 +0400 Subject: [PATCH 47/57] ++ --- contracts/src/token/erc1155/extensions/supply.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/src/token/erc1155/extensions/supply.rs b/contracts/src/token/erc1155/extensions/supply.rs index 0c5e218c3..3d965e7ee 100644 --- a/contracts/src/token/erc1155/extensions/supply.rs +++ b/contracts/src/token/erc1155/extensions/supply.rs @@ -358,7 +358,7 @@ impl Erc1155Supply { #[cfg(all(test, feature = "std"))] mod tests { - use alloy_primitives::{address, Address, U256}; + /*use alloy_primitives::{address, Address, U256}; use super::{Erc1155Supply, IErc1155Supply}; use crate::token::erc1155::{ @@ -517,5 +517,5 @@ mod tests { assert_eq!(U256::ZERO, contract.total_supply(token_ids[0])); assert_eq!(U256::ZERO, contract.total_supply_all()); assert!(!contract.exists(token_ids[0])); - } + }*/ } From f0f94acbda4ee07e4d28b8240c0c27109bffdbcb Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Thu, 12 Dec 2024 01:01:56 +0400 Subject: [PATCH 48/57] ++ --- Cargo.lock | 3 ++ .../src/token/erc1155/extensions/supply.rs | 4 +- .../token/erc1155/extensions/uri_storage.rs | 4 +- contracts/src/token/erc721/mod.rs | 44 +++++++++---------- 4 files changed, 27 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6c51dee45..62a7a4a8e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3334,6 +3334,9 @@ name = "rustc-hash" version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" +dependencies = [ + "rand", +] [[package]] name = "rustc-hex" diff --git a/contracts/src/token/erc1155/extensions/supply.rs b/contracts/src/token/erc1155/extensions/supply.rs index 0c5e218c3..3d965e7ee 100644 --- a/contracts/src/token/erc1155/extensions/supply.rs +++ b/contracts/src/token/erc1155/extensions/supply.rs @@ -358,7 +358,7 @@ impl Erc1155Supply { #[cfg(all(test, feature = "std"))] mod tests { - use alloy_primitives::{address, Address, U256}; + /*use alloy_primitives::{address, Address, U256}; use super::{Erc1155Supply, IErc1155Supply}; use crate::token::erc1155::{ @@ -517,5 +517,5 @@ mod tests { assert_eq!(U256::ZERO, contract.total_supply(token_ids[0])); assert_eq!(U256::ZERO, contract.total_supply_all()); assert!(!contract.exists(token_ids[0])); - } + }*/ } diff --git a/contracts/src/token/erc1155/extensions/uri_storage.rs b/contracts/src/token/erc1155/extensions/uri_storage.rs index fd0052ab3..19c439a56 100644 --- a/contracts/src/token/erc1155/extensions/uri_storage.rs +++ b/contracts/src/token/erc1155/extensions/uri_storage.rs @@ -87,7 +87,7 @@ impl Erc1155UriStorage { #[cfg(all(test, feature = "std"))] mod tests { - use alloy_primitives::U256; + /*use alloy_primitives::U256; use stylus_sdk::stylus_proc::sol_storage; use super::Erc1155UriStorage; @@ -216,5 +216,5 @@ mod tests { contract.set_base_uri(base_uri.clone()); assert_eq!(base_uri, contract._base_uri.get_string()); - } + }*/ } diff --git a/contracts/src/token/erc721/mod.rs b/contracts/src/token/erc721/mod.rs index 9138e060a..adfc6baf6 100644 --- a/contracts/src/token/erc721/mod.rs +++ b/contracts/src/token/erc721/mod.rs @@ -163,30 +163,26 @@ impl MethodError for Error { } } -pub use receiver::IERC721Receiver; - -#[allow(missing_docs)] -mod receiver { - stylus_sdk::stylus_proc::sol_interface! { - /// [`Erc721`] token receiver interface. +stylus_sdk::stylus_proc::sol_interface! { + /// [`Erc721`] token receiver interface. + /// + /// Interface for any contract that wants to support `safe_transfers` + /// from [`Erc721`] asset contracts. + #[allow(missing_docs)] + interface IERC721Receiver { + /// Whenever an [`Erc721`] `token_id` token is transferred + /// to this contract via [`Erc721::safe_transfer_from`]. /// - /// Interface for any contract that wants to support `safe_transfers` - /// from [`Erc721`] asset contracts. - interface IERC721Receiver { - /// Whenever an [`Erc721`] `token_id` token is transferred - /// to this contract via [`Erc721::safe_transfer_from`]. - /// - /// It must return its function selector to confirm the token transfer. - /// If any other value is returned or the interface is not implemented - /// by the recipient, the transfer will be reverted. - #[allow(missing_docs)] - function onERC721Received( - address operator, - address from, - uint256 token_id, - bytes calldata data - ) external returns (bytes4); - } + /// It must return its function selector to confirm the token transfer. + /// If any other value is returned or the interface is not implemented + /// by the recipient, the transfer will be reverted. + #[allow(missing_docs)] + function onERC721Received( + address operator, + address from, + uint256 token_id, + bytes calldata data + ) external returns (bytes4); } } @@ -2556,7 +2552,7 @@ mod tests { let token_id = random_token_id(); erc721 .sender(alice) - ._safe_mint(receiver.address(), token_id, vec![0, 1, 2, 3].into()) + ._safe_mint(receiver.address(), token_id, &vec![0, 1, 2, 3].into()) .unwrap(); let received_token_id = receiver.sender(alice).received_token_id(); From 32ad8fd9682a385727b4e694b775eb3e870b66c1 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Thu, 12 Dec 2024 03:34:20 +0400 Subject: [PATCH 49/57] test ping_pong_works pass with msg::sender() --- Cargo.lock | 3 --- Cargo.toml | 16 +++++++++++----- contracts/src/utils/context.rs | 4 +--- lib/motsu/Cargo.toml | 2 +- lib/motsu/src/context.rs | 13 ++++++++++++- lib/motsu/src/lib.rs | 30 +++++++++--------------------- lib/motsu/src/shims.rs | 5 +---- 7 files changed, 35 insertions(+), 38 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 62a7a4a8e..18691b716 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2515,7 +2515,6 @@ checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" [[package]] name = "mini-alloc" version = "0.7.0-beta.1" -source = "git+https://github.com/qalisander/stylus-sdk-rs?branch=fix-encoding-in-sol-interface#2af4d8e232fc90c464eed29d0c0396f330f183ea" dependencies = [ "cfg-if", ] @@ -3745,7 +3744,6 @@ dependencies = [ [[package]] name = "stylus-proc" version = "0.7.0-beta.1" -source = "git+https://github.com/qalisander/stylus-sdk-rs?branch=fix-encoding-in-sol-interface#2af4d8e232fc90c464eed29d0c0396f330f183ea" dependencies = [ "alloy-primitives", "alloy-sol-types", @@ -3765,7 +3763,6 @@ dependencies = [ [[package]] name = "stylus-sdk" version = "0.7.0-beta.1" -source = "git+https://github.com/qalisander/stylus-sdk-rs?branch=fix-encoding-in-sol-interface#2af4d8e232fc90c464eed29d0c0396f330f183ea" dependencies = [ "alloy-primitives", "alloy-sol-types", diff --git a/Cargo.toml b/Cargo.toml index a3630ea1d..95446d178 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -148,11 +148,17 @@ default = { extend-ignore-identifiers-re = [ ] } files = { extend-exclude = [] } -# TODO#q: remove this once the fix is released +## TODO#q: remove this once the fix is released +#[patch.crates-io.stylus-sdk] +#git = "https://github.com/qalisander/stylus-sdk-rs" +#branch = "fix-encoding-in-sol-interface" +# +#[patch.crates-io.stylus-proc] +#git = "https://github.com/qalisander/stylus-sdk-rs" +#branch = "fix-encoding-in-sol-interface" + [patch.crates-io.stylus-sdk] -git = "https://github.com/qalisander/stylus-sdk-rs" -branch = "fix-encoding-in-sol-interface" +path = "../stylus-sdk-rs/stylus-sdk" [patch.crates-io.stylus-proc] -git = "https://github.com/qalisander/stylus-sdk-rs" -branch = "fix-encoding-in-sol-interface" +path = "../stylus-sdk-rs/stylus-proc" diff --git a/contracts/src/utils/context.rs b/contracts/src/utils/context.rs index 9f66d44b5..ca442d36a 100644 --- a/contracts/src/utils/context.rs +++ b/contracts/src/utils/context.rs @@ -5,9 +5,7 @@ use stylus_sdk::{alloy_primitives::Address, msg}; /// Returns the address of the message sender. #[cfg(test)] pub fn msg_sender() -> Address { - motsu::prelude::Context::current() - .get_msg_sender() - .expect("msg_sender should be set") + msg::sender() } /// Returns the address of the message sender. diff --git a/lib/motsu/Cargo.toml b/lib/motsu/Cargo.toml index 2376089a2..d3110fbb9 100644 --- a/lib/motsu/Cargo.toml +++ b/lib/motsu/Cargo.toml @@ -12,7 +12,7 @@ version = "0.2.0" const-hex.workspace = true once_cell.workspace = true tiny-keccak.workspace = true -stylus-sdk.workspace = true +stylus-sdk = { version = "0.7.0-beta.1", default-features = false } motsu-proc.workspace = true dashmap.workspace = true alloy-primitives = { workspace = true, features = ["arbitrary", "rand"] } diff --git a/lib/motsu/src/context.rs b/lib/motsu/src/context.rs index 631c76e8c..790517a54 100644 --- a/lib/motsu/src/context.rs +++ b/lib/motsu/src/context.rs @@ -185,7 +185,9 @@ impl Context { } fn set_return_data(&self, data: Vec) { - let _ = self.get_call_storage().call_output.insert(data); + let mut call_storage = self.get_call_storage(); + let _ = call_storage.call_output_len.insert(data.len()); + let _ = call_storage.call_output.insert(data); } pub(crate) unsafe fn read_return_data_raw( @@ -198,6 +200,13 @@ impl Context { data.len() } + pub(crate) fn get_return_data_size(&self) -> usize { + self.get_call_storage() + .call_output_len + .take() + .expect("call_output_len should be set") + } + fn get_return_data(&self) -> Vec { self.get_call_storage() .call_output @@ -295,6 +304,8 @@ struct CallStorage { contract_router: HashMap>>, // Output of a contract call. call_output: Option>, + // Output length of a contract call. + call_output_len: Option, } /// A trait for routing messages to the appropriate selector in tests. diff --git a/lib/motsu/src/lib.rs b/lib/motsu/src/lib.rs index 317b60f9a..81afb4198 100644 --- a/lib/motsu/src/lib.rs +++ b/lib/motsu/src/lib.rs @@ -58,18 +58,11 @@ mod tests { use stylus_sdk::{ alloy_primitives::{Address, U256}, call::Call, + msg, prelude::{public, sol_storage, StorageType, TopLevelStorage}, }; - use crate::context::{Account, Contract, TestRouter}; - - /// Message sender that mocks `msg::sender()` in tests. - #[must_use] - pub fn msg_sender() -> Address { - crate::prelude::Context::current() - .get_msg_sender() - .expect("msg_sender should be set") - } + use crate::context::{Account, Contract}; sol_storage! { pub struct PingContract { @@ -81,14 +74,14 @@ mod tests { #[public] impl PingContract { fn ping(&mut self, to: Address, value: U256) -> Result> { - let receiver = receiver::PongContract::new(to); + let receiver = IPongContract::new(to); let call = Call::new_in(self); let value = receiver.pong(call, value).expect("should pong successfully"); let pings_count = self._pings_count.get(); self._pings_count.set(pings_count + uint!(1_U256)); - self._pinged_from.set(msg_sender()); + self._pinged_from.set(msg::sender()); Ok(value) } @@ -103,13 +96,10 @@ mod tests { unsafe impl TopLevelStorage for PingContract {} - mod receiver { - use super::alloc; - stylus_sdk::stylus_proc::sol_interface! { - interface PongContract { - #[allow(missing_docs)] - function pong(uint256 value) external returns (uint256); - } + stylus_sdk::stylus_proc::sol_interface! { + interface IPongContract { + #[allow(missing_docs)] + function pong(uint256 value) external returns (uint256); } } @@ -125,7 +115,7 @@ mod tests { pub fn pong(&mut self, value: U256) -> Result> { let pongs_count = self._pongs_count.get(); self._pongs_count.set(pongs_count + uint!(1_U256)); - self._ponged_from.set(msg_sender()); + self._ponged_from.set(msg::sender()); Ok(value + uint!(1_U256)) } @@ -143,9 +133,7 @@ mod tests { #[test] fn ping_pong_works() { let mut ping = Contract::::default(); - let ping = &mut ping; let mut pong = Contract::::default(); - let pong = &mut pong; let alice = Account::random(); diff --git a/lib/motsu/src/shims.rs b/lib/motsu/src/shims.rs index d7105c086..a83afc4e3 100644 --- a/lib/motsu/src/shims.rs +++ b/lib/motsu/src/shims.rs @@ -244,10 +244,7 @@ pub unsafe extern "C" fn account_codehash(address: *const u8, dest: *mut u8) { /// [`RETURN_DATA_SIZE`]: https://www.evm.codes/#3d #[no_mangle] pub unsafe extern "C" fn return_data_size() -> usize { - // TODO: #156 - // No-op: we do not use this function in our unit-tests, - // but the binary does include it. - 0 + Context::current().get_return_data_size() } /// Copies the bytes of the last EVM call or deployment return result. From 0b3137010e417d65764ae97e0ce9b2c28ccc2726 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Thu, 12 Dec 2024 03:56:24 +0400 Subject: [PATCH 50/57] remove context msg_sender --- Cargo.toml | 2 +- contracts/Cargo.toml | 3 ++- contracts/src/token/erc721/mod.rs | 16 +++++++--------- contracts/src/utils/context.rs | 15 --------------- contracts/src/utils/mod.rs | 1 - lib/motsu/Cargo.toml | 2 +- 6 files changed, 11 insertions(+), 28 deletions(-) delete mode 100644 contracts/src/utils/context.rs diff --git a/Cargo.toml b/Cargo.toml index 95446d178..64a632085 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -72,7 +72,7 @@ all = "warn" [workspace.dependencies] # Stylus SDK related -stylus-sdk = "0.7.0-beta.1" +stylus-sdk = { version = "0.7.0-beta.1", default-features = false } alloy = { version = "=0.7.2", features = [ "contract", diff --git a/contracts/Cargo.toml b/contracts/Cargo.toml index e305a5de9..a307f13ce 100644 --- a/contracts/Cargo.toml +++ b/contracts/Cargo.toml @@ -14,7 +14,7 @@ alloy-sol-types.workspace = true alloy-sol-macro.workspace = true alloy-sol-macro-expander.workspace = true alloy-sol-macro-input.workspace = true -stylus-sdk.workspace = true +stylus-sdk = { workspace = true, default-features = true } keccak-const.workspace = true openzeppelin-stylus-proc.workspace = true @@ -22,6 +22,7 @@ openzeppelin-stylus-proc.workspace = true alloy-primitives = { workspace = true, features = ["arbitrary"] } motsu.workspace = true rand.workspace = true +stylus-sdk.workspace = true [features] # Enables using the standard library. This is not included in the default diff --git a/contracts/src/token/erc721/mod.rs b/contracts/src/token/erc721/mod.rs index adfc6baf6..6ce105031 100644 --- a/contracts/src/token/erc721/mod.rs +++ b/contracts/src/token/erc721/mod.rs @@ -8,11 +8,9 @@ use stylus_sdk::{ call::{self, Call, MethodError}, evm, function_selector, msg, prelude::*, - stylus_proc::sol_interface, }; use crate::utils::{ - context::msg_sender, introspection::erc165::{Erc165, IErc165}, math::storage::{AddAssignUnchecked, SubAssignUnchecked}, }; @@ -505,7 +503,7 @@ impl IErc721 for Erc721 { data: Bytes, ) -> Result<(), Error> { self.transfer_from(from, to, token_id)?; - self._check_on_erc721_received(msg_sender(), from, to, token_id, &data) + self._check_on_erc721_received(msg::sender(), from, to, token_id, &data) } fn transfer_from( @@ -523,7 +521,7 @@ impl IErc721 for Erc721 { // Setting an "auth" argument enables the `_is_authorized` check which // verifies that the token exists (`from != 0`). Therefore, it is // not needed to verify that the return value is not 0 here. - let previous_owner = self._update(to, token_id, msg_sender())?; + let previous_owner = self._update(to, token_id, msg::sender())?; if previous_owner != from { return Err(ERC721IncorrectOwner { sender: from, @@ -536,7 +534,7 @@ impl IErc721 for Erc721 { } fn approve(&mut self, to: Address, token_id: U256) -> Result<(), Error> { - self._approve(to, token_id, msg_sender(), true) + self._approve(to, token_id, msg::sender(), true) } fn set_approval_for_all( @@ -544,7 +542,7 @@ impl IErc721 for Erc721 { operator: Address, approved: bool, ) -> Result<(), Error> { - self._set_approval_for_all(msg_sender(), operator, approved) + self._set_approval_for_all(msg::sender(), operator, approved) } fn get_approved(&self, token_id: U256) -> Result { @@ -825,7 +823,7 @@ impl Erc721 { ) -> Result<(), Error> { self._mint(to, token_id)?; self._check_on_erc721_received( - msg_sender(), + msg::sender(), Address::ZERO, to, token_id, @@ -970,7 +968,7 @@ impl Erc721 { data: &Bytes, ) -> Result<(), Error> { self._transfer(from, to, token_id)?; - self._check_on_erc721_received(msg_sender(), from, to, token_id, data) + self._check_on_erc721_received(msg::sender(), from, to, token_id, data) } /// Approve `to` to operate on `token_id`. @@ -1088,7 +1086,7 @@ impl Erc721 { /// Performs an acceptance check for the provided `operator` by calling /// [`IERC721Receiver::on_erc_721_received`] on the `to` address. The /// `operator` is generally the address that initiated the token transfer - /// (i.e. `msg_sender()`). + /// (i.e. `msg::sender()`). /// /// The acceptance call is not executed and treated as a no-op if the /// target address doesn't contain code (i.e. an EOA). Otherwise, the diff --git a/contracts/src/utils/context.rs b/contracts/src/utils/context.rs deleted file mode 100644 index ca442d36a..000000000 --- a/contracts/src/utils/context.rs +++ /dev/null @@ -1,15 +0,0 @@ -//! Context functions used for mocking unit tests. - -use stylus_sdk::{alloy_primitives::Address, msg}; - -/// Returns the address of the message sender. -#[cfg(test)] -pub fn msg_sender() -> Address { - msg::sender() -} - -/// Returns the address of the message sender. -#[cfg(not(test))] -pub fn msg_sender() -> Address { - msg::sender() -} diff --git a/contracts/src/utils/mod.rs b/contracts/src/utils/mod.rs index 4746849b1..b8f56cef7 100644 --- a/contracts/src/utils/mod.rs +++ b/contracts/src/utils/mod.rs @@ -1,5 +1,4 @@ //! Common Smart Contracts utilities. -pub mod context; pub mod cryptography; pub mod introspection; pub mod math; diff --git a/lib/motsu/Cargo.toml b/lib/motsu/Cargo.toml index d3110fbb9..2376089a2 100644 --- a/lib/motsu/Cargo.toml +++ b/lib/motsu/Cargo.toml @@ -12,7 +12,7 @@ version = "0.2.0" const-hex.workspace = true once_cell.workspace = true tiny-keccak.workspace = true -stylus-sdk = { version = "0.7.0-beta.1", default-features = false } +stylus-sdk.workspace = true motsu-proc.workspace = true dashmap.workspace = true alloy-primitives = { workspace = true, features = ["arbitrary", "rand"] } From b6898fc72d7c4563a08c9c678b5394332ac53854 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Fri, 13 Dec 2024 20:20:02 +0400 Subject: [PATCH 51/57] post merge fix --- contracts/src/access/control.rs | 10 +++++----- contracts/src/finance/vesting_wallet.rs | 2 +- contracts/src/token/erc1155/mod.rs | 2 +- contracts/src/token/erc721/mod.rs | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/contracts/src/access/control.rs b/contracts/src/access/control.rs index 1126461bb..cc50f3d83 100644 --- a/contracts/src/access/control.rs +++ b/contracts/src/access/control.rs @@ -43,8 +43,8 @@ //! this role. use alloc::vec::Vec; -use alloy_primitives::{Address, B256}; -use alloy_sol_types::sol; +use alloy_primitives::{Address, FixedBytes, B256}; +use sol::*; use stylus_sdk::{ evm, msg, prelude::storage, @@ -126,9 +126,6 @@ pub struct AccessControl { #[public] impl AccessControl { - /// The default admin role. `[0; 32]` by default. - pub const DEFAULT_ADMIN_ROLE: [u8; 32] = [0; 32]; - /// Returns `true` if `account` has been granted `role`. /// /// # Arguments @@ -280,6 +277,9 @@ impl AccessControl { } impl AccessControl { + /// The default admin role. `[0; 32]` by default. + pub const DEFAULT_ADMIN_ROLE: [u8; 32] = [0; 32]; + /// Sets `admin_role` as `role`'s admin role. /// /// # Arguments diff --git a/contracts/src/finance/vesting_wallet.rs b/contracts/src/finance/vesting_wallet.rs index 9efc36acf..8265141bd 100644 --- a/contracts/src/finance/vesting_wallet.rs +++ b/contracts/src/finance/vesting_wallet.rs @@ -34,7 +34,7 @@ use stylus_sdk::{ block, call::{self, call, Call}, contract, evm, function_selector, - prelude::storage, + prelude::{sol_interface, storage}, storage::{StorageMap, StorageU256, StorageU64}, stylus_proc::{public, SolidityError}, }; diff --git a/contracts/src/token/erc1155/mod.rs b/contracts/src/token/erc1155/mod.rs index 52b7929bf..389148b2d 100644 --- a/contracts/src/token/erc1155/mod.rs +++ b/contracts/src/token/erc1155/mod.rs @@ -7,7 +7,7 @@ use stylus_sdk::{ abi::Bytes, call::{self, Call, MethodError}, evm, function_selector, msg, - prelude::{public, storage, AddressVM, SolidityError}, + prelude::{public, sol_interface, storage, AddressVM, SolidityError}, storage::{StorageBool, StorageMap, StorageU256}, }; diff --git a/contracts/src/token/erc721/mod.rs b/contracts/src/token/erc721/mod.rs index a7c402139..6e57f511e 100644 --- a/contracts/src/token/erc721/mod.rs +++ b/contracts/src/token/erc721/mod.rs @@ -1,5 +1,5 @@ //! Implementation of the [`Erc721`] token standard. -use alloc::vec; +use alloc::{vec, vec::Vec}; use alloy_primitives::{uint, Address, FixedBytes, U128, U256}; use openzeppelin_stylus_proc::interface_id; From a16de97459369e3d453512461096c2873cb5e5b5 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Fri, 13 Dec 2024 20:24:44 +0400 Subject: [PATCH 52/57] ++ --- contracts/src/utils/pausable.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/contracts/src/utils/pausable.rs b/contracts/src/utils/pausable.rs index 507a13c0f..3ff800dee 100644 --- a/contracts/src/utils/pausable.rs +++ b/contracts/src/utils/pausable.rs @@ -16,7 +16,6 @@ use alloc::vec::Vec; -use alloy_sol_types::sol; pub use sol::*; use stylus_sdk::{ evm, msg, From acd843af700cc4d1cc36796d6be892b486041632 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Fri, 13 Dec 2024 20:25:43 +0400 Subject: [PATCH 53/57] ++ --- contracts/src/access/control.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/src/access/control.rs b/contracts/src/access/control.rs index cc50f3d83..b14199ae5 100644 --- a/contracts/src/access/control.rs +++ b/contracts/src/access/control.rs @@ -44,7 +44,7 @@ use alloc::vec::Vec; use alloy_primitives::{Address, FixedBytes, B256}; -use sol::*; +pub use sol::*; use stylus_sdk::{ evm, msg, prelude::storage, From 9a84c149174fdbbd928ec6da01bec91be47eb73f Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Fri, 13 Dec 2024 21:00:00 +0400 Subject: [PATCH 54/57] post merge fix --- contracts/src/token/erc721/mod.rs | 1 + lib/motsu-proc/src/test.rs | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/contracts/src/token/erc721/mod.rs b/contracts/src/token/erc721/mod.rs index d5c62cea4..a36196edd 100644 --- a/contracts/src/token/erc721/mod.rs +++ b/contracts/src/token/erc721/mod.rs @@ -2540,6 +2540,7 @@ mod tests { } unsafe impl TopLevelStorage for Erc721ReceiverMock {} + unsafe impl TopLevelStorage for Erc721 {} #[motsu::test] fn on_erc721_received( diff --git a/lib/motsu-proc/src/test.rs b/lib/motsu-proc/src/test.rs index 145848c8c..8036c96a2 100644 --- a/lib/motsu-proc/src/test.rs +++ b/lib/motsu-proc/src/test.rs @@ -37,7 +37,7 @@ pub(crate) fn test(_attr: &TokenStream, input: TokenStream) -> TokenStream { // Test case assumes, that contract's variable has `&mut` reference // to contract's type. quote! { - #arg_binding: &mut #contract_ty + #arg_binding: #contract_ty } }); @@ -45,7 +45,7 @@ pub(crate) fn test(_attr: &TokenStream, input: TokenStream) -> TokenStream { arg_binding_and_ty.iter().map(|(_arg_binding, contract_ty)| { // Pass mutable reference to the contract. quote! { - &mut <#contract_ty>::default() + <#contract_ty>::default() } }); @@ -56,7 +56,6 @@ pub(crate) fn test(_attr: &TokenStream, input: TokenStream) -> TokenStream { #( #attrs )* #[test] fn #fn_name() #fn_return_type { - use ::motsu::prelude::DefaultStorage; let test = | #( #contract_arg_defs ),* | #fn_block; let res = test( #( #contract_args ),* ); ::motsu::prelude::Context::current().reset_storage(); From ed41209cdc362a10d1d6dd45c3d9cae16f7928d4 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Wed, 18 Dec 2024 10:51:03 +0400 Subject: [PATCH 55/57] alloy-primitives 0.8.14 -> 0.8.13 --- Cargo.lock | 30 +++++++++++++++--------------- Cargo.toml | 10 +++++----- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 18691b716..8f7a2d15f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -247,9 +247,9 @@ dependencies = [ [[package]] name = "alloy-json-abi" -version = "0.8.14" +version = "0.8.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac4b22b3e51cac09fd2adfcc73b55f447b4df669f983c13f7894ec82b607c63f" +checksum = "1a500037938085feed8a20dbfc8fce58c599db68c948cfae711147175dee392c" dependencies = [ "alloy-primitives", "alloy-sol-type-parser", @@ -311,9 +311,9 @@ dependencies = [ [[package]] name = "alloy-primitives" -version = "0.8.14" +version = "0.8.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9db948902dfbae96a73c2fbf1f7abec62af034ab883e4c777c3fd29702bd6e2c" +checksum = "3aeeb5825c2fc8c2662167058347cd0cafc3cb15bcb5cdb1758a63c2dca0409e" dependencies = [ "alloy-rlp", "arbitrary", @@ -511,9 +511,9 @@ dependencies = [ [[package]] name = "alloy-sol-macro" -version = "0.8.14" +version = "0.8.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bfd7853b65a2b4f49629ec975fee274faf6dff15ab8894c620943398ef283c0" +checksum = "5c0279d09463a4695788a3622fd95443625f7be307422deba4b55dd491a9c7a1" dependencies = [ "alloy-sol-macro-expander", "alloy-sol-macro-input", @@ -525,9 +525,9 @@ dependencies = [ [[package]] name = "alloy-sol-macro-expander" -version = "0.8.14" +version = "0.8.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82ec42f342d9a9261699f8078e57a7a4fda8aaa73c1a212ed3987080e6a9cd13" +checksum = "4feea540fc8233df2ad1156efd744b2075372f43a8f942a68b3b19c8a00e2c12" dependencies = [ "alloy-json-abi", "alloy-sol-macro-input", @@ -544,9 +544,9 @@ dependencies = [ [[package]] name = "alloy-sol-macro-input" -version = "0.8.14" +version = "0.8.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed2c50e6a62ee2b4f7ab3c6d0366e5770a21cad426e109c2f40335a1b3aff3df" +checksum = "2a0ad281f3d1b613af814b66977ee698e443d4644a1510962d0241f26e0e53ae" dependencies = [ "alloy-json-abi", "const-hex", @@ -571,9 +571,9 @@ dependencies = [ [[package]] name = "alloy-sol-types" -version = "0.8.14" +version = "0.8.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9dc0fffe397aa17628160e16b89f704098bf3c9d74d5d369ebc239575936de5" +checksum = "cff34e0682d6665da243a3e81da96f07a2dd50f7e64073e382b1a141f5a2a2f6" dependencies = [ "alloy-json-abi", "alloy-primitives", @@ -2514,7 +2514,7 @@ checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" [[package]] name = "mini-alloc" -version = "0.7.0-beta.1" +version = "0.7.0-rc.1" dependencies = [ "cfg-if", ] @@ -3743,7 +3743,7 @@ dependencies = [ [[package]] name = "stylus-proc" -version = "0.7.0-beta.1" +version = "0.7.0-rc.1" dependencies = [ "alloy-primitives", "alloy-sol-types", @@ -3762,7 +3762,7 @@ dependencies = [ [[package]] name = "stylus-sdk" -version = "0.7.0-beta.1" +version = "0.7.0-rc.1" dependencies = [ "alloy-primitives", "alloy-sol-types", diff --git a/Cargo.toml b/Cargo.toml index 01e12ee23..cd2bf3cf1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -88,11 +88,11 @@ alloy = { version = "=0.7.2", features = [ # Even though `alloy` includes `alloy-primitives` and `alloy-sol-types` we need # to keep both versions for compatibility with the Stylus SDK. Once they start # using `alloy` we can remove these. -alloy-primitives = { version = "=0.8.14", default-features = false } -alloy-sol-types = { version = "=0.8.14", default-features = false } -alloy-sol-macro = { version = "=0.8.14", default-features = false } -alloy-sol-macro-expander = { version = "=0.8.14", default-features = false } -alloy-sol-macro-input = { version = "=0.8.14", default-features = false } +alloy-primitives = { version = "=0.8.13", default-features = false } +alloy-sol-types = { version = "=0.8.13", default-features = false } +alloy-sol-macro = { version = "=0.8.13", default-features = false } +alloy-sol-macro-expander = { version = "=0.8.13", default-features = false } +alloy-sol-macro-input = { version = "=0.8.13", default-features = false } const-hex = { version = "1.11.1", default-features = false } eyre = "0.6.8" From 780c6ec0e9147d2d21f8d55b50d0b94484d4b92b Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Mon, 23 Dec 2024 22:12:41 +0400 Subject: [PATCH 56/57] ++ --- Cargo.lock | 27 +++++++++++++++------------ Cargo.toml | 26 ++++++++++---------------- 2 files changed, 25 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8f7a2d15f..2ce59e36a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -247,9 +247,9 @@ dependencies = [ [[package]] name = "alloy-json-abi" -version = "0.8.13" +version = "0.8.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a500037938085feed8a20dbfc8fce58c599db68c948cfae711147175dee392c" +checksum = "ac4b22b3e51cac09fd2adfcc73b55f447b4df669f983c13f7894ec82b607c63f" dependencies = [ "alloy-primitives", "alloy-sol-type-parser", @@ -311,9 +311,9 @@ dependencies = [ [[package]] name = "alloy-primitives" -version = "0.8.13" +version = "0.8.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3aeeb5825c2fc8c2662167058347cd0cafc3cb15bcb5cdb1758a63c2dca0409e" +checksum = "9db948902dfbae96a73c2fbf1f7abec62af034ab883e4c777c3fd29702bd6e2c" dependencies = [ "alloy-rlp", "arbitrary", @@ -511,9 +511,9 @@ dependencies = [ [[package]] name = "alloy-sol-macro" -version = "0.8.13" +version = "0.8.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c0279d09463a4695788a3622fd95443625f7be307422deba4b55dd491a9c7a1" +checksum = "3bfd7853b65a2b4f49629ec975fee274faf6dff15ab8894c620943398ef283c0" dependencies = [ "alloy-sol-macro-expander", "alloy-sol-macro-input", @@ -525,9 +525,9 @@ dependencies = [ [[package]] name = "alloy-sol-macro-expander" -version = "0.8.13" +version = "0.8.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4feea540fc8233df2ad1156efd744b2075372f43a8f942a68b3b19c8a00e2c12" +checksum = "82ec42f342d9a9261699f8078e57a7a4fda8aaa73c1a212ed3987080e6a9cd13" dependencies = [ "alloy-json-abi", "alloy-sol-macro-input", @@ -544,9 +544,9 @@ dependencies = [ [[package]] name = "alloy-sol-macro-input" -version = "0.8.13" +version = "0.8.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a0ad281f3d1b613af814b66977ee698e443d4644a1510962d0241f26e0e53ae" +checksum = "ed2c50e6a62ee2b4f7ab3c6d0366e5770a21cad426e109c2f40335a1b3aff3df" dependencies = [ "alloy-json-abi", "const-hex", @@ -571,9 +571,9 @@ dependencies = [ [[package]] name = "alloy-sol-types" -version = "0.8.13" +version = "0.8.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cff34e0682d6665da243a3e81da96f07a2dd50f7e64073e382b1a141f5a2a2f6" +checksum = "c9dc0fffe397aa17628160e16b89f704098bf3c9d74d5d369ebc239575936de5" dependencies = [ "alloy-json-abi", "alloy-primitives", @@ -2515,6 +2515,7 @@ checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" [[package]] name = "mini-alloc" version = "0.7.0-rc.1" +source = "git+https://github.com/OffchainLabs/stylus-sdk-rs?branch=rel%2F0.7.0-rc.1#c2698e7bedb8340fa11caf55ee9332a3a53e5574" dependencies = [ "cfg-if", ] @@ -3744,6 +3745,7 @@ dependencies = [ [[package]] name = "stylus-proc" version = "0.7.0-rc.1" +source = "git+https://github.com/OffchainLabs/stylus-sdk-rs?branch=rel%2F0.7.0-rc.1#c2698e7bedb8340fa11caf55ee9332a3a53e5574" dependencies = [ "alloy-primitives", "alloy-sol-types", @@ -3763,6 +3765,7 @@ dependencies = [ [[package]] name = "stylus-sdk" version = "0.7.0-rc.1" +source = "git+https://github.com/OffchainLabs/stylus-sdk-rs?branch=rel%2F0.7.0-rc.1#c2698e7bedb8340fa11caf55ee9332a3a53e5574" dependencies = [ "alloy-primitives", "alloy-sol-types", diff --git a/Cargo.toml b/Cargo.toml index cd2bf3cf1..51fc0a156 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -73,7 +73,7 @@ all = "warn" [workspace.dependencies] # Stylus SDK related -stylus-sdk = { version = "0.7.0-beta.1", default-features = false } +stylus-sdk = { version = "0.7.0-rc.1", default-features = false } alloy = { version = "=0.7.2", features = [ "contract", @@ -88,11 +88,11 @@ alloy = { version = "=0.7.2", features = [ # Even though `alloy` includes `alloy-primitives` and `alloy-sol-types` we need # to keep both versions for compatibility with the Stylus SDK. Once they start # using `alloy` we can remove these. -alloy-primitives = { version = "=0.8.13", default-features = false } -alloy-sol-types = { version = "=0.8.13", default-features = false } -alloy-sol-macro = { version = "=0.8.13", default-features = false } -alloy-sol-macro-expander = { version = "=0.8.13", default-features = false } -alloy-sol-macro-input = { version = "=0.8.13", default-features = false } +alloy-primitives = { version = "=0.8.14", default-features = false } +alloy-sol-types = { version = "=0.8.14", default-features = false } +alloy-sol-macro = { version = "=0.8.14", default-features = false } +alloy-sol-macro-expander = { version = "=0.8.14", default-features = false } +alloy-sol-macro-input = { version = "=0.8.14", default-features = false } const-hex = { version = "1.11.1", default-features = false } eyre = "0.6.8" @@ -150,16 +150,10 @@ default = { extend-ignore-identifiers-re = [ files = { extend-exclude = [] } ## TODO#q: remove this once the fix is released -#[patch.crates-io.stylus-sdk] -#git = "https://github.com/qalisander/stylus-sdk-rs" -#branch = "fix-encoding-in-sol-interface" -# -#[patch.crates-io.stylus-proc] -#git = "https://github.com/qalisander/stylus-sdk-rs" -#branch = "fix-encoding-in-sol-interface" - [patch.crates-io.stylus-sdk] -path = "../stylus-sdk-rs/stylus-sdk" +git = "https://github.com/OffchainLabs/stylus-sdk-rs" +branch = "rel/0.7.0-rc.1" [patch.crates-io.stylus-proc] -path = "../stylus-sdk-rs/stylus-proc" +git = "https://github.com/OffchainLabs/stylus-sdk-rs" +branch = "rel/0.7.0-rc.1" From 297b574e29b2ab41add434c0f76823b778fd108b Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Mon, 23 Dec 2024 23:24:52 +0400 Subject: [PATCH 57/57] patch motsu --- Cargo.lock | 50 ++++++++++++------------- Cargo.toml | 7 +++- contracts/src/finance/vesting_wallet.rs | 2 +- contracts/src/token/erc1155/mod.rs | 2 +- contracts/src/token/erc721/mod.rs | 1 - 5 files changed, 32 insertions(+), 30 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2ce59e36a..0459477be 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,7 +4,7 @@ version = 4 [[package]] name = "access-control-example" -version = "0.2.0-alpha.1" +version = "0.2.0-alpha.2" dependencies = [ "alloy", "alloy-primitives", @@ -902,7 +902,7 @@ checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" [[package]] name = "basic-example" -version = "0.2.0-alpha.1" +version = "0.2.0-alpha.2" dependencies = [ "alloy-primitives", "openzeppelin-stylus", @@ -911,7 +911,7 @@ dependencies = [ [[package]] name = "basic-example-script" -version = "0.2.0-alpha.1" +version = "0.2.0-alpha.2" dependencies = [ "alloy", "alloy-primitives", @@ -922,7 +922,7 @@ dependencies = [ [[package]] name = "benches" -version = "0.2.0-alpha.1" +version = "0.2.0-alpha.2" dependencies = [ "alloy", "alloy-primitives", @@ -1358,7 +1358,7 @@ dependencies = [ [[package]] name = "cryptography-example" -version = "0.2.0-alpha.1" +version = "0.2.0-alpha.2" dependencies = [ "alloy", "alloy-primitives", @@ -1662,7 +1662,7 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "erc1155-example" -version = "0.2.0-alpha.1" +version = "0.2.0-alpha.2" dependencies = [ "alloy", "alloy-primitives", @@ -1675,7 +1675,7 @@ dependencies = [ [[package]] name = "erc1155-metadata-uri-example" -version = "0.2.0-alpha.1" +version = "0.2.0-alpha.2" dependencies = [ "alloy", "alloy-primitives", @@ -1688,7 +1688,7 @@ dependencies = [ [[package]] name = "erc1155-supply-example" -version = "0.2.0-alpha.1" +version = "0.2.0-alpha.2" dependencies = [ "alloy", "alloy-primitives", @@ -1701,7 +1701,7 @@ dependencies = [ [[package]] name = "erc20-example" -version = "0.2.0-alpha.1" +version = "0.2.0-alpha.2" dependencies = [ "alloy", "alloy-primitives", @@ -1714,7 +1714,7 @@ dependencies = [ [[package]] name = "erc20-permit-example" -version = "0.2.0-alpha.1" +version = "0.2.0-alpha.2" dependencies = [ "alloy", "alloy-primitives", @@ -1727,7 +1727,7 @@ dependencies = [ [[package]] name = "erc721-consecutive-example" -version = "0.2.0-alpha.1" +version = "0.2.0-alpha.2" dependencies = [ "alloy", "alloy-primitives", @@ -1742,7 +1742,7 @@ dependencies = [ [[package]] name = "erc721-example" -version = "0.2.0-alpha.1" +version = "0.2.0-alpha.2" dependencies = [ "alloy", "alloy-primitives", @@ -1756,7 +1756,7 @@ dependencies = [ [[package]] name = "erc721-metadata-example" -version = "0.2.0-alpha.1" +version = "0.2.0-alpha.2" dependencies = [ "alloy", "alloy-primitives", @@ -2498,7 +2498,7 @@ dependencies = [ [[package]] name = "merkle-proofs-example" -version = "0.2.0-alpha.1" +version = "0.2.0-alpha.2" dependencies = [ "alloy-primitives", "alloy-sol-types", @@ -2548,7 +2548,8 @@ checksum = "7843ec2de400bcbc6a6328c958dc38e5359da6e93e72e37bc5246bf1ae776389" [[package]] name = "motsu" -version = "0.2.0" +version = "0.2.1" +source = "git+https://github.com/OpenZeppelin/stylus-test-helpers?branch=unit-tests%2Fmultiple-contract-deployment#feb635a55d54463aa51d1c0a81d20903a6cbe99d" dependencies = [ "alloy-primitives", "alloy-sol-types", @@ -2562,14 +2563,11 @@ dependencies = [ [[package]] name = "motsu-proc" -version = "0.2.0" +version = "0.2.1" +source = "git+https://github.com/OpenZeppelin/stylus-test-helpers?branch=unit-tests%2Fmultiple-contract-deployment#feb635a55d54463aa51d1c0a81d20903a6cbe99d" dependencies = [ - "alloy-primitives", - "alloy-sol-types", - "motsu", "proc-macro2", "quote", - "stylus-sdk", "syn 2.0.89", ] @@ -2720,7 +2718,7 @@ dependencies = [ [[package]] name = "openzeppelin-crypto" -version = "0.2.0-alpha.1" +version = "0.2.0-alpha.2" dependencies = [ "crypto-bigint", "educe", @@ -2734,7 +2732,7 @@ dependencies = [ [[package]] name = "openzeppelin-stylus" -version = "0.2.0-alpha.1" +version = "0.2.0-alpha.2" dependencies = [ "alloy-primitives", "alloy-sol-macro", @@ -2760,7 +2758,7 @@ dependencies = [ [[package]] name = "ownable-example" -version = "0.2.0-alpha.1" +version = "0.2.0-alpha.2" dependencies = [ "alloy", "alloy-primitives", @@ -2773,7 +2771,7 @@ dependencies = [ [[package]] name = "ownable-two-step" -version = "0.2.0-alpha.1" +version = "0.2.0-alpha.2" dependencies = [ "alloy", "alloy-primitives", @@ -3417,7 +3415,7 @@ checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "safe-erc20-example" -version = "0.2.0-alpha.1" +version = "0.2.0-alpha.2" dependencies = [ "alloy", "alloy-primitives", @@ -4247,7 +4245,7 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "vesting-wallet-example" -version = "0.2.0-alpha.1" +version = "0.2.0-alpha.2" dependencies = [ "alloy", "alloy-primitives", diff --git a/Cargo.toml b/Cargo.toml index 87b1651a0..9a68b3532 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -148,7 +148,7 @@ default = { extend-ignore-identifiers-re = [ ] } files = { extend-exclude = [] } -## TODO#q: remove this once the fix is released +# TODO#q: remove stylus sdk patch once the fix is released [patch.crates-io.stylus-sdk] git = "https://github.com/OffchainLabs/stylus-sdk-rs" branch = "rel/0.7.0-rc.1" @@ -156,3 +156,8 @@ branch = "rel/0.7.0-rc.1" [patch.crates-io.stylus-proc] git = "https://github.com/OffchainLabs/stylus-sdk-rs" branch = "rel/0.7.0-rc.1" + +# TODO#q: remove motsu patch once update is released +[patch.crates-io.motsu] +git = "https://github.com/OpenZeppelin/stylus-test-helpers" +branch = "unit-tests/multiple-contract-deployment" diff --git a/contracts/src/finance/vesting_wallet.rs b/contracts/src/finance/vesting_wallet.rs index 44b7ef9d2..64da824a8 100644 --- a/contracts/src/finance/vesting_wallet.rs +++ b/contracts/src/finance/vesting_wallet.rs @@ -34,8 +34,8 @@ use stylus_sdk::{ block, call::{self, call, Call}, contract, evm, function_selector, - storage::{StorageMap, StorageU256, StorageU64, TopLevelStorage}, prelude::{sol_interface, storage}, + storage::{StorageMap, StorageU256, StorageU64, TopLevelStorage}, stylus_proc::{public, SolidityError}, }; diff --git a/contracts/src/token/erc1155/mod.rs b/contracts/src/token/erc1155/mod.rs index ac842287c..a8a7ab2e7 100644 --- a/contracts/src/token/erc1155/mod.rs +++ b/contracts/src/token/erc1155/mod.rs @@ -7,8 +7,8 @@ use stylus_sdk::{ abi::Bytes, call::{self, Call, MethodError}, evm, function_selector, msg, - storage::{StorageBool, StorageMap, StorageU256, TopLevelStorage}, prelude::{public, sol_interface, storage, AddressVM, SolidityError}, + storage::{StorageBool, StorageMap, StorageU256, TopLevelStorage}, }; use crate::utils::{ diff --git a/contracts/src/token/erc721/mod.rs b/contracts/src/token/erc721/mod.rs index dbe85c93d..7dd5d55de 100644 --- a/contracts/src/token/erc721/mod.rs +++ b/contracts/src/token/erc721/mod.rs @@ -2545,7 +2545,6 @@ mod tests { } unsafe impl TopLevelStorage for Erc721ReceiverMock {} - unsafe impl TopLevelStorage for Erc721 {} #[motsu::test] fn on_erc721_received(