Cryptoeconomics.Study

Cryptoeconomics.Study

  • Course
  • Community
  • Contribute
  • Languages iconEnglish
    • 中文

›1.2 Payment Processor

Getting Started

  • Welcome
  • Development Setup
  • Course Overview

Ch1: Payment Processor

    1.0 Chapter Overview

    • Lecture

    1.1 Hashes and Signatures

    • Lecture
    • Code Challenge

    1.2 Payment Processor

    • Lecture
    • Code Challenge

    1.3 Replay Protection

    • Lecture
    • Code Challenge

    1.4 Account Model vs UTXOs

    • Lecture
    • Code Challenge

    1.5 Centralized Systems

    • Lecture
    • Code Challenge

Ch2: Network Models

    2.0 Chapter Overview

    • Lecture

    2.1 Networks and Synchrony

    • Lecture

    2.2 Double Spends

    • Lecture
    • Code Challenge

    2.3 Latency-Based Consensus

    • Lecture
    • Code Challenge

    2.4 Proof of Authority

    • Lecture
    • Code Challenge

Ch3 Proof of Work

    3.0 Chapter Overview

    • Lecture

    3.1 Decentralized Consensus and Blockchains

    • Lecture

    3.2 Bitcoin and Nakamoto Consensus

    • Lecture
    • Code Challenge

    3.3 Merkle Trees

    • Lecture
    • Code Challenge

    3.4 Game Thoery in Bitcoin

    • Lecture
    • Code Challenge

    3.5 Selfish Mining

    • Lecture
    • Code Challenge

More

  • Resources
  • Glossary
Edit

Lecture


Payment Processor Implementation

  • Implementing a payment processor using the account model. Learn about state, state transitions, and replay protection.





Slides

Gooogle Sheets Link


Ch1.2 Overview

State

What is a state?

  • A state is a particular configuration of data.

Examples of state:

  • the physical world at any point in time
  • a blockchain at a particular block
  • a chess board after a player makes a move

State Transition Function

What is a state transition function?

  • a set of rules that determines how to transition the state from one configuration to another

Examples of state transition functions:

  • the laws of physics
  • the rules of a blockchain protocol
  • the rules of chess


Overview of PayPal structure

The state object which is a mapping of address->balance

There are two types of state mutations (each with their own logic)

  1. mint
  2. send

We start with an initial state (ie genesis block). We then receive transactions, and based on our state transition function reject invalid transactions and process valid transactions (ie create blocks). We then store the history of all transactions in a big ledger (ie a blockchain). Everyone's current accounts and balances is the current state (ie the latest block).

  • The list of transactions (blocks) is called the “history”
  • The result of computing all the transactions in the history leads to the current “state”
  • In Ethereum the full history is approx 250 GB, while the state is approx 3 GB.

Fun aside: Rent proposals say that people should pay rent on the state storage which they take up. There is no direct incentive to store the history, and so nodes today often do prune or delete historical data. If this happens too much there is a risk that we can’t recreate the chain anymore!


Recommended Resources

But how does a blockchain work? - Awesome video by 3Blue1Brown explaining how blockchains work.

Anders Brownworth's blockchain demo - Put data in a block, "mine" (hash) it, then add data to the next block, "mine" (hash) it, etc... The "mine" button perfoms the state transition function and you can see the history (blockchain) being created right in front of you.

Ethviewer - Live Ethereum blockchain visualization.

Blockscout Ethereum block explorer - You can see the current state of the Ethereum blockchain by clicking on the latest block. You can also explore the history by clicking on past blocks and seeing the transactions that were processed in that state transition function. You can also search for the current state of any account or contract.

Conways's Game Of Life

  • Wikipedia - Explains the rules of the game (state transition function) and shows some fun demos.
  • Peter Daily's React implimentation of the Game of Life - Let's you play the game (really start it and watch it unfold).
  • Code for the above demo


Last updated on 9/3/2019 by burrrata
← Code ChallengeCode Challenge →
  • State
  • State Transition Function
  • Overview of PayPal structure
  • Recommended Resources
Course
Getting Started
Community
ForumContributors
More
BlogNewsletterGitHub
Copyright © 2019 Cryptoeconomics.Study