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

feat: Optimism execution changes #682

Merged
merged 90 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
ec46f3e
Start `op-revm` changes
clabby Sep 1, 2023
66d200d
Start fee distribution changes
clabby Sep 1, 2023
c61c762
Add L1 fee deduction
clabby Sep 1, 2023
2257bb9
Start deposit tx gas accounting
clabby Sep 1, 2023
3fd2f61
Move L1 cost into `TxEnv`
clabby Sep 2, 2023
2cc96da
Add helpers for computing the L1 cost of a transaction back
clabby Sep 2, 2023
75f8287
:broom:
clabby Sep 2, 2023
4154183
Enforce runtime config flag for cross-compatibility
clabby Sep 2, 2023
9bb0c49
style: Use env rather than passing a flag
clabby Sep 2, 2023
a31c31c
review: Address first few comments
clabby Sep 5, 2023
9490270
Flatten optimism hoisted tx fields
refcell Sep 5, 2023
8f0caa1
feat flag ontop
refcell Sep 5, 2023
2d137e2
Merge pull request #2 from anton-rs/refcell/tx-field-flattening
refcell Sep 5, 2023
128e440
Refactor l1 cost and mint computations
refcell Sep 5, 2023
6b868b3
l1 cost erroring
refcell Sep 5, 2023
ae76b7e
Merge pull request #4 from anton-rs/refcell/refactors
refcell Sep 5, 2023
d642582
Refactor gas usage functions
refcell Sep 5, 2023
868f593
Rip gas construction back to the transact
refcell Sep 5, 2023
8eab1ad
Rip out crate use gas
refcell Sep 5, 2023
f2d59b9
Merge pull request #5 from anton-rs/refcell/gas-refactor
refcell Sep 5, 2023
063b4e6
push gas usage unit logic into the gas impl
refcell Sep 6, 2023
21bba33
Resolve env conflicts
refcell Sep 6, 2023
f97400f
Merge pull request #7 from anton-rs/refcell/upstream-sync
refcell Sep 6, 2023
b0d703c
Further document the cfg env optimism bool field.
refcell Sep 6, 2023
0404385
Reword
refcell Sep 6, 2023
d9cd733
Add deposit sys tx docs
refcell Sep 6, 2023
cee3dae
Fix the spec enabled function and add unit tests.
refcell Sep 6, 2023
af654a3
data gas tests
refcell Sep 6, 2023
e60a4d5
calculate tx l1 cost test
refcell Sep 6, 2023
fa8b4e0
Add a zero rollup data gas cost check
refcell Sep 6, 2023
f0d7ad6
Fix suggestions
refcell Sep 6, 2023
43254d1
Merge pull request #10 from anton-rs/refcell/spec-enabling-fixes
refcell Sep 6, 2023
5ef737f
Merge pull request #8 from anton-rs/refcell/optimism-hot-toggle
refcell Sep 6, 2023
fc227f6
Merge pull request #9 from anton-rs/refcell/deposit-sys-tx
refcell Sep 6, 2023
d193011
Bump the account nonce post-regolith for contract creation
refcell Sep 6, 2023
710c6ed
Add tx validation tests
refcell Sep 7, 2023
988d640
Add a deposit tx test
refcell Sep 7, 2023
f7a3373
Add gas tests
refcell Sep 7, 2023
b31029e
Add gas tests
refcell Sep 7, 2023
a0cc070
Fix regolith check
refcell Sep 7, 2023
dc28e02
Merge pull request #12 from anton-rs/refcell/validate-tx-tests
refcell Sep 7, 2023
99a364e
Merge pull request #11 from anton-rs/refcell/bump-nonce-post-regolith
refcell Sep 7, 2023
b163419
Fix func ordering
refcell Sep 7, 2023
742c79a
Merge pull request #6 from anton-rs/refcell/refactor-gas-usage
refcell Sep 7, 2023
b0f4d1f
Merge branch 'main' into refcell/upstreamsync
refcell Sep 7, 2023
d3057fd
Merge pull request #14 from anton-rs/refcell/upstreamsync
refcell Sep 7, 2023
23373ae
Fix test
refcell Sep 7, 2023
4acb344
Merge pull request #15 from anton-rs/refcell/fix-test
refcell Sep 7, 2023
531aca0
Swap the l1_cost to use the raw enveloped tx
refcell Sep 7, 2023
bdc334e
Update crates/revm/src/evm_impl.rs
refcell Sep 7, 2023
a92bb4f
Update crates/revm/src/evm_impl.rs
refcell Sep 7, 2023
21d907d
Update crates/primitives/src/env.rs
refcell Sep 7, 2023
8b0a222
Merge pull request #16 from anton-rs/refcell/l1_cost_refactor
refcell Sep 7, 2023
27760ca
Make clippy happy
clabby Sep 7, 2023
4fd2422
Merge pull request #17 from anton-rs/clippy
refcell Sep 7, 2023
0d4ccb5
perf: Only load `L1BlockInfo` once
clabby Sep 7, 2023
bb9acfe
Remove extra `try_fetch` fn
clabby Sep 7, 2023
3f9ca9d
perf: lazy `try_fetch` eval
clabby Sep 7, 2023
8fd3a3c
andreas was right
clabby Sep 8, 2023
2c72f86
Improve error abstraction
clabby Sep 8, 2023
03fd637
Merge pull request #18 from anton-rs/clabby/reduce-db-reads
refcell Sep 8, 2023
61b21a0
EVM Impl Tests
refcell Sep 7, 2023
476f7f2
More tests
refcell Sep 7, 2023
2096fd0
Merge pull request #13 from anton-rs/refcell/mint-value-commits
clabby Sep 8, 2023
e7a2440
Fix breaking changes
refcell Sep 8, 2023
21880f7
Merge pull request #21 from anton-rs/refcell/hot-fix
clabby Sep 8, 2023
2962e7a
Update the enveloped tx to be optional.
refcell Sep 8, 2023
0970280
Merge branch 'main' into refcell/quick-upstream-sync
refcell Sep 8, 2023
ad2c951
Merge pull request #23 from anton-rs/refcell/quick-upstream-sync
refcell Sep 8, 2023
bd03c2f
Merge pull request #22 from anton-rs/refcell/optional-envelope
refcell Sep 8, 2023
c1d667f
Merge REVM upgrades
clabby Sep 16, 2023
3c7878a
Merge pull request #24 from anton-rs/cl/merge-revm-upgrades
refcell Sep 17, 2023
fff1d42
Upstream sync?
refcell Sep 17, 2023
572f52c
Merge pull request #25 from anton-rs/refcell/upstream-fixes
clabby Sep 17, 2023
feec29a
Introduce call return handler
rakita Sep 22, 2023
2b9d0cc
Merge pull request #26 from rakita/call_return_handler
refcell Sep 25, 2023
5918f28
feat: Handler logic
rakita Sep 26, 2023
07c4cbc
Merge remote-tracking branch 'origin/main' into final_handler
rakita Sep 26, 2023
8fa4ea3
Merge pull request #27 from rakita/handler
refcell Sep 26, 2023
c656896
Merge pull request #28 from rakita/oprevm-merge
refcell Sep 26, 2023
8d97ea3
remove USE_GAS from handlers
rakita Sep 27, 2023
feaafe8
Merge pull request #30 from rakita/rm_handler_use_gas
refcell Sep 27, 2023
5eacff1
Fix lints
refcell Sep 27, 2023
ba0266a
Merge branch 'main' into refcell/quick-us
refcell Sep 27, 2023
d87381b
Merge pull request #31 from anton-rs/refcell/quick-us
refcell Sep 27, 2023
e63c990
Update runner.rs
clabby Sep 27, 2023
7aaf390
Merge branch 'main' into refcell/another-quick-us
refcell Sep 27, 2023
4a615ea
Merge pull request #32 from anton-rs/refcell/another-quick-us
refcell Sep 27, 2023
ec1f488
Fix param mutability
refcell Sep 27, 2023
8048613
Merge pull request #33 from anton-rs/refcell/fix-param-mutability
refcell Sep 27, 2023
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
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/interpreter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,4 @@ arbitrary = [
"dep:proptest-derive",
"revm-primitives/arbitrary",
]
optimism = ["revm-primitives/optimism"]
10 changes: 10 additions & 0 deletions crates/interpreter/src/instructions/opcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -924,5 +924,15 @@ pub const fn spec_opcode_gas(spec_id: SpecId) -> &'static [OpInfo; 256] {
gas_opcodee!(LATEST, SpecId::LATEST);
LATEST
}
#[cfg(feature = "optimism")]
SpecId::BEDROCK => {
gas_opcodee!(BEDROCK, SpecId::BEDROCK);
BEDROCK
}
#[cfg(feature = "optimism")]
SpecId::REGOLITH => {
gas_opcodee!(REGOLITH, SpecId::REGOLITH);
REGOLITH
}
}
}
1 change: 1 addition & 0 deletions crates/precompile/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ default = ["secp256k1"]
# Only problem that it has, it fails to build for wasm target on windows and mac as it is c lib.
# If you dont require wasm on win/mac, i would recommend its usage.
secp256k1 = ["dep:secp256k1"]
optimism = ["revm-primitives/optimism"]
2 changes: 2 additions & 0 deletions crates/precompile/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ impl SpecId {
Self::BERLIN
}
LATEST => Self::LATEST,
#[cfg(feature = "optimism")]
BEDROCK | REGOLITH => Self::LATEST,
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,4 @@ arbitrary = [
"dep:proptest-derive",
"bitflags/arbitrary",
]
optimism = []
39 changes: 39 additions & 0 deletions crates/primitives/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ pub struct TxEnv {
pub chain_id: Option<u64>,
pub nonce: Option<u64>,
pub access_list: Vec<(B160, Vec<U256>)>,
#[cfg(feature = "optimism")]
clabby marked this conversation as resolved.
Show resolved Hide resolved
pub source_hash: Option<B256>,
#[cfg(feature = "optimism")]
pub mint: Option<u128>,
#[cfg(feature = "optimism")]
pub is_system_transaction: Option<bool>,
#[cfg(feature = "optimism")]
pub l1_cost: Option<U256>,
clabby marked this conversation as resolved.
Show resolved Hide resolved
}

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -122,6 +130,10 @@ pub struct CfgEnv {
/// This is useful for testing method calls with zero gas price.
#[cfg(feature = "optional_no_base_fee")]
pub disable_base_fee: bool,
/// Enables Optimism's execution changes for deposit transactions and fee
/// collection.
#[cfg(feature = "optimism")]
pub optimism: bool,
}

