Skip to content

Commit

Permalink
Sync no-std Raiko (taikoxyz#19)
Browse files Browse the repository at this point in the history
* zeth-primitives --feature taiko no-std

* lib built

* raiko-host compile

* fmt & clippy

* guest compile

* fmt & clippy error with Lazy static

* fmt

* const to static

* move back host

* fmt & clippy

* fmt all

* fmt
  • Loading branch information
CeciliaZ030 authored Feb 1, 2024
1 parent 4594293 commit 99f2229
Show file tree
Hide file tree
Showing 48 changed files with 944 additions and 750 deletions.
66 changes: 56 additions & 10 deletions Cargo.lock

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

28 changes: 19 additions & 9 deletions lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,23 @@ version = "0.1.0"
edition = "2021"

[dependencies]
anyhow = "1.0"
alloy-sol-types = { version = "0.4", optional = true }
anyhow = { version = "1.0", default-features = false }
alloy-sol-types = { version = "0.4", default-features = false, optional = true }
ethers-core = { version = "2.0", features = ["optimism"] }
hashbrown = { workspace = true }
once_cell = "1.18"
once_cell = { version = "1.18", default-features = false }
revm = { workspace = true }
ruint = { version = "1.10", default-features = false }
serde = "1.0"
thiserror = "1.0"
serde = { version = "1.0", default-features = false, features = ["alloc"] }
thiserror-no-std = "2.0.2"
zeth-primitives = { path = "../primitives", features = ["revm"] }
hex = "0.4.3"
rlp = "0.5.2"
tracing = "0.1"
hex = { version = "0.4.3", optional = true}
rlp = { version = "0.5.2", optional = true}
tracing = { version = "0.1", optional = true}

[target.'cfg(not(target_os = "zkvm"))'.dependencies]
thiserror = "1.0"
anyhow = "1.0"
chrono = { version = "0.4", default-features = false }
ethers-providers = { version = "2.0", features = ["optimism"] }
flate2 = "1.0.26"
Expand All @@ -33,6 +35,14 @@ bincode = "1.3"
serde_with = "3.1"

[features]
taiko = ["zeth-primitives/taiko", "dep:alloy-sol-types"]
default = ["taiko"]
std = []
taiko = [
"zeth-primitives/taiko",
"dep:alloy-sol-types",
"dep:hex",
"dep:rlp",
"dep:tracing"
]
pos = []
server = []
8 changes: 6 additions & 2 deletions lib/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@

//! Constants for the Ethereum protocol.
use core::str::FromStr;
use std::collections::BTreeMap;
use alloc::{
collections::BTreeMap,
str::FromStr,
string::{String, ToString},
};

use anyhow::bail;
use once_cell::sync::Lazy;
Expand Down Expand Up @@ -69,6 +72,7 @@ pub static ETH_MAINNET_CHAIN_SPEC: Lazy<ChainSpec> = Lazy::new(|| {
}
});

#[cfg(feature = "taiko")]
macro_rules! taiko_chain_spec {
($a:ident, $b:ident ) => {
pub static $a: Lazy<ChainSpec> = Lazy::new(|| {
Expand Down
7 changes: 5 additions & 2 deletions lib/src/execution/ethereum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use std::{fmt::Debug, mem::take};
use alloc::format;
use core::{fmt::Debug, mem::take};

use anyhow::{anyhow, bail, Context};
#[cfg(not(target_os = "zkvm"))]
Expand Down Expand Up @@ -160,9 +160,11 @@ impl TxExecStrategy<EthereumTxEssence> for EthTxExecStrategy {
let trie_key = tx_no.to_rlp();
tx_trie
.insert_rlp(&trie_key, tx)
.map_err(Into::<anyhow::Error>::into)
.context("failed to insert transaction")?;
receipt_trie
.insert_rlp(&trie_key, receipt)
.map_err(Into::<anyhow::Error>::into)
.context("failed to insert receipt")?;

// update account states
Expand Down Expand Up @@ -222,6 +224,7 @@ impl TxExecStrategy<EthereumTxEssence> for EthTxExecStrategy {
// Add withdrawal to trie
withdrawals_trie
.insert_rlp(&i.to_rlp(), withdrawal)
.map_err(Into::<anyhow::Error>::into)
.context("failed to insert withdrawal")?;
}

Expand Down
27 changes: 16 additions & 11 deletions lib/src/execution/optimism.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use std::{fmt::Debug, mem::take, str::FromStr};
use alloc::{format, vec, vec::Vec};
use core::{fmt::Debug, mem::take, str::FromStr};

use anyhow::{anyhow, bail, Context, Result};
#[cfg(not(target_os = "zkvm"))]
Expand Down Expand Up @@ -295,9 +295,11 @@ impl TxExecStrategy<OptimismTxEssence> for OpTxExecStrategy {
let trie_key = tx_no.to_rlp();
tx_trie
.insert_rlp(&trie_key, tx)
.map_err(Into::<anyhow::Error>::into)
.context("failed to insert transaction")?;
receipt_trie
.insert_rlp(&trie_key, receipt)
.map_err(Into::<anyhow::Error>::into)
.context("failed to insert receipt")?;
}

Expand Down Expand Up @@ -339,6 +341,7 @@ impl TxExecStrategy<OptimismTxEssence> for OpTxExecStrategy {
// Add withdrawal to trie
withdrawals_trie
.insert_rlp(&i.to_rlp(), withdrawal)
.map_err(Into::<anyhow::Error>::into)
.context("failed to insert withdrawal")?;
}

Expand Down Expand Up @@ -403,15 +406,17 @@ where
bail!("Unsupported result");
};

let ethers_core::abi::Token::Uint(uint_result) =
ethers_core::abi::decode(&[ethers_core::abi::ParamType::Uint(256)], &result_encoded)?
.pop()
.unwrap()
else {
bail!("Could not decode result");
};

Ok(U256::from_limbs(uint_result.0))
// let ethers_core::abi::Token::Uint(uint_result) =
// ethers_core::abi::decode(&[ethers_core::abi::ParamType::Uint(256)],
// &result_encoded)? .pop()
// .unwrap()
// else {
// bail!("Could not decode result");
// };

// Ok(U256::from_limbs(uint_result.0))
// Todo (Cecilia): fix this
Ok(U256::default())
}

fn fill_deposit_tx_env(
Expand Down
13 changes: 6 additions & 7 deletions lib/src/host/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use std::{
collections::HashSet,
fmt::Debug,
Expand All @@ -36,17 +35,18 @@ use zeth_primitives::{
use crate::{
block_builder::{BlockBuilder, NetworkStrategyBundle},
consts::ChainSpec,
host::{
mpt::{orphaned_digests, resolve_digests, shorten_key},
provider::{new_provider, BlockQuery},
},
input::{Input, StorageEntry},
mem_db::MemDb,
};

pub mod mpt;
pub mod provider;
pub mod provider_db;
pub mod taiko;

use mpt::{orphaned_digests, resolve_digests, shorten_key};
use provider::{new_provider, BlockQuery};
use provider_db::ProviderDb;

#[derive(Clone)]
pub struct Init<E: TxEssence> {
Expand Down Expand Up @@ -94,8 +94,7 @@ where
info!("Transaction count: {:?}", fini_block.transactions.len());

// Create the provider DB
let provider_db =
crate::host::provider_db::ProviderDb::new(provider, init_block.number.unwrap().as_u64());
let provider_db = ProviderDb::new(provider, init_block.number.unwrap().as_u64());

// Create input
let input = Input {
Expand Down
Loading

0 comments on commit 99f2229

Please sign in to comment.