Ethereum and Smart Contracts

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 is NOT explicitly specified by a typical Bitcoin transaction, challenging the assumptions of deterministic transaction analysis?

  • The amount of Bitcoin being transferred in the transaction.
  • The input addresses from which the Bitcoin is being spent.
  • The output addresses to which the Bitcoin is being sent.
  • The exact geographical location of the sender at the time of transaction. (correct)

In the context of Ethereum, what critical role does 'Ether' play beyond being a mere cryptocurrency, particularly in relation to smart contract execution?

  • Ether functions as a governance token, allowing holders to vote on protocol upgrades and changes to the Ethereum Virtual Machine.
  • Ether is employed as 'gas' to meter and constrain the computational costs of executing smart contracts, preventing infinite loops and resource exhaustion. (correct)
  • Ether is used to directly subsidize transaction fees, making decentralized applications free for users.
  • Ether serves exclusively as a store of value, akin to digital gold.

How does Ethereum's design choice to be 'Turing-Complete' introduce a unique challenge not present in Bitcoin's 'non-Turing Complete' Script language, especially concerning resource management?

  • Bitcoin's non-Turing complete nature makes it impossible to implement complex financial instruments, limiting its potential applications. in decentralized finance (DeFi).
  • Turing completeness allows Ethereum smart contracts to execute infinitely complex computations, increasing the likelihood of resource exhaustion and the halting problem. (correct)
  • Ethereum's Turing completeness simplifies smart contract auditing, reducing the risk of vulnerabilities and unexpected behavior.
  • The halting problem is irrelevant in Ethereum because of its Proof-of-Stake consensus mechanism, which ensures all transactions are validated within a bounded time frame.

Considering the dual nature of Ethereum accounts, how does the codeHash differentiate an Externally Owned Account (EOA) from a Contract Account regarding smart contract execution?

<p>The codeHash for an EOA is a hash of an empty string, indicating no associated code, whereas for a Contract Account, it represents the hash of the contract's bytecode. (C)</p> Signup and view all the answers

In the context of Ethereum transactions, what is the significance of the 'Data' field when transmitting a data payload to a Contract Account, especially concerning the Ethereum Virtual Machine (EVM)?

<p>The 'Data' field is interpreted by the EVM as a function call, with the first four bytes typically specifying the function selector of the contract's function to be executed. (C)</p> Signup and view all the answers

What specific cryptographic process must occur before broadcasting a transaction in Ethereum, and how does this process ensure non-repudiation by linking the transaction to a specific Externally Owned Account (EOA)?

<p>The transaction data is signed using the originating EOA's private key with the Elliptic Curve Digital Signature Algorithm (ECDSA), producing a unique signature (v, r, s) that can be verified with the EOA's public key. (A)</p> Signup and view all the answers

How does Ethereum's 'Gas Limit' mechanism directly address the 'Halting Problem' inherent in Turing-complete smart contracts, preventing denial-of-service attacks and ensuring network stability?

<p>By setting a maximum amount of 'gas' that a transaction can consume; transactions halt if the gas limit is reached, reverting state changes and preventing infinite loops. (C)</p> Signup and view all the answers

In the context of Ethereum smart contracts, what is the precise relationship between 'gasPrice', 'gasLimit', and 'gasCost' in determining the overall transaction fee, and how do these parameters influence transaction prioritization on the network?

<p>'gasPrice' is the current market price per unit of gas in Wei, 'gasLimit' is the maximum gas the user is willing to spend, and 'gasCost' is calculated as gasLimit * gasPrice, with higher gasPrices leading to faster transaction confirmation. (A)</p> Signup and view all the answers

How would a transaction be constructed to deploy a new smart contract onto the Ethereum blockchain, differing from a transaction that merely calls a function on an existing contract (especially concerning the recipient address)?

<p>A contract deployment transaction includes the contract's bytecode in the 'data' field and sends it to a special destination address known as the zero address (<code>0x000...000</code>), whereas a function call sends data to the contract's specific address. (C)</p> Signup and view all the answers

Considering that Ethereum is described as a 'global singleton state machine,' what crucial implication does this have for smart contract execution and the sequence of state changes on the blockchain?

<p>All transactions are processed in a globally consistent and serialized manner, with each transaction atomically updating the single, shared state of the Ethereum blockchain. (C)</p> Signup and view all the answers

Before a transaction is successfully added to the Ethereum blockchain, what sequence of steps must the originating EOA complete to ensure validity and integrity, especially in the context of transaction data and cryptographic signatures?

