Hey Ethereum

📕 About the original work

Github.com/ethereumboo…

By Andreas M Antonopoulos and Gavin Wood

  • It introduces all the basic information needed to know about the virtual machine based block chain and the construction of smart contracts and DApps.

  • This book can be used as a technical reference manual, but also to give readers a more complete understanding of Ethereum.

📝 About this article

Hide Solidity code details for all smart contract development; Collect references to further digest and learn the key or difficult parts recorded in the reading process, and strive for a more general understanding of the foundation and vision of ethereum (or Web3.0).

The quoted content is excerpted from the original book

Chapter 1 What is Ethereum

Having a globally accessible monomer state; There is also a virtual machine that performs state changes

A state machine that is maintained by all participants and can be changed through a virtual machine (EVM); Programs that run on virtual machines are called Smart contracts.

In layman’s terms, if Bitcoin (the blockchain-based digital currency) is an agreed-upon data chain maintained by all, with transaction bills hanging from each node, ethereum is the equivalent of a calculator hanging from each node.

⛓️ 🖥 100 ⛓ 🖥 100 disk ⛓ 100 maximum maximum maximum maximum maximum maximum maximum maximum...

Some see Ethereum as a programmable digital currency platform…… Web 3 sees Ethereum as part of a decentralized technology, two other important components of which are Whisper and Swarm

The Ethereum VIRTUAL machine is not just a calculator that can be used to calculate currency transactions. It is actually a computing platform for the general purpose of “Turing complete” :

  • See reading – Turing complete
    • Turing-complete | three thinking – from the boy genius can chain technology website

    • Whisper and Swarm

      • whisper

      • White paper on Swarm

Each instruction has a pre-defined cost, in gas. When an Ethereum transaction triggers the execution of a smart contract, the transaction must include an upper limit on the amount of computing resources required to execute the smart contract. If the resource sales volume during execution exceeds the gas ceiling specified in the transaction, the EVM will voluntarily terminate the execution of the contract

Turing-complete means that the programs that EVM runs on — smart contracts — have the potential to run in an infinite loop until they run out of resources; Ethereum sets ⛽ as the fuel required to operate as a smart contract, and when fuel costs exceed a specified limit, the program terminates, preventing crashes

  • See Reading – Appendix C: CORRESPONDING EVM opcodesgasoverhead

Chapter 2 Basic concepts of Ethereum

We’ll use the term “wallet” to refer to a software application that helps you manage your Ethereum account

Never store your private key in the form of a digital message. It is recommended to keep this slip of paper locked in a drawer or safe

💰 wallet is the account/address/identity of each user in Ethereum. Due to the decentralized nature, there is no option to “retrieve password”, so each person must be responsible for their 💰.

Ethereum is designed to pay for smart contracts, which are computer programs that run on top of ethereum virtual machines (EVM)

As described in Chapter 1, the digital currency feature is just one of the features of ethereum’s general computing platform; The real purpose of ether is to pay for smart contracts, like coin-op games 🕹️, where only coins trigger programs to run.

Contracts have addresses, just like external accounts. Contracts can also send and receive Ether

Smart contracts have their own address (💰) just like you do.

The power of programmable blockchains is that you can control assets with decentralized software!

Assets are equivalent to consensus. When everyone agrees that you have $100, then you have $100 of assets. The consensus of all people is stored on the blockchain in the form of transaction records, which are jointly maintained by all people. The advantage of smart contracts is that they can control the flow of assets like human beings (provided, of course, that the rules of smart contracts are also shared by all people!).

Now wait 15 to 30 seconds for the trade to be confirmed by the miners on Ropsten’s network. The Remix IDE can’t speed this up either, so we just have to wait

  • Reference reading – The Life cycle of Ethereum Transactions

    The life cycle of ethereum transactions

Each transaction has to be proved by the miner through a large number of calculations and a certain fee (gas) is charged; This greatly limits the efficiency of transactions, which is obviously not enough if you want to support a global decentralized APP, and it is unacceptable to imagine that you have to wait 20 seconds and charge a fee to post a message. In the case of ENS (Ethereum Domain name Service), the cost of registering a domain name is 0.001 ETH ($5 USD), and the gas cost is nearly 30 times the cost of registration!

