Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(primitives): move primitives into lib #267

Merged
merged 2 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 6 additions & 43 deletions Cargo.lock

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

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ resolver = "2"
members = [
"lib",
"host",
"primitives",
"provers/sp1/driver",
"provers/sp1/builder",
"provers/risc0/driver",
Expand Down Expand Up @@ -33,7 +32,6 @@ opt-level = 3

# raiko
raiko-lib = { path = "./lib", features = ["std"] }
raiko-primitives = { path = "./primitives" }
raiko-core = { path = "./core" }

# revm
Expand Down
3 changes: 1 addition & 2 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ risc0-driver = { path = "../provers/risc0/driver", optional = true }
sgx-prover = { path = "../provers/sgx/prover", optional = true }

# raiko
raiko-lib = { workspace = true }
raiko-primitives = { workspace = true, features = ["c-kzg"] }
raiko-lib = { workspace = true, features = ["c-kzg"] }

# alloy
alloy-rlp = { workspace = true }
Expand Down
6 changes: 4 additions & 2 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,10 @@ mod tests {
};
use alloy_primitives::Address;
use clap::ValueEnum;
use raiko_lib::consts::{Network, SupportedChainSpecs};
use raiko_primitives::B256;
use raiko_lib::{
consts::{Network, SupportedChainSpecs},
primitives::B256,
};
use serde_json::{json, Value};
use std::{collections::HashMap, env};

Expand Down
12 changes: 6 additions & 6 deletions core/src/preflight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ use raiko_lib::{
decode_anchor, proposeBlockCall, BlockProposed, GuestInput, TaikoGuestInput,
TaikoProverData,
},
primitives::{
eip4844::{kzg_to_versioned_hash, MAINNET_KZG_TRUSTED_SETUP},
mpt::proofs_to_tries,
},
utils::{generate_transactions, to_header, zlib_compress_data},
Measurement,
};
use raiko_primitives::{
eip4844::{kzg_to_versioned_hash, MAINNET_KZG_TRUSTED_SETUP},
mpt::proofs_to_tries,
};
use serde::{Deserialize, Serialize};
use std::{collections::HashSet, sync::Arc};
use tracing::{info, warn};
Expand Down Expand Up @@ -488,7 +488,7 @@ async fn get_block_proposed_event(
};
let event = BlockProposed::decode_log(&log_struct, false)
.map_err(|_| RaikoError::Anyhow(anyhow!("Could not decode log")))?;
if event.blockId == raiko_primitives::U256::from(l2_block_number) {
if event.blockId == raiko_lib::primitives::U256::from(l2_block_number) {
let Some(log_tx_hash) = log.transaction_hash else {
bail!("No transaction hash in the log")
};
Expand Down Expand Up @@ -615,9 +615,9 @@ mod test {
use ethers_core::types::Transaction;
use raiko_lib::{
consts::{Network, SupportedChainSpecs},
primitives::{eip4844::parse_kzg_trusted_setup, kzg::KzgSettings},
utils::decode_transactions,
};
use raiko_primitives::{eip4844::parse_kzg_trusted_setup, kzg::KzgSettings};

use super::*;

Expand Down
9 changes: 7 additions & 2 deletions core/src/provider/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ use std::{collections::HashSet, mem::take};

use alloy_consensus::Header as AlloyConsensusHeader;
use alloy_primitives::Bytes;
use raiko_lib::{builder::OptimisticDatabase, consts::ChainSpec, mem_db::MemDb, utils::to_header};
use raiko_primitives::{Address, B256, U256};
use raiko_lib::{
builder::OptimisticDatabase,
consts::ChainSpec,
mem_db::MemDb,
primitives::{Address, B256, U256},
utils::to_header,
};
use revm::{
primitives::{Account, AccountInfo, Bytecode, HashMap},
Database, DatabaseCommit,
Expand Down
3 changes: 1 addition & 2 deletions host/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ risc0-driver = { path = "../provers/risc0/driver", optional = true }
sgx-prover = { path = "../provers/sgx/prover", optional = true }

# raiko
raiko-lib = { workspace = true }
raiko-primitives = { workspace = true, features = ["c-kzg"] }
raiko-lib = { workspace = true, features = ["c-kzg"] }
raiko-core = { workspace = true }

# alloy
Expand Down
30 changes: 20 additions & 10 deletions lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,40 @@ version = "0.1.0"
edition = "2021"

[dependencies]
raiko-primitives = { workspace = true }

alloy-rlp = { workspace = true }
alloy-eips = { workspace = true }
alloy-rlp-derive = { workspace = true }
alloy-sol-types = { workspace = true }
alloy-primitives = { workspace = true }
alloy-rpc-types = { workspace = true }
alloy-consensus = { workspace = true }
alloy-network = { workspace = true }

# errors
anyhow = { workspace = true }
libflate = { workspace = true }
once_cell = { workspace = true }
revm = { workspace = true }
thiserror-no-std = { workspace = true }
thiserror = { workspace = true, optional = true }

# serde
serde = { workspace = true }
serde_json = { workspace = true, optional = true }
serde_with = { workspace = true, optional = true }
thiserror-no-std = { workspace = true }

# revm
revm = { workspace = true }
revm-primitives = { workspace = true }

libflate = { workspace = true }
once_cell = { workspace = true }
url = { workspace = true }
hex = { workspace = true }
c-kzg = { workspace = true }
sha2 = { workspace = true }
sha3 = { workspace = true }
rlp = { workspace = true, features = ["std"] }
cfg-if = { workspace = true }

# [target.'cfg(feature = "std")'.dependencies]
thiserror = { workspace = true, optional = true }
flate2 = { workspace = true, optional = true }
log = { workspace = true, optional = true }

Expand All @@ -38,8 +46,11 @@ chrono = { workspace = true, optional = true }

lazy_static = { workspace = true }

tempfile = { workspace = true, optional = true }

[dev-dependencies]
bincode = "1.3"
hex-literal = { workspace = true }

[features]
default = ["std"]
Expand All @@ -55,9 +66,8 @@ std = [
"dep:serde_with",
# "dep:tokio",
]
tracer = [
"revm/serde-json",
]
tracer = ["revm/serde-json"]
sgx = []
sp1 = []
risc0 = []
c-kzg = ["revm-primitives/c-kzg", "dep:tempfile"]
11 changes: 6 additions & 5 deletions lib/src/builder/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ use alloy_primitives::{TxKind, U256};
use anyhow::{anyhow, bail, ensure, Context, Error, Result};
#[cfg(feature = "std")]
use log::debug;
use raiko_primitives::{
alloy_eips::eip4788::SYSTEM_ADDRESS, mpt::MptNode, receipt::Receipt, Bloom, Rlp2718Bytes,
RlpBytes,
};
use revm::{
interpreter::Host,
primitives::{
Expand All @@ -44,7 +40,12 @@ use crate::{
builder::BlockBuilder,
clear_line,
consts::GWEI_TO_WEI,
guest_mem_forget, inplace_print, print_duration,
guest_mem_forget, inplace_print,
primitives::{
alloy_eips::eip4788::SYSTEM_ADDRESS, mpt::MptNode, receipt::Receipt, Bloom, Rlp2718Bytes,
RlpBytes,
},
print_duration,
time::{AddAssign, Duration, Instant},
utils::{check_anchor_tx, generate_transactions},
Measurement,
Expand Down
8 changes: 4 additions & 4 deletions lib/src/builder/finalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ use core::mem;

use alloy_consensus::Header as AlloyConsensusHeader;
use anyhow::Result;
use raiko_primitives::{
keccak::keccak,
mpt::{MptNode, StateAccount},
};
use revm::{Database, DatabaseCommit};

use crate::{
builder::BlockBuilder,
guest_mem_forget,
mem_db::{AccountState, MemDb},
primitives::{
keccak::keccak,
mpt::{MptNode, StateAccount},
},
};

pub trait BlockFinalizeStrategy<D>
Expand Down
12 changes: 6 additions & 6 deletions lib/src/builder/initialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@
use core::mem;

use anyhow::{bail, Result};
use raiko_primitives::{
keccak::{keccak, KECCAK_EMPTY},
mpt::StateAccount,
Bytes,
};
use revm::{
primitives::{AccountInfo, Bytecode, HashMap, B256},
Database, DatabaseCommit,
Expand All @@ -30,6 +25,11 @@ use crate::{
consts::MAX_BLOCK_HASH_AGE,
guest_mem_forget,
mem_db::{AccountState, DbAccount, MemDb},
primitives::{
keccak::{keccak, KECCAK_EMPTY},
mpt::StateAccount,
Bytes,
},
utils::HeaderHasher,
};

Expand Down Expand Up @@ -98,7 +98,7 @@ impl DbInitStrategy<MemDb> for MemDbInitStrategy {
// load storage reads
let mut storage = HashMap::with_capacity(slots.len());
for slot in slots {
let value: raiko_primitives::U256 = storage_trie
let value: crate::primitives::U256 = storage_trie
.get_rlp(&keccak(slot.to_be_bytes::<32>()))?
.unwrap_or_default();
storage.insert(slot, value);
Expand Down
Loading
Loading