Entropy Costs Calculation
Last updated
Last updated
When writing, testing and debugging smart contracts, you should be aware of the different OpCode call costs. This article provides details on the calculation of entropy consumption and provides links to relevant references.
The entropy consumption of different OpCode is divided into different levels, with the cost level classification and corresponding entropy consumption as follows:
The concept of memory and storage exists in virtual machines, and the OpCode consumption for these two types of operations is calculated separately.
For example, for the memory type of OpCode, the memory size of the operation affects the consumption, for example MLOAD, MSTORE OpCode, the consumption is related to the word length of the operating memory.
For the storage type SSTORE OpCode, the consumption is not only related to the operation word length, but also need to distinguish whether the operation is reset, add, or delete.
Current value | Operation | Entropy Consumption | Type of Operation |
---|---|---|---|
When creating an account by transferring VS or CRC10 from a contract to an inactive account, an additional 25000 entropy is consumed and there is no account creation fee of 0.1 VS.
When invoking other contracts with actions such as CALL, DELEGATECALL, etc., and additional transfers are made, an additional 9000 entropy is consumed.
When using CREATE, CREATE2 to dynamically create a contract within a contract, it consumes 32000 entropy.
When deploying a contract, the contract code consumes 200 entropy per byte.
The bytecode provided when deploying a contract is generally divided into two parts, one called the creation code and the other is the contract's runtime code. The deployment code is generally used to execute the contract constructor logic and return the actual contract runtime code. To calculate the entropy consumption when deploying a contract, the length of the runtime code is used. It typically starts with the second 6060 or 6080 of the bytecode of the deployment code.
val = 0x0
sstore(val, n) n != 0 (val = n)
20000
SET
val != 0x0
sstore(val, n) n != 0 (val = n)
5000
RESET
val != 0x0
sstore(val, 0) (val = 0)
5000
CLEAR