Skip to content

Commit

Permalink
refactor: use op-alloy deposit signature (paradigmxyz#12016)
Browse files Browse the repository at this point in the history
  • Loading branch information
caglaryucekaya authored Oct 24, 2024
1 parent 4093532 commit 082f2cd
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 49 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

8 changes: 1 addition & 7 deletions crates/optimism/chainspec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ mod op_sepolia;
use alloc::{vec, vec::Vec};
use alloy_chains::Chain;
use alloy_genesis::Genesis;
use alloy_primitives::{Parity, Signature, B256, U256};
use alloy_primitives::{B256, U256};
pub use base::BASE_MAINNET;
pub use base_sepolia::BASE_SEPOLIA;
use core::fmt::Display;
Expand Down Expand Up @@ -178,12 +178,6 @@ pub struct OpChainSpec {
pub inner: ChainSpec,
}

/// Returns the signature for the optimism deposit transactions, which don't include a
/// signature.
pub fn optimism_deposit_tx_signature() -> Signature {
Signature::new(U256::ZERO, U256::ZERO, Parity::Parity(false))
}

impl EthChainSpec for OpChainSpec {
fn chain(&self) -> alloy_chains::Chain {
self.inner.chain()
Expand Down
5 changes: 3 additions & 2 deletions crates/optimism/evm/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,10 @@ mod tests {
use crate::OpChainSpec;
use alloy_consensus::TxEip1559;
use alloy_primitives::{b256, Address, StorageKey, StorageValue};
use op_alloy_consensus::TxDeposit;
use reth_chainspec::MIN_TRANSACTION_GAS;
use reth_evm::execute::{BasicBlockExecutorProvider, BatchExecutor, BlockExecutorProvider};
use reth_optimism_chainspec::{optimism_deposit_tx_signature, OpChainSpecBuilder};
use reth_optimism_chainspec::OpChainSpecBuilder;
use reth_primitives::{Account, Block, BlockBody, Signature, Transaction, TransactionSigned};
use reth_revm::{
database::StateProviderDatabase, test_utils::StateProviderTest, L1_BLOCK_CONTRACT,
Expand Down Expand Up @@ -465,7 +466,7 @@ mod tests {
gas_limit: MIN_TRANSACTION_GAS,
..Default::default()
}),
optimism_deposit_tx_signature(),
TxDeposit::signature(),
);

let provider = executor_provider(chain_spec);
Expand Down
52 changes: 23 additions & 29 deletions crates/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ reth-trie-common.workspace = true
revm-primitives = { workspace = true, features = ["serde"] }
reth-codecs = { workspace = true, optional = true }

# op-reth
reth-optimism-chainspec = { workspace = true, optional = true }

# ethereum
alloy-consensus.workspace = true
alloy-primitives = { workspace = true, features = ["rand", "rlp"] }
Expand All @@ -34,14 +31,15 @@ alloy-eips = { workspace = true, features = ["serde"] }
# optimism
op-alloy-rpc-types = { workspace = true, optional = true }
op-alloy-consensus = { workspace = true, features = [
"arbitrary",
"arbitrary",
"serde",
], optional = true }

# crypto
secp256k1 = { workspace = true, features = [
"global-context",
"recovery",
"rand",
"global-context",
"recovery",
"rand",
], optional = true }
k256.workspace = true
# for eip-4844
Expand Down Expand Up @@ -83,9 +81,9 @@ test-fuzz.workspace = true

criterion.workspace = true
pprof = { workspace = true, features = [
"flamegraph",
"frame-pointer",
"criterion",
"flamegraph",
"frame-pointer",
"criterion",
] }

[features]
Expand All @@ -101,13 +99,10 @@ std = [
"once_cell/std",
"revm-primitives/std",
"secp256k1?/std",
"serde/std"
"serde/std",
]
reth-codec = ["dep:reth-codecs", "dep:zstd", "dep:modular-bitfield", "std"]
asm-keccak = [
"alloy-primitives/asm-keccak",
"revm-primitives/asm-keccak"
]
asm-keccak = ["alloy-primitives/asm-keccak", "revm-primitives/asm-keccak"]
arbitrary = [
"dep:arbitrary",
"alloy-eips/arbitrary",
Expand All @@ -124,38 +119,37 @@ arbitrary = [
"alloy-rpc-types?/arbitrary",
"alloy-serde?/arbitrary",
"op-alloy-consensus?/arbitrary",
"op-alloy-rpc-types?/arbitrary"
"op-alloy-rpc-types?/arbitrary",
]
secp256k1 = ["dep:secp256k1"]
c-kzg = [
"dep:c-kzg",
"alloy-consensus/kzg",
"alloy-eips/kzg",
"revm-primitives/c-kzg",
"dep:c-kzg",
"alloy-consensus/kzg",
"alloy-eips/kzg",
"revm-primitives/c-kzg",
]
optimism = [
"dep:op-alloy-consensus",
"dep:reth-optimism-chainspec",
"reth-codecs?/optimism",
"revm-primitives/optimism",
"dep:op-alloy-consensus",
"reth-codecs?/optimism",
"revm-primitives/optimism",
]
alloy-compat = [
"dep:alloy-rpc-types",
"dep:alloy-serde",
"dep:op-alloy-rpc-types",
"dep:alloy-rpc-types",
"dep:alloy-serde",
"dep:op-alloy-rpc-types",
]
test-utils = [
"reth-primitives-traits/test-utils",
"reth-chainspec/test-utils",
"reth-codecs?/test-utils",
"reth-trie-common/test-utils"
"reth-trie-common/test-utils",
]
serde-bincode-compat = [
"alloy-consensus/serde-bincode-compat",
"op-alloy-consensus?/serde-bincode-compat",
"reth-primitives-traits/serde-bincode-compat",
"serde_with",
"alloy-eips/serde-bincode-compat"
"alloy-eips/serde-bincode-compat",
]

[[bench]]
Expand Down
9 changes: 3 additions & 6 deletions crates/primitives/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ mod variant;
#[cfg(feature = "optimism")]
use op_alloy_consensus::TxDeposit;
#[cfg(feature = "optimism")]
use reth_optimism_chainspec::optimism_deposit_tx_signature;
#[cfg(feature = "optimism")]
pub use tx_type::DEPOSIT_TX_TYPE_ID;
#[cfg(any(test, feature = "reth-codec"))]
use tx_type::{
Expand Down Expand Up @@ -955,7 +953,7 @@ impl TransactionSignedNoHash {
// transactions with an empty signature
//
// NOTE: this is very hacky and only relevant for op-mainnet pre bedrock
if self.is_legacy() && self.signature == optimism_deposit_tx_signature() {
if self.is_legacy() && self.signature == TxDeposit::signature() {
return Some(Address::ZERO)
}
}
Expand Down Expand Up @@ -1530,7 +1528,7 @@ impl Decodable2718 for TransactionSigned {
#[cfg(feature = "optimism")]
TxType::Deposit => Ok(Self::from_transaction_and_signature(
Transaction::Deposit(TxDeposit::decode(buf)?),
optimism_deposit_tx_signature(),
TxDeposit::signature(),
)),
}
}
Expand Down Expand Up @@ -1575,8 +1573,7 @@ impl<'a> arbitrary::Arbitrary<'a> for TransactionSigned {
}

#[cfg(feature = "optimism")]
let signature =
if transaction.is_deposit() { optimism_deposit_tx_signature() } else { signature };
let signature = if transaction.is_deposit() { TxDeposit::signature() } else { signature };

Ok(Self::from_transaction_and_signature(transaction, signature))
}
Expand Down
5 changes: 1 addition & 4 deletions crates/primitives/src/transaction/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ use alloy_rlp::{Decodable, Error as RlpError};

pub use alloy_primitives::Signature;

#[cfg(feature = "optimism")]
use reth_optimism_chainspec::optimism_deposit_tx_signature;

/// The order of the secp256k1 curve, divided by two. Signatures that should be checked according
/// to EIP-2 should have an S value less than or equal to this.
///
Expand Down Expand Up @@ -82,7 +79,7 @@ pub fn legacy_parity(signature: &Signature, chain_id: Option<u64>) -> Parity {
// transactions with an empty signature
//
// NOTE: this is very hacky and only relevant for op-mainnet pre bedrock
if *signature == optimism_deposit_tx_signature() {
if *signature == op_alloy_consensus::TxDeposit::signature() {
return Parity::Parity(false)
}
Parity::NonEip155(signature.v().y_parity())
Expand Down

0 comments on commit 082f2cd

Please sign in to comment.