<p>Create a transaction data structure with nine fields (nonce, gasPrice, gasLimit, to, value, data, chainID, v, r, s), RLP-encode the data, compute the Keccak-256 hash, compute the ECDSA signature with the private key, then append the signature to the transaction. (C)</p> Signup and view all the answers

How does the Solidity programming language facilitate the implementation of access control mechanisms within smart contracts, such as restricting certain functions to be executable only by the contract's owner?

<p>Solidity allows defining custom modifiers which can be attached to functions to implement conditional logic, such as checking if <code>msg.sender</code> is the owner. (A)</p> Signup and view all the answers

In Solidity smart contracts, how can developers handle distributing funds to multiple family members (represented by their wallet addresses) based on pre-defined inheritance amounts, ensuring that the distribution is automatically triggered upon a specific event like the contract owner's death?

<p>By iterating through an array of family member addresses and using the <code>transfer()</code> function to send the corresponding inheritance amount, triggered by a modifier that checks for the owner's deceased status. (C)</p> Signup and view all the answers

Within the Ethereum ecosystem, contrast the functionality and purpose of Solidity with that of Serpent, particularly in view of their roles in smart contract development and conversion into EVM bytecode.

<p><code>Solidity</code> is the flagship language of Ethereum, resembling JavaScript and offering high-level features, while <code>Serpent</code>, similar to Python, aimed for simplicity especially combined with LLL compilation. (A)</p> Signup and view all the answers

Critically analyze the implications of implementing a Proof-of-Stake (PoS) consensus mechanism in blockchain networks, particularly regarding its impacts on energy consumption, decentralization, and vulnerability to 51% attacks, compared to Proof-of-Work (PoW).

<p>PoS reduces energy consumption and makes 51% attacks virtually impossible due to economic disincentives, but may exacerbate centralization as validators are chosen based on stake. (A)</p> Signup and view all the answers

How can the 'Wei' be articulated with respect to scaling into denominations with higher numerical exponents with relation to other common denomination names?

<p>A wei is equal to 10^18 Ethers. (D)</p> Signup and view all the answers

What conditions inherently must be met for a smart contract transaction to be deemed atomic and have its state changes recorded?

<p>Having all of the function executions terminate successfully. (C)</p> Signup and view all the answers

Given the concept of function decorators or modifiers in Solidity, how can a programmer restrict the execution of a state-changing function to only external calls?

<p>Implement the check <code>require(tx.origin == msg.sender);</code>. (D)</p> Signup and view all the answers

When creating a 'Will' contract, what is the most secure way of ensuring the payout() is only triggered after death?

<p>Have the <code>deceased()</code> trigger, which is <code>onlyOwner</code>, also trigger <code>mustBeDeceased</code>. (A)</p> Signup and view all the answers

In reference to pragma solidity ^0.5.7;, what is the best practice to avoid compiler specificities?

<p>Setting <code>pragma solidity</code> to the version to which the contract was written. (D)</p> Signup and view all the answers

Given the statement 'Ethereum is a global singleton state machine', what best describes the impact on smart contract?

<p>Contracts are only executed with signed messages by an externally owned account. (B)</p> Signup and view all the answers

If a smart contract does not run correctly, what's the point of Halting problem (infinite loop) and why is it important?

<p>Fee's must be charged as it cannot be easily determined whether or not a program will run infinitely. (B)</p> Signup and view all the answers

Flashcards

Ethereum

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 and uses Ether to meter resource costs

Smart Contract

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

Bitcoin Consensus Latency

Time taken for a consensus to be reached and a new block added to the blockchain.

TPS (Transactions per Second)

The number of transactions that a blockchain can process per second.

Signup and view all the flashcards

Non-Turing Complete Language

It is designed without complex constructs such as loops and conditions, limiting its ability to create general-purpose programs.

Signup and view all the flashcards

Halting Problem

Halting refers to whether we can tell if code will run forever or stop early.

Signup and view all the flashcards

Proof of Stake

Increases the chance of a node's success in minting new tokens based on the holding amount.

Signup and view all the flashcards

Wei

Ethereum's lowest denomination of its cryptocurrency, Ether

Signup and view all the flashcards

Ethereum Accounts

Accounts contain two kinds: Contract Accounts, and External Owned Accounts

Signup and view all the flashcards

Balance of Account

An amount of cryptocurrency associated with an external account.

Signup and view all the flashcards

CodeHash

Hash of associated account code, for a smart contract.

Signup and view all the flashcards

Nonce

A number representing the number of transactions sent from an account.

Signup and view all the flashcards

Ethereum Transaction

