Skip to content

Commit e043fb4

Browse files
committed
validate header
1 parent 901cd5e commit e043fb4

File tree

12 files changed

+203
-32
lines changed

12 files changed

+203
-32
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ alloy = { version = "0.5.4", features = [
3232
"serde",
3333
"ssz",
3434
"getrandom",
35+
"providers",
3536
] }
3637
ssz_types = "0.8"
3738
ethereum_serde_utils = "0.7.0"
@@ -47,6 +48,7 @@ tokio = { version = "1.37.0", features = ["full"] }
4748
futures = "0.3.30"
4849
async-trait = "0.1.80"
4950
dashmap = "5.5.3"
51+
parking_lot = "0.12.3"
5052

5153
# serialization
5254
toml = "0.8.13"

config.example.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ relay_monitors = []
4747
# to force local building and miniminzing the risk of missed slots. See also the timing games section below
4848
# OPTIONAL, DEFAULT: 2000
4949
late_in_slot_time_ms = 2000
50+
# Whether to enable extra validation of get_header responses, if this is enabled you need to set `el_rpc_url`
51+
# OPTIONAL, DEFAULT: false
52+
extra_validation_enabled = false
53+
# EL RPC url to use for extra validation
54+
# OPTIONAL
55+
el_rpc_url = "http://abc.xyz"
5056

5157
# The PBS module needs one or more [[relays]] as defined below.
5258
[[relays]]

crates/common/src/config/pbs.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ pub struct PbsConfig {
6565
/// How late in the slot we consider to be "late"
6666
#[serde(default = "default_u64::<LATE_IN_SLOT_TIME_MS>")]
6767
pub late_in_slot_time_ms: u64,
68+
/// Enable extra validation of get_header responses
69+
#[serde(default = "default_bool::<false>")]
70+
pub extra_validation_enabled: bool,
71+
/// EL RPC url to use for extra validation
72+
pub el_rpc_url: Option<Url>,
6873
}
6974

7075
impl PbsConfig {
@@ -89,6 +94,13 @@ impl PbsConfig {
8994
format!("min bid is too high: {} ETH", format_ether(self.min_bid_wei))
9095
);
9196

97+
if self.extra_validation_enabled {
98+
ensure!(
99+
self.el_rpc_url.is_some(),
100+
"el_rpc_url is required if extra_validation_enabled is true"
101+
);
102+
}
103+
92104
Ok(())
93105
}
94106
}

crates/common/src/pbs/error.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,13 @@ pub enum ValidationError {
6969

7070
#[error("failed signature verification: {0:?}")]
7171
Sigverify(#[from] BlstErrorWrapper),
72+
73+
#[error("wrong timestamp: expected {expected} got {got}")]
74+
TimestampMismatch { expected: u64, got: u64 },
75+
76+
#[error("wrong block number: parent: {parent} header: {header}")]
77+
BlockNumberMismatch { parent: u64, header: u64 },
78+
79+
#[error("invalid gas limit: parent: {parent} header: {header}")]
80+
GasLimit { parent: u64, header: u64 },
7281
}

crates/common/src/utils.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ use crate::{
2222

2323
const MILLIS_PER_SECOND: u64 = 1_000;
2424

25+
pub fn timestamp_of_slot_start_sec(slot: u64, chain: Chain) -> u64 {
26+
chain.genesis_time_sec() + slot * chain.slot_time_sec()
27+
}
2528
pub fn timestamp_of_slot_start_millis(slot: u64, chain: Chain) -> u64 {
26-
let seconds_since_genesis = chain.genesis_time_sec() + slot * chain.slot_time_sec();
27-
seconds_since_genesis * MILLIS_PER_SECOND
29+
timestamp_of_slot_start_sec(slot, chain) * MILLIS_PER_SECOND
2830
}
2931
pub fn ms_into_slot(slot: u64, chain: Chain) -> u64 {
3032
let slot_start_ms = timestamp_of_slot_start_millis(slot, chain);

crates/pbs/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ tokio.workspace = true
2121
futures.workspace = true
2222
async-trait.workspace = true
2323
dashmap.workspace = true
24+
parking_lot.workspace = true
2425

2526
# serialization
2627
serde_json.workspace = true
@@ -37,4 +38,4 @@ thiserror.workspace = true
3738
eyre.workspace = true
3839
url.workspace = true
3940
uuid.workspace = true
40-
lazy_static.workspace = true
41+
lazy_static.workspace = true

0 commit comments

Comments
 (0)