@@ -199,9 +199,9 @@ impl L1BlockInfo {
199199 ///
200200 /// Prior to regolith, an extra 68 non-zero bytes were included in the rollup data costs to
201201 /// account for the empty signature.
202- pub fn data_gas ( & self , input : & [ u8 ] , spec_id : OpSpecId ) -> U256 {
202+ pub fn data_gas ( input : & [ u8 ] , spec_id : OpSpecId ) -> U256 {
203203 if spec_id. is_enabled_in ( OpSpecId :: FJORD ) {
204- let estimated_size = self . tx_estimated_size_fjord ( input) ;
204+ let estimated_size = Self :: tx_estimated_size_fjord ( input) ;
205205
206206 return estimated_size
207207 . saturating_mul ( U256 :: from ( NON_ZERO_BYTE_COST ) )
@@ -222,7 +222,7 @@ impl L1BlockInfo {
222222 // Calculate the estimated compressed transaction size in bytes, scaled by 1e6.
223223 // This value is computed based on the following formula:
224224 // max(minTransactionSize, intercept + fastlzCoef*fastlzSize)
225- fn tx_estimated_size_fjord ( & self , input : & [ u8 ] ) -> U256 {
225+ fn tx_estimated_size_fjord ( input : & [ u8 ] ) -> U256 {
226226 U256 :: from ( estimate_tx_compressed_size ( input) )
227227 }
228228
@@ -253,7 +253,7 @@ impl L1BlockInfo {
253253
254254 /// Calculate the gas cost of a transaction based on L1 block data posted on L2, pre-Ecotone.
255255 fn calculate_tx_l1_cost_bedrock ( & self , input : & [ u8 ] , spec_id : OpSpecId ) -> U256 {
256- let rollup_data_gas_cost = self . data_gas ( input, spec_id) ;
256+ let rollup_data_gas_cost = Self :: data_gas ( input, spec_id) ;
257257 rollup_data_gas_cost
258258 . saturating_add ( self . l1_fee_overhead . unwrap_or_default ( ) )
259259 . saturating_mul ( self . l1_base_fee )
@@ -279,7 +279,7 @@ impl L1BlockInfo {
279279 return self . calculate_tx_l1_cost_bedrock ( input, spec_id) ;
280280 }
281281
282- let rollup_data_gas_cost = self . data_gas ( input, spec_id) ;
282+ let rollup_data_gas_cost = Self :: data_gas ( input, spec_id) ;
283283 let l1_fee_scaled = self . calculate_l1_fee_scaled_ecotone ( ) ;
284284
285285 l1_fee_scaled
@@ -293,7 +293,7 @@ impl L1BlockInfo {
293293 /// `estimatedSize*(baseFeeScalar*l1BaseFee*16 + blobFeeScalar*l1BlobBaseFee)/1e12`
294294 fn calculate_tx_l1_cost_fjord ( & self , input : & [ u8 ] ) -> U256 {
295295 let l1_fee_scaled = self . calculate_l1_fee_scaled_ecotone ( ) ;
296- let estimated_size = self . tx_estimated_size_fjord ( input) ;
296+ let estimated_size = Self :: tx_estimated_size_fjord ( input) ;
297297
298298 estimated_size
299299 . saturating_mul ( l1_fee_scaled)
@@ -322,61 +322,47 @@ mod tests {
322322
323323 #[ test]
324324 fn test_data_gas_non_zero_bytes ( ) {
325- let l1_block_info = L1BlockInfo {
326- l1_base_fee : U256 :: from ( 1_000_000 ) ,
327- l1_fee_overhead : Some ( U256 :: from ( 1_000_000 ) ) ,
328- l1_base_fee_scalar : U256 :: from ( 1_000_000 ) ,
329- ..Default :: default ( )
330- } ;
331-
332325 // 0xFACADE = 6 nibbles = 3 bytes
333326 // 0xFACADE = 1111 1010 . 1100 1010 . 1101 1110
334327
335328 // Pre-regolith (ie bedrock) has an extra 68 non-zero bytes
336329 // gas cost = 3 non-zero bytes * NON_ZERO_BYTE_COST + NON_ZERO_BYTE_COST * 68
337330 // gas cost = 3 * 16 + 68 * 16 = 1136
338331 let input = bytes ! ( "FACADE" ) ;
339- let bedrock_data_gas = l1_block_info . data_gas ( & input, OpSpecId :: BEDROCK ) ;
332+ let bedrock_data_gas = L1BlockInfo :: data_gas ( & input, OpSpecId :: BEDROCK ) ;
340333 assert_eq ! ( bedrock_data_gas, U256 :: from( 1136 ) ) ;
341334
342335 // Regolith has no added 68 non zero bytes
343336 // gas cost = 3 * 16 = 48
344- let regolith_data_gas = l1_block_info . data_gas ( & input, OpSpecId :: REGOLITH ) ;
337+ let regolith_data_gas = L1BlockInfo :: data_gas ( & input, OpSpecId :: REGOLITH ) ;
345338 assert_eq ! ( regolith_data_gas, U256 :: from( 48 ) ) ;
346339
347340 // Fjord has a minimum compressed size of 100 bytes
348341 // gas cost = 100 * 16 = 1600
349- let fjord_data_gas = l1_block_info . data_gas ( & input, OpSpecId :: FJORD ) ;
342+ let fjord_data_gas = L1BlockInfo :: data_gas ( & input, OpSpecId :: FJORD ) ;
350343 assert_eq ! ( fjord_data_gas, U256 :: from( 1600 ) ) ;
351344 }
352345
353346 #[ test]
354347 fn test_data_gas_zero_bytes ( ) {
355- let l1_block_info = L1BlockInfo {
356- l1_base_fee : U256 :: from ( 1_000_000 ) ,
357- l1_fee_overhead : Some ( U256 :: from ( 1_000_000 ) ) ,
358- l1_base_fee_scalar : U256 :: from ( 1_000_000 ) ,
359- ..Default :: default ( )
360- } ;
361-
362348 // 0xFA00CA00DE = 10 nibbles = 5 bytes
363349 // 0xFA00CA00DE = 1111 1010 . 0000 0000 . 1100 1010 . 0000 0000 . 1101 1110
364350
365351 // Pre-regolith (ie bedrock) has an extra 68 non-zero bytes
366352 // gas cost = 3 non-zero * NON_ZERO_BYTE_COST + 2 * ZERO_BYTE_COST + NON_ZERO_BYTE_COST * 68
367353 // gas cost = 3 * 16 + 2 * 4 + 68 * 16 = 1144
368354 let input = bytes ! ( "FA00CA00DE" ) ;
369- let bedrock_data_gas = l1_block_info . data_gas ( & input, OpSpecId :: BEDROCK ) ;
355+ let bedrock_data_gas = L1BlockInfo :: data_gas ( & input, OpSpecId :: BEDROCK ) ;
370356 assert_eq ! ( bedrock_data_gas, U256 :: from( 1144 ) ) ;
371357
372358 // Regolith has no added 68 non zero bytes
373359 // gas cost = 3 * 16 + 2 * 4 = 56
374- let regolith_data_gas = l1_block_info . data_gas ( & input, OpSpecId :: REGOLITH ) ;
360+ let regolith_data_gas = L1BlockInfo :: data_gas ( & input, OpSpecId :: REGOLITH ) ;
375361 assert_eq ! ( regolith_data_gas, U256 :: from( 56 ) ) ;
376362
377363 // Fjord has a minimum compressed size of 100 bytes
378364 // gas cost = 100 * 16 = 1600
379- let fjord_data_gas = l1_block_info . data_gas ( & input, OpSpecId :: FJORD ) ;
365+ let fjord_data_gas = L1BlockInfo :: data_gas ( & input, OpSpecId :: FJORD ) ;
380366 assert_eq ! ( fjord_data_gas, U256 :: from( 1600 ) ) ;
381367 }
382368
@@ -479,7 +465,7 @@ mod tests {
479465
480466 // test
481467
482- let gas_used = l1_block_info . data_gas ( TX , OpSpecId :: ECOTONE ) ;
468+ let gas_used = L1BlockInfo :: data_gas ( TX , OpSpecId :: ECOTONE ) ;
483469
484470 assert_eq ! ( gas_used, expected_l1_gas_used) ;
485471
@@ -564,7 +550,7 @@ mod tests {
564550
565551 // test
566552
567- let data_gas = l1_block_info . data_gas ( TX , OpSpecId :: FJORD ) ;
553+ let data_gas = L1BlockInfo :: data_gas ( TX , OpSpecId :: FJORD ) ;
568554
569555 assert_eq ! ( data_gas, expected_data_gas) ;
570556
0 commit comments