Skip to content

Latest commit

 

History

History
669 lines (409 loc) · 28.4 KB

1. Ethereum 101.md

File metadata and controls

669 lines (409 loc) · 28.4 KB

Q1 Ethereum Virtual Machine is a

  • A) Register-based virtual machine

  • B) Stack-based virtual machine

  • C) Heap-based virtual machine

  • D) Stackless virtual machine

Click the reveal the answer

The EVM has a stack-based architecture, storing all in-memory values on a stack. It works with a word size of 256 bits (mainly to facilitate native hashing and elliptic curve operations) and has several addressable data components:

An immutable program code ROM, loaded with the bytecode of the smart contract to be executed

  • A volatile memory, with every location explicitly initialized to zero

  • A permanent storage that is part of the Ethereum state, also zero-initialized

  • There is also a set of environment variables and data that is available during execution.

Source: Mastering Ethereum


Q2 The length of addresses on Ethereum is

  • A) 256 bits

  • B) 20 bytes

  • C) Depends on Externally-Owned-Account or Contract address

  • D) Configurable

Click the reveal the answer

Ethereum addresses are hexadecimal numbers, identifiers derived from the last 20 bytes of the Keccak-256 hash of the public key (40 hex chars).

The rationale behind that decision was that Ethereum addresses would eventually be hidden behind abstractions (such as name services) at higher layers of the system and that checksums should be added at higher layers if necessary.

Source: Mastering Ethereum


Q3 The types of accounts on Ethereum are

  • A) All Accounts are the same

  • B) Permissioned Accounts and Permissionless Accounts

  • C) Externally-Owned-Accounts and Contract Accounts

  • D) User Accounts and Admin Accounts

Click the reveal the answer

Externally owned accounts are those that have a private key; having the private key means control over access to funds or contracts.

A contract account has smart contract code, which a simple EOA can’t have. Furthermore, a contract account does not have a private key. Instead, it is owned (and controlled) by the logic of its smart contract code: the software program recorded on the Ethereum blockchain at the contract account’s creation and executed by the EVM.

Contracts have addresses, just like EOAs. Contracts can also send and receive ether, just like EOAs. However, when a transaction destination is a contract address, it causes that contract to run in the EVM, using the transaction, and the transaction’s data, as its input. In addition to ether, transactions can contain data indicating which specific function in the contract to run and what parameters to pass to that function. In this way, transactions can call functions within contracts.

Note that because a contract account does not have a private key, it cannot initiate a transaction. Only EOAs can initiate transactions, but contracts can react to transactions by calling other contracts, building complex execution paths.

Source: Mastering Ethereum


Q4 The difference(s) between Bitcoin and Ethereum is/are

  • A) The underlying tokens: Bitcoin vs Ether

  • B) Smart contract support

  • C) UTXO vs Accounts

  • D) Nakamoto Consensus

Click the reveal the answer

A: Ethereum’s purpose is not primarily to be a digital currency payment network, unless Bitcoin. While the digital currency ether (!= Bitcoin) is both integral to and necessary for the operation of Ethereum, ether is intended as a utility currency to pay for use of the Ethereum platform as the world computer.

B: Unlike Bitcoin, which has a very limited scripting language, Ethereum is designed to be a general-purpose programmable blockchain that runs a virtual machine capable of executing code of arbitrary and unbounded complexity. Where Bitcoin’s Script language is, intentionally, constrained to simple true/false evaluation of spending conditions, Ethereum’s language is Turing complete, meaning that Ethereum can straightforwardly function as a general-purpose computer.

C: Bitcoin's UTXO model, or Unspent Transaction Output, represents the amount of digital currency remaining after a transaction has been executed. The UTXO Model does not incorporate accounts or wallets at the protocol level to track balances. The model is based entirely on individual transactions, grouped in blocks.

Ethereum's account-based transaction model represents assets as balances within accounts, similar to bank accounts. Every account in Ethereum has a balance, storage, and code-space for calling other accounts or addresses.

D: Previous the merge, Ethereum used Ethash, a PoW modified version of the Dagger-Hashimoto algorithm which was thought to make the algorithm ASIC resistant.

