Skip to content

Commit 19c0a7c

Browse files
author
danielntmd
committed
fix: use passthrough maxFeePerBlobGas for gas estimation and fix bump loop truncation The blob validateBlobs estimateGas call was intermittently failing with "max fee per blob gas less than block blob gas fee" because it computed a precise maxFeePerBlobGas that could go stale between the getBlobBaseFee RPC call and the estimateGas RPC call. Since gas estimation is a read-only, we now use a 2x buffer to pass EIP-4844 validation.
Also fix integer truncation in the base fee bump loop where ceil is needed to ensure fees increase at small values (e.g. 1 wei).
1 parent ed10419 commit 19c0a7c

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

yarn-project/ethereum/src/l1_tx_utils/readonly_l1_tx_utils.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,10 @@ export class ReadOnlyL1TxUtils {
130130
const numBlocks = Math.ceil(gasConfig.stallTimeMs! / BLOCK_TIME_MS);
131131
for (let i = 0; i < numBlocks; i++) {
132132
// each block can go up 12.5% from previous baseFee
133-
maxFeePerGas = (maxFeePerGas * (1_000n + 125n)) / 1_000n;
133+
// ceil, (a+b-1)/b, to avoid truncation at small values (e.g. 1 wei blob base fee)
134+
maxFeePerGas = (maxFeePerGas * (1_000n + 125n) + 999n) / 1_000n;
134135
// same for blob gas fee
135-
maxFeePerBlobGas = (maxFeePerBlobGas * (1_000n + 125n)) / 1_000n;
136+
maxFeePerBlobGas = (maxFeePerBlobGas * (1_000n + 125n) + 999n) / 1_000n;
136137
}
137138

138139
if (attempt > 0) {
@@ -242,13 +243,16 @@ export class ReadOnlyL1TxUtils {
242243
const gasConfig = { ...this.config, ..._gasConfig };
243244
let initialEstimate = 0n;
244245
if (_blobInputs) {
245-
// @note requests with blobs also require maxFeePerBlobGas to be set
246+
// @note requests with blobs also require maxFeePerBlobGas to be set.
247+
// Use 2x buffer for maxFeePerBlobGas to avoid stale fees and to pass EIP-4844 validation (even if it is a gas estimation call).
248+
// 1. maxFeePerBlobGas >= blobBaseFee
249+
// 2. account balance >= gas * maxFeePerGas + maxFeePerBlobGas * blobCount + value
246250
const gasPrice = await this.getGasPrice(gasConfig, true, 0);
247251
initialEstimate = await this.client.estimateGas({
248252
account,
249253
...request,
250254
..._blobInputs,
251-
maxFeePerBlobGas: gasPrice.maxFeePerBlobGas!,
255+
maxFeePerBlobGas: gasPrice.maxFeePerBlobGas! * 2n,
252256
gas: MAX_L1_TX_LIMIT,
253257
blockTag: 'latest',
254258
});

0 commit comments

Comments
 (0)