👋
Vision Network
  • Vision Basics
    • Vision Network
    • VS and VRC
    • The GitBook editor
    • Token Issuance
    • Minting Mechanism
  • Protocol
    • Account
    • Resource Model
    • Economic model
    • Multi-Signature
    • Transaction
    • Validator
      • First Validator & Reward Mechanism
      • To be Validated Candidate
      • Proposal and Committee
  • SMART CONTRACTS
    • Introduction
    • Deployment Cost
    • DevOps Flow
    • Key considerations
    • Security considerations
    • Features
      • Protobuf
      • Function Usage
      • Contract Address
      • Different Form Ethereum
  • VIRTUAL MACHINE
    • Introduction
    • Event
    • Entropy Costs Calculation
    • VM Exception Handling
    • Features between Ethereum
  • HTTP API
  • Signature and Broadcast Steps
  • Infragrid guide
  • Vtimes chrome integration
  • Introduction
  • Getting Started
  • Group 1
    • Introduction
    • GUI and Usage
  • VISION-WEB
    • Introduction
  • VISION WALLET
    • Vtimes Chrome Plugin
    • Visionscan
    • Metamask
  • DECENTRALIZED EXCHANGES
    • Operating principle
    • Trading pairs
    • Liquidity pool
  • Others
    • Term
Powered by GitBook
On this page
  • OpCode Entropy
  • Other higher-consumption operations
  • Entropy consumption for deploying contracts
  1. VIRTUAL MACHINE

Entropy Costs Calculation

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.

OpCode Entropy

The entropy consumption of different OpCode is divided into different levels, with the cost level classification and corresponding entropy consumption as follows:

public enum Tier {
    ZeroTier(0),
    BaseTier(2),
    VeryLowTier(3),
    LowTier(5),
    MidTier(8),
    HighTier(10),
    ExtTier(20),
    SpecialTier(1),
    InvalidTier(0);
  }

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

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

Other higher-consumption operations

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.

Entropy consumption for deploying contracts

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.

PreviousEventNextVM Exception Handling

Last updated 3 years ago