After the merge, ethereum has moved to Gasper (Casper FFG + LMD GHOST) where Consensus relies on both algorithms. LMD-GHOST adds new blocks and decides what the head of the chain is. Casper FFG makes the final decision on which blocks are and are not a part of the chain.

GHOST’s favourable liveness properties allow new blocks to quickly and efficiently be added to the chain, while FFG follows behind to provide safety by finalising epochs. The two protocols are merged by running GHOST from the last finalised block as decided upon by FFG. By construction, the last finalised block is always a part of the chain which means GHOST doesn’t need to consider earlier blocks.

Liveness favouring protocols such as Nakamoto continue to add blocks, but they may not come to finality and there will be always a risk of the chain being changed. Ethereum will achieve finality by checkpointing, thus removing the risk of the chain being changed.


Source: Mastering Ethereum
Source: Horizen Academy
Source: Ethereum Org
Source: Ethereum Org and Laurence Kirk talk

Q5 Ethereum smart contracts do not run into halting problem because

  • A) EVM is not Turing Complete

  • B) EVM is Turing Complete

  • C) EVM is Turing Complete but is bounded by gas sent in transaction

  • D) EVM is Turing Complete but is bounded by the stack depth

Click the reveal the answer

The EVM is a quasi–Turing-complete state machine; "quasi" because all execution processes are limited to a finite number of computational steps by the amount of gas available for any given smart contract execution. As such, the halting problem is "solved" (all program executions will halt) and the situation where execution might (accidentally or maliciously) run forever, thus bringing the Ethereum platform to halt in its entirety, is avoided.

Source: Mastering Ethereum


Q6 Ethereum nodes talk to each other via

  • A) Peer-to-Peer network

  • B) Client-Server network

  • C) Satellite network

  • D) None of the above

Click the reveal the answer Ethereum runs on the Ethereum main network, which is addressable on TCP port 30303, and runs a protocol called ÐΞVp2p which connects participants and propagates transactions and blocks of verified transactions, based on a "gossip" protocol.

Source: Mastering Ethereum


Q7 A nonce is present in

  • A) Ethereum transaction

  • B) Ethereum account

  • C) Both A & B

  • D) Neither A nor B

Click the reveal the answer The nonce is one of the serialized binary fields that a transaction contains. It is a sequence number, represented by a scalar value equal to the number of transactions sent from this address or, in the case of accounts with associated code, the number of contract-creations made by this account.

The nonce is not stored explicitly as part of an account’s state on the blockchain. Instead, it is calculated dynamically, by counting the number of confirmed transactions that have originated from an address.

There are two scenarios where the existence of a transaction-counting nonce is important: the usability feature of transactions being included in the order of creation, and the vital feature of transaction duplication protection (message replay).

Source: Mastering Ethereum


Q8 The gas tracking website https://etherscan.io/gastracker says that Low gas cost is 40 wei This affects

  • A) The transaction gasPrice

  • B) The transaction gasLimit

  • C) The transaction value

  • D) Both B & C

Click the reveal the answer

Gas is the fuel of Ethereum. Gas is not ether—it’s a separate virtual currency with its own exchange rate against ether. Ethereum uses gas to control the amount of resources that a transaction can use, since it will be processed on thousands of computers around the world. The open-ended (Turing-complete) computation model requires some form of metering in order to avoid denial-of-service attacks or inadvertently resource-devouring transactions.

Gas is separate from ether in order to protect the system from the volatility that might arise along with rapid changes in the value of ether, and also as a way to manage the important and sensitive ratios between the costs of the various resources that gas pays for (namely, computation, memory, and storage).

The gasPrice field in a transaction allows the transaction originator to set the price they are willing to pay in exchange for gas. The price is measured in wei per gas unit. Wallets can adjust the gasPrice in transactions they originate to achieve faster confirmation of transactions. The higher the gasPrice, the faster the transaction is likely to be confirmed.

Source: Mastering Ethereum


Q9 The number of transactions in a Ethereum block depend on

  • A) Nothing. It is a constant.

  • B) Gas used by transactions

  • C) Block gas limit

  • D) Block difficulty

