From 270f5466bee16c090576cb70fedfd1a500e82f27 Mon Sep 17 00:00:00 2001 From: Colin Roberts Date: Wed, 13 Dec 2023 11:20:11 -0700 Subject: [PATCH 1/6] feat: `ArbiterDB` (RwLock wrapper) Includes the three DB traits so we can grab and do read only txs --- Cargo.lock | 21 ++--- arbiter-core/Cargo.toml | 1 + arbiter-core/src/environment/mod.rs | 122 ++++++++++++++++++++++++---- 3 files changed, 116 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0c229484..1475a898 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -264,6 +264,7 @@ dependencies = [ "futures-locks", "futures-timer", "futures-util", + "hashbrown 0.14.3", "hex", "polars", "rand 0.8.5", @@ -2317,9 +2318,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.14.2" +version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f93e7192158dbcda357bdec5fb5788eebf8bbac027f3f33e719d29135ae84156" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" dependencies = [ "ahash 0.8.6", "allocator-api2", @@ -2582,7 +2583,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" dependencies = [ "equivalent", - "hashbrown 0.14.2", + "hashbrown 0.14.3", ] [[package]] @@ -3927,7 +3928,7 @@ dependencies = [ "foreign_vec", "futures", "getrandom 0.2.11", - "hashbrown 0.14.2", + "hashbrown 0.14.3", "itoa", "lz4", "multiversion", @@ -3954,7 +3955,7 @@ dependencies = [ "chrono", "comfy-table", "either", - "hashbrown 0.14.2", + "hashbrown 0.14.3", "indexmap 2.1.0", "num-traits", "once_cell", @@ -4031,7 +4032,7 @@ dependencies = [ "ahash 0.8.6", "chrono", "fallible-streaming-iterator", - "hashbrown 0.14.2", + "hashbrown 0.14.3", "indexmap 2.1.0", "itoa", "num-traits", @@ -4077,7 +4078,7 @@ dependencies = [ "argminmax", "bytemuck", "either", - "hashbrown 0.14.2", + "hashbrown 0.14.3", "indexmap 2.1.0", "memchr", "num-traits", @@ -4126,7 +4127,7 @@ dependencies = [ "crossbeam-channel", "crossbeam-queue", "enum_dispatch", - "hashbrown 0.14.2", + "hashbrown 0.14.3", "num-traits", "polars-arrow", "polars-core", @@ -4219,7 +4220,7 @@ checksum = "da6ce68169fe61d46958c8eab7447360f30f2f23f6e24a0ce703a14b0a3cfbfc" dependencies = [ "ahash 0.8.6", "bytemuck", - "hashbrown 0.14.2", + "hashbrown 0.14.3", "indexmap 2.1.0", "num-traits", "once_cell", @@ -4704,7 +4705,7 @@ dependencies = [ "bitvec", "c-kzg", "enumn", - "hashbrown 0.14.2", + "hashbrown 0.14.3", "hex", "once_cell", "serde", diff --git a/arbiter-core/Cargo.toml b/arbiter-core/Cargo.toml index 1e3944a4..bccf721a 100644 --- a/arbiter-core/Cargo.toml +++ b/arbiter-core/Cargo.toml @@ -14,6 +14,7 @@ readme = "../README.md" ethers.workspace = true revm.workspace = true revm-primitives.workspace = true +hashbrown = "0.14.3" # Serialization bytes = { version = "=1.5.0" } diff --git a/arbiter-core/src/environment/mod.rs b/arbiter-core/src/environment/mod.rs index 8cbf0d9d..065dd967 100644 --- a/arbiter-core/src/environment/mod.rs +++ b/arbiter-core/src/environment/mod.rs @@ -32,7 +32,7 @@ use std::{ convert::Infallible, fmt::Debug, - sync::{Arc, Mutex}, + sync::{Arc, Mutex, RwLock}, thread::{self, JoinHandle}, }; @@ -41,10 +41,11 @@ use ethers::core::types::U64; use revm::{ db::{CacheDB, EmptyDB}, primitives::{ - AccountInfo, EVMError, ExecutionResult, HashMap, InvalidTransaction, Log, TxEnv, U256, + AccountInfo, EVMError, ExecutionResult, HashMap, InvalidTransaction, Log, TxEnv, B256, U256, }, - EVM, + Database, DatabaseCommit, EVM, }; +use revm_primitives::{db::DatabaseRef, Bytecode}; // use hashbrown::{hash_map, HashMap as HashMapBrown}; use serde::{Deserialize, Serialize}; use thiserror::Error; @@ -130,7 +131,7 @@ pub struct Environment { /// The [`EVM`] that is used as an execution environment and database for /// calls and transactions. - db: Option>, + pub(crate) db: Option, /// This gives a means of letting the "outside world" connect to the /// [`Environment`] so that users (or agents) may send and receive data from @@ -143,6 +144,72 @@ pub struct Environment { pub(crate) handle: Option>>, } +#[derive(Clone, Debug)] +pub struct ArbiterDB(Arc>>); + +impl Database for ArbiterDB { + type Error = Infallible; // TODO: Not sure we want this, but it works for now. + + fn basic( + &mut self, + address: revm::primitives::Address, + ) -> Result, Self::Error> { + self.0.read().unwrap().basic(address) + } + + fn code_by_hash(&mut self, code_hash: B256) -> Result { + self.0.read().unwrap().code_by_hash(code_hash) + } + + fn storage( + &mut self, + address: revm::primitives::Address, + index: U256, + ) -> Result { + self.0.read().unwrap().storage(address, index) + } + + fn block_hash(&mut self, number: U256) -> Result { + self.0.read().unwrap().block_hash(number) + } +} + +impl DatabaseRef for ArbiterDB { + type Error = Infallible; // TODO: Not sure we want this, but it works for now. + + fn basic( + &self, + address: revm::primitives::Address, + ) -> Result, Self::Error> { + self.0.read().unwrap().basic(address) + } + + fn code_by_hash(&self, code_hash: B256) -> Result { + self.0.read().unwrap().code_by_hash(code_hash) + } + + fn storage( + &self, + address: revm::primitives::Address, + index: U256, + ) -> Result { + self.0.read().unwrap().storage(address, index) + } + + fn block_hash(&self, number: U256) -> Result { + self.0.read().unwrap().block_hash(number) + } +} + +impl DatabaseCommit for ArbiterDB { + fn commit( + &mut self, + changes: hashbrown::HashMap, + ) { + self.0.write().unwrap().commit(changes) + } +} + /// Allow the end user to be able to access a debug printout for the /// [`Environment`]. Note that the [`EVM`] does not implement debug display, /// hence the implementation by hand here. @@ -170,6 +237,7 @@ impl Environment { instruction_receiver, event_broadcaster: Arc::new(Mutex::new(EventBroadcaster::new())), }; + let db = db.map(|db| ArbiterDB(Arc::new(RwLock::new(db)))); Self { parameters: environment_parameters, @@ -187,9 +255,11 @@ impl Environment { let mut evm = EVM::new(); if self.db.is_some() { - evm.database(self.db.take().unwrap()); + evm.database(self.db.as_ref().unwrap().clone()); } else { - evm.database(CacheDB::new(EmptyDB::new())); + evm.database(ArbiterDB(Arc::new(RwLock::new(CacheDB::new( + EmptyDB::new(), + ))))); }; // Choose extra large code size and gas limit @@ -265,7 +335,13 @@ impl Environment { account_state: revm::db::AccountState::None, storage: HashMap::new(), }; - match db.accounts.insert(recast_address, account) { + match db + .0 + .write() + .unwrap() + .accounts + .insert(recast_address, account) + { None => { outcome_sender .send(Ok(Outcome::AddAccountCompleted)) @@ -324,7 +400,7 @@ impl Environment { let recast_key = revm::primitives::B256::from(key.as_fixed_bytes()); // Get the account storage value at the key in the db. - match db.accounts.get_mut(&recast_address) { + match db.0.write().unwrap().accounts.get_mut(&recast_address) { Some(account) => { // Returns zero if the account is missing. let value: revm::primitives::U256 = match account @@ -375,7 +451,7 @@ impl Environment { // Mutate the db by inserting the new key-value pair into the account's // storage and send the successful // CheatcodeCompleted outcome. - match db.accounts.get_mut(&recast_address) { + match db.0.write().unwrap().accounts.get_mut(&recast_address) { Some(account) => { account .storage @@ -402,7 +478,7 @@ impl Environment { let db = evm.db.as_mut().unwrap(); let recast_address = revm::primitives::Address::from(address.as_fixed_bytes()); - match db.accounts.get_mut(&recast_address) { + match db.0.write().unwrap().accounts.get_mut(&recast_address) { Some(account) => { account.info.balance += U256::from_limbs(amount.0); outcome_sender @@ -427,7 +503,7 @@ impl Environment { let recast_address = revm::primitives::Address::from(address.as_fixed_bytes()); - match db.accounts.get(&recast_address) { + match db.0.write().unwrap().accounts.get(&recast_address) { Some(account) => { let account_state = match account.account_state { revm::db::AccountState::None => { @@ -476,7 +552,7 @@ impl Environment { // Set the tx_env and prepare to process it evm.env.tx = tx_env; - let result = evm.transact()?.result; + let result = evm.transact_ref()?.result; outcome_sender .send(Ok(Outcome::CallCompleted(result))) .map_err(|e| EnvironmentError::Communication(e.to_string()))?; @@ -602,9 +678,14 @@ impl Environment { EnvironmentData::Balance(address) => { // This unwrap should never fail. let db = evm.db().unwrap(); - match db.accounts.get::( - &address.as_fixed_bytes().into(), - ) { + match db + .0 + .write() + .unwrap() + .accounts + .get::( + &address.as_fixed_bytes().into(), + ) { Some(account) => { Ok(Outcome::QueryReturn(account.info.balance.to_string())) } @@ -616,9 +697,14 @@ impl Environment { EnvironmentData::TransactionCount(address) => { let db = evm.db().unwrap(); - match db.accounts.get::( - &address.as_fixed_bytes().into(), - ) { + match db + .0 + .write() + .unwrap() + .accounts + .get::( + &address.as_fixed_bytes().into(), + ) { Some(account) => { Ok(Outcome::QueryReturn(account.info.nonce.to_string())) } From d4aace60dd9e848a778d22f410c68e4b60beb69a Mon Sep 17 00:00:00 2001 From: Colin Roberts Date: Wed, 13 Dec 2023 11:49:52 -0700 Subject: [PATCH 2/6] feat: `coprocessor` scaffold --- arbiter-core/src/coprocessor.rs | 35 +++++++++++++++++++++++++++++++++ arbiter-core/src/lib.rs | 1 + 2 files changed, 36 insertions(+) create mode 100644 arbiter-core/src/coprocessor.rs diff --git a/arbiter-core/src/coprocessor.rs b/arbiter-core/src/coprocessor.rs new file mode 100644 index 00000000..6dcd6f67 --- /dev/null +++ b/arbiter-core/src/coprocessor.rs @@ -0,0 +1,35 @@ +use std::convert::Infallible; + +use revm::EVM; +use revm_primitives::{EVMError, ResultAndState}; + +use crate::environment::{ArbiterDB, Environment}; + +pub struct Coprocessor { + evm: EVM, +} + +impl Coprocessor { + pub fn new(environment: &Environment) -> Self { + let db = environment.db.as_ref().unwrap().clone(); + let mut evm = EVM::new(); + evm.database(db); + Self { evm } + } + + pub fn transact_ref(&self) -> Result> { + self.evm.transact_ref() + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::environment::builder::EnvironmentBuilder; + + #[test] + fn coprocessor() { + let environment = EnvironmentBuilder::new().build(); + let coprocessor = Coprocessor::new(&environment); + } +} diff --git a/arbiter-core/src/lib.rs b/arbiter-core/src/lib.rs index 8a75394d..38c4c4ec 100644 --- a/arbiter-core/src/lib.rs +++ b/arbiter-core/src/lib.rs @@ -31,6 +31,7 @@ #![warn(missing_docs)] +pub mod coprocessor; pub mod data_collection; pub mod environment; pub mod math; From 33c82b2376ffa3f516bae94ad0a84db1c136372d Mon Sep 17 00:00:00 2001 From: Colin Roberts Date: Wed, 13 Dec 2023 13:20:25 -0700 Subject: [PATCH 3/6] save state for serialize --- arbiter-core/src/environment/mod.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/arbiter-core/src/environment/mod.rs b/arbiter-core/src/environment/mod.rs index 065dd967..91cedbd3 100644 --- a/arbiter-core/src/environment/mod.rs +++ b/arbiter-core/src/environment/mod.rs @@ -47,7 +47,7 @@ use revm::{ }; use revm_primitives::{db::DatabaseRef, Bytecode}; // use hashbrown::{hash_map, HashMap as HashMapBrown}; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, Serializer}; use thiserror::Error; use super::*; @@ -144,9 +144,25 @@ pub struct Environment { pub(crate) handle: Option>>, } +use serde::ser::SerializeStruct; + #[derive(Clone, Debug)] pub struct ArbiterDB(Arc>>); +impl Serialize for ArbiterDB { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + let db = self.0.read().unwrap(); + let mut state = serializer.serialize_struct("ArbiterDB", 2)?; + let accounts = db.accounts; + state.serialize_field("accounts", &db.accounts)?; + state.serialize_field("contracts", &db.contracts)?; + state.end() + } +} + impl Database for ArbiterDB { type Error = Infallible; // TODO: Not sure we want this, but it works for now. From 39e9b5c996474f001ebd6705c328da2494c57c92 Mon Sep 17 00:00:00 2001 From: Colin Roberts Date: Wed, 20 Dec 2023 18:17:52 -0700 Subject: [PATCH 4/6] `arbiter-core` compiling --- Cargo.lock | 499 ++++++++++++++++++++-------- Cargo.toml | 16 +- arbiter-core/Cargo.toml | 4 +- arbiter-core/src/environment/mod.rs | 42 +-- arbiter-engine/Cargo.toml | 2 +- 5 files changed, 390 insertions(+), 173 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b836606c..0a547b92 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -106,6 +106,25 @@ dependencies = [ "hex-literal", "itoa", "ruint", + "tiny-keccak", +] + +[[package]] +name = "alloy-primitives" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c0e5e60ff0e0c34c553822dabcfe0f5fece5a8c52f08a915be8c737de4b03fa" +dependencies = [ + "alloy-rlp", + "bytes", + "cfg-if", + "const-hex", + "derive_more", + "hex-literal", + "itoa", + "proptest", + "rand 0.8.5", + "ruint", "serde", "tiny-keccak", ] @@ -130,7 +149,7 @@ checksum = "c0391754c09fab4eae3404d19d0d297aa1c670c1775ab51d8a5312afeca23157" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.42", ] [[package]] @@ -198,9 +217,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.75" +version = "1.0.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" +checksum = "59d2a3357dde987206219e78ecfbbb6e8dad06cbb65292758d3270e6254f7355" [[package]] name = "approx" @@ -226,10 +245,10 @@ dependencies = [ "quote", "rayon", "revm", - "revm-primitives", + "revm-primitives 1.3.0 (git+https://github.com/bluealloy/revm.git)", "serde", "serde_json", - "syn 2.0.39", + "syn 2.0.42", "tempfile", "thiserror", "tokio", @@ -254,7 +273,7 @@ dependencies = [ "assert_matches", "async-trait", "bytes", - "cargo_metadata 0.18.1", + "cargo_metadata", "chrono", "crossbeam-channel", "ethers", @@ -268,7 +287,7 @@ dependencies = [ "rand 0.8.5", "rand_distr", "revm", - "revm-primitives", + "revm-primitives 1.3.0 (git+https://github.com/bluealloy/revm.git)", "serde", "serde_json", "statrs", @@ -285,7 +304,7 @@ version = "0.1.3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.42", ] [[package]] @@ -317,6 +336,130 @@ dependencies = [ "num-traits", ] +[[package]] +name = "ark-ff" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b3235cc41ee7a12aaaf2c575a2ad7b46713a8a50bda2fc3b003a04845c05dd6" +dependencies = [ + "ark-ff-asm 0.3.0", + "ark-ff-macros 0.3.0", + "ark-serialize 0.3.0", + "ark-std 0.3.0", + "derivative", + "num-bigint", + "num-traits", + "paste", + "rustc_version 0.3.3", + "zeroize", +] + +[[package]] +name = "ark-ff" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec847af850f44ad29048935519032c33da8aa03340876d351dfab5660d2966ba" +dependencies = [ + "ark-ff-asm 0.4.2", + "ark-ff-macros 0.4.2", + "ark-serialize 0.4.2", + "ark-std 0.4.0", + "derivative", + "digest 0.10.7", + "itertools 0.10.5", + "num-bigint", + "num-traits", + "paste", + "rustc_version 0.4.0", + "zeroize", +] + +[[package]] +name = "ark-ff-asm" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db02d390bf6643fb404d3d22d31aee1c4bc4459600aef9113833d17e786c6e44" +dependencies = [ + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ark-ff-asm" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ed4aa4fe255d0bc6d79373f7e31d2ea147bcf486cba1be5ba7ea85abdb92348" +dependencies = [ + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ark-ff-macros" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db2fd794a08ccb318058009eefdf15bcaaaaf6f8161eb3345f907222bac38b20" +dependencies = [ + "num-bigint", + "num-traits", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ark-ff-macros" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7abe79b0e4288889c4574159ab790824d0033b9fdcb2a112a3182fac2e514565" +dependencies = [ + "num-bigint", + "num-traits", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ark-serialize" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d6c2b318ee6e10f8c2853e73a83adc0ccb88995aa978d8a3408d492ab2ee671" +dependencies = [ + "ark-std 0.3.0", + "digest 0.9.0", +] + +[[package]] +name = "ark-serialize" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adb7b85a02b83d2f22f89bd5cac66c9c89474240cb6207cb1efc16d098e822a5" +dependencies = [ + "ark-std 0.4.0", + "digest 0.10.7", + "num-bigint", +] + +[[package]] +name = "ark-std" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1df2c09229cbc5a028b1d70e00fdb2acee28b1055dfb5ca73eea49c5a25c4e7c" +dependencies = [ + "num-traits", + "rand 0.8.5", +] + +[[package]] +name = "ark-std" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94893f1e0c6eeab764ade8dc4c0db24caf4fe7cbbaafc0eba0a9030f447b5185" +dependencies = [ + "num-traits", + "rand 0.8.5", +] + [[package]] name = "array-init-cursor" version = "0.2.0" @@ -443,7 +586,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.42", ] [[package]] @@ -454,7 +597,7 @@ checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.42", ] [[package]] @@ -465,7 +608,7 @@ checksum = "b6d7b9decdf35d8908a7e3ef02f64c5e9b1695e230154c0e8de3969142d9b94c" dependencies = [ "futures", "pharos", - "rustc_version", + "rustc_version 0.4.0", ] [[package]] @@ -492,6 +635,16 @@ dependencies = [ "bytemuck", ] +[[package]] +name = "aurora-engine-modexp" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfacad86e9e138fca0670949eb8ed4ffdf73a55bded8887efe0863cd1a3a6f70" +dependencies = [ + "hex", + "num", +] + [[package]] name = "auto_impl" version = "1.1.0" @@ -597,7 +750,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.39", + "syn 2.0.42", "which", ] @@ -751,7 +904,7 @@ checksum = "965ab7eb5f8f97d2a083c799f3a1b994fc397b2fe2da5d1da1626ce15a39f2b1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.42", ] [[package]] @@ -792,9 +945,9 @@ dependencies = [ [[package]] name = "c-kzg" -version = "0.1.1" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac926d808fb72fe09ebf471a091d6d72918876ccf0b4989766093d2d0d24a0ef" +checksum = "32700dc7904064bb64e857d38a1766607372928e2466ee5f02a869829b3297d7" dependencies = [ "bindgen", "blst", @@ -823,20 +976,6 @@ dependencies = [ "serde", ] -[[package]] -name = "cargo_metadata" -version = "0.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7daec1a2a2129eeba1644b220b4647ec537b0b5d4bfd6876fcc5a540056b592" -dependencies = [ - "camino", - "cargo-platform", - "semver", - "serde", - "serde_json", - "thiserror", -] - [[package]] name = "cargo_metadata" version = "0.18.1" @@ -845,7 +984,7 @@ checksum = "2d886547e41f740c616ae73108f6eb70afe6d940c7bc697cb30f13daec073037" dependencies = [ "camino", "cargo-platform", - "semver", + "semver 1.0.20", "serde", "serde_json", "thiserror", @@ -942,7 +1081,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.42", ] [[package]] @@ -1116,9 +1255,9 @@ dependencies = [ [[package]] name = "crossbeam-channel" -version = "0.5.8" +version = "0.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200" +checksum = "14c3242926edf34aec4ac3a77108ad4854bffaa2e4ddc1824124ce59231302d5" dependencies = [ "cfg-if", "crossbeam-utils", @@ -1160,9 +1299,9 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.16" +version = "0.8.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294" +checksum = "c06d96137f14f244c37f989d9fff8f95e6c18b918e71f36638f8c49112e4c78f" dependencies = [ "cfg-if", ] @@ -1251,6 +1390,17 @@ dependencies = [ "powerfmt", ] +[[package]] +name = "derivative" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "derive_more" version = "0.99.17" @@ -1260,7 +1410,7 @@ dependencies = [ "convert_case", "proc-macro2", "quote", - "rustc_version", + "rustc_version 0.4.0", "syn 1.0.109", ] @@ -1385,9 +1535,9 @@ checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" [[package]] name = "elliptic-curve" -version = "0.13.6" +version = "0.13.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d97ca172ae9dc9f9b779a6e3a65d308f2af74e5b8c921299075bdb4a0370e914" +checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" dependencies = [ "base16ct", "crypto-bigint", @@ -1447,7 +1597,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.42", ] [[package]] @@ -1458,7 +1608,7 @@ checksum = "c2ad8cef1d801a4686bfd8919f0b30eac4c8e48968c437a6405ded4fb5272d2b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.42", ] [[package]] @@ -1558,9 +1708,9 @@ dependencies = [ [[package]] name = "ethers" -version = "2.0.10" +version = "2.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ad13497f6e0a24292fc7b408e30d22fe9dc262da1f40d7b542c3a44e7fc0476" +checksum = "1a5344eea9b20effb5efeaad29418215c4d27017639fd1f908260f59cbbd226e" dependencies = [ "ethers-addressbook", "ethers-contract", @@ -1574,9 +1724,9 @@ dependencies = [ [[package]] name = "ethers-addressbook" -version = "2.0.10" +version = "2.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6e9e8acd0ed348403cc73a670c24daba3226c40b98dc1a41903766b3ab6240a" +checksum = "8c405f24ea3a517899ba7985385c43dc4a7eb1209af3b1e0a1a32d7dcc7f8d09" dependencies = [ "ethers-core", "once_cell", @@ -1586,9 +1736,9 @@ dependencies = [ [[package]] name = "ethers-contract" -version = "2.0.10" +version = "2.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d79269278125006bb0552349c03593ffa9702112ca88bc7046cc669f148fb47c" +checksum = "0111ead599d17a7bff6985fd5756f39ca7033edc79a31b23026a8d5d64fa95cd" dependencies = [ "const-hex", "ethers-contract-abigen", @@ -1605,9 +1755,9 @@ dependencies = [ [[package]] name = "ethers-contract-abigen" -version = "2.0.10" +version = "2.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce95a43c939b2e4e2f3191c5ad4a1f279780b8a39139c9905b43a7433531e2ab" +checksum = "51258120c6b47ea9d9bec0d90f9e8af71c977fbefbef8213c91bfed385fe45eb" dependencies = [ "Inflector", "const-hex", @@ -1622,16 +1772,16 @@ dependencies = [ "reqwest", "serde", "serde_json", - "syn 2.0.39", - "toml 0.7.8", + "syn 2.0.42", + "toml 0.8.8", "walkdir", ] [[package]] name = "ethers-contract-derive" -version = "2.0.10" +version = "2.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9ce44906fc871b3ee8c69a695ca7ec7f70e50cb379c9b9cb5e532269e492f6" +checksum = "936e7a0f1197cee2b62dc89f63eff3201dbf87c283ff7e18d86d38f83b845483" dependencies = [ "Inflector", "const-hex", @@ -1640,18 +1790,18 @@ dependencies = [ "proc-macro2", "quote", "serde_json", - "syn 2.0.39", + "syn 2.0.42", ] [[package]] name = "ethers-core" -version = "2.0.10" +version = "2.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0a17f0708692024db9956b31d7a20163607d2745953f5ae8125ab368ba280ad" +checksum = "2f03e0bdc216eeb9e355b90cf610ef6c5bb8aca631f97b5ae9980ce34ea7878d" dependencies = [ "arrayvec", "bytes", - "cargo_metadata 0.17.0", + "cargo_metadata", "chrono", "const-hex", "elliptic-curve", @@ -1666,7 +1816,7 @@ dependencies = [ "serde", "serde_json", "strum", - "syn 2.0.39", + "syn 2.0.42", "tempfile", "thiserror", "tiny-keccak", @@ -1675,13 +1825,14 @@ dependencies = [ [[package]] name = "ethers-etherscan" -version = "2.0.10" +version = "2.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e53451ea4a8128fbce33966da71132cf9e1040dcfd2a2084fd7733ada7b2045" +checksum = "abbac2c890bdbe0f1b8e549a53b00e2c4c1de86bb077c1094d1f38cdf9381a56" dependencies = [ + "chrono", "ethers-core", "reqwest", - "semver", + "semver 1.0.20", "serde", "serde_json", "thiserror", @@ -1708,9 +1859,9 @@ dependencies = [ [[package]] name = "ethers-middleware" -version = "2.0.10" +version = "2.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "473f1ccd0c793871bbc248729fa8df7e6d2981d6226e4343e3bbaa9281074d5d" +checksum = "681ece6eb1d10f7cf4f873059a77c04ff1de4f35c63dd7bccde8f438374fcb93" dependencies = [ "async-trait", "auto_impl", @@ -1735,9 +1886,9 @@ dependencies = [ [[package]] name = "ethers-providers" -version = "2.0.10" +version = "2.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6838fa110e57d572336178b7c79e94ff88ef976306852d8cb87d9e5b1fc7c0b5" +checksum = "25d6c0c9455d93d4990c06e049abf9b30daf148cf461ee939c11d88907c60816" dependencies = [ "async-trait", "auto_impl", @@ -1773,9 +1924,9 @@ dependencies = [ [[package]] name = "ethers-signers" -version = "2.0.10" +version = "2.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ea44bec930f12292866166f9ddbea6aa76304850e4d8dcd66dc492b43d00ff1" +checksum = "0cb1b714e227bbd2d8c53528adb580b203009728b17d0d0e4119353aa9bc5532" dependencies = [ "async-trait", "coins-bip32", @@ -1792,9 +1943,9 @@ dependencies = [ [[package]] name = "ethers-solc" -version = "2.0.10" +version = "2.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de34e484e7ae3cab99fbfd013d6c5dc7f9013676a4e0e414d8b12e1213e8b3ba" +checksum = "a64f710586d147864cff66540a6d64518b9ff37d73ef827fee430538265b595f" dependencies = [ "cfg-if", "const-hex", @@ -1810,7 +1961,7 @@ dependencies = [ "path-slash", "rayon", "regex", - "semver", + "semver 1.0.20", "serde", "serde_json", "sha2", @@ -1874,6 +2025,17 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" +[[package]] +name = "fastrlp" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "139834ddba373bbdd213dffe02c8d110508dcf1726c2be27e8d1f7d7e1856418" +dependencies = [ + "arrayvec", + "auto_impl", + "bytes", +] + [[package]] name = "ff" version = "0.13.0" @@ -2003,8 +2165,8 @@ dependencies = [ "path-slash", "regex", "reqwest", - "revm-primitives", - "semver", + "revm-primitives 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "semver 1.0.20", "serde", "serde_json", "serde_regex", @@ -2113,7 +2275,7 @@ checksum = "53b153fd91e4b0147f4aced87be237c98248656bb01050b96bf3ee89220a8ddb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.42", ] [[package]] @@ -2861,9 +3023,9 @@ dependencies = [ [[package]] name = "k256" -version = "0.13.1" +version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cadb76004ed8e97623117f3df85b17aaa6626ab0b0831e6573f104df16cd1bcc" +checksum = "3f01b677d82ef7a676aa37e099defd83a28e15687112cafdd112d60236b6115b" dependencies = [ "cfg-if", "ecdsa", @@ -3429,7 +3591,7 @@ dependencies = [ "proc-macro-crate 2.0.0", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.42", ] [[package]] @@ -3449,9 +3611,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.18.0" +version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "opaque-debug" @@ -3521,7 +3683,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.42", ] [[package]] @@ -3700,7 +3862,7 @@ dependencies = [ "proc-macro2", "proc-macro2-diagnostics", "quote", - "syn 2.0.39", + "syn 2.0.42", ] [[package]] @@ -3755,7 +3917,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.42", ] [[package]] @@ -3786,7 +3948,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e9567389417feee6ce15dd6527a8a1ecac205ef62c2932bcf3d9f6fc5b78b414" dependencies = [ "futures", - "rustc_version", + "rustc_version 0.4.0", ] [[package]] @@ -3819,7 +3981,7 @@ dependencies = [ "phf_shared 0.11.2", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.42", ] [[package]] @@ -3875,7 +4037,7 @@ checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.42", ] [[package]] @@ -3956,7 +4118,7 @@ dependencies = [ "num-traits", "polars-error", "polars-utils", - "rustc_version", + "rustc_version 0.4.0", "ryu", "simdutf8", "streaming-iterator", @@ -4305,7 +4467,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae005bd773ab59b4725093fd7df83fd7892f7d8eafb48dbd7de6e024e4215f9d" dependencies = [ "proc-macro2", - "syn 2.0.39", + "syn 2.0.42", ] [[package]] @@ -4367,9 +4529,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.69" +version = "1.0.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" +checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" dependencies = [ "unicode-ident", ] @@ -4382,7 +4544,7 @@ checksum = "af066a9c399a26e020ada66a034357a868728e72cd426f3adcd35f80d88d88c8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.42", "version_check", "yansi 1.0.0-rc.1", ] @@ -4393,6 +4555,8 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "31b476131c3c86cb68032fdc5cb6d5a1045e3e42d96b69fa599fd77701e1f5bf" dependencies = [ + "bit-set", + "bit-vec", "bitflags 2.4.1", "lazy_static", "num-traits", @@ -4400,9 +4564,17 @@ dependencies = [ "rand_chacha 0.3.1", "rand_xorshift", "regex-syntax 0.8.2", + "rusty-fork", + "tempfile", "unarray", ] +[[package]] +name = "quick-error" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" + [[package]] name = "quote" version = "1.0.33" @@ -4571,7 +4743,7 @@ checksum = "7f7473c2cfcf90008193dd0e3e16599455cb601a9fce322b5bb55de799664925" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.42", ] [[package]] @@ -4672,8 +4844,7 @@ dependencies = [ [[package]] name = "revm" version = "3.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68f4ca8ae0345104523b4af1a8a7ea97cfa1865cdb7a7c25d23c1a18d9b48598" +source = "git+https://github.com/bluealloy/revm.git#67331de7aae47499a35e1907a67692c9d923aa15" dependencies = [ "auto_impl", "ethers-core", @@ -4689,24 +4860,22 @@ dependencies = [ [[package]] name = "revm-interpreter" version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f959cafdf64a7f89b014fa73dc2325001cf654b3d9400260b212d19a2ebe3da0" +source = "git+https://github.com/bluealloy/revm.git#67331de7aae47499a35e1907a67692c9d923aa15" dependencies = [ - "revm-primitives", + "revm-primitives 1.3.0 (git+https://github.com/bluealloy/revm.git)", "serde", ] [[package]] name = "revm-precompile" version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d360a88223d85709d2e95d4609eb1e19c649c47e28954bfabae5e92bb37e83e" +source = "git+https://github.com/bluealloy/revm.git#67331de7aae47499a35e1907a67692c9d923aa15" dependencies = [ + "aurora-engine-modexp", "c-kzg", "k256", - "num", "once_cell", - "revm-primitives", + "revm-primitives 1.3.0 (git+https://github.com/bluealloy/revm.git)", "ripemd", "secp256k1", "sha2", @@ -4719,12 +4888,28 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51187b852d9e458816a2e19c81f1dd6c924077e1a8fccd16e4f044f865f299d7" dependencies = [ - "alloy-primitives", + "alloy-primitives 0.4.2", + "alloy-rlp", + "auto_impl", + "bitflags 2.4.1", + "bitvec", + "enumn", + "hashbrown 0.14.3", + "hex", +] + +[[package]] +name = "revm-primitives" +version = "1.3.0" +source = "git+https://github.com/bluealloy/revm.git#67331de7aae47499a35e1907a67692c9d923aa15" +dependencies = [ + "alloy-primitives 0.5.3", "alloy-rlp", "auto_impl", "bitflags 2.4.1", "bitvec", "c-kzg", + "derive_more", "enumn", "hashbrown 0.14.3", "hex", @@ -4815,13 +5000,22 @@ dependencies = [ [[package]] name = "ruint" -version = "1.11.0" +version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "724fd11728a3804e9944b14cab63825024c40bf42f8af87c8b5d97c4bbacf426" +checksum = "608a5726529f2f0ef81b8fde9873c4bb829d6b5b5ca6be4d97345ddf0749c825" dependencies = [ "alloy-rlp", + "ark-ff 0.3.0", + "ark-ff 0.4.2", + "bytes", + "fastrlp", + "num-bigint", + "num-traits", + "parity-scale-codec", + "primitive-types", "proptest", "rand 0.8.5", + "rlp", "ruint-macro", "serde", "valuable", @@ -4862,13 +5056,22 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3e75f6a532d0fd9f7f13144f392b6ad56a32696bfcd9c78f797f16bbb6f072d6" +[[package]] +name = "rustc_version" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0dfe2087c51c460008730de8b57e6a320782fbfb312e1f4d520e6c6fae155ee" +dependencies = [ + "semver 0.11.0", +] + [[package]] name = "rustc_version" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" dependencies = [ - "semver", + "semver 1.0.20", ] [[package]] @@ -4955,6 +5158,18 @@ version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" +[[package]] +name = "rusty-fork" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb3dcc6e454c328bb824492db107ab7c0ae8fcffe4ad210136ef014458c1bc4f" +dependencies = [ + "fnv", + "quick-error", + "tempfile", + "wait-timeout", +] + [[package]] name = "ryu" version = "1.0.15" @@ -5065,18 +5280,18 @@ dependencies = [ [[package]] name = "secp256k1" -version = "0.27.0" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25996b82292a7a57ed3508f052cfff8640d38d32018784acd714758b43da9c8f" +checksum = "2acea373acb8c21ecb5a23741452acd2593ed44ee3d343e72baaa143bc89d0d5" dependencies = [ "secp256k1-sys", ] [[package]] name = "secp256k1-sys" -version = "0.8.1" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70a129b9e9efbfb223753b9163c4ab3b13cff7fd9c7f010fbac25ab4099fa07e" +checksum = "4dd97a086ec737e30053fd5c46f097465d25bb81dd3608825f65298c4c98be83" dependencies = [ "cc", ] @@ -5104,6 +5319,15 @@ dependencies = [ "libc", ] +[[package]] +name = "semver" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6" +dependencies = [ + "semver-parser", +] + [[package]] name = "semver" version = "1.0.20" @@ -5113,6 +5337,15 @@ dependencies = [ "serde", ] +[[package]] +name = "semver-parser" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0bef5b7f9e0df16536d3961cfb6e84331c065b4066afb39768d0e319411f7" +dependencies = [ + "pest", +] + [[package]] name = "send_wrapper" version = "0.4.0" @@ -5133,22 +5366,22 @@ checksum = "a3f0bf26fd526d2a95683cd0f87bf103b8539e2ca1ef48ce002d67aad59aa0b4" [[package]] name = "serde" -version = "1.0.192" +version = "1.0.193" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bca2a08484b285dcb282d0f67b26cadc0df8b19f8c12502c13d966bf9482f001" +checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.192" +version = "1.0.193" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6c7207fbec9faa48073f3e3074cbe553af6ea512d7c21ba46e434e70ea9fbc1" +checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.42", ] [[package]] @@ -5429,9 +5662,9 @@ dependencies = [ [[package]] name = "solang-parser" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cb9fa2fa2fa6837be8a2495486ff92e3ffe68a99b6eeba288e139efdd842457" +checksum = "c425ce1c59f4b154717592f0bdf4715c3a1d55058883622d3157e1f0908a5b26" dependencies = [ "itertools 0.11.0", "lalrpop", @@ -5553,7 +5786,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.39", + "syn 2.0.42", ] [[package]] @@ -5586,7 +5819,7 @@ dependencies = [ "hex", "once_cell", "reqwest", - "semver", + "semver 1.0.20", "serde", "serde_json", "sha2", @@ -5603,7 +5836,7 @@ checksum = "aa64b5e8eecd3a8af7cfc311e29db31a268a62d5953233d3e8243ec77a71c4e3" dependencies = [ "build_const", "hex", - "semver", + "semver 1.0.20", "serde_json", "svm-rs", ] @@ -5621,9 +5854,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.39" +version = "2.0.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" +checksum = "5b7d0a2c048d661a1a59fcd7355baa232f7ed34e0ee4df2eef3c1c1c0d3852d8" dependencies = [ "proc-macro2", "quote", @@ -5725,27 +5958,27 @@ checksum = "7ba277e77219e9eea169e8508942db1bf5d8a41ff2db9b20aab5a5aadc9fa25d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.42", ] [[package]] name = "thiserror" -version = "1.0.50" +version = "1.0.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2" +checksum = "f11c217e1416d6f036b870f14e0413d480dbf28edbee1f877abaf0206af43bb7" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.50" +version = "1.0.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" +checksum = "01742297787513b79cf8e29d1056ede1313e2420b7b3b15d0a768b4921f549df" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.42", ] [[package]] @@ -5847,7 +6080,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.42", ] [[package]] @@ -6068,7 +6301,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.42", ] [[package]] @@ -6406,7 +6639,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.42", "wasm-bindgen-shared", ] @@ -6440,7 +6673,7 @@ checksum = "c5353b8dab669f5e10f5bd76df26a9360c748f054f862ff5f3f8aae0c7fb3907" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.42", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -6657,7 +6890,7 @@ dependencies = [ "js-sys", "log", "pharos", - "rustc_version", + "rustc_version 0.4.0", "send_wrapper 0.6.0", "thiserror", "wasm-bindgen", @@ -6718,14 +6951,14 @@ checksum = "c2f140bda219a26ccc0cdb03dba58af72590c53b22642577d88a927bc5c87d6b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.42", ] [[package]] name = "zeroize" -version = "1.6.0" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9" +checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" dependencies = [ "zeroize_derive", ] @@ -6738,7 +6971,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.42", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index cd4bb8b9..a4c30ba4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,18 +21,18 @@ name = "arbiter" path = "bin/main.rs" [workspace.dependencies] -ethers = { version = "=2.0.10" } -serde = { version = "=1.0.192", features = ["derive"] } +ethers = { version = "2.0.11" } +serde = { version = "1.0.193", features = ["derive"] } serde_json = { version = "=1.0.108" } -revm = { version = "=3.5.0", features = [ "ethersdb", "std", "serde"] } -revm-primitives = { version = "1.3.0" } -thiserror = { version = "=1.0.50" } -syn = { version = "=2.0.39" } +revm = { git = "https://github.com/bluealloy/revm.git", features = [ "ethersdb", "std", "serde"] } +revm-primitives = { git = "https://github.com/bluealloy/revm.git" } +thiserror = { version = "1.0.51" } +syn = { version = "2.0.42" } quote = { version = "=1.0.33" } -proc-macro2 = { version = "=1.0.69" } +proc-macro2 = { version = "1.0.70" } tokio = { version = "1.35.0", features = ["macros", "full"] } arbiter-core = { path = "./arbiter-core" } -crossbeam-channel = { version = "=0.5.8" } +crossbeam-channel = { version = "0.5.9" } futures-util = { version = "=0.3.29" } async-trait = { version = "0.1.74" } tracing = "0.1.40" diff --git a/arbiter-core/Cargo.toml b/arbiter-core/Cargo.toml index 60a37c31..862e0127 100644 --- a/arbiter-core/Cargo.toml +++ b/arbiter-core/Cargo.toml @@ -24,7 +24,7 @@ serde_json.workspace = true # Concurrency/async tokio.workspace = true async-trait.workspace = true -crossbeam-channel = { version = "=0.5.8" } +crossbeam-channel.workspace = true futures-timer = { version = "=3.0.2" } futures-locks = { version = "=0.7.1" } @@ -48,7 +48,7 @@ polars = { version = "0.35.4", features = ["parquet", "csv", "json"] } arbiter-derive = { path = "../arbiter-derive" } arbiter-bindings = { path = "../arbiter-bindings" } hex = { version = "=0.4.3", default-features = false } -anyhow = { version = "=1.0.75" } +anyhow = { version = "1.0.76" } test-log = { version = "=0.2.14" } tracing-test = "0.2.4" diff --git a/arbiter-core/src/environment/mod.rs b/arbiter-core/src/environment/mod.rs index 4ef327b1..bbc16c6a 100644 --- a/arbiter-core/src/environment/mod.rs +++ b/arbiter-core/src/environment/mod.rs @@ -143,25 +143,9 @@ pub struct Environment { pub(crate) handle: Option>>, } -use serde::ser::SerializeStruct; - -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct ArbiterDB(Arc>>); -impl Serialize for ArbiterDB { - fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { - let db = self.0.read().unwrap(); - let mut state = serializer.serialize_struct("ArbiterDB", 2)?; - let accounts = db.accounts; - state.serialize_field("accounts", &db.accounts)?; - state.serialize_field("contracts", &db.contracts)?; - state.end() - } -} - impl Database for ArbiterDB { type Error = Infallible; // TODO: Not sure we want this, but it works for now. @@ -169,11 +153,11 @@ impl Database for ArbiterDB { &mut self, address: revm::primitives::Address, ) -> Result, Self::Error> { - self.0.read().unwrap().basic(address) + self.0.write().unwrap().basic(address) } fn code_by_hash(&mut self, code_hash: B256) -> Result { - self.0.read().unwrap().code_by_hash(code_hash) + self.0.write().unwrap().code_by_hash(code_hash) } fn storage( @@ -181,38 +165,38 @@ impl Database for ArbiterDB { address: revm::primitives::Address, index: U256, ) -> Result { - self.0.read().unwrap().storage(address, index) + self.0.write().unwrap().storage(address, index) } fn block_hash(&mut self, number: U256) -> Result { - self.0.read().unwrap().block_hash(number) + self.0.write().unwrap().block_hash(number) } } impl DatabaseRef for ArbiterDB { type Error = Infallible; // TODO: Not sure we want this, but it works for now. - fn basic( + fn basic_ref( &self, address: revm::primitives::Address, ) -> Result, Self::Error> { - self.0.read().unwrap().basic(address) + self.0.read().unwrap().basic_ref(address) } - fn code_by_hash(&self, code_hash: B256) -> Result { - self.0.read().unwrap().code_by_hash(code_hash) + fn code_by_hash_ref(&self, code_hash: B256) -> Result { + self.0.read().unwrap().code_by_hash_ref(code_hash) } - fn storage( + fn storage_ref( &self, address: revm::primitives::Address, index: U256, ) -> Result { - self.0.read().unwrap().storage(address, index) + self.0.read().unwrap().storage_ref(address, index) } - fn block_hash(&self, number: U256) -> Result { - self.0.read().unwrap().block_hash(number) + fn block_hash_ref(&self, number: U256) -> Result { + self.0.read().unwrap().block_hash_ref(number) } } diff --git a/arbiter-engine/Cargo.toml b/arbiter-engine/Cargo.toml index a7cef2df..085921b9 100644 --- a/arbiter-engine/Cargo.toml +++ b/arbiter-engine/Cargo.toml @@ -19,7 +19,7 @@ async-trait.workspace = true serde_json.workspace = true serde.workspace = true tokio.workspace = true -anyhow = { version = "=1.0.75" } +anyhow = { version = "1.0.76" } tracing.workspace = true flume = "0.11.0" From 3832f7d1ba8478eac4aa1d0fc4b541de614ec656 Mon Sep 17 00:00:00 2001 From: Colin Roberts Date: Wed, 20 Dec 2023 18:39:47 -0700 Subject: [PATCH 5/6] mod database and `coprocessor` --- arbiter-core/src/coprocessor.rs | 25 ++++- arbiter-core/src/database.rs | 94 +++++++++++++++++++ arbiter-core/src/environment/builder.rs | 2 - arbiter-core/src/environment/cheatcodes.rs | 2 - arbiter-core/src/environment/errors.rs | 2 - arbiter-core/src/environment/instruction.rs | 4 +- arbiter-core/src/environment/mod.rs | 89 +++--------------- arbiter-core/src/lib.rs | 1 + .../src/tests/environment_integration.rs | 9 ++ 9 files changed, 138 insertions(+), 90 deletions(-) create mode 100644 arbiter-core/src/database.rs diff --git a/arbiter-core/src/coprocessor.rs b/arbiter-core/src/coprocessor.rs index 6dcd6f67..1d44ba06 100644 --- a/arbiter-core/src/coprocessor.rs +++ b/arbiter-core/src/coprocessor.rs @@ -3,7 +3,7 @@ use std::convert::Infallible; use revm::EVM; use revm_primitives::{EVMError, ResultAndState}; -use crate::environment::{ArbiterDB, Environment}; +use crate::{database::ArbiterDB, environment::Environment}; pub struct Coprocessor { evm: EVM, @@ -11,7 +11,14 @@ pub struct Coprocessor { impl Coprocessor { pub fn new(environment: &Environment) -> Self { - let db = environment.db.as_ref().unwrap().clone(); + let db = ArbiterDB( + environment + .db + .as_ref() + .unwrap_or(&ArbiterDB::new()) + .0 + .clone(), + ); let mut evm = EVM::new(); evm.database(db); Self { evm } @@ -24,12 +31,24 @@ impl Coprocessor { #[cfg(test)] mod tests { + use revm_primitives::{InvalidTransaction, U256}; + use super::*; use crate::environment::builder::EnvironmentBuilder; #[test] fn coprocessor() { let environment = EnvironmentBuilder::new().build(); - let coprocessor = Coprocessor::new(&environment); + let mut coprocessor = Coprocessor::new(&environment); + coprocessor.evm.env.tx.value = U256::from(100); + let outcome = coprocessor.transact_ref(); + if let Err(EVMError::Transaction(InvalidTransaction::LackOfFundForMaxFee { + fee, + balance, + })) = outcome + { + assert_eq!(*fee, U256::from(100)); + assert_eq!(*balance, U256::from(0)); + } } } diff --git a/arbiter-core/src/database.rs b/arbiter-core/src/database.rs new file mode 100644 index 00000000..e9fc59ca --- /dev/null +++ b/arbiter-core/src/database.rs @@ -0,0 +1,94 @@ +use std::{ + convert::Infallible, + fmt::Debug, + sync::{Arc, RwLock}, +}; + +use revm::{ + db::{CacheDB, EmptyDB}, + primitives::{AccountInfo, B256, U256}, + Database, DatabaseCommit, +}; +use revm_primitives::{db::DatabaseRef, Bytecode}; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct ArbiterDB(pub(crate) Arc>>); + +impl ArbiterDB { + pub fn new() -> Self { + Self(Arc::new(RwLock::new(CacheDB::new(EmptyDB::new())))) + } +} + +// TODO: This is a BAD implementation of PartialEq, but it works for now as we +// do not ever really need to compare DBs directly at the moment. +// This is only used in the `Outcome` enum for `instruction.rs`. +impl PartialEq for ArbiterDB { + fn eq(&self, other: &Self) -> bool { + true + } +} + +impl Database for ArbiterDB { + type Error = Infallible; // TODO: Not sure we want this, but it works for now. + + fn basic( + &mut self, + address: revm::primitives::Address, + ) -> Result, Self::Error> { + self.0.write().unwrap().basic(address) + } + + fn code_by_hash(&mut self, code_hash: B256) -> Result { + self.0.write().unwrap().code_by_hash(code_hash) + } + + fn storage( + &mut self, + address: revm::primitives::Address, + index: U256, + ) -> Result { + self.0.write().unwrap().storage(address, index) + } + + fn block_hash(&mut self, number: U256) -> Result { + self.0.write().unwrap().block_hash(number) + } +} + +impl DatabaseRef for ArbiterDB { + type Error = Infallible; // TODO: Not sure we want this, but it works for now. + + fn basic_ref( + &self, + address: revm::primitives::Address, + ) -> Result, Self::Error> { + self.0.read().unwrap().basic_ref(address) + } + + fn code_by_hash_ref(&self, code_hash: B256) -> Result { + self.0.read().unwrap().code_by_hash_ref(code_hash) + } + + fn storage_ref( + &self, + address: revm::primitives::Address, + index: U256, + ) -> Result { + self.0.read().unwrap().storage_ref(address, index) + } + + fn block_hash_ref(&self, number: U256) -> Result { + self.0.read().unwrap().block_hash_ref(number) + } +} + +impl DatabaseCommit for ArbiterDB { + fn commit( + &mut self, + changes: hashbrown::HashMap, + ) { + self.0.write().unwrap().commit(changes) + } +} diff --git a/arbiter-core/src/environment/builder.rs b/arbiter-core/src/environment/builder.rs index 65edd04d..044483b1 100644 --- a/arbiter-core/src/environment/builder.rs +++ b/arbiter-core/src/environment/builder.rs @@ -3,8 +3,6 @@ //! [`EnvironmentParameters`] structures as well as the [`BlockSettings`] and //! [`GasSettings`] enums. -#![warn(missing_docs)] - use super::*; /// Parameters necessary for creating or modifying an `Environment`. diff --git a/arbiter-core/src/environment/cheatcodes.rs b/arbiter-core/src/environment/cheatcodes.rs index 6f53f038..7967c722 100644 --- a/arbiter-core/src/environment/cheatcodes.rs +++ b/arbiter-core/src/environment/cheatcodes.rs @@ -1,8 +1,6 @@ //! Cheatcodes are a direct way to access the underlying [`EVM`] environment // and database. ! Use them via the `apply_cheatcode` method on a `client`. -#![warn(missing_docs)] - use revm_primitives::{AccountInfo, HashMap, U256}; /// Cheatcodes are a direct way to access the underlying [`EVM`] environment and diff --git a/arbiter-core/src/environment/errors.rs b/arbiter-core/src/environment/errors.rs index 6e9f5e05..a889b4ed 100644 --- a/arbiter-core/src/environment/errors.rs +++ b/arbiter-core/src/environment/errors.rs @@ -1,8 +1,6 @@ //! Errors that can occur when managing or interfacing with Arbiter's sandboxed //! Ethereum environment. -#![warn(missing_docs)] - use super::*; /// Errors that can occur when managing or interfacing with the Ethereum diff --git a/arbiter-core/src/environment/instruction.rs b/arbiter-core/src/environment/instruction.rs index cbd86492..0adab195 100644 --- a/arbiter-core/src/environment/instruction.rs +++ b/arbiter-core/src/environment/instruction.rs @@ -1,5 +1,3 @@ -#![warn(missing_docs)] - use super::*; /// [`Instruction`]s that can be sent to the [`Environment`] via the @@ -135,7 +133,7 @@ pub(crate) enum Outcome { /// The outcome of a `Stop` instruction that is used to signify that the /// [`Environment`] was stopped successfully. - StopCompleted, + StopCompleted(ArbiterDB), } /// [`EnvironmentData`] is an enum used inside of the [`Instruction::Query`] to diff --git a/arbiter-core/src/environment/mod.rs b/arbiter-core/src/environment/mod.rs index bbc16c6a..995fab2b 100644 --- a/arbiter-core/src/environment/mod.rs +++ b/arbiter-core/src/environment/mod.rs @@ -27,8 +27,6 @@ //! - `EventBroadcaster`: Responsible for broadcasting Ethereum logs to //! subscribers. -#![warn(missing_docs, unsafe_code)] - use std::{ convert::Infallible, fmt::Debug, @@ -45,16 +43,15 @@ use revm::{ }, Database, DatabaseCommit, EVM, }; -use revm_primitives::{db::DatabaseRef, Bytecode}; -use serde::{Deserialize, Serialize, Serializer}; +use serde::{Deserialize, Serialize}; use thiserror::Error; use super::*; -use crate::math::SeededPoisson; #[cfg_attr(doc, doc(hidden))] #[cfg_attr(doc, allow(unused_imports))] #[cfg(doc)] use crate::middleware::RevmMiddleware; +use crate::{database::ArbiterDB, math::SeededPoisson}; pub mod cheatcodes; use cheatcodes::*; @@ -143,72 +140,6 @@ pub struct Environment { pub(crate) handle: Option>>, } -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct ArbiterDB(Arc>>); - -impl Database for ArbiterDB { - type Error = Infallible; // TODO: Not sure we want this, but it works for now. - - fn basic( - &mut self, - address: revm::primitives::Address, - ) -> Result, Self::Error> { - self.0.write().unwrap().basic(address) - } - - fn code_by_hash(&mut self, code_hash: B256) -> Result { - self.0.write().unwrap().code_by_hash(code_hash) - } - - fn storage( - &mut self, - address: revm::primitives::Address, - index: U256, - ) -> Result { - self.0.write().unwrap().storage(address, index) - } - - fn block_hash(&mut self, number: U256) -> Result { - self.0.write().unwrap().block_hash(number) - } -} - -impl DatabaseRef for ArbiterDB { - type Error = Infallible; // TODO: Not sure we want this, but it works for now. - - fn basic_ref( - &self, - address: revm::primitives::Address, - ) -> Result, Self::Error> { - self.0.read().unwrap().basic_ref(address) - } - - fn code_by_hash_ref(&self, code_hash: B256) -> Result { - self.0.read().unwrap().code_by_hash_ref(code_hash) - } - - fn storage_ref( - &self, - address: revm::primitives::Address, - index: U256, - ) -> Result { - self.0.read().unwrap().storage_ref(address, index) - } - - fn block_hash_ref(&self, number: U256) -> Result { - self.0.read().unwrap().block_hash_ref(number) - } -} - -impl DatabaseCommit for ArbiterDB { - fn commit( - &mut self, - changes: hashbrown::HashMap, - ) { - self.0.write().unwrap().commit(changes) - } -} - /// Allow the end user to be able to access a debug printout for the /// [`Environment`]. Note that the [`EVM`] does not implement debug display, /// hence the implementation by hand here. @@ -719,7 +650,7 @@ impl Environment { } Instruction::Stop(outcome_sender) => { outcome_sender - .send(Ok(Outcome::StopCompleted)) + .send(Ok(Outcome::StopCompleted(evm.db.unwrap()))) .map_err(|e| EnvironmentError::Communication(e.to_string()))?; event_broadcaster.lock().unwrap().broadcast(None, true)?; break; @@ -740,7 +671,7 @@ impl Environment { /// stopped. /// * `Err(EnvironmentError::Stop(String))` if the environment is in an /// invalid state. - pub fn stop(mut self) -> Result<(), EnvironmentError> { + pub fn stop(mut self) -> Result, EnvironmentError> { let (outcome_sender, outcome_receiver) = bounded(1); self.socket .instruction_sender @@ -754,10 +685,12 @@ impl Environment { let outcome = outcome_receiver .recv() .map_err(|e| EnvironmentError::Communication(e.to_string()))??; - match outcome { - Outcome::StopCompleted => {} - _ => Err(EnvironmentError::Stop("Failed to stop environment!".into()))?, - } + + let db = match outcome { + Outcome::StopCompleted(stopped_db) => Some(stopped_db), + _ => return Err(EnvironmentError::Stop("Failed to stop environment!".into())), + }; + if let Some(label) = &self.parameters.label { warn!("Stopped environment with label: {}", label); } else { @@ -773,7 +706,7 @@ impl Environment { .map_err(|_| { EnvironmentError::Stop("Failed to join environment handle.".to_owned()) })??; - Ok(()) + Ok(db) } } diff --git a/arbiter-core/src/lib.rs b/arbiter-core/src/lib.rs index 38c4c4ec..04e4992a 100644 --- a/arbiter-core/src/lib.rs +++ b/arbiter-core/src/lib.rs @@ -33,6 +33,7 @@ pub mod coprocessor; pub mod data_collection; +pub mod database; pub mod environment; pub mod math; pub mod middleware; diff --git a/arbiter-core/src/tests/environment_integration.rs b/arbiter-core/src/tests/environment_integration.rs index 95320a87..d63b787c 100644 --- a/arbiter-core/src/tests/environment_integration.rs +++ b/arbiter-core/src/tests/environment_integration.rs @@ -282,3 +282,12 @@ async fn middleware_from_forked_eo() { .unwrap(); assert_eq!(eth_balance, U256::from(934034962177715175765_u128)); } + +#[tokio::test] +async fn env_returns_db() { + let (environment, client) = startup_user_controlled().unwrap(); + deploy_arbx(client).await.unwrap(); + let db = environment.stop().unwrap(); + assert!(db.is_some()); + assert!(!db.unwrap().0.read().unwrap().accounts.is_empty()) +} From 20459d27ee493c6ad645336300ae0f4d21c0f95a Mon Sep 17 00:00:00 2001 From: Colin Roberts Date: Wed, 3 Jan 2024 14:02:52 -0700 Subject: [PATCH 6/6] feat: database disk handling --- arbiter-core/src/coprocessor.rs | 15 ++++++++ arbiter-core/src/database.rs | 54 ++++++++++++++++++++++++++++- arbiter-core/src/environment/mod.rs | 4 +-- 3 files changed, 70 insertions(+), 3 deletions(-) diff --git a/arbiter-core/src/coprocessor.rs b/arbiter-core/src/coprocessor.rs index 1d44ba06..42ea4f5a 100644 --- a/arbiter-core/src/coprocessor.rs +++ b/arbiter-core/src/coprocessor.rs @@ -1,3 +1,7 @@ +//! The `Coprocessor` is used to process calls and can access read-only from the +//! `Environment`'s database. The `Coprocessor` will stay up to date with the +//! latest state of the `Environment`'s database. + use std::convert::Infallible; use revm::EVM; @@ -5,11 +9,21 @@ use revm_primitives::{EVMError, ResultAndState}; use crate::{database::ArbiterDB, environment::Environment}; +// TODO: I have not tested that the coprocessor actually maintains state parity +// with the environment. At the moment, it is only able to be constructed and +// can certainly act as a read-only EVM. + +/// A `Coprocessor` is used to process calls and can access read-only from the +/// `Environment`'s database. This can eventually be used for things like +/// parallelized compute for agents that are not currently sending transactions +/// that need to be processed by the `Environment`, but are instead using the +/// current state to make decisions. pub struct Coprocessor { evm: EVM, } impl Coprocessor { + /// Create a new `Coprocessor` with the given `Environment`. pub fn new(environment: &Environment) -> Self { let db = ArbiterDB( environment @@ -24,6 +38,7 @@ impl Coprocessor { Self { evm } } + /// Used as an entrypoint to process a call with the `Coprocessor`. pub fn transact_ref(&self) -> Result> { self.evm.transact_ref() } diff --git a/arbiter-core/src/database.rs b/arbiter-core/src/database.rs index e9fc59ca..0ce91659 100644 --- a/arbiter-core/src/database.rs +++ b/arbiter-core/src/database.rs @@ -1,6 +1,13 @@ +//! The `ArbiterDB` is a wrapper around a `CacheDB` that is used to provide +//! access to the `Environment`'s database to multiple `Coprocessors`. +//! It is also used to be able to write out the `Environment` database to a +//! file. + use std::{ convert::Infallible, fmt::Debug, + fs, + io::{self, Read, Write}, sync::{Arc, RwLock}, }; @@ -11,21 +18,52 @@ use revm::{ }; use revm_primitives::{db::DatabaseRef, Bytecode}; use serde::{Deserialize, Serialize}; +use serde_json; +/// A `ArbiterDB` is a wrapper around a `CacheDB` that is used to provide +/// access to the `Environment`'s database to multiple `Coprocessors`. #[derive(Clone, Debug, Serialize, Deserialize)] pub struct ArbiterDB(pub(crate) Arc>>); impl ArbiterDB { + /// Create a new `ArbiterDB`. pub fn new() -> Self { Self(Arc::new(RwLock::new(CacheDB::new(EmptyDB::new())))) } + + /// Write the `ArbiterDB` to a file at the given path. + pub fn write_to_file(&self, path: &str) -> io::Result<()> { + // Serialize the ArbiterDB + let serialized = serde_json::to_string(self)?; + // Write to file + let mut file = fs::File::create(path)?; + file.write_all(serialized.as_bytes())?; + Ok(()) + } + + /// Read the `ArbiterDB` from a file at the given path. + pub fn read_from_file(path: &str) -> io::Result { + // Read the file content + let mut file = fs::File::open(path)?; + let mut contents = String::new(); + file.read_to_string(&mut contents)?; + // Deserialize the content into ArbiterDB + let cache_db = serde_json::from_str(&contents)?; + Ok(Self(Arc::new(RwLock::new(cache_db)))) + } +} + +impl Default for ArbiterDB { + fn default() -> Self { + Self::new() + } } // TODO: This is a BAD implementation of PartialEq, but it works for now as we // do not ever really need to compare DBs directly at the moment. // This is only used in the `Outcome` enum for `instruction.rs`. impl PartialEq for ArbiterDB { - fn eq(&self, other: &Self) -> bool { + fn eq(&self, _other: &Self) -> bool { true } } @@ -92,3 +130,17 @@ impl DatabaseCommit for ArbiterDB { self.0.write().unwrap().commit(changes) } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn read_write_to_file() { + let db = ArbiterDB::new(); + db.write_to_file("test.json").unwrap(); + let db = ArbiterDB::read_from_file("test.json").unwrap(); + assert_eq!(db, ArbiterDB::new()); + fs::remove_file("test.json").unwrap(); + } +} diff --git a/arbiter-core/src/environment/mod.rs b/arbiter-core/src/environment/mod.rs index 995fab2b..3f91f7e7 100644 --- a/arbiter-core/src/environment/mod.rs +++ b/arbiter-core/src/environment/mod.rs @@ -39,9 +39,9 @@ use ethers::core::types::U64; use revm::{ db::{CacheDB, EmptyDB}, primitives::{ - AccountInfo, EVMError, ExecutionResult, HashMap, InvalidTransaction, Log, TxEnv, B256, U256, + AccountInfo, EVMError, ExecutionResult, HashMap, InvalidTransaction, Log, TxEnv, U256, }, - Database, DatabaseCommit, EVM, + EVM, }; use serde::{Deserialize, Serialize}; use thiserror::Error;