impl CfgEnv {
Expand Down Expand Up @@ -174,6 +186,16 @@ impl CfgEnv {
pub fn is_block_gas_limit_disabled(&self) -> bool {
false
}

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

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

#[derive(Clone, Default, Debug, Eq, PartialEq)]
Expand Down Expand Up @@ -205,6 +227,8 @@ impl Default for CfgEnv {
disable_gas_refund: false,
#[cfg(feature = "optional_no_base_fee")]
disable_base_fee: false,
#[cfg(feature = "optimism")]
optimism: false,
}
}
}
Expand Down Expand Up @@ -236,6 +260,14 @@ impl Default for TxEnv {
chain_id: None,
nonce: None,
access_list: Vec::new(),
#[cfg(feature = "optimism")]
source_hash: None,
#[cfg(feature = "optimism")]
mint: None,
#[cfg(feature = "optimism")]
is_system_transaction: None,
#[cfg(feature = "optimism")]
l1_cost: None,
}
}
}
Expand Down Expand Up @@ -331,6 +363,13 @@ impl Env {
return Err(InvalidTransaction::RejectCallerWithCode);
}

// On Optimism, deposit transactions do not have verification on the nonce
// nor the balance of the account.
#[cfg(feature = "optimism")]
if self.cfg.optimism && self.tx.source_hash.is_some() {
return Ok(());
}

