-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add well-known 0.13.2-style block hashes for Sepolia testnet
We will use these 0.13.2 block hashes for all pre-0.13.2 blocks to verify data we receive from peers via P2P.
- Loading branch information
Showing
7 changed files
with
73 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
[workspace] | ||
members = [ | ||
"crates/block-hashes", | ||
"crates/common", | ||
"crates/compiler", | ||
"crates/crypto", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "pathfinder-block-hashes" | ||
version = { workspace = true } | ||
authors = { workspace = true } | ||
edition = { workspace = true } | ||
license = { workspace = true } | ||
rust-version = { workspace = true } | ||
|
||
[dependencies] | ||
pathfinder-common = { path = "../common" } | ||
pathfinder-crypto = { path = "../crypto" } |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use pathfinder_common::{BlockHash, BlockNumber, Chain}; | ||
|
||
mod sepolia; | ||
|
||
#[derive(Clone)] | ||
pub struct BlockHashDb { | ||
chain: Chain, | ||
} | ||
|
||
impl BlockHashDb { | ||
pub fn new(chain: Chain) -> Self { | ||
Self { chain } | ||
} | ||
|
||
pub fn block_hash(&self, block_number: BlockNumber) -> Option<BlockHash> { | ||
match self.chain { | ||
Chain::SepoliaTestnet => sepolia::block_hash(block_number), | ||
_ => None, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use pathfinder_common::{BlockHash, BlockNumber}; | ||
use pathfinder_crypto::Felt; | ||
|
||
const FIRST_0_13_2_BLOCK: usize = 86311; | ||
static BLOCK_HASHES: &[u8; 32 * FIRST_0_13_2_BLOCK] = | ||
include_bytes!("../fixtures/sepolia_block_hashes.bin"); | ||
|
||
pub(super) fn block_hash(block_number: BlockNumber) -> Option<BlockHash> { | ||
if block_number.get() >= FIRST_0_13_2_BLOCK as u64 { | ||
None | ||
} else { | ||
let offset = (block_number.get() as usize) * 32; | ||
let felt = Felt::from_be_slice(&BLOCK_HASHES[offset..offset + 32]).unwrap(); | ||
Some(BlockHash(felt)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters