Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the ethernet intelligent contract principle of block chain?

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

Today, Xiaobian will share with you the relevant knowledge points of what the principle of blockchain Ethereum network smart contract is. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you will gain something after reading this article. Let's find out together.

1 Block chain 101

Blockchain is simply a decentralized distributed ledger, a specific type of database shared by multiple participants.

The ledger holds all transactions that take place in the blockchain network, and every node that joins the network has a full copy of the data. Economic incentive models weaken or even eliminate the trust base between independent nodes, shifting digital assets in open networks that do not require trust.

The blockchain world adheres to the principle of don't trust, verify it.

2 Smart contracts

Turing-complete smart contracts make Ethereum the biggest highlight of blockchain technology after Bitcoin. Bitcoin is a digital asset as a carrier of value, while Ethereum transcends the attributes of digital assets and empowers decentralized applications. Smart contracts are code logic capable of running on blockchain networks.

3 Ethereum Account Model and State Model

Bitcoin uses the UTXO model, while Ethereum uses the account model. Smart contracts are also accounts in Ethereum. The Ethereum network has one and only one global state, the State trie, which is updated frequently. The state trie maintains all accounts that have traded on the Ethereum network through key pairs.

Key is the Ethereum address with a length of 160 bits, and value is encoded using RLP (Recursive-Length Prefix) for the following four elements. State Trie-Ketcak-256-bit hash of the state trie's root node stored as the "stateRoot" value  

nonce

balance

storageRoot

codeHash

The following figure shows the relationship between state trie and block

Relationship between the State Trie (leveldb implementation of a Merkle Patricia Trie) and an Ethereum block

The nonce (number of successful transfers in the account) and balance (eth balance) fields of the two accounts have data, and the smart contract account storageRoot (all data of the contract) and codeHash (byte code after the contract code is compiled) have data, while the two fields of the ordinary account are empty.

The data of the contract is stored in storage trie. Just like state trie, storage trie is also stored in key value pairs (keys are storage locations and values are storage values) corresponding to the variable names and values in the contract. These key value pairs are stored in the account after Merkel hash.

The following diagram shows the relationship between storage trie and state trie.

eth_storage_tree.png

It is worth emphasizing that the block data only holds transaction trie (similar to the block header in Bitcoin that stores the root node of all transactions in the block), state trie root and receivers trie root.

4 Smart contract account contract Counter { uint counter; function Counter() public { counter = 0; } functioncount() public { counter = counter + 1; } }

Simple smart contract, counter of type uint is the state of the contract, after the count function is called, the counter value is increased by 1

smart_contract_account.png

5 Ethereum transactions

There is a special field data in the transaction information. This field value combined with the to field can divide Ethereum transactions into three categories:

transfer

TO Collection Address

DATA is empty or any transaction comment information

AMOUNT Number of ether transactions

New contract

TO field is empty, new contract is triggered

The DATA field is the smart contract bytecode

The AMOUNT field can be blank or any number. If it is not negative, it will be transferred to the newly created contract account.

call contract

The TO field is the contract account address

The DATA field is the contract function and its parameters

AMOUNT Empty or arbitrary

// Transfer of value{ to: '0x687422eEA2cB73B5d3e242bA5456b782919AFc85', value: 0.0005 data: '0x' // Could also send a message here if we want to}// Create smart contract{ to: '', value: 0.0 data: '0x6060604052341561000c57fe5b60405160c0806……………' }// Call contract{ to: '0x687422eEA2cB73B5d3e242bA5456b782919AFc85', // Contract value: 0.0 data: '0x6060604052341561000c57fe5b60405160c0806……………'}

It is worth emphasizing that there is a concept of gas in the Ethereum transaction. There is a certain cost in the Ethereum network. At the same time, a gas limit must be set. After the transaction is completed, the remaining gash will be returned.

The above is all the contents of this article "What is the principle of Ethereum network smart contract in blockchain". Thank you for reading! I believe everyone has a great harvest after reading this article. Xiaobian will update different knowledge for everyone every day. If you want to learn more knowledge, please pay attention to 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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report