Ethereum and Smart Contracts: Blockchain Basics

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

Which of the following best describes Ethereum's primary function?

  • A decentralized platform that executes programs called smart contracts. (correct)
  • A digital currency designed to be a peer-to-peer electronic cash system.
  • A secure network for transferring traditional financial assets.
  • A distributed ledger for recording Bitcoin transactions.

What is the purpose of 'ether' in the Ethereum network?

  • To meter and constrain execution resource costs. (correct)
  • To reward developers who contribute to the Ethereum codebase.
  • To serve as the primary voting mechanism for network governance.
  • To provide a discount on transaction fees.

According to Nick Szabo's definition, what is a key component of a smart contract?

  • A handshake agreement to foster good business relationships.
  • A set of promises specified in digital form, including protocols for execution. (correct)
  • An informal understanding between parties to collaborate on a project.
  • A legally binding agreement enforced by a court of law.

What is a critical characteristic of smart contracts that is enabled by blockchain technology?

<p>Contracts are traditionally regarded as irrevocable. (D)</p> Signup and view all the answers

In the context of Ethereum, what is an EOA?

<p>Externally Owned Account. (C)</p> Signup and view all the answers

Which component is NOT considered a part of the data associated with an External Account (EOA) in Ethereum?

<p>Public Key Certificate (A)</p> Signup and view all the answers

What distinguishes a Contract Account from an Externally Owned Account in Ethereum?

<p>Contract Accounts can store and execute code, while EOAs cannot. (A)</p> Signup and view all the answers

What is the significance of the storageRoot in an Ethereum Contract Account?

<p>It contains a Merkle tree of associated storage data. (B)</p> Signup and view all the answers

In Ethereum, what is the purpose of a transaction?

<p>To request a modification to the state of the blockchain. (A)</p> Signup and view all the answers

Which action can an Ethereum transaction NOT perform?

<p>Modify the code of an existing smart contract after deployment. (C)</p> Signup and view all the answers

What does the 'nonce' represent in the context of an Ethereum transaction?

<p>A sequence number issued by the originating EOA to prevent message replay. (B)</p> Signup and view all the answers

What is the role of 'gas' in Ethereum transactions?

<p>It represents the computational effort required to execute the transaction. (C)</p> Signup and view all the answers

What happens if a transaction runs out of gas before completing its execution?

<p>The transaction is reverted, the sender still pays for the gas consumed, and no state changes are applied. (C)</p> Signup and view all the answers

How is the gasCost of an Ethereum transaction calculated?

<p>It is the product of <code>gasLimit</code> and <code>gasPrice</code>. (C)</p> Signup and view all the answers

What is the destination address for a 'Contract Creation' special transaction?

<p>The zero address (0x000...000dEaD). (C)</p> Signup and view all the answers

What must an originator do to sign a transaction in Ethereum?

<p>Create a transaction data structure and compute the ECDSA signature using their private key. (B)</p> Signup and view all the answers

What does it mean for transactions on Ethereum to be 'atomic'?

<p>Transactions execute in their entirety, and changes are recorded only if all execution terminates successfully. (A)</p> Signup and view all the answers

What is the primary role of a Solidity compiler?

<p>To translate Solidity code into EVM bytecode. (C)</p> Signup and view all the answers

What does the pragma solidity ^0.5.7; statement specify in a Solidity contract?

<p>The Solidity compiler version. (D)</p> Signup and view all the answers

What is the significance of the constructor keyword in a Solidity contract?

<p>It is run only once when the contract is deployed to initialize the contract's state. (A)</p> Signup and view all the answers

What is the purpose of a modifier in Solidity?

<p>To attach additional conditional logic to functions. (D)</p> Signup and view all the answers

What is the purpose of payable keyword in a Solidity function definition?

<p>It indicates that the function can receive ether. (A)</p> Signup and view all the answers

In Solidity, what is a mapping?

<p>A key-value data structure. (C)</p> Signup and view all the answers

What security risk is Ethereum's 'Gas' mechanism primarily designed to mitigate?

<p>Denial-of-Service attacks. (C)</p> Signup and view all the answers

What is a key difference between Bitcoin's Script language and Ethereum's smart contract languages?

<p>Bitcoin Script is non-Turing Complete, while Ethereum's languages are Turing-Complete . (A)</p> Signup and view all the answers

What problem is overcome in Ethereum by charging a fee per computational step?

<p>The halting problem (infinite loops). (B)</p> Signup and view all the answers

In Proof-of-Stake (PoS) systems, what primarily determines a node’s chance of minting new digital tokens?

<p>The number of digital tokens already owned by the node. (D)</p> Signup and view all the answers

What potential issue can arise from Proof-of-Stake consensus mechanisms?

<p>Centralization of power among the largest token holders. (C)</p> Signup and view all the answers

Which of the following is the smallest denomination of Ether?

<p>Wei (C)</p> Signup and view all the answers

If someone sends ether to your Ethereum address, which component of your account is directly incremented?

<p>Balance (D)</p> Signup and view all the answers

