gas

package
v0.0.0-...-7be72bc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 2, 2024 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Overview

Package gas implements helper functions for calculating EIP-4337 gas parameters.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EstimateGas

func EstimateGas(in *EstimateInput) (verificationGas uint64, callGas uint64, err error)

EstimateGas uses the simulateHandleOp method on the AiMiddleware to derive an estimate for verificationGasLimit and callGasLimit.

Types

type CalcPreVerificationGasFunc

type CalcPreVerificationGasFunc = func(op *aiop.AiOperation, static *big.Int) (*big.Int, error)

CalcPreVerificationGasFunc defines an interface for a function to calculate PVG given a aiOp and a static value. The static input is the value derived from the default overheads.

func CalcArbitrumPVGWithEthClient

func CalcArbitrumPVGWithEthClient(
	rpc *rpc.Client,
	aiMiddleware common.Address,
) CalcPreVerificationGasFunc

CalcArbitrumPVGWithEthClient uses Arbitrum's NodeInterface precompile to get an estimate for preVerificationGas that takes into account the L1 gas component. see https://medium.com/offchainlabs/understanding-arbitrum-2-dimensional-fees-fd1d582596c9.

func CalcOptimismPVGWithEthClient

func CalcOptimismPVGWithEthClient(
	rpc *rpc.Client,
	chainID *big.Int,
	aiMiddleware common.Address,
) CalcPreVerificationGasFunc

CalcOptimismPVGWithEthClient uses Optimism's Gas Price Oracle precompile to get an estimate for preVerificationGas that takes into account the L1 gas component.

type EstimateInput

type EstimateInput struct {
	Rpc          *rpc.Client
	AiMiddleware common.Address
	Op           *aiop.AiOperation
	Sos          state.OverrideSet
	Ov           *Overhead
	ChainID      *big.Int
	MaxGasLimit  *big.Int
	Tracer       string
	// contains filtered or unexported fields
}

type GasEstimates

type GasEstimates struct {
	PreVerificationGas   *big.Int `json:"preVerificationGas"`
	VerificationGasLimit *big.Int `json:"verificationGasLimit"`
	CallGasLimit         *big.Int `json:"callGasLimit"`

	// TODO: Deprecate in v0.7
	VerificationGas *big.Int `json:"verificationGas"`
}

GasEstimates provides estimate values for all gas fields in a AiOperation.

type Overhead

type Overhead struct {
	// contains filtered or unexported fields
}

Overhead provides helper methods for calculating gas limits based on pre-defined parameters.

func NewDefaultOverhead

func NewDefaultOverhead() *Overhead

NewDefaultOverhead returns an instance of Overhead using parameters defined by the Ethereum protocol.

func (*Overhead) CalcCallDataCost

func (ov *Overhead) CalcCallDataCost(op *aiop.AiOperation) float64

CalcCallDataCost calculates the additional gas cost required to serialize the aiOp when making the transaction to submit the entire batch.

func (*Overhead) CalcPerAiOpCost

func (ov *Overhead) CalcPerAiOpCost(op *aiop.AiOperation) float64

CalcPerAiOpCost calculates the gas overhead from processing a AiOperation's validation and execution phase. This overhead is not constant and is correlated to the number of 32 byte words in the AiOperation. It can be summarized in the equation perAiOpMultiplier * lenInWord + perAiOpFixed.

Note: The constant values have been derived empirically by plotting the relationship between per aiOp overhead vs length in words with a sample size of 30.

func (*Overhead) CalcPreVerificationGas

func (ov *Overhead) CalcPreVerificationGas(op *aiop.AiOperation) (*big.Int, error)

CalcPreVerificationGas returns an expected gas cost for processing a AiOperation from a batch.

func (*Overhead) CalcPreVerificationGasWithBuffer

func (ov *Overhead) CalcPreVerificationGasWithBuffer(op *aiop.AiOperation) (*big.Int, error)

CalcPreVerificationGasWithBuffer returns CalcPreVerificationGas increased by the set PVG buffer factor.

func (*Overhead) NonZeroValueCall

func (ov *Overhead) NonZeroValueCall() *big.Int

NonZeroValueCall returns an expected gas cost of using the CALL opcode with non-zero value. See https://github.com/wolflo/evm-opcodes/blob/main/gas.md#aa-1-call.

func (*Overhead) SetCalcPreVerificationGasFunc

func (ov *Overhead) SetCalcPreVerificationGasFunc(fn CalcPreVerificationGasFunc)

SetCalcPreVerificationGasFunc allows a custom function to be defined that can control how it calculates PVG. This is useful for networks that have different models for gas.

func (*Overhead) SetPreVerificationGasBufferFactor

func (ov *Overhead) SetPreVerificationGasBufferFactor(factor int64)

SetPreVerificationGasBufferFactor defines the percentage to increase the preVerificationGas by during an estimation. This is useful for rollups that use 2D gas values where the L1 gas component is non-deterministic. This buffer accounts for any variability in-between eth_estimateAiOperationGas and eth_sendAiOperation. Defaults to 0.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL