Skip to content

GasTracker

Gas tracker used to track gas usage by the EVM.

Properties

struct {
  /// The gas size limit that the interpreter can run.
  gas_limit: u64
  /// The amount of gas that has already been used.
  used_amount: u64
  /// The amount of gas to refund to the caller.
  refund_amount: i64
}

Error

Set of errors that can be returned while updating the tracker.

error{ OutOfGas, GasOverflow }

Init

Sets the tracker's initial state.

Signature

pub fn init(gas_limit: u64) GasTracker

AvailableGas

Returns the remaining gas that can be used.

Signature

pub fn availableGas(self: GasTracker) u64

UpdateTracker

Updates the gas tracker based on the opcode cost.

Signature

pub inline fn updateTracker(self: *GasTracker, cost: u64) GasTracker.Error!void

Error

Set of errors that can be returned while updating the tracker.

error{ OutOfGas, GasOverflow }

CalculateCallCost

Calculates the gas cost for the CALL opcode.

Signature

pub inline fn calculateCallCost(spec: SpecId, values_transfered: bool, is_cold: bool, new_account: bool) u64

CalculateCodeSizeCost

Calculates the gas cost for the EXTCODESIZE opcode.

Signature

pub inline fn calculateCodeSizeCost(spec: SpecId, is_cold: bool) u64

CalculateCostPerMemoryWord

Calculates the gas cost per Memory word. Returns null in case of overflow.

Signature

pub inline fn calculateCostPerMemoryWord(length: u64, multiple: u64) ?u64

CalculateCreateCost

Calculates the cost of using the CREATE opcode. PANICS if the gas cost overflows

Signature

pub inline fn calculateCreateCost(length: u64) u64

CalculateCreate2Cost

Calculates the cost of using the CREATE2 opcode. Returns null in case of overflow.

Signature

pub inline fn calculateCreate2Cost(length: u64) ?u64

CalculateExponentCost

Calculates the gas used for the EXP opcode.

Signature

pub inline fn calculateExponentCost(exp: u256, spec: SpecId) error{Overflow}!u64

CalculateExtCodeCopyCost

Calculates the gas used for the EXTCODECOPY opcode.

Signature

pub inline fn calculateExtCodeCopyCost(spec: SpecId, len: u64, is_cold: bool) ?u64

CalculateKeccakCost

Calculates the cost of using the KECCAK256 opcode. Returns null in case of overflow.

Signature

pub inline fn calculateKeccakCost(length: u64) ?u64

CalculateLogCost

Calculates the gas cost for a LOG instruction.

Signature

pub inline fn calculateLogCost(size: u8, length: u64) ?u64

CalculateMemoryCost

Calculates the memory expansion cost based on the provided word_count

Signature

pub inline fn calculateMemoryCost(count: u64) u64

CalculateMemoryCopyLowCost

Calculates the cost of a memory copy.

Signature

pub inline fn calculateMemoryCopyLowCost(length: u64) ?u64

CalculateFrontierSstoreCost

Calculates the cost of the SSTORE opcode after the FRONTIER spec.

Signature

pub inline fn calculateFrontierSstoreCost(current: u256, new: u256) u64

CalculateIstanbulSstoreCost

Calculates the cost of the SSTORE opcode after the ISTANBUL spec.

Signature

pub inline fn calculateIstanbulSstoreCost(original: u256, current: u256, new: u256) u64

CalculateSloadCost

Calculate the cost of an SLOAD opcode based on the spec and if the access is cold or warm if the BERLIN spec is enabled.

Signature

pub inline fn calculateSloadCost(spec: SpecId, is_cold: bool) u64

CalculateSstoreCost

Calculate the cost of an SSTORE opcode based on the spec, if the access is cold and the value in storage. Returns null if the spec is ISTANBUL enabled and the provided gas is lower than CALL_STIPEND.

Signature

pub inline fn calculateSstoreCost(spec: SpecId, original: u256, current: u256, new: u256, gas: u64, is_cold: bool) ?u64

CalculateSstoreRefund

Calculate the refund of an SSTORE opcode.

Signature

pub inline fn calculateSstoreRefund(spec: SpecId, original: u256, current: u256, new: u256) i64

CalculateSelfDestructCost

Calculate the cost of an SELFDESTRUCT opcode based on the spec and it's result.

Signature

pub inline fn calculateSelfDestructCost(spec: SpecId, result: SelfDestructResult) u64

WarmOrColdCost

Returns the gas cost for reading from a warm or cold storage slot.

Signature

pub inline fn warmOrColdCost(cold: bool) u64