Click the reveal the answer The block gas limit is the maximum amount of gas that may be consumed by all the transactions in a block, and constrains how many transactions can fit into a block. However, there is not an exact number of transactions that fit in an Ethereum block as gas used by transactions is variable.

Source: Mastering Ethereum


Q10 Miners are responsible for setting

  • A) Transaction gas price

  • B) Block gas limit

  • C) Both A & B

  • D) Neither A nor B

Click the reveal the answer The miners on the network collectively decide the block gas limit. The Ethereum protocol has a built-in mechanism where miners can vote on the gas limit so capacity can be increased or decreased in subsequent blocks.

Source: Mastering Ethereum


Q11 User A sends transaction T1 from address A1 with gasPrice G1 and later transaction T2 from address A2 with gasPrice G2

  • A) T1 will be always included in an earlier block than T2

  • B) Inclusion/Ordering of these transactions depends only on gas prices G1 and G2

  • C) Inclusion/Ordering of these transactions depends only on network congestion

  • D) Inclusion/Ordering of these transactions depends on miners

Click the reveal the answer When constructing a new block, miners on the Ethereum network can choose among pending transactions by selecting those that offer to pay a higher gas price. Offering a higher gas price will therefore incentivize miners to include your transaction and get it confirmed faster. Different miners are likely to select different combinations, mainly because they receive transactions from the network in a different order.

Source: Mastering Ethereum


Q12 Which of the following statements is/are true about gas?

  • A) Unused gas is returned to the transaction destination account

  • B) Gas used by the transaction is credited to the beneficiary address in block header

  • C) Unused gas is credited to the beneficiary address in block header

  • D) Both A & B

Click the reveal the answer

Gas exists only inside the EVM, as a count of how much computational work is being performed. The sender is charged a transaction fee in ether, which is then converted to gas for EVM accounting and then back to ether as a transaction fee paid to the miners. The beneficiary field holds the address of the miner that generated the block and is used to transfer the block reward + tx fees in ether.

Source: Mastering Ethereum


Q13 Which of the following EVM components is/are non-volatile across transactions?

  • A) Stack

  • B) Memory

  • C) Storage

  • D) Calldata

Click the reveal the answer

Source: Mastering Ethereum

The EVM has a stack-based architecture, storing all in-memory values on a stack. It works with a word size of 256 bits (mainly to facilitate native hashing and elliptic curve operations) and has several addressable data components:

  • A volatile memory, with every location explicitly initialized to zero

  • A permanent storage that is part of the Ethereum state, also zero-initialized


Q14 Which of the following operation(s) touch(es) storage?

  • A) SWAP

  • B) SLOAD

  • C) DUP

  • D) PUSH

Click the reveal the answer Storage is a map of 32-byte slots to 32-byte values. Storage is read and written with instructions SLOAD and SSTORE.

SLOAD retrieves 32-byte value from storage at given 32-byte key.

Source: Storage
Source: EVM Opcodes


Q15 Which of the following statement(s) is/are false?

  • A) EVM can get the block number only of the current block

  • B) EVM can get the block hash only of the current block

  • C) EVM can get the account balance only of the current account

  • D) EVM can get the code hash only of the current account

Click the reveal the answer
  • BLOCKHASH instruction gets the hash of one of the 256 most recent complete blocks
  • BALANCE instruction gets balance of the given account
  • EXTCODESIZE instruction gets size of an account’s code

Source: BLOCKHASH
Source: BALANCE
Source: EXTCODESIZE


Q16 Which of the following information cannot be obtained in the EVM?

  • A) Block difficulty

  • B) Transaction logs

  • C) Balance of an account

  • D) Block hash of any block

Click the reveal the answer
  • DIFFICULTY has been deprecated and supplanted with PREVRANDAO.
  • LOG instructions are only to appending log records. You cannot access these logs from INSIDE the EVM.
  • BLOCKHASH instruction gets the hash of one of the 256 most recent complete blocks.

Source: EXTCODESIZE
Source: LOGS
Source: BLOCKHASH


