Introduction | Briefly compare the data structure of Ethereum and Bitcoin

Introduction: Why is Ethereum a second-generation blockchain?

At the end of 2017, when I started to understand the blockchain, I noticed that Ethereum was very much concerned. I always see others saying that Bitcoin is the first generation blockchain, and Ethereum is the second generation blockchain. After reading a lot of articles about the comparison between Bitcoin and Ethereum, I understood "why": Bitcoin is a cryptocurrency that uses a limited scripting language to build a decentralized payment system, but not only in Ethereum. Ethereum is not just a cryptocurrency, it is also a global, decentralized computing infrastructure that can execute smart contracts and program code (written in multiple programming languages) to control digital assets. On the Ethereum platform, developers can build decentralized applications (dApps) on their own. I am very interested in decentralized application development (dApp), so I didn't spend a lot of time reading the Ethereum Yellow Book to understand its specific build principle ("How").

When I started reading the Ethereum Yellow Book during Devcon v, I not only understood why Ethereum was the second generation blockchain, but was also impressed by these great ideas that eventually turned the wonderful ideas into reality.

Let's take a closer look at a few key parts:

  • data structure
  • Block structure
  • transaction
  • Trading Fees in Gas & Bitcoin in Ethereum
  • Status & Account Type

data structure

Bitcoin uses a Merkel tree (a binary tree of cryptographic hashes), while Ethereum uses a modified Merkel Patricia tree. If you want to know more about it, you can watch this video. Interpolation: Medium does not support subscript format. If you want to read the version of this article that contains some symbols in the Yellow Book, please check the document.

Block

Let's take a look at the Ethereum block structure. – Source: Interpretation of the Ethereum Yellow Book – Block contains:

Block header:

Note that there is only one Merkel tree in the bitcoin block header, and there are four in the Ethereum block (State Trie – State Tree, Storage Trie – Storage Tree, Transaction Trie – Transaction Tree & Receipts Trie – Receipt Tree). The Ethereum block header contains:

  1. parentHash: The parent block block header hash value.
  2. ommersHash: The hash value of the list of unblocked blocks in the current block.
  3. Beneficiary: The address of the Ethereum used by miners to receive transaction fees.
  4. stateRoot: The root node hash of the state tree after the execution of this block and its transaction.
  5. transactionsRoot: The root node hash of the transaction tree consisting of all transactions in the block transaction list.
  6. receiptsRoot: The root node hash of the receipt tree made up of receipts for each transaction in the transaction list. Each transaction receipt (the i-th item in the BR array corresponds to the receipt of the i-th transaction) is stored in the receipt tree of the key-value index, and the root hash value of the tree is stored in the block header. This is very useful for generating zero-knowledge proofs or for indexing and searching. The transaction receipt R is a tuple of the following four items:
    1. R u : The cumulative consumption of the block containing the transaction receipt after the transaction is executed.
    2. R l : The set of logs generated during the execution of the transaction.
    3. R b : Bloom filter built from log information.
    4. Transaction status code.
  7. logsBloom: This field is used to store Ethereum events, which can be indexed according to the logger address or log subject.
  8. Difficulty: The difficulty level of this block is calculated based on the difficulty level and time stamp of the previous block.
  9. Number: the number of all previous blocks (ie, the block number of this block), the number field of the creation block is 0;
  10. gasLimit: The maximum gas consumption allowed for the current block.
  11. gasUsed: The total amount of gas consumed by all transactions in the current block.
  12. Timestamp: Unix time when the block is initialized.
  13. extraData: a byte array that can be used by miners to add arbitrary data
  14. mixHash: A hash value used to verify that a block is processed correctly.
  15. Nonce: A hash value used to verify that a block is processed correctly. (The function is the same as mixHash)

The block body contains:

  1. Ommer Block Header list
  2. Transaction sequence: The list of transactions in this block.

Overall effectiveness: To determine the validity of a block, if and only if it meets the following conditions: the block's unblocked block hash, the trading block hash, and the internals of the given transaction

The process of packing blocks consists of four phases:

  • Verify (or make sure, if mining) the list of uncle blocks:
  1. A block must specify a parent block and must specify zero or more unblocks
  2. The tertiary block contained in block B must have the following properties:
    a. The block of block B must be a direct sub-block of block B ancestor block, where 2 <= k <= 7. b. The block of block B cannot be the ancestor of block B. c. The block header of the unblock must be valid, but it does not need to be verified or valid.

