Skip to content

Commit 87d3325

Browse files
greged93mattsseshekhirinfrisitano
authored
feat: update scroll consensus (#314)
* feat: block validation Signed-off-by: Gregory Edison <[email protected]> * feat: header validation Signed-off-by: Gregory Edison <[email protected]> * feat: body validation Signed-off-by: Gregory Edison <[email protected]> * feat: withdraw trie root slot (#312) * feat: update execute_with_state_closure closure Signed-off-by: Gregory Edison <[email protected]> * feat: LoadWithdrawRoot Signed-off-by: Gregory Edison <[email protected]> * chore: fix clippy docs (paradigmxyz#17726) Co-authored-by: Alexey Shekhirin <[email protected]> * fix: clippy Signed-off-by: Gregory Edison <[email protected]> --------- Signed-off-by: Gregory Edison <[email protected]> Co-authored-by: Matthias Seitz <[email protected]> Co-authored-by: Alexey Shekhirin <[email protected]> * chore: reorg Signed-off-by: Gregory Edison <[email protected]> * feat: answer comment + add unit test Signed-off-by: Gregory Edison <[email protected]> * feat: answer comment Signed-off-by: Gregory Edison <[email protected]> * feat: check sequential L1 message post EuclidV2 Signed-off-by: Gregory Edison <[email protected]> --------- Signed-off-by: Gregory Edison <[email protected]> Co-authored-by: Matthias Seitz <[email protected]> Co-authored-by: Alexey Shekhirin <[email protected]> Co-authored-by: frisitano <[email protected]>
1 parent 3b4a3c3 commit 87d3325

File tree

11 files changed

+770
-35
lines changed

11 files changed

+770
-35
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/scroll/alloy/consensus/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ extern crate alloc as std;
1313
mod transaction;
1414
pub use transaction::{
1515
ScrollAdditionalInfo, ScrollL1MessageTransactionFields, ScrollPooledTransaction,
16-
ScrollTransactionInfo, ScrollTxEnvelope, ScrollTxType, ScrollTypedTransaction, TxL1Message,
17-
L1_MESSAGE_TRANSACTION_TYPE, L1_MESSAGE_TX_TYPE_ID,
16+
ScrollTransaction, ScrollTransactionInfo, ScrollTxEnvelope, ScrollTxType,
17+
ScrollTypedTransaction, TxL1Message, L1_MESSAGE_TRANSACTION_TYPE, L1_MESSAGE_TX_TYPE_ID,
1818
};
1919

2020
mod receipt;

crates/scroll/alloy/consensus/src/transaction/envelope.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,30 @@ impl ScrollTxEnvelope {
424424
}
425425
}
426426

427+
/// A Scroll chain transaction.
428+
pub trait ScrollTransaction {
429+
/// Returns true if the transaction is a L1 message.
430+
fn is_l1_message(&self) -> bool;
431+
/// Returns the queue index if the transaction is a L1 message, None otherwise.
432+
fn queue_index(&self) -> Option<u64>;
433+
}
434+
435+
impl ScrollTransaction for ScrollTxEnvelope {
436+
fn is_l1_message(&self) -> bool {
437+
match self {
438+
Self::Legacy(_) | Self::Eip2930(_) | Self::Eip1559(_) | Self::Eip7702(_) => false,
439+
Self::L1Message(_) => true,
440+
}
441+
}
442+
443+
fn queue_index(&self) -> Option<u64> {
444+
match self {
445+
Self::Legacy(_) | Self::Eip2930(_) | Self::Eip1559(_) | Self::Eip7702(_) => None,
446+
Self::L1Message(tx) => Some(tx.queue_index),
447+
}
448+
}
449+
}
450+
427451
#[cfg(feature = "reth-codec")]
428452
impl ToTxCompact for ScrollTxEnvelope {
429453
fn to_tx_compact(&self, buf: &mut (impl BufMut + AsMut<[u8]>)) {

crates/scroll/alloy/consensus/src/transaction/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ mod tx_type;
44
pub use tx_type::{ScrollTxType, L1_MESSAGE_TX_TYPE_ID};
55

66
mod envelope;
7-
pub use envelope::ScrollTxEnvelope;
7+
pub use envelope::{ScrollTransaction, ScrollTxEnvelope};
88

99
mod l1_message;
1010
pub use l1_message::{ScrollL1MessageTransactionFields, TxL1Message, L1_MESSAGE_TRANSACTION_TYPE};

crates/scroll/consensus/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ workspace = true
1414
[dependencies]
1515
# alloy
1616
alloy-consensus.workspace = true
17-
alloy-primitives.workspace = true
17+
alloy-primitives = { workspace = true, features = ["getrandom"] }
1818

1919
# reth
2020
reth-chainspec.workspace = true
@@ -26,6 +26,7 @@ reth-primitives-traits.workspace = true
2626

2727
# scroll
2828
reth-scroll-primitives = { workspace = true, default-features = false }
29+
scroll-alloy-consensus.workspace = true
2930
scroll-alloy-hardforks.workspace = true
3031

3132
# misc
@@ -34,3 +35,6 @@ tracing.workspace = true
3435

3536
[package.metadata.cargo-udeps.ignore]
3637
normal = ["reth-primitives"]
38+
39+
[dev-dependencies]
40+
reth-scroll-chainspec.workspace = true

crates/scroll/consensus/src/constants.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,12 @@ use alloy_primitives::U256;
22

33
/// The maximum value Rollup fee.
44
pub const MAX_ROLLUP_FEE: U256 = U256::from_limbs([u64::MAX, 0, 0, 0]);
5+
6+
/// The block difficulty for in turn signing in the Clique consensus.
7+
pub const CLIQUE_IN_TURN_DIFFICULTY: U256 = U256::from_limbs([2, 0, 0, 0]);
8+
9+
/// The block difficulty for out of turn signing in the Clique consensus.
10+
pub const CLIQUE_NO_TURN_DIFFICULTY: U256 = U256::from_limbs([1, 0, 0, 0]);
11+
12+
/// Maximum allowed base fee. We would only go above this if L1 base fee hits 2931 Gwei.
13+
pub const SCROLL_MAXIMUM_BASE_FEE: u64 = 10000000000;

crates/scroll/consensus/src/error.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
use crate::constants::SCROLL_MAXIMUM_BASE_FEE;
2+
3+
use alloy_primitives::{Address, B256, B64, U256};
14
use reth_consensus::ConsensusError;
25

36
/// Scroll consensus error.
@@ -6,10 +9,55 @@ pub enum ScrollConsensusError {
69
/// L1 [`ConsensusError`], that also occurs on L2.
710
#[error(transparent)]
811
Eth(#[from] ConsensusError),
12+
/// Invalid L1 messages order.
13+
#[error("invalid L1 message order")]
14+
InvalidL1MessageOrder,
15+
/// Block has non zero coinbase.
16+
#[error("block coinbase not zero: {0}")]
17+
CoinbaseNotZero(Address),
18+
/// Block has non zero nonce.
19+
#[error("block nonce not zero: {0:?}")]
20+
NonceNotZero(Option<B64>),
21+
/// Block has invalid clique nonce.
22+
#[error("block nonce should be 0x0 or 0xffffffffffffffff: {0:?}")]
23+
InvalidCliqueNonce(Option<B64>),
24+
/// Block has non zero mix hash.
25+
#[error("block mix hash not zero: {0:?}")]
26+
MixHashNotZero(Option<B256>),
27+
/// Block difficulty is not one.
28+
#[error("block difficulty not one: {0}")]
29+
DifficultyNotOne(U256),
30+
/// Block has invalid clique difficulty.
31+
#[error("block difficulty should be 1 or 2: {0}")]
32+
InvalidCliqueDifficulty(U256),
33+
/// Block extra data missing vanity.
34+
#[error("block extra data missing vanity")]
35+
MissingVanity,
36+
/// Block extra data missing signature.
37+
#[error("block extra data missing signature")]
38+
MissingSignature,
39+
/// Block extra data with invalid checkpoint signers.
40+
#[error("block extra data contains invalid checkpoint signers")]
41+
InvalidCheckpointSigners,
42+
/// Block base fee present before Curie.
43+
#[error("block base fee is set before Curie fork activation")]
44+
UnexpectedBaseFee,
45+
/// Block base fee over limit.
46+
#[error("block base fee is over limit of {SCROLL_MAXIMUM_BASE_FEE}")]
47+
BaseFeeOverLimit,
948
/// Block body has non-empty withdrawals list.
1049
#[error("non-empty block body withdrawals list")]
1150
WithdrawalsNonEmpty,
1251
/// Chain spec yielded unexpected blob params.
1352
#[error("unexpected blob params at timestamp")]
1453
UnexpectedBlobParams,
1554
}
55+
56+
impl From<ScrollConsensusError> for ConsensusError {
57+
fn from(value: ScrollConsensusError) -> Self {
58+
match value {
59+
ScrollConsensusError::Eth(eth) => eth,
60+
err => Self::Other(err.to_string()),
61+
}
62+
}
63+
}

crates/scroll/consensus/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
extern crate alloc;
44

55
mod constants;
6-
pub use constants::MAX_ROLLUP_FEE;
6+
pub use constants::{
7+
CLIQUE_IN_TURN_DIFFICULTY, CLIQUE_NO_TURN_DIFFICULTY, MAX_ROLLUP_FEE, SCROLL_MAXIMUM_BASE_FEE,
8+
};
79

810
mod error;
911
pub use error::ScrollConsensusError;

0 commit comments

Comments
 (0)