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(anvil): support for op-stack deposit transactions #6073

Merged
merged 21 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from 14 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
29 changes: 16 additions & 13 deletions Cargo.lock

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

36 changes: 18 additions & 18 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,14 @@ revm = { version = "3", default-features = false }
revm-primitives = { version = "1", default-features = false }

## ethers
ethers = { version = "2.0", default-features = false }
ethers-core = { version = "2.0", default-features = false }
ethers-contract = { version = "2.0", default-features = false }
ethers-contract-abigen = { version = "2.0", default-features = false }
ethers-providers = { version = "2.0", default-features = false }
ethers-signers = { version = "2.0", default-features = false }
ethers-middleware = { version = "2.0", default-features = false }
ethers-solc = { version = "2.0", default-features = false }
ethers = { version = "2.0.11", default-features = false }
ethers-core = { version = "2.0.11", default-features = false }
ethers-contract = { version = "2.0.11", default-features = false }
ethers-contract-abigen = { version = "2.0.11", default-features = false }
ethers-providers = { version = "2.0.11", default-features = false }
ethers-signers = { version = "2.0.11", default-features = false }
ethers-middleware = { version = "2.0.11", default-features = false }
ethers-solc = { version = "2.0.11", default-features = false }

## alloy
alloy-primitives = "0.4.1"
Expand Down Expand Up @@ -196,16 +196,16 @@ tower-http = "0.4"
#ethers-solc = { path = "../ethers-rs/ethers-solc" }

[patch.crates-io]
ethers = { git = "https://github.com/gakonst/ethers-rs", rev = "4e09be88730045dd6c4ed8a4e198a9956931e7bd" }
ethers-addressbook = { git = "https://github.com/gakonst/ethers-rs", rev = "4e09be88730045dd6c4ed8a4e198a9956931e7bd" }
ethers-core = { git = "https://github.com/gakonst/ethers-rs", rev = "4e09be88730045dd6c4ed8a4e198a9956931e7bd" }
ethers-contract = { git = "https://github.com/gakonst/ethers-rs", rev = "4e09be88730045dd6c4ed8a4e198a9956931e7bd" }
ethers-contract-abigen = { git = "https://github.com/gakonst/ethers-rs", rev = "4e09be88730045dd6c4ed8a4e198a9956931e7bd" }
ethers-providers = { git = "https://github.com/gakonst/ethers-rs", rev = "4e09be88730045dd6c4ed8a4e198a9956931e7bd" }
ethers-signers = { git = "https://github.com/gakonst/ethers-rs", rev = "4e09be88730045dd6c4ed8a4e198a9956931e7bd" }
ethers-middleware = { git = "https://github.com/gakonst/ethers-rs", rev = "4e09be88730045dd6c4ed8a4e198a9956931e7bd" }
ethers-etherscan = { git = "https://github.com/gakonst/ethers-rs", rev = "4e09be88730045dd6c4ed8a4e198a9956931e7bd" }
ethers-solc = { git = "https://github.com/gakonst/ethers-rs", rev = "4e09be88730045dd6c4ed8a4e198a9956931e7bd" }
ethers = { git = "https://github.com/gakonst/ethers-rs", rev = "4a38a957d6cc4e7efb3de112b74363b657ee1c06" }
ethers-core = { git = "https://github.com/gakonst/ethers-rs", rev = "4a38a957d6cc4e7efb3de112b74363b657ee1c06" }
ethers-contract = { git = "https://github.com/gakonst/ethers-rs", rev = "4a38a957d6cc4e7efb3de112b74363b657ee1c06" }
ethers-contract-abigen = { git = "https://github.com/gakonst/ethers-rs", rev = "4a38a957d6cc4e7efb3de112b74363b657ee1c06" }
ethers-providers = { git = "https://github.com/gakonst/ethers-rs", rev = "4a38a957d6cc4e7efb3de112b74363b657ee1c06" }
ethers-signers = { git = "https://github.com/gakonst/ethers-rs", rev = "4a38a957d6cc4e7efb3de112b74363b657ee1c06" }
ethers-middleware = { git = "https://github.com/gakonst/ethers-rs", rev = "4a38a957d6cc4e7efb3de112b74363b657ee1c06" }
ethers-solc = { git = "https://github.com/gakonst/ethers-rs", rev = "4a38a957d6cc4e7efb3de112b74363b657ee1c06" }

