@@ -161,6 +161,105 @@ describe('blob gas tests', () => {
161161 const nextBlobGas = highGasHeader . calcNextBlobGasPrice ( common )
162162 assert . strictEqual ( nextBlobGas , BigInt ( 7 ) ) // TODO verify that this is correct
163163 } )
164+
165+ describe ( 'EIP-7918: Blob base fee bounded by execution cost' , ( ) => {
166+ const osakaCommon = createCommonFromGethGenesis ( eip4844GethGenesis , {
167+ chain : 'customChain' ,
168+ hardfork : Hardfork . Cancun ,
169+ params : paramsBlock ,
170+ customCrypto : { kzg } ,
171+ eips : [ 7918 ] ,
172+ } )
173+
174+ it ( 'applies reserve price when exec cost dominates' , ( ) => {
175+ const highBaseFee = 1_000_000_000_000_000n
176+ const target = osakaCommon . param ( 'targetBlobGasPerBlock' )
177+ const max = osakaCommon . param ( 'maxBlobGasPerBlock' )
178+ const BLOB_BASE_COST = osakaCommon . param ( 'blobBaseCost' )
179+ const GAS_PER_BLOB = osakaCommon . param ( 'blobGasPerBlob' )
180+
181+ const header = createBlockHeader (
182+ {
183+ number : 1 ,
184+ baseFeePerGas : highBaseFee ,
185+ excessBlobGas : 0n ,
186+ blobGasUsed : target ,
187+ } ,
188+ { common : osakaCommon , skipConsensusFormatValidation : true } ,
189+ )
190+
191+ assert . isTrue ( BLOB_BASE_COST * highBaseFee > GAS_PER_BLOB * header . getBlobGasPrice ( ) )
192+
193+ const got = header . calcNextExcessBlobGas ( osakaCommon )
194+ const expected = ( target * ( max - target ) ) / max
195+ assert . strictEqual ( got , expected )
196+ } )
197+
198+ it ( 'should use original EIP-4844 logic when reserve price condition is not met' , ( ) => {
199+ // Create a header with low base fee and high blob gas price
200+ const lowBaseFee = 1n // Very low base fee (1 wei)
201+
202+ // Set excessBlobGas to a high value to get high blob gas price
203+ const highExcessBlobGas = 1000000000n
204+ const header = createBlockHeader (
205+ {
206+ number : 1 ,
207+ baseFeePerGas : lowBaseFee ,
208+ excessBlobGas : highExcessBlobGas ,
209+ blobGasUsed : blobGasPerBlob * 2n , // 2 blobs used
210+ } ,
211+ { common : osakaCommon , skipConsensusFormatValidation : true } ,
212+ )
213+
214+ const excessBlobGas = header . calcNextExcessBlobGas ( osakaCommon )
215+
216+ // Should use original EIP-4844 logic
217+ const blobBaseCost = osakaCommon . param ( 'blobBaseCost' )
218+ const currentBlobGasPrice = header . getBlobGasPrice ( )
219+
220+ // Check that reserve price condition is not met
221+ assert . isTrue (
222+ blobBaseCost * lowBaseFee <= blobGasPerBlob * currentBlobGasPrice ,
223+ 'reserve price condition should not be met' ,
224+ )
225+
226+ const targetGasConsumed = highExcessBlobGas + blobGasPerBlob * 2n
227+ const targetBlobGasPerBlock = osakaCommon . param ( 'targetBlobGasPerBlock' )
228+ const expectedExcessBlobGas = targetGasConsumed - targetBlobGasPerBlock
229+
230+ assert . strictEqual (
231+ excessBlobGas ,
232+ expectedExcessBlobGas ,
233+ 'should use original EIP-4844 logic when reserve price condition is not met' ,
234+ )
235+ } )
236+
237+ it ( 'should not apply EIP-7918 logic when EIP is not activated' , ( ) => {
238+ // Use Cancun hardfork where EIP-7918 is not activated
239+ const header = createBlockHeader (
240+ {
241+ number : 1 ,
242+ baseFeePerGas : 1000000000n ,
243+ excessBlobGas : 1000000n ,
244+ blobGasUsed : blobGasPerBlob ,
245+ } ,
246+ { common, skipConsensusFormatValidation : true } ,
247+ )
248+
249+ const excessBlobGas = header . calcNextExcessBlobGas ( common )
250+
251+ // Should use original EIP-4844 logic since EIP-7918 is not activated
252+ const targetGasConsumed = 1000000n + blobGasPerBlob
253+ const targetBlobGasPerBlock = common . param ( 'targetBlobGasPerBlock' )
254+ const expectedExcessBlobGas = targetGasConsumed - targetBlobGasPerBlock
255+
256+ assert . strictEqual (
257+ excessBlobGas ,
258+ expectedExcessBlobGas ,
259+ 'should use original EIP-4844 logic when EIP-7918 is not activated' ,
260+ )
261+ } )
262+ } )
164263} )
165264
166265describe ( 'transaction validation tests' , ( ) => {
0 commit comments