// Check that the transaction's nonce is correct
if let Some(tx) = self.tx.nonce {
let state = account.info.nonce;
Expand Down
2 changes: 2 additions & 0 deletions crates/primitives/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ pub enum InvalidTransaction {
/// Access list is not supported is not supported
/// for blocks before Berlin hardfork.
AccessListNotSupported,
#[cfg(feature = "optimism")]
DepositSystemTxPostRegolith,
}

/// When transaction return successfully without halts.
Expand Down
25 changes: 25 additions & 0 deletions crates/primitives/src/specification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ pub enum SpecId {
SHANGHAI = 16,
CANCUN = 17,
LATEST = 18,
#[cfg(feature = "optimism")]
BEDROCK = 128,
#[cfg(feature = "optimism")]
REGOLITH = 129,
}

impl SpecId {
Expand Down Expand Up @@ -52,6 +56,10 @@ impl From<&str> for SpecId {
"Merge" => SpecId::MERGE,
"Shanghai" => SpecId::SHANGHAI,
"Cancun" => SpecId::CANCUN,
#[cfg(feature = "optimism")]
"Bedrock" => SpecId::BEDROCK,
#[cfg(feature = "optimism")]
"Regolith" => SpecId::REGOLITH,
_ => SpecId::LATEST,
}
}
Expand All @@ -69,6 +77,17 @@ pub trait Spec: Sized {

#[inline(always)]
fn enabled(spec_id: SpecId) -> bool {
// Optimism's Bedrock and Regolith hardforks implement changes on top of the Merge
// hardfork. This function is modified to preserve the original behavior of the
// spec IDs without having to put hardforks past Merge under
// `#[cfg(not(feature = "optimism"))]`.
#[cfg(feature = "optimism")]
if (Self::SPEC_ID == SpecId::BEDROCK || Self::SPEC_ID == SpecId::REGOLITH)
&& spec_id > SpecId::MERGE
{
return false;
}

Self::SPEC_ID as u8 >= spec_id as u8
}
}
Expand Down Expand Up @@ -103,3 +122,9 @@ spec!(MERGE, MergeSpec);
spec!(SHANGHAI, ShanghaiSpec);
spec!(CANCUN, CancunSpec);
spec!(LATEST, LatestSpec);

// Optimism Hardforks
#[cfg(feature = "optimism")]
spec!(BEDROCK, BedrockSpec);
#[cfg(feature = "optimism")]
spec!(REGOLITH, RegolithSpec);
3 changes: 3 additions & 0 deletions crates/revm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ revm-interpreter = { path = "../interpreter", version = "1.1.2", default-feature

#misc
auto_impl = { version = "1.1", default-features = false }
once_cell = "1.18.0"
bytes = "1.4.0"
clabby marked this conversation as resolved.
Show resolved Hide resolved

# Optional
serde = { version = "1.0", features = ["derive", "rc"], optional = true }
Expand Down Expand Up @@ -65,6 +67,7 @@ arbitrary = ["revm-interpreter/arbitrary"]
# deprecated feature
web3db = []
with-serde = []
optimism = ["revm-interpreter/optimism", "revm-precompile/optimism"]

[[example]]
name = "fork_ref_transact"
Expand Down
6 changes: 6 additions & 0 deletions crates/revm/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ pub fn to_precompile_id(spec_id: SpecId) -> revm_precompile::SpecId {
| SpecId::SHANGHAI
| SpecId::CANCUN
| SpecId::LATEST => revm_precompile::SpecId::BERLIN,
#[cfg(feature = "optimism")]
SpecId::BEDROCK | SpecId::REGOLITH => revm_precompile::SpecId::BERLIN,
}
}

Expand All @@ -264,5 +266,9 @@ pub fn evm_inner<'a, DB: Database, const INSPECT: bool>(
SpecId::SHANGHAI => create_evm!(ShanghaiSpec, db, env, insp),
SpecId::CANCUN => create_evm!(CancunSpec, db, env, insp),
SpecId::LATEST => create_evm!(LatestSpec, db, env, insp),
#[cfg(feature = "optimism")]
SpecId::BEDROCK => create_evm!(BedrockSpec, db, env, insp),
#[cfg(feature = "optimism")]
SpecId::REGOLITH => create_evm!(RegolithSpec, db, env, insp),
}
}
Loading