-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
### Description Sets up a `p2p` crate for `hera` based off of paradigmxyz/reth-exex-examples#15. ### Metadata Makes progress on #6
- Loading branch information
Showing
5 changed files
with
93 additions
and
0 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
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 @@ | ||
[package] | ||
name = "p2p" | ||
description = "Consensus P2P Stack for L2" | ||
version = "0.0.0" | ||
edition.workspace = true | ||
authors.workspace = true | ||
license.workspace = true | ||
keywords.workspace = true | ||
repository.workspace = true | ||
categories.workspace = true | ||
rust-version.workspace = true | ||
|
||
[dependencies] | ||
alloy.workspace = true | ||
|
||
kona-primitives = { git = "https://github.com/ethereum-optimism/kona", default-features = true } |
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,10 @@ | ||
//! Consensus P2P Stack | ||
|
||
#![doc(issue_tracker_base_url = "https://github.com/paradigmxyz/op-rs/issues/")] | ||
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] | ||
#![cfg_attr(not(test), warn(unused_crate_dependencies))] | ||
#![cfg_attr(not(test), no_std)] | ||
|
||
extern crate alloc; | ||
|
||
pub mod types; |
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,58 @@ | ||
//! Types for the P2P network. | ||
|
||
use alloc::vec::Vec; | ||
use alloy::primitives::{keccak256, Signature, B256}; | ||
use kona_primitives::L2ExecutionPayload; | ||
|
||
/// An envelope around the execution payload for L2. | ||
#[derive(Debug)] | ||
pub struct ExecutionPayloadEnvelope { | ||
/// The execution payload. | ||
pub payload: L2ExecutionPayload, | ||
/// A signature for the payload. | ||
pub signature: Signature, | ||
/// The hash of the payload. | ||
pub hash: PayloadHash, | ||
/// The parent beacon block root. | ||
pub parent_beacon_block_root: Option<B256>, | ||
} | ||
|
||
/// Represents the Keccak256 hash of the block | ||
#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
pub struct PayloadHash(B256); | ||
|
||
impl From<&[u8]> for PayloadHash { | ||
/// Returns the Keccak256 hash of a sequence of bytes | ||
fn from(value: &[u8]) -> Self { | ||
Self(keccak256(value)) | ||
} | ||
} | ||
|
||
impl PayloadHash { | ||
/// The expected message that should be signed by the unsafe block signer. | ||
pub fn signature_message(&self, chain_id: u64) -> B256 { | ||
let domain = B256::ZERO; | ||
let chain_id = B256::left_padding_from(&chain_id.to_be_bytes()[..]); | ||
let payload_hash = self.0; | ||
|
||
let data: Vec<u8> = | ||
[domain.as_slice(), chain_id.as_slice(), payload_hash.as_slice()].concat(); | ||
|
||
keccak256(data) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use alloy::primitives::b256; | ||
|
||
#[test] | ||
fn test_signature_message() { | ||
let inner = b256!("9999999999999999999999999999999999999999999999999999999999999999"); | ||
let hash = PayloadHash::from(inner.as_slice()); | ||
let chain_id = 10; | ||
let expected = b256!("44a0e2b1aba1aae1771eddae1dcd2ad18a8cdac8891517153f03253e49d3f206"); | ||
assert_eq!(hash.signature_message(chain_id), expected); | ||
} | ||
} |