Q17 Which call instruction could be used to allow modifying the caller account’s state?

  • A) CALL

  • [] B) CALLCODE

  • C) DELEGATECALL

  • D) STATICALL

Click the reveal the answer
  • DELEGATECALL: Message-call into this account with an alternative account’s code, but persisting the current values for sender and value. Note that CALLCODE has been deprecated in favour of DELEGATECALL. If you write a contract with the callcode opcode and a solidity version of 0.5.X or newer, you will get an error preventing the contract from compiling with the message TypeError: "callcode" has been deprecated in favour of "delegatecall".

Source: DELEGATECALL


Q18 The most gas-expensive operation is

  • A) SLOAD

  • B) SSTORE

  • C) CREATE

  • D) SELFDESTRUCT

Click the reveal the answer The most expensive operation is CREATE, that creates a new account with associated code, costing at least 32000 units of gas. The final cost is dynamic, described by the following equation:
code_deposit_cost = 200 * deployed_code_size
static_gas = 32000
dynamic_gas = memory_expansion_cost + deployment_code_execution_cost + code_deposit_cost

Source: CREATE


Q19 Transaction T1 attempts to write to storage values S1 and S2 of contract C. Transaction T2 attempts to read the same storage values S1 and S2. However, T1 reverts due an exception after writing S1 but before writing S2. Which of the following is/are true?

  • A) T2 reads the value of S1 updated by T1

  • B) T2 reads the value of S1 prior to T1’s attempted update

  • C) T2 also reverts because of the dependency on T1

  • D) This scenario is not possible

Click the reveal the answer

Transactions are atomic, they are either successfully terminated or reverted. If a transaction is reverted, all of its effects (changes in state) are “rolled back” as if the transaction never ran. A failed transaction is still recorded as having been attempted, and the ether spent on gas for the execution is deducted from the originating account, but it otherwise has no other effects on contract or account state.

Source: Mastering Ethereum


Q20 Ethereum’s threat model is characterised by

  • A) Trusted miners and users

  • B) Trusted users, untrusted miners

  • C) Trusted miners, untrusted users

  • D) Everyone is untrusted

Click the reveal the answer In ethereum everyone is untrusted and could become an abuser. That's why there exist consensus mechanisms to incentive distributed set of nodes to agree on the state of the blockchain. Ethereum uses a proof-of-stake-based consensus mechanism that derives its crypto-economic security from a set of rewards and penalties applied to capital locked by stakers. This incentive structure encourages individual stakers to operate honest validators, punishes those who don't, and creates an extremely high cost to attack the network.

Source: Ethereum Org


Q21 The number of modified Merkle-Patricia trees in an Ethereum block is

  • A) One

  • B) Three

  • C) Three plus number of contract accounts

  • D) Three plus number of transactions included in the block

Click the reveal the answer

Inside header we can find three modified Merkle-Patricia trees:

  • state_root: root hash for the global state after applying changes in this block
  • receipts_root: hash of the transaction receipts trie
  • transactions_root: root hash of the transactions in the payload

As state_root tracks the state of every account, and every account has a storage which is also a tree then there will be one tree per account too.

Source: Ethereum Org
Source: Ethereum Blog


Q22 EVM is not a von Neumann architecture because

  • A) It was co-founded by Vitalik Buterin, not John von Neumann

  • B) Program instructions are stored separately from data

  • C) Program instructions are stored in a ROM not RAM

  • D) It is quasi Turing complete

Click the reveal the answer The standard Von Neumann architecture stores code and data in the same memory. The EVM does not follow this standard for security reasons - sharing volatile memory makes it possible to change program code. Instead, code is saved to storage.

Source: Ethereum org


Q23 EVM stores

  • A) Most significant byte in the smallest memory address

  • B) Most significant byte in the largest memory address

  • C) In Big-endian order

  • D) In Little-endian order

Click the reveal the answer A and C are equivalent. Ethereum is big endian, where most significant bytes are located in smaller memory addresses.

Source: All About Bytes


Q24 Miners are incentivized to validate and create new blocks by

  • A) Block rewards

  • B) Altruism

  • C) Transaction fees

  • D) Their belief in decentralization

