current position:Home>Conflux advanced course - the main differences between CVM and EVM virtual machine layers of conflux

Conflux advanced course - the main differences between CVM and EVM virtual machine layers of conflux

2022-02-03 00:39:23 Conflux Chinese community

 take EVM Bytecode migration to Conflux On 
 Copy code 

Conflux The deposit mechanism is adopted . When executing smart contracts , If you pass   SSTORE (0x55)  When an instruction writes non-zero data to storage , You need to pay a deposit . When this data is cleared , The deposit will be returned to the payer .

The price of deposit is 1/1024 CFX/byte. Each storage unit counts 64 byte . besides , After the contract is created , The code also requires a storage deposit .

 The difference between the deposit mechanism 
 Copy code 

Conflux The deposit mechanism is adopted . When executing smart contracts , If you pass SSTORE (0x55) When an instruction writes non-zero data to storage , You need to pay a deposit . When this data is cleared , The deposit will be returned to the payer .

The price of deposit is 1/1024 CFX/byte. Each storage unit counts 64 byte . besides , After the contract is created , The code also requires a storage deposit .

 The maximum storage domain of the transaction 
 Copy code 

  stay Conflux in , You need to fill in the upper limit of each transaction , Unit is byte . If the storage limit is too high , It exceeds the deposit that can be paid by the account balance , The deal will fail . If the storage limit is too low , As a result, the actual newly added storage at the end of transaction execution exceeds the storage limit , The deal will also fail .

One of the simplest solutions is , adopt Conflux RPC Estimate ( Please refer to the relevant sections ) The maximum amount of storage required for a transaction . perhaps , Can pass   n*1024  Calculate the maximum supported storage limit of account balance according to the formula of .( among   n  Is the balance after paying the transaction fee and account transfer fee . For the sake of insurance , You can also fill in a smaller number , Such as   n*1000

Write the fuel consumed by storage

That's enough . stay Conflux in , all   SSTORE (0x55)  The fuel consumed by the command is 5000 gas. Comparison , The logic of Ethereum here is very complicated . however , The average developer doesn't need to care about the specifics of each instruction gas pricing , Just go through RPC Just estimate the fuel consumption of the whole transaction .

 Differences arising from consensus mechanisms 

 Block height and block hash related instructions 
 Copy code 

  In Ethereum , BLOCKHASH (0x40)  Instructions (Solidity Medium   block.blockhash(n)  function ) Accept block number ( Block height )  n As input , Output the hash value corresponding to the block height . Where the parameter height is   n  The height difference from the block where the transaction is executed cannot exceed 256, Otherwise it will return to 0.

Conflux Tree graph structure is adopted , When blocks are sorted , Each block will generate a sort number , This sort number is different from the block height . Because after the tree structure is sorted , Two adjacent blocks may have no parent-child relationship , So the number is   n-1  The block is not necessarily numbered    n  The father of the block .

Conflux in   BLOCKHASH (0x40)  Instructions (Solidity Medium   block.blockhash(n)  function ) Accept block sort number   n  As input . Corresponding , NUMBER (0x43)  Instructions (Solidity Medium block.number  Variable ) The result is also a sort number .

Besides , Ethereal   BLOCKHASH (0x40)  The order can ask the exchange in front of the block 256 Hash value of blocks , and Conflux The instruction can only query the hash value of the previous block . however ,Conflux The number of parameters is no different from Ethereum .

 Block out speed 
 Copy code 

  Conflux The output speed of is per second 2 Block , Much faster than Ethereum . If the block speed is hard coded in the code logic of the smart contract , Changes need to be made accordingly .

 Fill in the information in the transaction 
 Copy code 

When a user initiates a transaction ,Conflux The information you need to fill in is different . But in general RPC and SDK Will do this for developers and users .

Storage Limit: Storage cap . See The maximum storage domain of the transaction Section .

Gas Limit: Fuel cap . For unused gas, Conflux At most... Will be returned Gas Limit Of 1/4, So before sending out the deal , Be sure to estimate a more accurate upper fuel limit .

Chain ID: Blockchain number . Specify the blockchain number that can execute this transaction , Avoid someone replaying the transactions of the test network on the main network . at present , Test network Chain ID yes 1, Main network Chain ID yes 2.

Epoch Height: When the transaction is executed ( About the )epoch. If the transaction is actually executed Epoch With the transaction Epoch Height Difference between 100000 above (Epoch Number growth 100000 The time varies from half a day to a few days ), The transaction will fail . in other words , Transactions that have not been packaged for too long will not be executed .

Recipient: Conflux Your address algorithm is different from Ethereum . The first four addresses generated by all public keys bits All are 0001, The first four of all contract addresses bits All are 1000. The first four of all built-in contract addresses bits All are 0000. If the payee's address recipient The first four bits Not one of the three , Transaction execution failed .

 Other differences 
 Copy code 

After the contract is created , The creator ( That is, when the contract is created   msg.sender ) Automatically become the administrator of the contract . The administrator has the right to destroy the contract , Or transfer administrator privileges to others . The administrator can be a normal address , It can also be the contract address .

Conflux The maximum number of contract codes created is 49152 byte , Twice as much as Ethereum .

Please check whether there is a hard coded Ethereum address in your contract .

Conflux There are other differences in , It's something that contract developers and users don't need to care about , Here we omit .

copyright notice
author[Conflux Chinese community],Please bring the original link to reprint, thank you.
https://en.fheadline.com/2022/02/202202030039187840.html

Random recommended