The 2021-12-6 sons

To address this, and to enable more people to use Ethereum as a decentralized application (DApps) for underlying services, there are two solutions, on-chain and off-chain, namely Ethereum 2.0 and Layer 2.

  • See also – Ethereum 2.0

    • The ETH 2.0

    • What’s Ethereum 2.0, and What does it mean for ETH? – Deltec Bank & Trust

  • See also – Ethereum Scaling

    • Scaling | ethereum.org

Chapter 3 Ethereum Client

You need at least 80GB of disk space to run a fully functional node on the public chain and hold blockchain data for the entire Ethereum public chain. If you want to run fully functional nodes on your test network, you need about 15GB of disk space. Downloading 80GB of blockchain data requires a fast Internet connection, otherwise it can take a very long time

You can also run a client that only calls Ethereum remotely, that is, does not hold blockchain data locally and does not participate in block and transaction validation. Such clients provide wallet functionality and can also create and broadcast transactions

Fully functional nodes need to maintain all ethereum data and become part of a decentralized blockchain; However, this requires more disk space and bandwidth (as well as power consumption), and if you just want to be a micro developer developing DApps in Ethereum, you can always interact with Ethereum via remote calls (JSON-PRC).

  • See reading – Different types of nodes

    Classification and importance of nodes in a blockchain network

Instead, it injects a Web3 instance into the browser as an RPC client that can connect to multiple Ethereum blockchains (e.g., main network, Ropsten test network, Kovan test network, local RPC nodes, etc.). Injecting Web3 instances and acting as a gateway to external RPC services makes MetaMask a holy grail for developers

🦊 MetaMask is a wallet 💰 application in the form of a browser plug-in. It has the advantage of allowing developers to quickly interact with Ethereum on different test networks when developing DApps via Web3.js, without having to maintain a client themselves.

Chapter 4 The cryptography behind Ethereum

Cryptography can be used for proof of knowledge, which means proving knowledge of secret information without disclosing secret data (digital signatures); Can also be used to prove the authenticity of information (digital fingerprints, also known as hashes)

Advanced cryptography tools, such as zero-knowledge proof and homomorphic encryption, will also be available in the future

The public key can be deduced from the private key, but the public key cannot be reversely computed from the private key because the mathematical algorithm is one-way

The ethereum address is a hexadecimal number from the last 20 bits of the result of a kecCAK-256 hash of the public key

Blockchain is based on consensus, consensus is based on proof of knowledge (authenticity), and cryptography is used to prove knowledge.

  • See reading – Zero knowledge proof, homomorphic encryption

    Proof of zero knowledge: casting out bricks to attract jade

    Homomorphic encryption and its application in machine learning -InfoQ

Chapter 5 The Purse

A wallet is a key ring containing a pair of private and public keys. By signing transactions with these private keys, users can prove their ownership of Ether, which itself is held on the blockchain

Only the correct public and private keys can prove that the encrypted information is accurate, and only your private key can prove that your transaction information (the transaction consensus is the ownership) is accurate; So your wallet 💰 is your identity

Chapter 6 Transactions

Transactions are signed messages sent by external accounts, propagated through the Ethereum network, recorded on the blockchain by miners… A transaction is the only thing that can trigger a change in the state of the blockchain, or trigger the execution of a contract on an EVM

Transactions are made by the user from their wallet 💰 (external account) and can be transferred to another account or to a smart contract (which, like a coin, triggers the execution of the smart contract).

In a decentralized system like Ethereum, nodes receive transactions in any order; There is no way to ensure that one node receives a transaction before another

Transaction information needs to be synchronized across all nodes to be confirmed, which is another reason for the slow transaction speed. To solve this problem, a Nonce value is stored in the transaction information to represent the sequence number of the transaction, thus preventing repeated transactions due to delay.

Equivalent to 🪙 into a black hole, raising the market value

You can send Ether to an “address” that has no corresponding private key, which essentially destroys ether. Recipient address authentication needs to be done at the user application level… Since there are a finite number of Ether coins, destroying them effectively spreads the value to all ether holders (in proportion to what they own).

