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-codecs",
"reth-ethereum-forks",
"reth-optimism-chainspec",
"reth-primitives-traits",
"reth-static-file-types",
"reth-testing-utils",

View File

@ -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;
@ -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()

View File

@ -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,
@ -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);

View File

@ -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"] }
@ -35,6 +32,7 @@ alloy-eips = { workspace = true, features = ["serde"] }
op-alloy-rpc-types = { workspace = true, optional = true }
op-alloy-consensus = { workspace = true, features = [
"arbitrary",
"serde",
], optional = true }
# crypto
@ -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",
@ -124,7 +119,7 @@ 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 = [
@ -135,7 +130,6 @@ c-kzg = [
]
optimism = [
"dep:op-alloy-consensus",
"dep:reth-optimism-chainspec",
"reth-codecs?/optimism",
"revm-primitives/optimism",
]
@ -148,14 +142,14 @@ 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]]

View File

@ -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::{
@ -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)
}
}
@ -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(),
)),
}
}
@ -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))
}

View File

@ -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.
///
@ -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())