From 10048a2ddede57c209413047a4668548a9d1614d Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Wed, 5 Apr 2023 12:31:07 +0200 Subject: [PATCH] fix: checked u64 downcast (#2122) --- Cargo.lock | 1 + crates/primitives/Cargo.toml | 1 + crates/primitives/src/lib.rs | 3 ++- crates/rpc/rpc-types/src/eth/engine/payload.rs | 11 ++++++++--- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 50c1e48ff9..dee57f8411 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4954,6 +4954,7 @@ dependencies = [ "reth-rlp", "reth-rlp-derive", "revm-primitives", + "ruint", "secp256k1 0.26.0", "serde", "serde_json", diff --git a/crates/primitives/Cargo.toml b/crates/primitives/Cargo.toml index 7beb0d52ec..569b55e496 100644 --- a/crates/primitives/Cargo.toml +++ b/crates/primitives/Cargo.toml @@ -19,6 +19,7 @@ revm-primitives = { version = "1.1", features = ["serde"] } ethers-core = { git = "https://github.com/gakonst/ethers-rs", default-features = false } tiny-keccak = { version = "2.0", features = ["keccak"] } crunchy = { version = "0.2.2", default-features = false, features = ["limit_256"] } +ruint = { version = "1.7.0", features = ["primitive-types", "rlp"] } # Bloom fixed-hash = { version = "0.8", default-features = false, features = [ diff --git a/crates/primitives/src/lib.rs b/crates/primitives/src/lib.rs index bd6ac03b65..7101910171 100644 --- a/crates/primitives/src/lib.rs +++ b/crates/primitives/src/lib.rs @@ -103,7 +103,8 @@ pub use ethers_core::{ types::{BigEndianHash, H128, H64, U64}, utils as rpc_utils, }; -pub use revm_primitives::{ruint::aliases::U128, B160 as H160, B256 as H256, U256}; +pub use revm_primitives::{B160 as H160, B256 as H256, U256}; +pub use ruint::{aliases::U128, UintTryTo}; #[doc(hidden)] mod __reexport { diff --git a/crates/rpc/rpc-types/src/eth/engine/payload.rs b/crates/rpc/rpc-types/src/eth/engine/payload.rs index 753166c98d..514e3674b5 100644 --- a/crates/rpc/rpc-types/src/eth/engine/payload.rs +++ b/crates/rpc/rpc-types/src/eth/engine/payload.rs @@ -1,7 +1,7 @@ use reth_primitives::{ proofs::{self, EMPTY_LIST_HASH}, - Address, Block, Bloom, Bytes, Header, SealedBlock, TransactionSigned, Withdrawal, H256, U256, - U64, + Address, Block, Bloom, Bytes, Header, SealedBlock, TransactionSigned, UintTryTo, Withdrawal, + H256, U256, U64, }; use reth_rlp::{Decodable, Encodable}; use serde::{Deserialize, Serialize}; @@ -106,7 +106,12 @@ impl TryFrom for SealedBlock { gas_used: payload.gas_used.as_u64(), timestamp: payload.timestamp.as_u64(), mix_hash: payload.prev_randao, - base_fee_per_gas: Some(payload.base_fee_per_gas.to::()), + base_fee_per_gas: Some( + payload + .base_fee_per_gas + .uint_try_to() + .map_err(|_| PayloadError::BaseFee(payload.base_fee_per_gas))?, + ), extra_data: payload.extra_data, // Defaults ommers_hash: EMPTY_LIST_HASH,