Blockchain core code calls and virtual currency Development library tutorials in detail

Source: Internet
Author: User
Tags data structures error code
Instruction set (instruction set)
EVM's instruction set is deliberately kept to a minimum size to avoid possible error implementations that could lead to consensus issues. All instructions are for 256-bit operation of this basic data type. With the usual arithmetic, bit, logic and comparison operations. can also be achieved conditional and unconditional jump. In addition, the contract can access the relevant properties of the current chunk, such as its number and timestamp.





Message invocation (msg Calls)
Contracts can be invoked by means of a message to invoke other contracts or to send an etheric currency to a non-contract account. Message invocation and trading are very similar, they all have a source, a target, data payload, ether currency, 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 distribution of the remaining gas. For example, how much gas is used for internal message invocation, or how much gas is expected to be retained. If an Out-of-gas exception (or other exception) occurs when an internal message is called, the contract is notified and an error code is pressed on the stack. This is only the gas exhaustion of the internal message call. In solidity, in this case, the contract initiating the call triggers a manual exception by default. This exception will print out the call stack.


As I said before, the called contract (the same as the contract that initiates the call) will have a new main memory and be able to access the payload of the call. The call payload is stored in a separate area known as Calldata. After the call execution finishes, the returned data is stored in the caller's pre-allocated chunk of memory.


The number of call tiers is limited to 1024, so for more complex operations, we should use loops instead of recursion.





code calls and libraries (Delegatecall/callcode and Libraries)
There is a special type of message call, called Callcode. It is almost exactly the same as a message invocation, except that the code that loads the destination address will run in the contract context in which the call originated.


This means that a contract can dynamically load code from another address at run time. Store, both the current address and the balance point to the contract that originated the call, and only the code is fetched from the called address.


This allows the 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.





Log (Logs)
At the block level, data can be stored in a special, indexable structure. This feature is called a log, and solidity uses it to implement events. The log data cannot be accessed after the contract is created, but the data can be accessed efficiently from outside the blockchain. Because part of the log data is stored in the Bron filter (Bloom filter), we can search the log efficiently and securely, so those network nodes (light clients) that do not download the entire blockchain can also find these logs.





Creation (Create)
Contracts can even create other contracts with a special directive (not a simple call to a 0 address). The call to create a contract differs from a normal message invocation 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-destruct (selfdestruct)
The contract code is removed from the blockchain only if the contract on an address is performing a self-destruct operation. The remaining etheric currency on the contract address is sent to the specified target, and then its storage and code is removed. Note that even if the code for a contract does not contain self-destruct instructions, you can still perform this operation through code calls (Callcode).
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.