What is the first step to take in order to create a transaction on the Ethereum network?

<p>Create a transaction data structure. (A)</p> Signup and view all the answers

After building a transaction data structure but before broadcasting, what cryptographic operation must be performed?

<p>Create the Keccak-256 hash of the transaction and sign it with the EOA's private key. (A)</p> Signup and view all the answers

Why does every transaction on Ethereum need to specify an estimate (gasLimit) of the amount of gas it will spend?

<p>To prevent the network from being stalled by infinitely running code. (C)</p> Signup and view all the answers

Once a smart contract is deployed on the Ethereum blockchain, can its code be changed?

<p>No, smart contracts are immutable once deployed. (D)</p> Signup and view all the answers

Which language is specifically designed for developing smart contracts on the Ethereum blockchain and is also the most popular?

<p>Solidity (B)</p> Signup and view all the answers

Serpent is a language similar to which language for developing smart contracts and compiling to EVM bytecode?

<p>Python (D)</p> Signup and view all the answers

What is the purpose of the require keyword in a Solidity Modifier?

<p>Expresses the conditions that must be true for the modifier to execute. (B)</p> Signup and view all the answers

Flashcards

Ethereum

Ethereum is an open source, globally decentralized computing infrastructure that executes programs called smart contracts. It uses a blockchain to synchronize and store the system's state changes, along with a crypto-currency called ether to meter and constrain execution resource costs.

Smart Contract

A set of promises, specified in digital form, including protocols within which the parties perform on these promises.

Ethereum Blockchain and Gas

Halting Problem (infinite loop): Cannot tell whether or not a program will run infinitely from compiled code. Solution: charge fee per computational step to limit infinite loops and stop flawed code from executing

Proof-of-Stake

Increasing the chance of a node's success in minting new digital tokens in proportion with the number of digital tokens already owned by the node.

Signup and view all the flashcards

Contract Account

Accounts can store and execute code.

Signup and view all the flashcards

Gas Price

current market price of a unit of Gas (in Wei)

Signup and view all the flashcards

Fee paid by a transaction

Each transaction on the Ethereum network requires that you pay a certain fee based on the amount of gas you spend

Signup and view all the flashcards

Gas Limit

maximum amount of Gas user is willing to spend

Signup and view all the flashcards

Ethereum Transactions

Transactions are signed messages originated by an externally owned account, transmitted by the Ethereum network, and recorded on the Ethereum blockchain.

Signup and view all the flashcards

Study Notes

Seminar 4: Blockchain Technology Basics II – Ethereum and Smart Contract

  • Readings: Mastering Ethereum Ch 1, 2 & 7

Agenda

  • Quick introduction of Ethereum

Ethereum History

  • An open-source and globally decentralized computing infrastructure which executes programs called smart contracts.
  • It uses a blockchain to synchronize and store the system's state changes.
  • Ether is a crypto-currency used to meter and constrain execution resource costs on the Ethereum network.

Smart Contract

  • A set of promises, specified in digital form, including protocols within which the parties perform on these promises (Nick Szabo, 1996)

Creating a Wallet

  • Creating a password is required for Metamask.

Ethereum vs. Bitcoin

  • Next section in the slide deck compares Ethereum and Bitcoin.

Bitcoin Performance Bottleneck

  • Consensus latency: 60 minutes.
  • TPS: 7 transactions per second (TPS) based on a block size of 1MB.
  • Visa: average 2,000TPS with a peak of 56,000 TPS.
  • Solutions to performance bottlenecks include speeding up block generation, and increasing block size.

Turing-Complete

  • Bitcoin blockchain's programming language: Script.
  • Script expressions use reverse polish notation.
  • Processed using stacks and postfix algorithm.
  • Limited to only Boolean output (e.g., either true or false).
  • Script language is also known as a non-Turing Complete language.
  • The language is designed without complex constructs such as loops and conditions, which limits its ability to create general purpose programs.
  • This is by design as it avoids the risks of bad programming such as infinite loop from bringing down the entire network.
  • Turing completeness is a mathematical concept and is a measure of the computability of a programming language.

Ethereum Blockchain - Gas

  • Halting Problem (infinite loop): cannot tell whether or not a program will run infinitely from compiled code.
  • Solution: charge fee per computational step to limit infinite loops and stop flawed code from executing.

Proof-of-Stake vs. Proof-of-Work

  • Increasing the chance of a node's success in minting new digital tokens in proportion with the number of digital tokens already owned by the node.

Proof of Stake

  • This approach does not require large expenditures on computing and energy.
  • Miners are now "validators" and post a deposit in an escrow account.
  • The more escrow you post, the higher the probability you will be chosen to nominate the next block.
  • If you nominate a block with invalid transactions, you lose your escrow.
  • One issue with this approach is that those that have the most Ethereum will be able to get even more.
  • This leads to centralization eventually.
  • It reduces the chance of a 51% attack and allows for near instant transaction approvals.

Important Concepts

  • Next section in the slide deck discusses important concepts.

