Skip to content
This repository was archived by the owner on Oct 20, 2024. It is now read-only.

Commit 9c603ab

Browse files
authored
Only account for execution gas in sanity checks (#250)
1 parent c78316b commit 9c603ab

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

internal/testutils/opmock.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var (
1919
"maxFeePerGas": "0xa862145e",
2020
"maxPriorityFeePerGas": "0xa8621440",
2121
"paymasterAndData": "0x",
22-
"preVerificationGas": "0xc869",
22+
"preVerificationGas": "0xc539",
2323
"signature": "0xa925dcc5e5131636e244d4405334c25f034ebdd85c0cb12e8cdb13c15249c2d466d0bade18e2cafd3513497f7f968dcbb63e519acd9b76dcae7acd61f11aa8421b",
2424
}
2525
MockByteCode = common.Hex2Bytes("6080604052")

pkg/modules/checks/gas.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,24 @@ import (
44
"fmt"
55
"math/big"
66

7+
"github.com/stackup-wallet/stackup-bundler/pkg/gas"
78
"github.com/stackup-wallet/stackup-bundler/pkg/userop"
89
)
910

1011
// ValidateGasAvailable checks that the max available gas is less than the batch gas limit.
1112
func ValidateGasAvailable(op *userop.UserOperation, maxBatchGasLimit *big.Int) error {
12-
if op.GetMaxGasAvailable().Cmp(maxBatchGasLimit) > 0 {
13+
// This calculation ensures that we are only checking the gas used for execution. In rollups, the PVG also
14+
// includes the L1 callData cost. If the L1 gas component spikes, it can cause the PVG value of legit ops
15+
// to be greater than the maxBatchGasLimit. For non-rollups, the results would be the same as just calling
16+
// op.GetMaxGasAvailable().
17+
static, err := gas.NewDefaultOverhead().CalcPreVerificationGas(op)
18+
if err != nil {
19+
return err
20+
}
21+
mgl := big.NewInt(0).Sub(op.GetMaxGasAvailable(), op.PreVerificationGas)
22+
mga := big.NewInt(0).Add(mgl, static)
23+
24+
if mga.Cmp(maxBatchGasLimit) > 0 {
1325
return fmt.Errorf("gasLimit: exceeds maxBatchGasLimit of %s", maxBatchGasLimit.String())
1426
}
1527

0 commit comments

Comments
 (0)