The destination address for contract registration transactions is a special address – zero address. Simply put, the TO field for a contract registration transaction contains 0x0. This address is neither an external account address (with no corresponding private or public key) nor a contract address

Chapter 7 Smart Contracts and Solidity

For the transaction context that triggered the execution of the smart contract, or the ethereum blockchain state at the time of execution, the output of the result of the execution of the smart contract is the same for everyone running or calling it

In a smart contract (or EVM), there is no random function.

  • Refer to reading – Solidity development for the full video tutorial

    Solidity Blockchain Smart Contract Course

The “concurrent execution” of smart contracts is meaningless in any case: the Ethereum world computer can be thought of as a single-threaded computer

Chapter 8 Smart Contract and Vyper

Vyper is a powerful and interesting new contract-oriented programming language. It was designed to be “right” at the expense of flexibility

Vyper is a contract-oriented, pythonic programming language that targets the Ethereum Virtual Machine (EVM).

  • Reference reading – Vyper

    Vyper – Vyper documentation

Chapter 9 smart Contract Security

DAO (Decentralized Autonomous Organization) attack is a serious attack in the early stage of Ethereum. The contract held assets worth more than $150 million at the time. Reentrant played a major role in the attack, which eventually led to a hard fork and the creation of Ethereum Classic (ETC). Please refer to the detailed analysis of the loopholes in the DAO hackingdistributed.com/2016/06/18/…

Chapter 10 Tokens – Tokens

The term has been redefined by blockchain-based tokens, which refer to abstract blockchain-based assets that can be held and used to represent assets, cash, or access rights

The Ethereum balance of an Ethereum account is handled at the protocol level, while the token balance of an Ethereum account is handled at the smart contract level. To create a new token on Ethereum, you have to create a new smart contract

Tokens in Ethereum are an application of smart contracts. Erc-20 (Ethereum Demand Proposal, No. 20) specifies a mechanism for the issuance and transfer of tokens. Just like a company’s equity allocation mechanism, erC-20 specifies the total number of shares and records the transaction process between equity holders. The difference is that it is based on ethereum’s smart contract, so once published, all rules and transaction information are open and transparent and cannot be changed.

From a technical point of view, ERC-20 defines a set of functions and events that, like an Interface in object-oriented, all smart contracts that issue tokens must implement methods in the Interface so that all tokens can communicate easily with each other.

  • Erc-20 TOKEN Standard

    • ERC-20 Token Standard | ethereum.org

    • Understand the ERC-20 Token contract

    • What is NFT? What are the ERC20, ERC721, ERC1155 protocols?

Another, less obvious problem with the ERC20 token is that it represents a slight difference between tokens and Ether… Token contracts track balances and issue events. There is no transaction to the recipient address during the transfer of the token. The recipient’s address is added to the balance mapping table of the token contract.

Erc-20 is like a “mini Ethereum” embedded in Ethereum. The owner of a token may own an equity stake in the “token company,” but it may be a shell company, or even a junk company, that generates no value. Value is determined by consensus, and Ethereum and ERC-20 just make it easier to build a consensual base, like the government allowing companies to register for $1 to encourage entrepreneurship, regardless of whether or not value is actually created.

Chapter 11 The Prophecy Machine – Oracles

In the context of blockchain, a predictor is a system that can answer questions outside of Ethereum

To maintain consensus, EVM execution must be fully determined and based only on ethereum state and the shared context of signed transactions. This has two particularly important consequences: one is that EVMs and smart contracts have no inherent source of randomness; Another is that external data can only be brought in as a data payload for a transaction

One of the peculiarities of blockchain is that once agreed upon data cannot be changed. This results in all data on the chain being deterministic, with two consequences: first, there are no random functions, and external data can only be loaded as data and not as an executable.

Data in the real world are mostly random or constantly changing, making the sources of much data artificially or objectively unreliable. Ethereum needs to capture real-world data without compromising its credibility.

  • Reference link – Oracle

    • A comprehensive overview of decentralized prognosticators

    • Prognosticators: Let smart contracts take off

The three main ways to set up a predictor can be divided into request and response, publish and subscribe, and read now

  • Read now: For fully trusted data sources (e.g., information published by governments, official agencies, such as degrees)
  • Publish and subscribe: similar to RSS
  • Request and response: similar to the relationship between a traditional Web2.0 client and server, except that the predictor requires data to be authoritative and trusted