d. The tertiary block must be different from the unpacked block of the previous block and the other unblocks of the block (to prevent duplicate packing).

  • Transaction verification (or ok if mining): The value of gasUsed in the block header must match the gas consumption accumulated in the block after the last transaction.
  • Apply for a reward: If there is a decent block, the uncle block can be used to increase the account balance of the beneficiary of the block and the beneficiary who generated the uncle. When there are multiple active blocks in the same block height, the Ommer Block helps to encourage the miners to maintain the normal operation of the network. Uncle block reward division rules: the uncle block gets 87.5% of its base reward, and the main chain block containing the uncle block gets 3.125% of the base reward. However, neither the bad block beneficiary nor the block beneficiary can get the transaction fee in the uncle block (Translator's Note: Because the trade in the uncle block will be considered invalid, return to the trading pool and wait for packing).
  • Verify (or calculate valid if mining) state and block nonce. This can be verified by checking if the final state is consistent with the stateRoot in the block header.

The block structure in Bitcoin is as follows

– Source: 5minuteblockchain-

The block contains:

Block header:

  1. Timestamp: Unix time when the block is initialized.
  2. Nonce: Counter for the PoW algorithm.
  3. Version: The version number used to track software or protocol upgrades.
  4. Previous: The parent block hash value on the chain.
  5. Merkel Root: The hash of the Merkel tree root constructed by the exchange in this block.
  6. Difficulty: The difficulty value necessary to generate the block. This value is dynamically adjusted during the mining process based on the time taken by a certain number of blocks before the block.

The block body contains:

  1. Transaction sequence: This block contains a list of transactions

transaction

Ethereum Trading T

There are two types of transactions (transactions) in Ethereum: message calls and contract creation. Execution of each transaction will cause a change in the machine state μ (μ is a temporary state that includes all the changes necessary in all calculations before the block is added to the world state). Each transaction includes the following fields:

  1. Nonce: The total number of transactions previously sent by the sender.
  2. gasPrice: The amount of ether (in Wei) that the unit gas consumes to pay to the network.
  3. gasLimit: The maximum amount of gas that can be consumed during the execution of the transaction.
  4. To: The message calls the recipient address.
  5. Value: The number of Ethernet coins (unit: Wei) that the sender has transferred to the recipient of the message.
  6. v, r, s: Transaction signature related fields.
  7. Init: (for contract creation transactions only) A byte array of unlimited size, containing the EVM bytecode required for contract creation.
  8. Data: A byte array of unlimited size that specifies the input data for the message to invoke the transaction.

Bitcoin trading

– Source: gomedici-

  • Trading header
    • Bitcoin protocol version
    • Input quantity
    • Output quantity
    • Block lock time (when you don't want the transaction to be packaged immediately)
  • One or more inputs (UTXO)
    • The hash of the previous transaction (UTXO input is the UTXO output for the previous transaction)
    • The index number of the output of the previous transaction.
    • The unlock script (called 'scriptSig') and the length of the unlock script are used to prove ownership of the UTXO.
  • One or more outputs (UTXO)
    • The number of bitcoins sent by the sender to the receiver.
    • Lock the script (called 'scriptPubKey') and lock the script length. 'scriptPubKey' is a conditional public key script. Anyone who can satisfy the conditions of the public key script can spend the bitcoin in the UTXO.

Ethereum's Gas & Bitcoin transaction fee

Ethereum Gas

Since Ethereum is a Turing-complete system, in order to avoid the misuse of computing resources, all programming calculations in Ethereum require a transaction fee. The calculation requires input costs, and the more computing resources required, the higher the transaction fee corresponding to it. The Ethereum used to purchase gas is transferred to the beneficiary address. If the (transaction sender) account balance address cannot pay for the cost of gas, then the transaction is considered invalid. In the Ethereum platform, gas consumption is only involved in the execution of the transaction.

Each transaction has a specific gas consumption associated with it. gasLimit and gasPrice are also specified in the transaction.

  • gasLimit: The sender is willing to pay the maximum amount of gas used for trade execution. The existence of gasLimit helps to resolve situations where the transaction is in an infinite loop and cannot exit. After the trade is executed, if there is still gas remaining, then these gas will be returned to the sender. However, if the transaction fails for some reason, gas will not return.
  • gasPrice: gasPrice means "how much ethanol do you want to pay to buy a unit of gas?" The sender of the transaction can arbitrarily specify the specific value of gasPrice, however, miners can also freely ignore transactions where gasPrice does not meet their needs.

Bitcoin transaction fee

The Bitcoin transaction fee is a small amount charged by the miner. Bitcoin transaction fees are not required, but because miners are free to ignore any trades, adding a fee can force miners to package your trades into the blockchain. The value of the Bitcoin transaction fee is equal to the difference between the transaction input minus the output.

Status & Account Type

Bitcoin

The Bitcoin address is an ECDSA public key whose balance is not stored in the Bitcoin blockchain. If you want to know how to view the bitcoin balance, the personal wallet application calculates all the UTXOs associated with a particular address by scanning the blockchain database to determine the bitcoin balance for that address.

Ethereum

The Ethereum blockchain always maintains a world state σ that contains a mapping of addresses and account status.

  • Ethereum contains two types of accounts:
    1. Externally held account (EOA) controlled by private key
    2. Contract Account controlled by a smart contract.
  • Account status σ [a] :
    The account status is stored in a modified version of the Merkle Patricia Trie tree outside of the blockchain. If you want to learn more about how the MPT tree is stored in the state database, watch this video. The account status consists of four fields:
    1. Nonce: The number of all transactions issued by this address, including contract creation transactions.
    2. Balance: The number of Ethereum held by this address (unit: Wei).
    3. storageRoot: The root node hash of the Merkel Patricia tree that encodes the contents of the account store.
    4. codeHash: (for contract accounts only) The hash value of the EVM bytecode stored in the state database. Unlike other fields, this field is immutable.

Interested in seeing the yellow book? !

I am sure that you will very much hope to learn more about the design details of Ethereum by reading the Yellow Book. The difference between Bitcoin and Ethereum mentioned above is only my personal opinion. However, if you are really determined to read, you can refer to my experience, because this is not an easy task.

I remember when I told a friend that I wanted to start reading the yellow book and write some related blogs, he told me:

"Scorpio! Impossible: D. Although very educational, it is still impossible!"

He is right. The purpose of reading the Ethereum Yellow Book is to write a summary, just like I read the Bitcoin white paper, but when I read the Yellow Book for the first time, it was too difficult to write a summary. In order to write a summary of the Yellow Book, I read it 4 times: D

After I finished reading the Yellow Book for the first time, I could only master about 50%-60% of the content, because I encountered great difficulties in reading mathematics deduction ("Like my friend told me: D"). However, after reading the Yellow Book many times, I have a deeper understanding of the design principles of Ethereum and some of the bugs I encountered when developing decentralized applications on Ethereum. Overall, I am still very satisfied.

Here are some links to articles that helped me a lot at the time:

  • This is the best article I have ever read to explain the Yellow Book (Editor's Note: The Chinese translation is in this "How Ethereum Works ").
  • Special thanks to my colleague @shaqueilla.seale in the devcon scholar project, she sent me an article explaining the Ethereum Yellow Book series [but these articles are not complete, blue]
  • How is the data stored in Ethereum?
  • For me, the hardest part of the Yellow Book is:
    1. Algebraic symbol, this answer gave me a lot of help
    2. In the contract part, this gist gave me a lot of help.

(Finish)

(A lot of hyperlinks are provided in the article, please click to read the original text to get the EthFans website)

Original link:

Https://medium.com/ethereum-foundation-devcon-scholars/the-mystery-behind-ethereums-shine-76f9011deb8a

Author: Eman Herawy

Translation & proofreading: stormpang & Ajian

We will continue to update Blocking; if you have any questions or suggestions, please contact us!

Share:

Was this article helpful?

93 out of 132 found this helpful

Discover more

Bitcoin

US Government Seizes $130 Million Worth of Bitcoins from Silk Road: What You Need to Know

The US government has successfully seized Bitcoin assets associated with the notorious Silk Road marketplace in two s...

Blockchain

Root Protocol Raises $10 Million in Seed Rounds, Paving the Way for a Unified Web3 Experience

Root Protocol, a rising star in the field of blockchain technology, has successfully raised $10 million to enhance di...

Web3

Validation Cloud: Revolutionizing Web3 Infrastructure 🌐💻🚀

Exciting news for Validation Cloud as they secure a whopping $5.8 million in their first external funding round for t...

Blockchain

Swiss National Bank Partners with SIX Digital Exchange for CBDC Pilot Project

The Swiss National Bank (SNB) has teamed up with SIX Digital Exchange (SDX) to launch a trial project for a new wCBDC...

Bitcoin

Injective Protocol and Ethena Collab: Unleashing the Power of DeFi Beyond Ethereum

Ethena has successfully expanded their reach beyond the Ethereum ecosystem by integrating with Injective, showcasing ...

Blockchain

Reviving FTX SEC Gives Green Light for a Compliance-Focused Comeback

Possible Approval for FTX Revival from US SEC Depends on Adherence to Regulatory Guidelines by New Leadership.