@@ -83,10 +83,10 @@ where
8383/// Calculates the blob gas used ratio for a block, accounting for the case where
8484/// `max_blob_gas_per_block` is zero.
8585///
86- /// Returns `0.0` if `blob_gas_used ` is `0`, otherwise returns the ratio
86+ /// Returns `0.0` if `max_blob_gas_per_block ` is `0`, otherwise returns the ratio
8787/// `blob_gas_used/max_blob_gas_per_block`.
8888pub fn checked_blob_gas_used_ratio ( blob_gas_used : u64 , max_blob_gas_per_block : u64 ) -> f64 {
89- if blob_gas_used == 0 {
89+ if max_blob_gas_per_block == 0 {
9090 0.0
9191 } else {
9292 blob_gas_used as f64 / max_blob_gas_per_block as f64
@@ -124,6 +124,8 @@ mod tests {
124124 fn test_checked_blob_gas_used_ratio ( ) {
125125 // No blob gas used, max blob gas per block is 0
126126 assert_eq ! ( checked_blob_gas_used_ratio( 0 , 0 ) , 0.0 ) ;
127+ // Blob gas used is non-zero, max blob gas per block is 0 (division by zero protection)
128+ assert_eq ! ( checked_blob_gas_used_ratio( 50 , 0 ) , 0.0 ) ;
127129 // Blob gas used is zero, max blob gas per block is non-zero
128130 assert_eq ! ( checked_blob_gas_used_ratio( 0 , 100 ) , 0.0 ) ;
129131 // Blob gas used is non-zero, max blob gas per block is non-zero
0 commit comments