Skip to content

Commit 7293e5c

Browse files
authored
change chain IDs to 256-bit numbers (#353)
1 parent 21a3856 commit 7293e5c

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

crates/common/src/commit/response.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::{fmt, fmt::Display};
22

33
use alloy::{
44
hex,
5-
primitives::{Address, B256},
5+
primitives::{Address, B256, U256},
66
rpc::types::beacon::BlsSignature,
77
};
88
use serde::{Deserialize, Serialize};
@@ -15,7 +15,7 @@ pub struct BlsSignResponse {
1515
pub object_root: B256,
1616
pub module_signing_id: B256,
1717
pub nonce: u64,
18-
pub chain_id: u64,
18+
pub chain_id: U256,
1919
pub signature: BlsSignature,
2020
}
2121

@@ -25,7 +25,7 @@ impl BlsSignResponse {
2525
object_root: B256,
2626
module_signing_id: B256,
2727
nonce: u64,
28-
chain_id: u64,
28+
chain_id: U256,
2929
signature: BlsSignature,
3030
) -> Self {
3131
Self { pubkey, object_root, module_signing_id, nonce, chain_id, signature }
@@ -53,7 +53,7 @@ pub struct EcdsaSignResponse {
5353
pub object_root: B256,
5454
pub module_signing_id: B256,
5555
pub nonce: u64,
56-
pub chain_id: u64,
56+
pub chain_id: U256,
5757
pub signature: EcdsaSignature,
5858
}
5959

@@ -63,7 +63,7 @@ impl EcdsaSignResponse {
6363
object_root: B256,
6464
module_signing_id: B256,
6565
nonce: u64,
66-
chain_id: u64,
66+
chain_id: U256,
6767
signature: EcdsaSignature,
6868
) -> Self {
6969
Self { address, object_root, module_signing_id, nonce, chain_id, signature }

crates/common/src/config/pbs.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,13 @@ impl PbsConfig {
169169
if !matches!(chain, Chain::Custom { .. }) {
170170
let provider = ProviderBuilder::new().on_http(rpc_url.clone());
171171
let chain_id = provider.get_chain_id().await?;
172+
let chain_id_big = U256::from(chain_id);
172173
ensure!(
173-
chain_id == chain.id(),
174+
chain_id_big == chain.id(),
174175
"Rpc url is for the wrong chain, expected: {} ({:?}) got {}",
175176
chain.id(),
176177
chain,
177-
chain_id
178+
chain_id_big
178179
);
179180
}
180181
}

crates/common/src/types.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::path::PathBuf;
22

3-
use alloy::primitives::{aliases::B32, hex, Bytes, B256};
3+
use alloy::primitives::{aliases::B32, hex, Bytes, B256, U256};
44
use derive_more::{Deref, Display, From, Into};
55
use eyre::{bail, Context};
66
use serde::{Deserialize, Serialize};
@@ -72,7 +72,9 @@ impl std::fmt::Debug for Chain {
7272
}
7373

7474
impl Chain {
75-
pub fn id(&self) -> u64 {
75+
// Chain IDs are 256-bit unsigned integers because they need to support
76+
// Keccak256 hashes
77+
pub fn id(&self) -> U256 {
7678
match self {
7779
Chain::Mainnet => KnownChain::Mainnet.id(),
7880
Chain::Holesky => KnownChain::Holesky.id(),
@@ -146,13 +148,13 @@ pub enum KnownChain {
146148

147149
// Constants
148150
impl KnownChain {
149-
pub fn id(&self) -> u64 {
151+
pub fn id(&self) -> U256 {
150152
match self {
151-
KnownChain::Mainnet => 1,
152-
KnownChain::Holesky => 17000,
153-
KnownChain::Sepolia => 11155111,
154-
KnownChain::Helder => 167000,
155-
KnownChain::Hoodi => 560048,
153+
KnownChain::Mainnet => U256::from(1),
154+
KnownChain::Holesky => U256::from(17000),
155+
KnownChain::Sepolia => U256::from(11155111),
156+
KnownChain::Helder => U256::from(167000),
157+
KnownChain::Hoodi => U256::from(560048),
156158
}
157159
}
158160

@@ -305,7 +307,7 @@ pub struct PropCommitSigningInfo {
305307
pub data: B256,
306308
pub module_signing_id: B256,
307309
pub nonce: u64, // As per https://eips.ethereum.org/EIPS/eip-2681
308-
pub chain_id: u64,
310+
pub chain_id: U256,
309311
}
310312

311313
/// Information about a signature request, including the module signing ID and

0 commit comments

Comments
 (0)