From ac9a70c7eb40928fee3dba9e2b765befaaaf0c91 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Mon, 30 Sep 2024 14:25:00 +0200 Subject: [PATCH] fix: safe match for next base fee --- crates/eips/src/eip1559/helpers.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/crates/eips/src/eip1559/helpers.rs b/crates/eips/src/eip1559/helpers.rs index a37bac89097..056f25f722b 100644 --- a/crates/eips/src/eip1559/helpers.rs +++ b/crates/eips/src/eip1559/helpers.rs @@ -44,17 +44,18 @@ pub fn calc_next_block_base_fee( + (core::cmp::max( // Ensure a minimum increase of 1. 1, - base_fee * (gas_used - gas_target) - / (gas_target * base_fee_params.max_change_denominator as u64), - )) + base_fee as u128 * (gas_used - gas_target) as u128 + / (gas_target as u128 * base_fee_params.max_change_denominator), + ) as u64) } // If the gas used in the current block is less than the gas target, calculate a new // decreased base fee. core::cmp::Ordering::Less => { // Calculate the decrease in base fee based on the formula defined by EIP-1559. base_fee.saturating_sub( - base_fee * (gas_target - gas_used) - / (gas_target * base_fee_params.max_change_denominator as u64), + (base_fee as u128 * (gas_target - gas_used) as u128 + / (gas_target as u128 * base_fee_params.max_change_denominator)) + as u64, ) } }