Detailed explanation of Ethereum
Yellow book (part 4) ——Transaction
How transactions are performed on Ethereum. In this article, we’ll talk about transaction validation rules, and why they exist; then we’ll take a deep dive into how a transaction is executed, and each step a node takes when validating a transaction.
Welcome to follow and discuss with us
In simple terms, the state transition function uses the current state and transaction as input to calculate the next state.
0x02 Transaction verification
Before executing a transaction, a node verifies that the transaction satisfies some basic rules. If even these basic rules are not passed, the node will not execute the transaction.
- Meet the RLP encoding format
- Have a legal signature
- Has a legal nonce (same as the transaction sender’s current nonce value)
- Transactions where the (intrinsic cost) of executing the transaction is less than the gas limit set by the transaction
- The sender’s account balance is greater than or equal to the prepayment required for the transaction
There is also a rule, which is not an inherent rule of transactions — if a series of transactions that are ready to be packaged into a block, plus this transaction, will make the total Gas Limit of all transactions exceed the gas limit of the block, then that transaction cannot be packaged into a block with those transactions.
- Meet the RLP encoding format
RLP （Recursive Length Prefix) is an encoding method for serializing objects in Ethereum; like other methods, if you do not encode an object according to RLP, you cannot decode the object, and you cannot get the original object through data encoding information. The purpose of this rule is to ensure that the Ethereum client can successfully decode and execute the transaction after receiving it.
- Transactions must have legal signatures
Suppose you have a lot of ether in your Ethereum account, and now someone is trying to initiate a transaction to transfer the money from your account for his own, what do you think? You definitely don’t want to see someone impersonating you and stealing your money, that’s why we need transaction signatures. Ethereum uses asymmetric encryption to ensure that only the actual controller can initiate transactions from the account. On Ethereum, account addresses are generated from an individual’s public key. When sending a transaction, the private key is used to sign the transaction, and all nodes can then determine whether the transaction was actually signed by the owner of the private key of the associated account. A transaction without a legal signature has no meaning for execution, so it is one of the inherent rules of the transaction that a legal signature must be present.
- Transaction nonce and account nonce must match
In Ethereum, the account nonce value represents the number of transactions sent by the account (in the case of a contract account, the nonce value refers to the number of contracts created by the account). Without the nonce, the same transaction could be executed multiple times by mistake (a so-called “replay attack”). Ethereum enforces that the transaction nonce value matches the account nonce value. This not only prevents replay attacks, but also ensures that a transaction will only execute and change state once.
- The inherent cost of a transaction must be less than the gas cap set by the transaction
Every transaction has gas associated with it — the cost of sending a transaction consists of two parts: inherent cost and execution cost. Execution costs depend on how much Ethereum Virtual Machine (EVM) resources the transaction needs to operate, and the more operations it takes to execute a transaction, the more expensive it will be to execute. The inherent cost is determined by the payload of the transaction, which is divided into the following three payloads:
- If the transaction is to create a smart contract, the payload is the EVM code that created the smart contract
- If the transaction is to call a function of a smart contract, the payload is the input data for the execution message
- If the transaction is simply a transfer between two accounts, the payload is empty
- Gtransaction = 21,000 Wei
- Gtxcreate = 32,000 Wei
- Gtxdatazero = 4 Wei
- Gtxdatanonzero = 68 Wei
Pre-Transaction=gasLimit * gasPrice + value(Gas Limit for a transaction)
0x03 Execute transaction
After verifying the transaction, it is time to execute it. In Ethereum, executing a transaction changes state — several transactions are packaged into a block, and each block is equivalent to a list of transactions; when transactions are executed sequentially, a new legal state is an output. Transactions are performed as follows:
- Increment the sender account nonce value by 1
- Debit transaction prepayment from sender account（ gasLimit * gasPrice)
- Determine the gas value that the transaction can be used to execute (gasLimit — intrinsic cost)
- Execute the operation contained in the transaction (transfer, call or create a smart contract)
- Refund the sender via the SELFDESTRUCT and SSTORE functions
- Refund any unused gas to the sender of the transaction
- Transfer mining revenue to the beneficiary account (usually belonging to the miner that mined the block containing the transaction)
- Godex.io Review | Invity Review | BitForex Review
- Best Bitcoin Margin Trading | Lolli Review | Bityard Margin Trading
- Create and sell your first NFT | Crypto Trading Bot
- How to buy Shiba (SHIB) Coin on CoinDCX?
- CBET Review | KuCoin vs Coinbase | Bybit vs Coinbase
- Fold App Review | LocalBitcoins review | Bybit vs Binance