gas

package
v1.67.6 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2023 License: BSD-3-Clause Imports: 5 Imported by: 4

Documentation

Index

Constants

View Source
const (
	// GasQuickStep 计费
	GasQuickStep uint64 = 2
	// GasFastestStep 计费
	GasFastestStep uint64 = 3
	// GasFastStep 计费
	GasFastStep uint64 = 5
	// GasMidStep 计费
	GasMidStep uint64 = 8
	// GasSlowStep 计费
	GasSlowStep uint64 = 10
	// GasExtStep 计费
	GasExtStep uint64 = 20

	// MaxNewMemSize 允许开辟的最大内存空间大小,超过此值时将会导致溢出
	MaxNewMemSize uint64 = 0xffffffffe0
)

Variables

View Source
var (
	// TableHomestead 定义各种操作的Gas定价
	TableHomestead = Table{
		ExtcodeSize: 20,
		ExtcodeCopy: 20,
		Balance:     20,
		SLoad:       50,
		Calls:       40,
		Suicide:     0,
		ExpByte:     10,
	}
)

Functions

func Balance

func Balance(gt Table, evm *params.EVMParam, contractGas *params.GasParam, stack *mm.Stack, mem *mm.Memory, memorySize uint64) (uint64, error)

Balance 获取余额计费

func Call

func Call(gt Table, evm *params.EVMParam, contractGas *params.GasParam, stack *mm.Stack, mem *mm.Memory, memorySize uint64) (uint64, error)

Call 调用合约计费

func CallCode

func CallCode(gt Table, evm *params.EVMParam, contractGas *params.GasParam, stack *mm.Stack, mem *mm.Memory, memorySize uint64) (uint64, error)

CallCode 调用合约代码计费

func CallDataCopy

func CallDataCopy(gt Table, evm *params.EVMParam, contractGas *params.GasParam, stack *mm.Stack, mem *mm.Memory, memorySize uint64) (uint64, error)

CallDataCopy 计算数据复制需要花费的Gas

func CodeCopy

func CodeCopy(gt Table, evm *params.EVMParam, contractGas *params.GasParam, stack *mm.Stack, mem *mm.Memory, memorySize uint64) (uint64, error)

CodeCopy 代码复制计费

func Create

func Create(gt Table, evm *params.EVMParam, contractGas *params.GasParam, stack *mm.Stack, mem *mm.Memory, memorySize uint64) (uint64, error)

Create 开辟内存计费

func DelegateCall

func DelegateCall(gt Table, evm *params.EVMParam, contractGas *params.GasParam, stack *mm.Stack, mem *mm.Memory, memorySize uint64) (uint64, error)

DelegateCall 委托调用计费

func Dup

func Dup(gt Table, evm *params.EVMParam, contractGas *params.GasParam, stack *mm.Stack, mem *mm.Memory, memorySize uint64) (uint64, error)

Dup dup操作计费

func Exp

func Exp(gt Table, evm *params.EVMParam, contractGas *params.GasParam, stack *mm.Stack, mem *mm.Memory, memorySize uint64) (uint64, error)

Exp exp运算计费

func ExtCodeCopy

func ExtCodeCopy(gt Table, evm *params.EVMParam, contractGas *params.GasParam, stack *mm.Stack, mem *mm.Memory, memorySize uint64) (uint64, error)

ExtCodeCopy 扩展代码复制计费

func ExtCodeSize

func ExtCodeSize(gt Table, evm *params.EVMParam, contractGas *params.GasParam, stack *mm.Stack, mem *mm.Memory, memorySize uint64) (uint64, error)

ExtCodeSize 获取代码大小计费

func MLoad

func MLoad(gt Table, evm *params.EVMParam, contractGas *params.GasParam, stack *mm.Stack, mem *mm.Memory, memorySize uint64) (uint64, error)

MLoad 内存加载计费

func MStore

func MStore(gt Table, evm *params.EVMParam, contractGas *params.GasParam, stack *mm.Stack, mem *mm.Memory, memorySize uint64) (uint64, error)

MStore 内存存储计费

func MStore8

func MStore8(gt Table, evm *params.EVMParam, contractGas *params.GasParam, stack *mm.Stack, mem *mm.Memory, memorySize uint64) (uint64, error)

MStore8 内存存储计费

func Push

func Push(gt Table, evm *params.EVMParam, contractGas *params.GasParam, stack *mm.Stack, mem *mm.Memory, memorySize uint64) (uint64, error)

Push 压栈计费

func Return

func Return(gt Table, evm *params.EVMParam, contractGas *params.GasParam, stack *mm.Stack, mem *mm.Memory, memorySize uint64) (uint64, error)

Return 返回操作计费

func ReturnDataCopy

func ReturnDataCopy(gt Table, evm *params.EVMParam, contractGas *params.GasParam, stack *mm.Stack, mem *mm.Memory, memorySize uint64) (uint64, error)

ReturnDataCopy 计算数据复制的价格

func Revert

func Revert(gt Table, evm *params.EVMParam, contractGas *params.GasParam, stack *mm.Stack, mem *mm.Memory, memorySize uint64) (uint64, error)

Revert revert操作计费

func SLoad

func SLoad(gt Table, evm *params.EVMParam, contractGas *params.GasParam, stack *mm.Stack, mem *mm.Memory, memorySize uint64) (uint64, error)

SLoad 加载存储计费

func SStore

func SStore(gt Table, evm *params.EVMParam, contractGas *params.GasParam, stack *mm.Stack, mem *mm.Memory, memorySize uint64) (uint64, error)

SStore 计算数据存储的价格

func Sha3

func Sha3(gt Table, evm *params.EVMParam, contractGas *params.GasParam, stack *mm.Stack, mem *mm.Memory, memorySize uint64) (uint64, error)

Sha3 sha3计费

func StaticCall

func StaticCall(gt Table, evm *params.EVMParam, contractGas *params.GasParam, stack *mm.Stack, mem *mm.Memory, memorySize uint64) (uint64, error)

StaticCall 静态调用计费

func Suicide

func Suicide(gt Table, evm *params.EVMParam, contractGas *params.GasParam, stack *mm.Stack, mem *mm.Memory, memorySize uint64) (uint64, error)

Suicide 自杀操作计费

func Swap

func Swap(gt Table, evm *params.EVMParam, contractGas *params.GasParam, stack *mm.Stack, mem *mm.Memory, memorySize uint64) (uint64, error)

Swap 交换计费

Types

type CalcGasFunc

type CalcGasFunc func(Table, *params.EVMParam, *params.GasParam, *mm.Stack, *mm.Memory, uint64) (uint64, error) // last parameter is the requested memory size as a uint64

CalcGasFunc 计算Gas的方法定义

func ConstGasFunc

func ConstGasFunc(gas uint64) CalcGasFunc

ConstGasFunc Gas计算逻辑封装,返回固定值的Gas计算都可以使用此方法

func MakeGasLog

func MakeGasLog(n uint64) CalcGasFunc

MakeGasLog 生成Gas计算方法

type Table

type Table struct {
	// ExtcodeSize 扩展代码大小计价
	ExtcodeSize uint64
	// ExtcodeCopy 代码复制价格
	ExtcodeCopy uint64
	// Balance 账户计价
	Balance uint64
	// SLoad 加载数据计价
	SLoad uint64
	// Calls 调用方法计价
	Calls uint64
	// Suicide 自杀计价
	Suicide uint64
	// ExpByte 额外数据计价
	ExpByte uint64
}

Table 此文件中定义各种指令操作花费的Gas计算 Gas定价表结构

Jump to

Keyboard shortcuts

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