From a05235d608fe882dfa0e352ee40f82f97a24b7bc Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Wed, 27 Sep 2023 20:29:39 -0400 Subject: [PATCH 1/2] fix: use u128 for calc data fee result --- crates/primitives/src/env.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/primitives/src/env.rs b/crates/primitives/src/env.rs index 8d883c7e54..60defdbe07 100644 --- a/crates/primitives/src/env.rs +++ b/crates/primitives/src/env.rs @@ -463,10 +463,10 @@ impl Env { /// /// [EIP-4844]: https://eips.ethereum.org/EIPS/eip-4844 #[inline] - pub fn calc_data_fee(&self) -> Option { + pub fn calc_data_fee(&self) -> Option { self.block .get_blob_gasprice() - .map(|blob_gas_price| blob_gas_price * self.tx.get_total_blob_gas()) + .map(|blob_gas_price| blob_gas_price as u128 * self.tx.get_total_blob_gas() as u128) } /// Validate the block environment. From 6ba601593f45e21f235341d0ba2a7ebfd6112a0e Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Thu, 28 Sep 2023 10:23:45 -0400 Subject: [PATCH 2/2] use U256 for data fee --- crates/primitives/src/env.rs | 8 ++++---- crates/revm/src/evm_impl.rs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/primitives/src/env.rs b/crates/primitives/src/env.rs index 60defdbe07..b876ef603c 100644 --- a/crates/primitives/src/env.rs +++ b/crates/primitives/src/env.rs @@ -463,10 +463,10 @@ impl Env { /// /// [EIP-4844]: https://eips.ethereum.org/EIPS/eip-4844 #[inline] - pub fn calc_data_fee(&self) -> Option { - self.block - .get_blob_gasprice() - .map(|blob_gas_price| blob_gas_price as u128 * self.tx.get_total_blob_gas() as u128) + pub fn calc_data_fee(&self) -> Option { + self.block.get_blob_gasprice().map(|blob_gas_price| { + U256::from(blob_gas_price).saturating_mul(U256::from(self.tx.get_total_blob_gas())) + }) } /// Validate the block environment. diff --git a/crates/revm/src/evm_impl.rs b/crates/revm/src/evm_impl.rs index ba7291603b..98997d5ca2 100644 --- a/crates/revm/src/evm_impl.rs +++ b/crates/revm/src/evm_impl.rs @@ -275,7 +275,7 @@ impl<'a, GSPEC: Spec, DB: Database, const INSPECT: bool> Transact // EIP-4844 if GSPEC::enabled(CANCUN) { let data_fee = self.data.env.calc_data_fee().expect("already checked"); - gas_cost = gas_cost.saturating_add(U256::from(data_fee)); + gas_cost = gas_cost.saturating_add(data_fee); } caller_account.info.balance = caller_account.info.balance.saturating_sub(gas_cost);