In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
In this article, the editor introduces in detail "what are the terms of virtual machine account trading in Ethernet Square", the content is detailed, the steps are clear, and the details are handled properly. I hope that this article "what are the terms of virtual machine account trading in Etay Square" can help you solve your doubts? let's follow the editor's train of thought to learn new knowledge.
How do you explain the terms such as virtual machine, account, transaction, gas, storage, main memory, stack, instruction set, message call, code call, library, log, creation, self-destruct? Let's take a look. Let's first take a look at the virtual machine of Etay Square.
The Ethernet Square Virtual Machine (EVM) is the operating environment for intelligent contracts in Ethernet Square. Not only is it sandboxed, but it is actually completely isolated, meaning that code running inside the virtual machine EVM cannot touch the network, file system, or other processes. Even smart contracts have limited access to other smart contracts.
Account
There are two types of accounts in Tai Fong, which share the same address space. External accounts, which are controlled by public-private key pairs (human). Contract accounts, which are controlled by the code stored in the account.
The address of the external account is determined by the public key, and the address of the contract account is determined when the contract is created (this address is calculated from the address of the contract creator and the number of transactions sent out by that address, which is also known as "nonce").
Apart from the fact that contract accounts store codes and external accounts do not, these two types of accounts are the same for EVM.
Each account has a persistent storage in the form of key-value. Among them, key and value are both 256 bits long and are called storage.
In addition, each account has an etheric balance (in "Wei"), which can be changed by sending it transactions with Ethernet coins.
Trade
A transaction is a message sent from one account to another (it may be the same account or zero account, see below). Transactions can contain binary data (payload) and Ethernet coins.
If the target account contains a code, the code is executed, and payload is the input data.
If the target account is a zero account (account address is 0), the transaction will create a new contract. As mentioned above, the contract address is not a zero address, but is calculated from the address of the contract creator and the number of transactions issued by that address (known as nonce). The payload that creates the contract transaction is executed as EVM bytecode. The output of the execution is permanently stored as a contract code. This means that in order to create a contract, you don't need to send the real contract code to the contract, but send the code that returns the real code.
Gas
A certain amount of gas,gas is charged for each transaction on Ethernet Square in order to limit the amount of work required to execute the transaction and to pay for it. When EVM executes a transaction, the gas is gradually consumed according to specific rules.
The gas price (etheric currency meter) is set by the transaction creator, and the transaction fee required to send the account in advance is gas price * gas amount. If there is any gas left at the end of the execution, the gas will be returned to the sending account.
No matter where it is executed, once the gas is exhausted (for example, reduced to a negative value), an out-of-gas exception will be triggered. All state changes made by the current calling frame will be rolled back.
Storage, main memory and stack
Each account has an area of persistent memory called storage. It is in the form of key-value,key and value with a length of 256bits. In the contract, the storage of the account cannot be traversed. Compared with the other two, the read operation of storage is relatively expensive, and the modification of storage is more serious. A contract can only read and write to its own storage.
The second area of memory is called main memory. Each time the contract executes a message call, there is a new piece of main memory that has been cleared. Main memory can be addressed at a byte granularity, but the read and write granularity is 32 bytes (256 bits). The cost of operating main memory increases as it grows (square level).
EVM is not a register-based virtual machine but a stack-based virtual machine. So all calculations are performed in an area called a stack. The stack has a maximum of 1024 elements, each with 256 bits. Access to the stack is limited to its top by allowing one of the top 16 elements to be copied to the top of the stack, or swapping the top element of the stack with one of the following 16 elements. All other operations can only take the top two (or one, or more, depending on the specific operation) elements and press the results on the top of the stack. Of course, you can put the elements on the stack into storage or main memory. However, you cannot access only the element of the specified depth on the stack, and all elements above the specified depth must be removed from the stack before that.
Instruction set
EVM's instruction set is deliberately kept to a minimum to avoid incorrect implementations that could lead to consensus problems as much as possible. All instructions are for operations of the basic data type 256 bits. Have common arithmetic, bit, logic and comparison operations. Conditional and unconditional jumps can also be achieved. In addition, the contract can access the relevant attributes of the current block, such as its number and timestamp.
Message call
A contract can invoke another contract through a message call or send etheric currency to a non-contract account. Message calls are very similar to transactions in that they both have a source, a target, a data payload, ethernet, gas, and return data. In fact, each transaction can be thought of as a top-level message call, which in turn produces more message calls.
A contract can determine the allocation of the remaining gas. For example, how much gas is used for internal message calls, or how much gas is expected to be retained. If an out-of-gas exception (or other exception) occurs during an internal message call, the contract is notified and an error code is pressed on the stack. In this case, the gas of the internal message call is exhausted. In solidity, the contract that initiates the call in this case triggers a human exception by default. This exception prints out the call stack. As mentioned earlier, the invoked contract (as well as the contract that initiated the call) will have new main memory and be able to access the payload of the call. The call payload is stored in a separate area called calldata. After the call execution is completed, the returned data will be stored in a piece of memory pre-allocated by the caller.
The number of call layers is limited to 1024, so for more complex operations, we should use loops instead of recursion.
Code calls and libraries
There is a special type of message call called callcode. It is almost exactly the same as a message call, except that the code loaded from the target address will run in the context of the contract that initiated the call.
This means that a contract can dynamically load code from another address at run time. The storage, the current address and the balance all point to the contract that initiated the call, and only the code is obtained from the called address.
This allows Solidity to implement "libraries". Reusable library code can be applied to the storage of a contract and can be used to implement complex data structures.
Journal
At the block level, a special indexable data structure can be used to store data. This feature is called logging, and Solidity uses it to implement events. Log data cannot be accessed after the contract is created, but it can be accessed efficiently from outside the blockchain. Because some of the log data is stored in the Bloom filter (Bloom filter), we can search the logs efficiently and safely, so those network nodes (light clients) that do not download the entire blockchain can also find these logs.
Create
Contracts can even create other contracts with a special instruction (rather than simply making a call to zero address). A call to create a contract differs from a normal message call in that the result of the execution of the payload data is treated as code, and the caller / creator gets the address of the new contract on the stack.
Self-destruction
The contract code is removed from the block chain only if the contract at an address performs a self-destruct operation. The remaining etheric coins on the contract address are sent to the specified destination, and then its storage and code are removed.
Note that even if the code for a contract does not contain self-destruct instructions, this can still be done through code calls (callcode).
After reading this, the article "what are the terms of virtual machine account transactions in Ethernet Square" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it before you can understand it. If you want to know more about related articles, welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.