Klaytn Docs
Search…
Computation Cost (Previous docs)
Since Klaytn aims to maintain 1-second block time, the execution time of transactions has to be managed. Here are three approaches to achieve that:
  1. 1.
    Limiting the gas limit of a transaction 2. Limiting the execution time of a transaction 3. Limiting the computation cost of a transaction
Limiting the gas limit of a transaction was not a feasible solution because the concept of the gas represents the current exchange value of the various resources in the blockchain platform such as computation, storage, network bandwidth, and so on. It is not suitable as a metric for the transaction execution time.
Limiting the execution time of a transaction was not feasible either because the execution time can vary between nodes on the blockchain platform. For example, consider the case in which we limit the execution time of a transaction to be 100 milli-second. If a node executes a transaction in 90 ms and another node executes it in 110 ms, the two nodes cannot reach a consensus. Hence, this solution is not appropriate.
The last approach is to limit the computation cost of a transaction. We modelled the computation cost of each EVM opcode based on its actual execution time and limit the sum of computation cost of a transaction. With this approach, we eliminate other factors and only count the normalized execution time unit, and nodes can reach a consensus as well.
Therefore, we chose the third option for Klaytn. For now, the limit of the execution cost is set to 100,000,000. Since the limit is determined by the platform, developers should be aware of the computation cost of a transaction. To calculate the computation cost of a transaction, Klaytn provides klay_estimateComputationCost. The usage is almost the same as klay_estimateGas.

Computation Cost of Opcodes

The below table shows the computation cost of EVM opcodes. The computation cost was determined based on experiments.
NOTE: This document contains computation costs used before the activation of the protocol upgrade. If you want the latest document, please refer to latest document.
Opcode
ComputationCost
STOP
0
ADD
150
MUL
200
SUB
219
DIV
404
SDIV
739
MOD
812
SMOD
560
ADDMOD
3349
MULMOD
4757
EXP
5000
SIGNEXTEND
481
LT
201
GT
264
SLT
176
SGT
222
EQ
220
ISZERO
165
AND
288
OR
160
Copy link
Edit on GitHub