refactor: use op-alloy deposit signature (#12016)

This commit is contained in:
caglarkaya
2024-10-24 04:19:39 +03:00
committed by GitHub
parent 40935321e3
commit 082f2cd235
6 changed files with 31 additions and 49 deletions

1
Cargo.lock generated
View File

@ -8394,7 +8394,6 @@ dependencies = [
"reth-chainspec", "reth-chainspec",
"reth-codecs", "reth-codecs",
"reth-ethereum-forks", "reth-ethereum-forks",
"reth-optimism-chainspec",
"reth-primitives-traits", "reth-primitives-traits",
"reth-static-file-types", "reth-static-file-types",
"reth-testing-utils", "reth-testing-utils",

View File

@ -20,7 +20,7 @@ mod op_sepolia;
use alloc::{vec, vec::Vec}; use alloc::{vec, vec::Vec};
use alloy_chains::Chain; use alloy_chains::Chain;
use alloy_genesis::Genesis; use alloy_genesis::Genesis;
use alloy_primitives::{Parity, Signature, B256, U256}; use alloy_primitives::{B256, U256};
pub use base::BASE_MAINNET; pub use base::BASE_MAINNET;
pub use base_sepolia::BASE_SEPOLIA; pub use base_sepolia::BASE_SEPOLIA;
use core::fmt::Display; use core::fmt::Display;
@ -178,12 +178,6 @@ pub struct OpChainSpec {
pub inner: ChainSpec, 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 { impl EthChainSpec for OpChainSpec {
fn chain(&self) -> alloy_chains::Chain { fn chain(&self) -> alloy_chains::Chain {
self.inner.chain() self.inner.chain()

View File

@ -297,9 +297,10 @@ mod tests {
use crate::OpChainSpec; use crate::OpChainSpec;
use alloy_consensus::TxEip1559; use alloy_consensus::TxEip1559;
use alloy_primitives::{b256, Address, StorageKey, StorageValue}; use alloy_primitives::{b256, Address, StorageKey, StorageValue};
use op_alloy_consensus::TxDeposit;
use reth_chainspec::MIN_TRANSACTION_GAS; use reth_chainspec::MIN_TRANSACTION_GAS;
use reth_evm::execute::{BasicBlockExecutorProvider, BatchExecutor, BlockExecutorProvider}; 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_primitives::{Account, Block, BlockBody, Signature, Transaction, TransactionSigned};
use reth_revm::{ use reth_revm::{
database::StateProviderDatabase, test_utils::StateProviderTest, L1_BLOCK_CONTRACT, database::StateProviderDatabase, test_utils::StateProviderTest, L1_BLOCK_CONTRACT,
@ -465,7 +466,7 @@ mod tests {
gas_limit: MIN_TRANSACTION_GAS, gas_limit: MIN_TRANSACTION_GAS,
..Default::default() ..Default::default()
}), }),
optimism_deposit_tx_signature(), TxDeposit::signature(),
); );
let provider = executor_provider(chain_spec); let provider = executor_provider(chain_spec);

View File

@ -20,9 +20,6 @@ reth-trie-common.workspace = true
revm-primitives = { workspace = true, features = ["serde"] } revm-primitives = { workspace = true, features = ["serde"] }
reth-codecs = { workspace = true, optional = true } reth-codecs = { workspace = true, optional = true }
# op-reth
reth-optimism-chainspec = { workspace = true, optional = true }
# ethereum # ethereum
alloy-consensus.workspace = true alloy-consensus.workspace = true
alloy-primitives = { workspace = true, features = ["rand", "rlp"] } alloy-primitives = { workspace = true, features = ["rand", "rlp"] }
@ -34,14 +31,15 @@ alloy-eips = { workspace = true, features = ["serde"] }
# optimism # optimism
op-alloy-rpc-types = { workspace = true, optional = true } op-alloy-rpc-types = { workspace = true, optional = true }
op-alloy-consensus = { workspace = true, features = [ op-alloy-consensus = { workspace = true, features = [
"arbitrary", "arbitrary",
"serde",
], optional = true } ], optional = true }
# crypto # crypto
secp256k1 = { workspace = true, features = [ secp256k1 = { workspace = true, features = [
"global-context", "global-context",
"recovery", "recovery",
"rand", "rand",
], optional = true } ], optional = true }
k256.workspace = true k256.workspace = true
# for eip-4844 # for eip-4844
@ -83,9 +81,9 @@ test-fuzz.workspace = true
criterion.workspace = true criterion.workspace = true
pprof = { workspace = true, features = [ pprof = { workspace = true, features = [
"flamegraph", "flamegraph",
"frame-pointer", "frame-pointer",
"criterion", "criterion",
] } ] }
[features] [features]
@ -101,13 +99,10 @@ std = [
"once_cell/std", "once_cell/std",
"revm-primitives/std", "revm-primitives/std",
"secp256k1?/std", "secp256k1?/std",
"serde/std" "serde/std",
] ]
reth-codec = ["dep:reth-codecs", "dep:zstd", "dep:modular-bitfield", "std"] reth-codec = ["dep:reth-codecs", "dep:zstd", "dep:modular-bitfield", "std"]
asm-keccak = [ asm-keccak = ["alloy-primitives/asm-keccak", "revm-primitives/asm-keccak"]
"alloy-primitives/asm-keccak",
"revm-primitives/asm-keccak"
]
arbitrary = [ arbitrary = [
"dep:arbitrary", "dep:arbitrary",
"alloy-eips/arbitrary", "alloy-eips/arbitrary",
@ -124,38 +119,37 @@ arbitrary = [
"alloy-rpc-types?/arbitrary", "alloy-rpc-types?/arbitrary",
"alloy-serde?/arbitrary", "alloy-serde?/arbitrary",
"op-alloy-consensus?/arbitrary", "op-alloy-consensus?/arbitrary",
"op-alloy-rpc-types?/arbitrary" "op-alloy-rpc-types?/arbitrary",
] ]
secp256k1 = ["dep:secp256k1"] secp256k1 = ["dep:secp256k1"]
c-kzg = [ c-kzg = [
"dep:c-kzg", "dep:c-kzg",
"alloy-consensus/kzg", "alloy-consensus/kzg",
"alloy-eips/kzg", "alloy-eips/kzg",
"revm-primitives/c-kzg", "revm-primitives/c-kzg",
] ]
optimism = [ optimism = [
"dep:op-alloy-consensus", "dep:op-alloy-consensus",
"dep:reth-optimism-chainspec", "reth-codecs?/optimism",
"reth-codecs?/optimism", "revm-primitives/optimism",
"revm-primitives/optimism",
] ]
alloy-compat = [ alloy-compat = [
"dep:alloy-rpc-types", "dep:alloy-rpc-types",
"dep:alloy-serde", "dep:alloy-serde",
"dep:op-alloy-rpc-types", "dep:op-alloy-rpc-types",
] ]
test-utils = [ test-utils = [
"reth-primitives-traits/test-utils", "reth-primitives-traits/test-utils",
"reth-chainspec/test-utils", "reth-chainspec/test-utils",
"reth-codecs?/test-utils", "reth-codecs?/test-utils",
"reth-trie-common/test-utils" "reth-trie-common/test-utils",
] ]
serde-bincode-compat = [ serde-bincode-compat = [
"alloy-consensus/serde-bincode-compat", "alloy-consensus/serde-bincode-compat",
"op-alloy-consensus?/serde-bincode-compat", "op-alloy-consensus?/serde-bincode-compat",
"reth-primitives-traits/serde-bincode-compat", "reth-primitives-traits/serde-bincode-compat",
"serde_with", "serde_with",
"alloy-eips/serde-bincode-compat" "alloy-eips/serde-bincode-compat",
] ]
[[bench]] [[bench]]

View File

@ -56,8 +56,6 @@ mod variant;
#[cfg(feature = "optimism")] #[cfg(feature = "optimism")]
use op_alloy_consensus::TxDeposit; use op_alloy_consensus::TxDeposit;
#[cfg(feature = "optimism")] #[cfg(feature = "optimism")]
use reth_optimism_chainspec::optimism_deposit_tx_signature;
#[cfg(feature = "optimism")]
pub use tx_type::DEPOSIT_TX_TYPE_ID; pub use tx_type::DEPOSIT_TX_TYPE_ID;
#[cfg(any(test, feature = "reth-codec"))] #[cfg(any(test, feature = "reth-codec"))]
use tx_type::{ use tx_type::{
@ -955,7 +953,7 @@ impl TransactionSignedNoHash {
// transactions with an empty signature // transactions with an empty signature
// //
// NOTE: this is very hacky and only relevant for op-mainnet pre bedrock // 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) return Some(Address::ZERO)
} }
} }
@ -1530,7 +1528,7 @@ impl Decodable2718 for TransactionSigned {
#[cfg(feature = "optimism")] #[cfg(feature = "optimism")]
TxType::Deposit => Ok(Self::from_transaction_and_signature( TxType::Deposit => Ok(Self::from_transaction_and_signature(
Transaction::Deposit(TxDeposit::decode(buf)?), Transaction::Deposit(TxDeposit::decode(buf)?),
optimism_deposit_tx_signature(), TxDeposit::signature(),
)), )),
} }
} }
@ -1575,8 +1573,7 @@ impl<'a> arbitrary::Arbitrary<'a> for TransactionSigned {
} }
#[cfg(feature = "optimism")] #[cfg(feature = "optimism")]
let signature = let signature = if transaction.is_deposit() { TxDeposit::signature() } else { signature };
if transaction.is_deposit() { optimism_deposit_tx_signature() } else { signature };
Ok(Self::from_transaction_and_signature(transaction, signature)) Ok(Self::from_transaction_and_signature(transaction, signature))
} }

View File

@ -4,9 +4,6 @@ use alloy_rlp::{Decodable, Error as RlpError};
pub use alloy_primitives::Signature; 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 /// 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. /// to EIP-2 should have an S value less than or equal to this.
/// ///
@ -82,7 +79,7 @@ pub fn legacy_parity(signature: &Signature, chain_id: Option<u64>) -> Parity {
// transactions with an empty signature // transactions with an empty signature
// //
// NOTE: this is very hacky and only relevant for op-mainnet pre bedrock // 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) return Parity::Parity(false)
} }
Parity::NonEip155(signature.v().y_parity()) Parity::NonEip155(signature.v().y_parity())