Ethereum Blockchain - Ether Denominations

  • Wei (lowest denomination) is named after Wei Dai, author of b-money paper (1998) and core concepts used in BTC implementation, it is 1/1,000,000,000,000,000,000 (quintillion).
  • Szabo is the denomination after Wei, named after Nick Szabo, the author of Bit-Gold
  • Finney is the 2nd highest denomination and is named after Hal Finney
  • Hal Finney received the first Tx from Nakamoto.

Ethereum Blockchain – Accounts and Wallets

  • Accounts: can be external or contract accounts, consist of a public/private keypair, and allow for interaction with the blockchain.
  • Wallets: a set of one or more external accounts used to store/transfer ether

Ethereum Blockchain – Accounts and Wallets, External Account (EOA, Valid Ethereum Address)

  • Has an associated nonce (amount of transactions sent from the account) and a balance
  • codeHash - Hash of associated account code, i.e. a computer program for a smart contract (hash of an empty string for external accounts, EOAs)
  • Storage Root is root hash of Merkle-Patricia trie of associated account data

Ethereum Blockchain – Accounts and Wallets, Contract Account

  • Ethereum accounts can store and execute code

Example Account

  • Private Key: 0x2dcef1bfb03d6a950f91c573616cdd778d9581690db1cc43141f7cca06fd08ee. Ethereum private keys are 66 character strings (with Ox appended). Case is irrelevant. Same derivation through ECDSA as BTC.
  • Address: 0xA6fA5e50da698F6E4128994a4c1ED345E98Df50. Ethereum Private keys map to addresses directly. Simply the last 40 characters of the Keccak-256 hash of the public key. Address is 42 characters total (append Ox to front).

Ethereum Blockchain – Transactions

  • A request to modify the state of the blockchain.
  • Can run code (contracts) which change global state
  • Contrasts only balance updates in BTC.
  • Signed by originating account.
  • Types of transactions: send value from one account to another, create a smart contract and execute smart contract code.

Ethereum Blockchain - Transactions

  • Nonce is 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-creation made by this account, a sequence number, issued by the originating EOA, used to prevent message replay.
  • Gas price: the price of gas (in wei) the originator is willing to pay
  • The recipient is the destination Ethereum address
  • Value: the amount of ether to send to the destination

Ethereum Blockchain - Gas

  • Gas issues from the Halting problem (infinite loop) as it cannot tell whether or not a program will run infinitely from compiled code
  • Solution: Charge fee per computational step to limit infinite loops and stop flawed code from executing.
  • Every transaction needs to specify an estimate of the amount of gas it will spend.
  • Essentially a measure of how much one is willing to spend on a transaction, even if buggy.
  • Gas Price: current market price of a unit of Gas (in Wei)
  • Check gas price:
  • Gas Limit: maximum amount of Gas user is willing to spend
  • For simple payments that transfer ether from one EOA to another EOA, it is fixed at 21,000 gas units. 21,000 * gasPrice = fee.
  • If the destination address is a contract -> fuel tank in your car/ credit account for a gas station
  • Gas Cost (used when sending transactions) is calculated by gasLimit*gasPrice.
  • All blocks have a Gas Limit (maximum Gas each block can use)

Ethereum Blockchain - Transaction

  • Transmitting Value to EOAs and Contracts
    • To EOAs: update state
    • To contract: EVM will execute the contract and will attempt to call the function named in the data payload of your transaction
  • Transmitting a Data Payload to an EOA or Contract most likely addressed to a contract address - data will be interpreted by the EVM as a contract invocation
  • Special Transaction: Contract Creation sent to a special destination address called the zero address 0x000000000000000000000000000000000000dEaD

Ethereum Blockchain- transaction signing

  • To sign a transaction in Ethereum, the originator must:
  • Create a transaction data structure, containing nine fields: nonce, gasPrice, gas Limit, to, value, data, chainID, 0, 0.
  • Produce an RLP-encoded serialized message of the transaction data structure.
  • Compute the Keccak-256 hash of this serialized message.
  • Compute the ECDSA signature, signing the hash with the originating EOA's private key.
  • Append the ECDSA signature's computed v, r, and s values to the transaction.

Transaction Facts

  • Transactions are signed messages originated by an externally owned account, transmitted by the Ethereum network, and recorded on the Ethereum blockchain.
  • Transactions are the only things that can trigger a change of state, or cause a contract to execute in the EVM.
  • Ethereum is a global singleton state machine, and transactions are what make that state machine "tick," changing its state.
  • Contracts do not run on their own. Everything starts with a transaction.
  • Transactions are atomic, and execute in their entirety, with any changes in the global state recorded only if all execution terminates successfully.

Smart Contract Programming

  • Solidity: a language similar to JavaScript which allows you to develop contracts and compile to EVM bytecode. It is currently the flagship language of Ethereum and the most popular.
  • Solidity Documentation - Solidity is the flagship Ethereum high level language that is used to write contracts, as well as offer a Solidity online realtime compiler

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

More Like This

Use Quizgecko on...
Browser
Browser