foundry-block-explorers = { git = "https://github.com/foundry-rs/block-explorers" }

alloy-dyn-abi = { git = "https://github.com/alloy-rs/core/" }
alloy-json-abi = { git = "https://github.com/alloy-rs/core/" }
Expand Down
5 changes: 3 additions & 2 deletions crates/anvil/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ vergen = { version = "8", default-features = false, features = ["build", "git",

[dependencies]
# foundry internal
anvil-core = { path = "core", features = ["fastrlp", "serde", "impersonated-tx"] }
anvil-core = { path = "core", features = ["fastrlp", "serde", "impersonated-tx", "optimism"] }
anvil-rpc = { path = "rpc" }
anvil-server = { path = "server" }
foundry-common.workspace = true
Expand All @@ -32,7 +32,7 @@ foundry-utils.workspace = true
bytes = "1.4.0"
# needed as documented in https://github.com/foundry-rs/foundry/pull/6358
k256 = "=0.13.1"
ethers = { workspace = true, features = ["rustls", "ws", "ipc"] }
ethers = { workspace = true, features = ["rustls", "ws", "ipc", "optimism"] }
trie-db = "0.23"
hash-db = "0.15"
memory-db = "0.29"
Expand Down Expand Up @@ -76,6 +76,7 @@ ethereum-forkid = "0.12"

[dev-dependencies]
ethers = { workspace = true, features = ["abigen"] }
ethers-core = { workspace = true, features = ["optimism"] }
ethers-solc = { workspace = true, features = ["project-util", "full"] }
pretty_assertions = "1.3.0"
tokio = { version = "1", features = ["full"] }
Expand Down
8 changes: 6 additions & 2 deletions crates/anvil/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ foundry-utils.workspace = true
revm = { workspace = true, default-features = false, features = ["std", "serde", "memory_limit"] }

alloy-primitives = { workspace = true, features = ["serde"] }
ethers-core.workspace = true
ethers-core = { workspace = true, features = ["optimism"], optional = true }
ethers-contract = { workspace = true, features = ["optimism"], optional = true }
ethers-providers = { workspace = true, features = ["optimism"], optional = true }
ethers-middleware = { workspace = true, features = ["optimism"], optional = true }
mattsse marked this conversation as resolved.
Show resolved Hide resolved
serde = { workspace = true, optional = true }
serde_json.workspace = true
bytes = { version = "1.4" }
Expand All @@ -33,7 +36,8 @@ keccak-hasher = "0.15"
anvil-core = { path = ".", features = ["serde"] }

[features]
default = ["serde"]
default = ["serde","optimism"]
impersonated-tx = []
fastrlp = ["dep:open-fastrlp"]
serde = ["dep:serde"]
optimism = ["ethers-core/optimism", "ethers-contract/optimism", "ethers-providers/optimism", "ethers-middleware/optimism"]
37 changes: 31 additions & 6 deletions crates/anvil/core/src/eth/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ impl Decodable for EIP658Receipt {
// same underlying data structure
pub type EIP2930Receipt = EIP658Receipt;
pub type EIP1559Receipt = EIP658Receipt;
pub type DepositReceipt = EIP658Receipt;

#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
Expand All @@ -104,6 +105,8 @@ pub enum TypedReceipt {
EIP2930(EIP2930Receipt),
/// EIP-1559 receipt
EIP1559(EIP1559Receipt),
/// op-stack deposit receipt
Deposit(DepositReceipt),
}

// == impl TypedReceipt ==
Expand All @@ -112,18 +115,20 @@ impl TypedReceipt {
/// Returns the gas used by the transactions
pub fn gas_used(&self) -> U256 {
match self {
TypedReceipt::Legacy(r) | TypedReceipt::EIP2930(r) | TypedReceipt::EIP1559(r) => {
r.gas_used
}
TypedReceipt::Legacy(r) |
TypedReceipt::EIP2930(r) |
TypedReceipt::EIP1559(r) |
TypedReceipt::Deposit(r) => r.gas_used,
}
}

/// Returns the gas used by the transactions
pub fn logs_bloom(&self) -> &Bloom {
match self {
TypedReceipt::Legacy(r) | TypedReceipt::EIP2930(r) | TypedReceipt::EIP1559(r) => {
&r.logs_bloom
}
TypedReceipt::Legacy(r) |
TypedReceipt::EIP2930(r) |
TypedReceipt::EIP1559(r) |
TypedReceipt::Deposit(r) => &r.logs_bloom,
}
}
}
Expand All @@ -134,6 +139,7 @@ impl Encodable for TypedReceipt {
TypedReceipt::Legacy(r) => r.rlp_append(s),
TypedReceipt::EIP2930(r) => enveloped(1, r, s),
TypedReceipt::EIP1559(r) => enveloped(2, r, s),
TypedReceipt::Deposit(r) => enveloped(0x7E, r, s),
}
}
}
Expand All @@ -158,6 +164,10 @@ impl Decodable for TypedReceipt {
return rlp::decode(s).map(TypedReceipt::EIP1559)
}

if first == 0x7E {
return rlp::decode(s).map(TypedReceipt::Deposit)
}

Err(DecoderError::Custom("unknown receipt type"))
}
}
Expand All @@ -171,6 +181,7 @@ impl open_fastrlp::Encodable for TypedReceipt {
let payload_len = match receipt {
TypedReceipt::EIP2930(r) => r.length() + 1,
TypedReceipt::EIP1559(r) => r.length() + 1,
TypedReceipt::Deposit(r) => r.length() + 1,
_ => unreachable!("receipt already matched"),
};

Expand All @@ -188,6 +199,7 @@ impl open_fastrlp::Encodable for TypedReceipt {
let payload_len = match receipt {
TypedReceipt::EIP2930(r) => r.length() + 1,
TypedReceipt::EIP1559(r) => r.length() + 1,
TypedReceipt::Deposit(r) => r.length() + 1,
_ => unreachable!("receipt already matched"),
};

Expand All @@ -208,6 +220,14 @@ impl open_fastrlp::Encodable for TypedReceipt {
out.put_u8(0x02);
r.encode(out);
}
TypedReceipt::Deposit(r) => {
let receipt_string_header =
Header { list: false, payload_length: payload_len };

receipt_string_header.encode(out);
out.put_u8(0x7E);
r.encode(out);
}
_ => unreachable!("receipt already matched"),
}
}
Expand Down Expand Up @@ -244,6 +264,10 @@ impl open_fastrlp::Decodable for TypedReceipt {
buf.advance(1);
<EIP1559Receipt as open_fastrlp::Decodable>::decode(buf)
.map(TypedReceipt::EIP1559)
} else if receipt_type == 0x7E {
buf.advance(1);
<DepositReceipt as open_fastrlp::Decodable>::decode(buf)
.map(TypedReceipt::Deposit)
} else {
Err(open_fastrlp::DecodeError::Custom("invalid receipt type"))
}
Expand All @@ -264,6 +288,7 @@ impl From<TypedReceipt> for EIP658Receipt {
TypedReceipt::Legacy(receipt) => receipt,
TypedReceipt::EIP2930(receipt) => receipt,
TypedReceipt::EIP1559(receipt) => receipt,
TypedReceipt::Deposit(receipt) => receipt,
}
}
}
Expand Down
Loading
Loading