Two common methods of data authentication are Authenticity Proof and Trusted Execution Environment (TEE)

The former uses cryptographic algorithms (such as digital signatures) to prove that data has not been tampered with, while the latter ensures that the program execution environment cannot be disturbed or attacked at the hardware level.

ChainLink has proposed a decentralized network of prognosticators that consists of three key smart contracts (reputation contracts, order matching contracts, and data aggregation contracts) and an off-chain registry of data providers

Smart contracts record the creditworthiness of data providers, rewarding those who are trustworthy and penalizing those who are not.

Prognosticators provide a vital service for smart contracts: they bring external facts into contract execution

Chapter 12: Decentralized Applications – DApps

The back-end

Any calculations performed in smart contracts are extremely expensive, so keep smart contracts as small as possible

A major consideration in the design of a smart contract architecture is that once the contract code has been deployed, it cannot be modified

The constraints of the decentralized application back end (business logic) are mainly “expensive”, both in terms of gas consumed to run and security risks that cannot be modified once deployed.

The front end

DApps are no different for Web-based front-end technologies

However, there is no best practice for creating mobile DApps. The main reason is that there is no mobile client with key management function to assume the role of light client

Data is stored

Most dapps use off-chain data storage services, which means they store a lot of their data on the (off-chain) data storage platform rather than on the Ethereum chain. Data storage platforms can be centralized (such as a typical cloud database) or point-to-point like IPFS and Ethereum’s own platform Swarm

Depending on how much you trust the centralized cloud database to be trustworthy, the level of trust depends on how much you can lose at worst.

Message communication

The most noteworthy P2P messaging protocol for DApps is Whisper

Name resolution

ENS is mainly defined by three Ethereum improvements: IP-137, which defines the basic functions of ENS; IP-162, describes the roots. Eth auction system; Ip-181, which specifies the reverse registration rules for addresses.

Based on ethereum domain name resolution service, the mapping relationship between wallet address and domain name address is agreed.

  • ENS

    • EIPs/ EIP-137. md at Master · Ethereum /EIPs

    • EIPs/ EIP-162. md at Master · Ethereum /EIPs

    • EIPs/ EIP-181. md at Master · Ethereum /EIPs

Decentralized applications are the ultimate vision of Ethereum

Chapter 13 EVM entry

EVM’s task is to update ethereum’s state by calculating legal state transitions based on the execution of smart contract code based on the Ethereum protocol.

Gas is an extremely important component of Ethereum, serving a dual role: as a buffer between ethereum’s floating prices and miner rewards, and as a safeguard against denial-of-service attacks.

On the one hand, gas is designed to resist DDoS attacks. However, when the currency circle is activated, a large number of “normal” transactions greatly increase gas charges, and even affect normal users’ use (as shown above, gas charges are much higher than actual transfers by tens of times).

Vitalik Buterin’s recent proposal, EIP-4488, sees Layer2 as the only solution to scale ethereum in the short to medium term and even in the long term.

Rollups are in the short and medium term, and possibly the long term, the only trustless scaling solution for Ethereum.

  • See reading – IP-4488

    • Vitalik Buterin makes proposal EIP-4488 to lower gas fees for Ethereum Layer-2 in the short term – CoinCu News

    • Transaction CallData Gas Cost reduction with Total Calldata limit by Vbuterin · Pull Request #4488 · Ethereum /EIPs

Chapter 14: Consensus

“Consensus rules” : A set of rules that each node must agree to in order for the system to operate decentralized and deterministically

The real purpose of mining (and all other consensus models) is to secure the blockchain while ensuring that control over the system is decentralized (distributed as widely as possible among participants). Offering newly minted money as a reward is an incentive to contribute to system security: it is a means to an end, not an end in itself. Rewards are just tools, decentralized security is the end

Ethereum’s PoW algorithm was carefully built into a mechanism called a “difficulty bomb” that was designed to gradually make PoW mining for Ethereum harder and harder, forcing the network to move to PoS

The whole blockchain industry is a giant experiment, and these questions will be tested in a hostile environment, with huge financial stakes at stake. In the end, history will tell