1
1
use std:: sync:: mpsc:: { channel, Receiver , Sender } ;
2
2
use std:: time:: SystemTime ;
3
3
4
- use ethers:: types:: { Address , Bytes , Signature , H256 } ;
5
- use ethers:: utils:: keccak256;
4
+ use alloy_primitives:: { keccak256, Address , Bytes , Signature , B256 , U64 } ;
6
5
use eyre:: Result ;
7
6
use libp2p:: gossipsub:: { IdentTopic , Message , MessageAcceptance , TopicHash } ;
8
7
use ssz_rs:: { prelude:: * , List , Vector , U256 } ;
@@ -32,7 +31,7 @@ struct ExecutionPayloadEnvelope {
32
31
signature : Signature ,
33
32
hash : PayloadHash ,
34
33
#[ allow( unused) ]
35
- parent_beacon_block_root : Option < H256 > ,
34
+ parent_beacon_block_root : Option < B256 > ,
36
35
}
37
36
38
37
impl Handler for BlockHandler {
@@ -109,7 +108,10 @@ impl BlockHandler {
109
108
110
109
let msg = envelope. hash . signature_message ( self . chain_id ) ;
111
110
let block_signer = * self . unsafe_signer_recv . borrow ( ) ;
112
- let sig_valid = envelope. signature . verify ( msg, block_signer) . is_ok ( ) ;
111
+ let sig_valid = envelope
112
+ . signature
113
+ . recover_address_from_prehash ( & msg)
114
+ . map_or ( false , |addr| addr == block_signer) ;
113
115
114
116
time_valid && sig_valid
115
117
}
@@ -154,7 +156,7 @@ fn decode_post_ecotone_block_msg(data: Vec<u8>) -> Result<ExecutionPayloadEnvelo
154
156
155
157
let signature = Signature :: try_from ( sig_data) ?;
156
158
157
- let parent_beacon_block_root = Some ( H256 :: from_slice ( parent_beacon_block_root) ) ;
159
+ let parent_beacon_block_root = Some ( B256 :: from_slice ( parent_beacon_block_root) ) ;
158
160
159
161
let payload: ExecutionPayloadV3SSZ = deserialize ( block_data) ?;
160
162
let payload = ExecutionPayload :: from ( payload) ;
@@ -170,30 +172,30 @@ fn decode_post_ecotone_block_msg(data: Vec<u8>) -> Result<ExecutionPayloadEnvelo
170
172
}
171
173
172
174
/// Represents the Keccak256 hash of the block
173
- struct PayloadHash ( H256 ) ;
175
+ struct PayloadHash ( B256 ) ;
174
176
175
177
impl From < & [ u8 ] > for PayloadHash {
176
178
/// Returns the Keccak256 hash of a sequence of bytes
177
179
fn from ( value : & [ u8 ] ) -> Self {
178
- Self ( keccak256 ( value) . into ( ) )
180
+ Self ( keccak256 ( value) )
179
181
}
180
182
}
181
183
182
184
impl PayloadHash {
183
185
/// The expected message that should be signed by the unsafe block signer.
184
- fn signature_message ( & self , chain_id : u64 ) -> H256 {
185
- let domain = H256 :: zero ( ) ;
186
- let chain_id = H256 :: from_low_u64_be ( chain_id) ;
186
+ fn signature_message ( & self , chain_id : u64 ) -> B256 {
187
+ let domain = B256 :: ZERO ;
188
+ let chain_id = B256 :: from_slice ( & chain_id. to_be_bytes ( ) ) ;
187
189
let payload_hash = self . 0 ;
188
190
189
191
let data: Vec < u8 > = [
190
- domain. as_bytes ( ) ,
191
- chain_id. as_bytes ( ) ,
192
- payload_hash. as_bytes ( ) ,
192
+ domain. as_slice ( ) ,
193
+ chain_id. as_slice ( ) ,
194
+ payload_hash. as_slice ( ) ,
193
195
]
194
196
. concat ( ) ;
195
197
196
- keccak256 ( data) . into ( )
198
+ keccak256 ( data)
197
199
}
198
200
}
199
201
@@ -246,10 +248,10 @@ impl From<ExecutionPayloadV1SSZ> for ExecutionPayload {
246
248
receipts_root : convert_hash ( value. receipts_root ) ,
247
249
logs_bloom : convert_byte_vector ( value. logs_bloom ) ,
248
250
prev_randao : convert_hash ( value. prev_randao ) ,
249
- block_number : value. block_number . into ( ) ,
250
- gas_limit : value. gas_limit . into ( ) ,
251
- gas_used : value. gas_used . into ( ) ,
252
- timestamp : value. timestamp . into ( ) ,
251
+ block_number : value. block_number . try_into ( ) . unwrap_or_default ( ) ,
252
+ gas_limit : value. gas_limit . try_into ( ) . unwrap_or_default ( ) ,
253
+ gas_used : value. gas_used . try_into ( ) . unwrap_or_default ( ) ,
254
+ timestamp : value. timestamp . try_into ( ) . unwrap_or_default ( ) ,
253
255
extra_data : convert_byte_list ( value. extra_data ) ,
254
256
base_fee_per_gas : convert_uint ( value. base_fee_per_gas ) ,
255
257
block_hash : convert_hash ( value. block_hash ) ,
@@ -320,10 +322,10 @@ impl From<ExecutionPayloadV2SSZ> for ExecutionPayload {
320
322
receipts_root : convert_hash ( value. receipts_root ) ,
321
323
logs_bloom : convert_byte_vector ( value. logs_bloom ) ,
322
324
prev_randao : convert_hash ( value. prev_randao ) ,
323
- block_number : value. block_number . into ( ) ,
324
- gas_limit : value. gas_limit . into ( ) ,
325
- gas_used : value. gas_used . into ( ) ,
326
- timestamp : value. timestamp . into ( ) ,
325
+ block_number : value. block_number . try_into ( ) . unwrap_or_default ( ) ,
326
+ gas_limit : value. gas_limit . try_into ( ) . unwrap_or_default ( ) ,
327
+ gas_used : value. gas_used . try_into ( ) . unwrap_or_default ( ) ,
328
+ timestamp : value. timestamp . try_into ( ) . unwrap_or_default ( ) ,
327
329
extra_data : convert_byte_list ( value. extra_data ) ,
328
330
base_fee_per_gas : convert_uint ( value. base_fee_per_gas ) ,
329
331
block_hash : convert_hash ( value. block_hash ) ,
@@ -365,24 +367,24 @@ impl From<ExecutionPayloadV3SSZ> for ExecutionPayload {
365
367
receipts_root : convert_hash ( value. receipts_root ) ,
366
368
logs_bloom : convert_byte_vector ( value. logs_bloom ) ,
367
369
prev_randao : convert_hash ( value. prev_randao ) ,
368
- block_number : value. block_number . into ( ) ,
369
- gas_limit : value. gas_limit . into ( ) ,
370
- gas_used : value. gas_used . into ( ) ,
371
- timestamp : value. timestamp . into ( ) ,
370
+ block_number : value. block_number . try_into ( ) . unwrap_or_default ( ) ,
371
+ gas_limit : value. gas_limit . try_into ( ) . unwrap_or_default ( ) ,
372
+ gas_used : value. gas_used . try_into ( ) . unwrap_or_default ( ) ,
373
+ timestamp : value. timestamp . try_into ( ) . unwrap_or_default ( ) ,
372
374
extra_data : convert_byte_list ( value. extra_data ) ,
373
375
base_fee_per_gas : convert_uint ( value. base_fee_per_gas ) ,
374
376
block_hash : convert_hash ( value. block_hash ) ,
375
377
transactions : convert_tx_list ( value. transactions ) ,
376
378
withdrawals : Some ( Vec :: new ( ) ) ,
377
- blob_gas_used : Some ( value. blob_gas_used . into ( ) ) ,
378
- excess_blob_gas : Some ( value. excess_blob_gas . into ( ) ) ,
379
+ blob_gas_used : Some ( value. blob_gas_used . try_into ( ) . unwrap_or_default ( ) ) ,
380
+ excess_blob_gas : Some ( value. excess_blob_gas . try_into ( ) . unwrap_or_default ( ) ) ,
379
381
}
380
382
}
381
383
}
382
384
383
- /// Converts [Bytes32] into [H256 ]
384
- fn convert_hash ( bytes : Bytes32 ) -> H256 {
385
- H256 :: from_slice ( bytes. as_slice ( ) )
385
+ /// Converts [Bytes32] into [B256 ]
386
+ fn convert_hash ( bytes : Bytes32 ) -> B256 {
387
+ B256 :: from_slice ( bytes. as_slice ( ) )
386
388
}
387
389
388
390
/// Converts [VecAddress] into [Address]
@@ -400,12 +402,10 @@ fn convert_byte_list<const N: usize>(list: List<u8, N>) -> Bytes {
400
402
Bytes :: from ( list. to_vec ( ) )
401
403
}
402
404
403
- /// Converts a [U256] into [ethers::types:: U64]
404
- fn convert_uint ( value : U256 ) -> ethers :: types :: U64 {
405
+ /// Converts a [U256] into [U64]
406
+ fn convert_uint ( value : U256 ) -> U64 {
405
407
let bytes = value. to_bytes_le ( ) ;
406
- ethers:: types:: U256 :: from_little_endian ( & bytes)
407
- . as_u64 ( )
408
- . into ( )
408
+ U64 :: from_le_slice ( & bytes)
409
409
}
410
410
411
411
/// Converts [ssz_rs::List] of [Transaction] into a vector of [RawTransaction]
0 commit comments