Skip to content

Commit 0e733fc

Browse files
yahgwaigzeoneth
authored andcommitted
Added both block basefee and blob basefee to batch spending report
1 parent a4e709c commit 0e733fc

File tree

3 files changed

+37
-12
lines changed

3 files changed

+37
-12
lines changed

src/bridge/SequencerInbox.sol

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,9 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox
418418
afterDelayedMessagesRead
419419
);
420420

421+
// we use addSequencerL2BatchImpl for submitting the message
422+
// normally this would also submit a batch spending report but that is skipped if we pass
423+
// an empty call data size, then we submit a separate batch spending report later
421424
(
422425
uint256 seqMessageIndex,
423426
bytes32 beforeAcc,
@@ -453,11 +456,7 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox
453456

454457
// submit a batch spending report to refund the entity that produced the blob batch data
455458
uint256 blobBasefee = blobBasefeeReader.getBlobBaseFee();
456-
457-
// TODO: This report the gas spending using the blob basefee, however the actual spending actually involve
458-
// 2 parts: 1. data cost priced in blob basefee, 2. tx cost priced in block basefee
459-
// We might need to change the batch spending report format so both costs are reported.
460-
submitBatchSpendingReport(dataHash, seqMessageIndex, blobBasefee);
459+
submitBatchSpendingReport(dataHash, seqMessageIndex, block.basefee, blobBasefee);
461460
}
462461

463462
function addSequencerL2Batch(
@@ -625,7 +624,8 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox
625624
function submitBatchSpendingReport(
626625
bytes32 dataHash,
627626
uint256 seqMessageIndex,
628-
uint256 gasPrice
627+
uint256 gasPrice,
628+
uint256 blobBaseFeePrice
629629
) internal {
630630
bytes memory spendingReportMsg;
631631
address batchPoster = msg.sender;
@@ -646,12 +646,16 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox
646646
uint64(extraGas)
647647
);
648648
} else {
649+
// when a blob base fee is supplied we include it into the batch spending report
649650
spendingReportMsg = abi.encodePacked(
650651
block.timestamp,
651652
batchPoster,
652653
dataHash,
653654
seqMessageIndex,
654-
gasPrice
655+
gasPrice,
656+
// we add an empty extraGas since the parsing code expects a value here
657+
uint64(0),
658+
blobBaseFeePrice
655659
);
656660
}
657661

@@ -691,7 +695,7 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox
691695
totalDelayedMessagesRead = afterDelayedMessagesRead;
692696

693697
if (calldataLengthPosted > 0) {
694-
submitBatchSpendingReport(dataHash, seqMessageIndex, block.basefee);
698+
submitBatchSpendingReport(dataHash, seqMessageIndex, block.basefee, 0);
695699
}
696700
}
697701

test/contract/sequencerInbox.spec.4844.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,8 +445,11 @@ describe('SequencerInbox', async () => {
445445
const batchSendTx = await Toolkit4844.getTx(txHash)
446446
const blobHashes = (batchSendTx as any)['blobVersionedHashes'] as string[]
447447
const batchSendReceipt = await Toolkit4844.getTxReceipt(txHash)
448-
const { timestamp: blockTimestamp, number: blockNumber } =
449-
await wallet.provider.getBlock(batchSendReceipt.blockNumber)
448+
const {
449+
timestamp: blockTimestamp,
450+
number: blockNumber,
451+
baseFeePerGas,
452+
} = await wallet.provider.getBlock(batchSendReceipt.blockNumber)
450453

451454
const timeBounds = await getTimeBounds(
452455
blockNumber,
@@ -516,8 +519,12 @@ describe('SequencerInbox', async () => {
516519
'0x' + inboxMsgDeliveredEvent.data.substring(106, 170)
517520
const spendingSeqMessageIndex =
518521
'0x' + inboxMsgDeliveredEvent.data.substring(170, 234)
519-
const spendingBlobBasefee =
522+
const spendingBlockBaseFee =
520523
'0x' + inboxMsgDeliveredEvent.data.substring(234, 298)
524+
const spendingExtraGas =
525+
'0x' + inboxMsgDeliveredEvent.data.substring(298, 314)
526+
const spendingBlobBasefee =
527+
'0x' + inboxMsgDeliveredEvent.data.substring(314, 378)
521528

522529
expect(
523530
BigNumber.from(spendingTimestamp).eq(blockTimestamp),
@@ -531,6 +538,18 @@ describe('SequencerInbox', async () => {
531538
BigNumber.from(spendingSeqMessageIndex).eq(sequenceNumber),
532539
'spending seq message index'
533540
).to.eq(true)
541+
542+
if (baseFeePerGas == null) {
543+
throw new Error('Missing base fee')
544+
}
545+
expect(
546+
BigNumber.from(spendingBlockBaseFee).eq(baseFeePerGas),
547+
`spending basefee: ${BigNumber.from(spendingBlockBaseFee).toString()}`
548+
).to.eq(true)
549+
expect(
550+
BigNumber.from(spendingExtraGas).eq(0),
551+
`spending extra gas: ${BigNumber.from(spendingExtraGas).toString()}`
552+
).to.eq(true)
534553
// we expect a very low - 1 - basefee since we havent sent many blobs
535554
expect(
536555
BigNumber.from(spendingBlobBasefee).eq(1),

test/foundry/SequencerInbox.t.sol

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ contract SequencerInboxTest is Test {
106106
msg.sender,
107107
dataHash,
108108
sequenceNumber,
109-
block.basefee
109+
block.basefee,
110+
uint64(0),
111+
uint256(0)
110112
);
111113
bytes32 beforeAcc = bytes32(0);
112114
bytes32 delayedAcc = bridge.delayedInboxAccs(delayedMessagesRead - 1);

0 commit comments

Comments
 (0)