Skip to content

Commit 9fdb987

Browse files
authored
CBST-03: validate more get header (#188)
* validate header * url name
1 parent b999b38 commit 9fdb987

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
@@ -52,6 +52,12 @@ relay_monitors = []
5252
# to force local building and miniminzing the risk of missed slots. See also the timing games section below
5353
# OPTIONAL, DEFAULT: 2000
5454
late_in_slot_time_ms = 2000
55+
# Whether to enable extra validation of get_header responses, if this is enabled you need to set `rpc_url`
56+
# OPTIONAL, DEFAULT: false
57+
extra_validation_enabled = false
58+
# Execution Layer RPC url to use for extra validation
59+
# OPTIONAL
60+
rpc_url = "http://abc.xyz"
5561

5662
# The PBS module needs one or more [[relays]] as defined below.
5763
[[relays]]

crates/common/src/config/pbs.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ pub struct PbsConfig {
8080
/// How late in the slot we consider to be "late"
8181
#[serde(default = "default_u64::<LATE_IN_SLOT_TIME_MS>")]
8282
pub late_in_slot_time_ms: u64,
83+
/// Enable extra validation of get_header responses
84+
#[serde(default = "default_bool::<false>")]
85+
pub extra_validation_enabled: bool,
86+
/// Execution Layer RPC url to use for extra validation
87+
pub rpc_url: Option<Url>,
8388
}
8489

8590
impl PbsConfig {
@@ -104,6 +109,13 @@ impl PbsConfig {
104109
format!("min bid is too high: {} ETH", format_ether(self.min_bid_wei))
105110
);
106111

112+
if self.extra_validation_enabled {
113+
ensure!(
114+
self.rpc_url.is_some(),
115+
"rpc_url is required if extra_validation_enabled is true"
116+
);
117+
}
118+
107119
Ok(())
108120
}
109121
}

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
@@ -25,9 +25,11 @@ use crate::{
2525

2626
const MILLIS_PER_SECOND: u64 = 1_000;
2727

28+
pub fn timestamp_of_slot_start_sec(slot: u64, chain: Chain) -> u64 {
29+
chain.genesis_time_sec() + slot * chain.slot_time_sec()
30+
}
2831
pub fn timestamp_of_slot_start_millis(slot: u64, chain: Chain) -> u64 {
29-
let slot_start_seconds = chain.genesis_time_sec() + slot * chain.slot_time_sec();
30-
slot_start_seconds * MILLIS_PER_SECOND
32+
timestamp_of_slot_start_sec(slot, chain) * MILLIS_PER_SECOND
3133
}
3234
pub fn ms_into_slot(slot: u64, chain: Chain) -> u64 {
3335
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)