Table of contents
Metering
Gas metering in Ethereum is used to calculate the cost of a particular contract execution. This article discusses improvements we can do to make metering better.
Miner-controlled metering
This section discusses miner-controlled metering, a method to combat opcode gas mis-price, by allowing it to be controlled by miners. For background, refer to this paper and the discussions in Istanbul hard fork.
Specification
Define the gas table, stored in each client in RLP encoded format. We
do not present a complete gas table here, but provide an example. The
format of gas table can be changed in each hard fork. Below, consider
we only want to let miners control the gas cost of SLOAD
and
BALANCE
opcode. The gas table is defined as follows:
[ SLOAD_GAS, BALANCE_GAS ]
Change EVM so that when calling SLAOD
and BALANCE
, use the gas
cost of values defined in the new gas table.
Add an additional header RLP field cost
. The new field can have one
of the following values:
-
Empty RLP: This indicates that the miner proposes no gas cost change in current block.
-
[ ff ff, < raw RLP encoding of the new gas table > ]
: This indicates that a hard fork happened, and the gas cost table is changed to a new one, encoded as the second item. -
[ < other 2-byte value >, < keccak256 hash of RLP encoding of the new gas table > ]
: This indicates that miners propose to change the current gas table, with instructions provided in the first RLP item, and new gas table hash provided in the second RLP item.
Given the above example gas table of SLOAD
and BALANCE
, we can
define the following instruction table:
Instruction | Description |
---|---|
|
Increase |
|
Decrease |
|
Increase |
|
Decrease |