Click the reveal the answer The beneficiary field holds the address of the miner that generated the block and is used to transfer the block reward + tx fees in ether.

Source: Mastering Ethereum


Q25 Hardfork on Ethereum

  • A) Has never happened

  • B) Happened only once after the DAO attack

  • C) Happens with backwards-incompatible protocol changes

  • D) Happens when developers and miners disagree on changes

Click the reveal the answer

A hard fork is a permanent divergence in the blockchain; also known as a hard-forking change. One commonly occurs when nonupgraded nodes can't validate blocks created by upgraded nodes that follow newer consensus rules.

Source: Ethereum Org


Q26 Gas for EVM opcodes

  • A) Is constant and the same for all opcodes

  • B) May be changed over time to prevent DoS attacks

  • C) Depend on the gas price

  • D) Depend on the miners

Click the reveal the answer

From EIP 150: "Recent denial-of-service attacks have shown that opcodes that read the state tree are under-priced relative to other opcodes. There are software changes that have been made, are being made and can be made in order to mitigate the situation; however, the fact will remain that such opcodes will be by a substantial margin the easiest known mechanism to degrade network performance via transaction spam. The concern arises because it takes a long time to read from disk, and is additionally a risk to future sharding proposals as the “attack transactions” that have so far been most successful in degrading network performance would also require tens of megabytes to provide Merkle proofs for. This EIP increases the cost of storage reading opcodes to address this concern."

Source: EIP 150


Q27 Smart contracts on Ethereum

  • A) May be deployed by anyone

  • B) May be deployed only through the DApp store

  • C) May have some form of access control

  • D) Are guaranteed to be secure

Click the reveal the answer A: A smart contract can be deployed by any of the two Ethereum account types, in other words, EOAs or another smart contract.

C: You can write code to provide a form of access control inside a smart contract.

Source: Mastering Ethereum

Source: Mastering Ethereum


Q28 EVM opcodes

  • A) Are multi-byte instructions

  • B) Are single byte instructions

  • C) Take operands in registers

  • D) Take operands on stack

Click the reveal the answer

EVM opcodes are single byte instructions (2 hex characters) whose operands are taken from the stack, and the result (where applicable) is often put back on the top of the stack.

Source: Mastering Ethereum


Q29 Security of Ethereum DApps depend on

  • A) Security of their smart contracts

  • B) Security of their off-chain components

  • C) Security of Ethereum

  • D) None of the above

Click the reveal the answer An Ethereum dApp is an application that has a smart contract running in top of Ethereum Blockchain plus a WebApp for the user to interact with the smart contract. As we can see, a dApp is composed by 3 main components:
  • Ethereum Blockchain
  • Smart contract running on top of Ethereum Blockchain
  • An off chain WebApp for the user to interact with the smart contract.

Any security issue in any of the layers will have an impact on the overall dApp security.

Source: Te lo juro por Dieguito Maradona.


Q30 Security Audits for smart contracts are performed because

  • A) They are required for listing DApp on the DApp store

  • B) They are required for deployment on Ethereum

  • C) They help remove vulnerabilities and reduce risk

  • D) They are required by exchanges to list tokens

Click the reveal the answer A smart contract security audit provides a detailed analysis of a project's smart contracts. These are important to safeguard funds invested through them. As all transactions on the blockchain are final, funds cannot be retrieved should they be stolen. Typically, auditors will examine the code of smart contracts, produce a report, and provide it to the project for them to work with. A final report is then released, detailing any outstanding errors and the work already done to address performance or security issues. It's important to highlight that an audit cannot guarantee no bugs or vulnerabilities will arise.

Source: Binance Academy


Q31 The high-level languages typically used for writing Ethereum smart contracts are

  • A) Go

  • B) C++

  • C) Vyper

  • D) Solidity

Click the reveal the answer

Source: Mastering Ethereum


Q32 The number of decimals in Ether is

  • A) 0

  • B) 1

  • C) 18

  • D) Configurable

Click the reveal the answer ETH is divisible up to 18 decimal places. The smallest unit is called a wei that represents 0.000000000000000001 ETH.

Source: Yellow Paper