Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
CeciliaZ030 committed Jan 16, 2024
1 parent 23cbac4 commit c7aee3a
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
45 changes: 45 additions & 0 deletions crates/primitives/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ pub struct OptimismFields {
pub enveloped_tx: Option<Bytes>,
}

#[cfg(feature = "taiko")]
#[derive(Clone, Debug, Default, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct TaikoFields {
pub is_anchor: bool
}

impl BlockEnv {
/// Takes `blob_excess_gas` saves it inside env
/// and calculates `blob_fee` with [`BlobGasAndFee`].
Expand Down Expand Up @@ -183,6 +190,11 @@ pub struct TxEnv {
#[cfg_attr(feature = "serde", serde(flatten))]
#[cfg(feature = "optimism")]
pub optimism: OptimismFields,

#[cfg_attr(feature = "serde", serde(flatten))]
#[cfg(feature = "taiko")]
pub optimism: TaikoFields,

}

impl TxEnv {
Expand Down Expand Up @@ -306,6 +318,9 @@ pub struct CfgEnv {
/// compilation with the optimism feature flag.
#[cfg(feature = "optimism")]
pub optimism: bool,

#[cfg(feature = "taiko")]
pub taiko: bool,
}

impl CfgEnv {
Expand Down Expand Up @@ -368,6 +383,16 @@ impl CfgEnv {
pub fn is_optimism(&self) -> bool {
false
}

#[cfg(feature = "taiko")]
pub fn is_taiko(&self) -> bool {
self.taiko
}

#[cfg(not(feature = "taiko"))]
pub fn is_taiko(&self) -> bool {
false
}
}

/// What bytecode analysis to perform.
Expand Down Expand Up @@ -406,6 +431,8 @@ impl Default for CfgEnv {
disable_base_fee: false,
#[cfg(feature = "optimism")]
optimism: false,
#[cfg(feature = "taiko")]
taiko: false,
}
}
}
Expand Down Expand Up @@ -442,6 +469,8 @@ impl Default for TxEnv {
max_fee_per_blob_gas: None,
#[cfg(feature = "optimism")]
optimism: OptimismFields::default(),
#[cfg(feature = "taiko")]
taiko: TaikoFields::default(),
}
}
}
Expand Down Expand Up @@ -503,6 +532,11 @@ impl Env {
}
}

#[cfg(feature = "taiko")]
if self.cfg.taiko {
// TODO:(Cecilia)
}

let gas_limit = self.tx.gas_limit;
let effective_gas_price = self.effective_gas_price();
let is_create = self.tx.transact_to.is_create();
Expand Down Expand Up @@ -622,6 +656,11 @@ impl Env {
return Ok(());
}

#[cfg(feature = "taiko")]
if self.cfg.taiko {
// TODO(Cecilia): do we do anything with this?
}

// Check that the transaction's nonce is correct
if let Some(tx) = self.tx.nonce {
let state = account.info.nonce;
Expand Down Expand Up @@ -711,6 +750,12 @@ mod tests {
.is_ok());
}

#[cfg(feature = "taiko")]
#[test]
fn test_taiko() {
// TODO(Cecilia): taiko tests
}

#[test]
fn test_validate_tx_chain_id() {
let mut env = Env::default();
Expand Down
41 changes: 41 additions & 0 deletions crates/primitives/src/specification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ pub enum SpecId {
BEDROCK = 128,
#[cfg(feature = "optimism")]
REGOLITH = 129,
#[cfg(feature = "taiko")]
KATLA = 100, // TODO(Cecilia): update this range of bits
LATEST = u8::MAX,
}

Expand Down Expand Up @@ -58,6 +60,10 @@ impl SpecId {
return false;
}
}
#[cfg(feature = "taiko")]
{
// TODO(Cecilia): update this range of bits
}

our as u8 >= other as u8
}
Expand All @@ -84,6 +90,8 @@ impl From<&str> for SpecId {
"Bedrock" => SpecId::BEDROCK,
#[cfg(feature = "optimism")]
"Regolith" => SpecId::REGOLITH,
#[cfg(feature = "taiko")]
"Katla" => SpecId::KATLA,
_ => Self::LATEST,
}
}
Expand All @@ -110,6 +118,17 @@ pub trait Spec: Sized {
return false;
}
}
#[cfg(feature = "taiko")]
{
// TODO(Cecilia): update this range of bits
let is_self_taiko = Self::SPEC_ID == SpecId::KATLA;
let input_not_taiko = spec_id != SpecId::KATLA;
let after_merge = spec_id > SpecId::MERGE;

if is_self_taiko && input_not_taiko && after_merge {
return false;
}
}

Self::SPEC_ID as u8 >= spec_id as u8
}
Expand Down Expand Up @@ -152,6 +171,10 @@ spec!(BEDROCK, BedrockSpec);
#[cfg(feature = "optimism")]
spec!(REGOLITH, RegolithSpec);

// Taiko Hardforks
#[cfg(feature = "taiko")]
spec!(KATLA, KatlaSpec);

#[cfg(feature = "optimism")]
#[cfg(test)]
mod tests {
Expand Down Expand Up @@ -197,3 +220,21 @@ mod tests {
assert!(SpecId::enabled(SpecId::REGOLITH, SpecId::REGOLITH));
}
}

#[cfg(feature = "taiko")]
#[cfg(test)]
mod tests {
use super::*;

// TODO(Cecilia): update this range of bits
#[test]
fn test_katla_post_merge_hardforks() {
assert!(SpecId::enabled(SpecId::MERGE));
assert!(!SpecId::enabled(SpecId::SHANGHAI));
assert!(!SpecId::enabled(SpecId::CANCUN));
assert!(!SpecId::enabled(SpecId::LATEST));
assert!(!SpecId::enabled(SpecId::BEDROCK));
assert!(!SpecId::enabled(SpecId::REGOLITH));
assert!(SpecId::enabled(SpecId::KATLA));
}
}
3 changes: 3 additions & 0 deletions crates/revm/src/evm_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ use revm_precompile::{Precompile, Precompiles};
#[cfg(feature = "optimism")]
use crate::optimism;

#[cfg(feature = "taiko")]
use crate::taiko;

pub struct EVMData<'a, DB: Database> {
pub env: &'a mut Env,
pub journaled_state: JournaledState,
Expand Down

0 comments on commit c7aee3a

Please sign in to comment.