Cryptoeconomics.Study

Cryptoeconomics.Study

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

›2.4 Proof of Authority

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

Code Challenge

The code challenges in this course build upon each other. It's highly recommended that you start from the beginning. If you haven't already, get started with our Installation Instructions.

! The chapter 2 coding challenges use a network simulation. This is created by nodeAgent.js, networkSim.js, and netTest.js in the ch2 directory. You do not need to understand how this network simulation works to complete the chapter two coding challenges, but we highly recommend it. The README in the ch2 directory will give you a high level overview of the network demo. Each file also has detailed code comments explaining how each function works.


Proof of Authority

Proof of Authority networks are a hybrid between completely open public blockchains and completely private blockchains. This is possible thanks to permissioning. Anyone can participate in the network, but only certain nodes have the permission (authority) to process transactions and create state transitions (new blocks). This allows participants to verify that everything is working correctly, while also allowing for faster transaction processing because we just trust the validators rather than making them perform a complex algorithm to earn the right to be the next validator.


Authority Client

Authority.js extends the Node class to create a node that has the authority to, verify, order, and sign transactions as valid.

// TODO
// Order transactions and broadcast that ordering to the network
orderAndBroadcast(tx) {
    // give the transactiona the latest nonce in the Authority node's state
    // increment the nonce
    // sign the transaction to give it "proof of authority"
    // add the signed transaction to the history
    // broadcast the transaction to the network
}


PoA Client

PoAClient.js extends the Node class to create nodes that can participate in the Proof of Authority network. This means that PoA client nodes can send, receive, and verify transactions, but cannot order and then sign them as "verified" because they don't have the authority.

// TODO
applyTransaction(tx) {
    // get the transaction from before the authority node added ordering and make a copy of it
    // delete the order nonce from the original transaction
    // clear the transaction signatures
    // get tx from before the auth node signed it
    // check the signer of the transaction and throw an error if the signature cannot be verified
    // check the autority for the network and throw an error if the transaction does not
    // Check that this is the next transaction in the Authority node's ordering
    // - hint: check if the nonce ordering is greater or less than it's supposed to be
    // if all checks pass...
    if (tx.contents.type === 'send') {
        // Send coins
        if (this.state[tx.contents.from].balance - tx.contents.amount < 0) {
            throw new Error('Not enough money!');
        }
        this.state[tx.contents.from].balance -= tx.contents.amount;
        this.state[tx.contents.to].balance += tx.contents.amount;
    } else {
        throw new Error('Invalid transaction type!');
    }
    // increment nonce
    this.state[tx.contents.from].nonce++;
    this.orderNonce++;
}


Testing

In this last section we will use a few tests to make sure that our Proof of Authority network is functioning as intended.

  • doubleSpendTest.js => same as usual
  • orderNonceTest.js => sends transactions out of order on purpose to check that our PoA nodes can correctly process and order them
  • PoATest.js => just send random tx to check basic PoA node functionality

As always, if you have questions or get stuck please hit up the community on the forum!

Last updated on 9/2/2019 by burrrata
← LectureLecture →
  • Proof of Authority
  • Authority Client
  • PoA Client
  • Testing
Course
Getting Started
Community
ForumContributors
More
BlogNewsletterGitHub
Copyright © 2019 Cryptoeconomics.Study