multigas

package
v0.0.0-...-6138ca8 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2025 License: GPL-3.0 Imports: 1 Imported by: 0

Documentation

Overview

Package multigas defines multi-dimensional gas for the EVM.

This package introduces mechanisms to track each resource used by the EVM separately. The possible resources are computation, history growth, storage access, and storage growth. By tracking each one individually and setting specific constraints, we can increase the overall gas target for the chain.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MultiGas

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

MultiGas tracks gas usage across multiple resource kinds, while also maintaining a single-dimensional total gas sum and refund amount.

func ComputationGas

func ComputationGas(amount uint64) *MultiGas

ComputationGas returns a MultiGas initialized with computation gas.

func HistoryGrowthGas

func HistoryGrowthGas(amount uint64) *MultiGas

HistoryGrowthGas returns a MultiGas initialized with history growth gas.

func NewMultiGas

func NewMultiGas(kind ResourceKind, amount uint64) *MultiGas

NewMultiGas creates a new MultiGas with the given resource kind initialized to `amount`. All other kinds are zero. The total is also set to `amount`.

func StorageAccessGas

func StorageAccessGas(amount uint64) *MultiGas

StorageAccessGas returns a MultiGas initialized with storage access gas.

func StorageGrowthGas

func StorageGrowthGas(amount uint64) *MultiGas

StorageGrowthGas returns a MultiGas initialized with storage growth gas.

func UnknownGas

func UnknownGas(amount uint64) *MultiGas

UnknownGas returns a MultiGas initialized with unknown gas.

func ZeroGas

func ZeroGas() *MultiGas

ZeroGas creates a MultiGas value with all fields set to zero.

func (*MultiGas) Get

func (z *MultiGas) Get(kind ResourceKind) uint64

Get returns the gas amount for the specified resource kind.

func (*MultiGas) GetRefund

func (z *MultiGas) GetRefund() uint64

GetRefund gets the SSTORE refund computed at the end of the transaction.

func (*MultiGas) SafeAdd

func (z *MultiGas) SafeAdd(x *MultiGas, y *MultiGas) (*MultiGas, bool)

SafeAdd sets z to the sum of x and y, per resource kind and total. Returns the modified MultiGas and a boolean indicating if an overflow occurred in either the kind-specific or total value.

func (*MultiGas) SafeIncrement

func (z *MultiGas) SafeIncrement(kind ResourceKind, gas uint64) bool

SafeIncrement increments the given resource kind by the amount of gas and to the total. Returns true if an overflow occurred in either the kind-specific or total value.

func (*MultiGas) Set

func (z *MultiGas) Set(kind ResourceKind, gas uint64) (*MultiGas, bool)

Set sets the gas for a given resource kind to `gas`, adjusting the total accordingly. Returns the same MultiGas and a boolean indicating if an overflow occurred when updating the total.

func (*MultiGas) SetRefund

func (z *MultiGas) SetRefund(amount uint64) *MultiGas

SetRefund sets the SSTORE refund computed at the end of the transaction and returns the modified MultiGas.

func (*MultiGas) SingleGas

func (z *MultiGas) SingleGas() uint64

SingleGas returns single-dimensional gas sum.

type ResourceKind

type ResourceKind uint8

ResourceKind represents a dimension for the multi-dimensional gas.

const (
	ResourceKindUnknown ResourceKind = iota
	ResourceKindComputation
	ResourceKindHistoryGrowth
	ResourceKindStorageAccess
	ResourceKindStorageGrowth
	NumResourceKind
)

Jump to

Keyboard shortcuts

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