@@ -26,6 +26,7 @@ type Overhead struct {
2626 sanitizedVGL * big.Int
2727 sanitizedCGL * big.Int
2828 calcPVGFunc CalcPreVerificationGasFunc
29+ pvgBufferFactor int64
2930}
3031
3132// NewDefaultOverhead returns an instance of Overhead using parameters defined by the Ethereum protocol.
@@ -45,6 +46,7 @@ func NewDefaultOverhead() *Overhead {
4546 sanitizedVGL : big .NewInt (1000000 ),
4647 sanitizedCGL : big .NewInt (1000000 ),
4748 calcPVGFunc : calcPVGFuncNoop (),
49+ pvgBufferFactor : 0 ,
4850 }
4951}
5052
@@ -54,6 +56,14 @@ func (ov *Overhead) SetCalcPreVerificationGasFunc(fn CalcPreVerificationGasFunc)
5456 ov .calcPVGFunc = fn
5557}
5658
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+
5767// CalcPreVerificationGas returns an expected gas cost for processing a UserOperation from a batch.
5868func (ov * Overhead ) CalcPreVerificationGas (op * userop.UserOperation ) (* big.Int , error ) {
5969 // 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,
95105 return static , nil
96106}
97107
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+
98117// NonZeroValueCall returns an expected gas cost of using the CALL opcode in the context of EIP-4337.
99118// See https://github.com/wolflo/evm-opcodes/blob/main/gas.md#aa-1-call.
100119func (ov * Overhead ) NonZeroValueCall () * big.Int {
0 commit comments