@@ -26,6 +26,7 @@ type Overhead struct {
26
26
sanitizedVGL * big.Int
27
27
sanitizedCGL * big.Int
28
28
calcPVGFunc CalcPreVerificationGasFunc
29
+ pvgBufferFactor int64
29
30
}
30
31
31
32
// NewDefaultOverhead returns an instance of Overhead using parameters defined by the Ethereum protocol.
@@ -45,6 +46,7 @@ func NewDefaultOverhead() *Overhead {
45
46
sanitizedVGL : big .NewInt (1000000 ),
46
47
sanitizedCGL : big .NewInt (1000000 ),
47
48
calcPVGFunc : calcPVGFuncNoop (),
49
+ pvgBufferFactor : 0 ,
48
50
}
49
51
}
50
52
@@ -54,6 +56,14 @@ func (ov *Overhead) SetCalcPreVerificationGasFunc(fn CalcPreVerificationGasFunc)
54
56
ov .calcPVGFunc = fn
55
57
}
56
58
59
+ // SetPreVerificationGasBufferFactor defines the percentage to increase the preVerificationGas by during an
60
+ // estimation. This is useful for rollups that use 2D gas values where the L1 gas component is
61
+ // non-deterministic. This buffer accounts for any variability in-between eth_estimateUserOperationGas and
62
+ // eth_sendUserOperation. Defaults to 0.
63
+ func (ov * Overhead ) SetPreVerificationGasBufferFactor (factor int64 ) {
64
+ ov .pvgBufferFactor = factor
65
+ }
66
+
57
67
// CalcPreVerificationGas returns an expected gas cost for processing a UserOperation from a batch.
58
68
func (ov * Overhead ) CalcPreVerificationGas (op * userop.UserOperation ) (* big.Int , error ) {
59
69
// Sanitize fields to reduce as much variability due to length and zero bytes
@@ -95,6 +105,15 @@ func (ov *Overhead) CalcPreVerificationGas(op *userop.UserOperation) (*big.Int,
95
105
return static , nil
96
106
}
97
107
108
+ // CalcPreVerificationGasWithBuffer returns CalcPreVerificationGas increased by the set PVG buffer factor.
109
+ func (ov * Overhead ) CalcPreVerificationGasWithBuffer (op * userop.UserOperation ) (* big.Int , error ) {
110
+ pvg , err := ov .CalcPreVerificationGas (op )
111
+ if err != nil {
112
+ return nil , err
113
+ }
114
+ return addBuffer (pvg , ov .pvgBufferFactor ), nil
115
+ }
116
+
98
117
// NonZeroValueCall returns an expected gas cost of using the CALL opcode in the context of EIP-4337.
99
118
// See https://github.com/wolflo/evm-opcodes/blob/main/gas.md#aa-1-call.
100
119
func (ov * Overhead ) NonZeroValueCall () * big.Int {
0 commit comments