Changes global state, and contrasts balance-only updates in BTC

Signup and view all the flashcards

Nonce(in transactions)

A sequence number issued by the originating EOA, used to prevent message replay.

Signup and view all the flashcards

Ethereum Gas

A measure of how much one is willing to spend on a transaction, even if buggy

Signup and view all the flashcards

Solidity

Allows you to develop contracts and compile to EVM bytecode; the flagship Ethereum language

Signup and view all the flashcards

Study Notes

Seminar 4: Blockchain Technology Basics II - Ethereum and Smart Contracts

  • Readings include Mastering Ethereum Ch 1, 2 & 7
  • Agenda:
    • Quick Introduction to Ethereum
    • Ethereum vs. Bitcoin
    • Important concepts
    • Smart Contract

Ethereum History

  • Ethereum is an open-source, globally decentralized computing infrastructure.
  • This executes programs called smart contracts.
  • It uses a blockchain to synchronize and store the system's state changes.
  • A crypto-currency called ether meters and constrains execution resource costs.

Smart Contract

  • A smart contract constitutes a set of promises, specified in digital form, including protocols within which the parties perform these promises.
  • Nick Szabo defined smart contracts in 1996.
  • Wallets can be created by using metamask.

Ethereum vs Bitcoin

  • Performance bottleneck of Bitcoin: 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. Overcome solutions by 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 Boolean output, e.g., either true or false
  • Script language: a non-Turing Complete language
  • Designed without complex constructs such as loops and conditions which limits its ability to create general purpose programs.
  • Turing Completeness: a mathematical concept that measures the computability of a programming language.
  • This is by design as it avoids the risks of bad programming such as infinite loop from bringing down the entire network

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, stopping 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.
  • The proof of stake 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
  • An issue with this approach is that those with the most ethereum will be able to get even more
  • This leads to centralization eventually
  • Reduces the chance of a 51% attack, allowing for near-instant transaction approvals

Important concepts

  • Ethereum Blockchain - Ether Denominations:
    • Wei - lowest denomination
    • Named after Wei Dai - author of b-money paper (1998), many core concepts used in BTC implementation
    • 1/1,000,000,000,000,000,000 (quintillion)
    • Szabo - next denomination
    • Named after Nick Szabo author of Bit-Gold
    • Finney – 2nd highest denomination
    • Named after Hal Finney
    • received first Tx from Nakamoto

Ethereum Blockchain – Accounts and Wallets

  • Accounts:
    • Two Kinds:
    • External Owned Accounts - (EOA, most common account)
    • Contract Accounts
    • Consist of a public/private keypair
    • 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: root hash of Merkle-Patricia trie of associated account data
  • Contract Account Ethereum accounts can store and execute code Has an associated nonce and balance codeHash - hash of associated account code storageRoot contains Merkle tree of associated storage data

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:
    • Send value from one account to another account
    • Create smart contract
    • Execute smart contract code 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.
    • 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
  • Gas limit
    • The maximum amount of gas the originator is willing to buy for this transaction Recipient
    • The destination Ethereum address
  • Value
    • The amount of ether to send to the destination
  • Data
    • The variable-length binary data payload
  • v,r,s
    • The three components of an ECDSA digital signature of the originating EOA

Ethereum Blockchain – Gas

  • Halting problem (infinite loop) – reason for Gas
    • Problem: 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 must 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: the current market price of a unit of Gas (in Wei) Check gas price here: https://ethgasstation.info/; https://etherscan.io/gastracker Is always set before a transaction by user
  • Gas Limit: the 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.

Fascinating fact on the transaction

  • Transactions are signed messages originated by an externally owned account, transmitted by the Ethereum network, and recorded on the Ethereum blockchain.
    • Another way to look at transactions is that they are the only things that can trigger a change of state, or cause a contract to execute in the EVM.
    • Ethereum functions as a global singleton state machine, and what makes it tick" is transactions, they change its state.
  • Contracts don't run on their own.
  • Ethereum doesn't run alone, everything begins with a transaction.
  • Transactions are viewed as atomic. Transactions execute in entirety, global states only record any all execution terminates successfully.

Smart contract code

  • 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. Serpent: a language similar to Python which can be used to develop contracts and compile to EVM bytecode. It is intended to be maximally clean and simple, combining many of the efficiency benefits of a low-level language with ease-of-use in programming style, and at the same time adding special domain-specific features for contract programming. Serpent is compiled using LLL.
  • Website to use if you'd like to learn more: https://cryptozombies.io/en/lesson/1/chapter/1

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