Cryptoeconomics.Study

Cryptoeconomics.Study

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

›2.2 Double Spends

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.


Double Spending

As we mentioned in 2.1, the Spender nodes are altruistic (or naive) in that they only try to send transactions when they have funds. They could, however, try to send multiple transactions at the same time, and... if network latency was great enough, they might be able to fool multiple nodes into thinking they've both received the same transaction.

The way to do this would be to duplicate the same transaction (including the nonce), but with different receivers. To each recipient the transactions would look valid, but when broadcast to the network and compared to the state of other nodes there would be a conflict. At best this would result in some disgruntled nodes and a reversion of one of the transactions, but this could potentially also create a network fork where one set of nodes accepts one of the transactions and another set of nodes accepts another. This would create 2 different versions of the state, and thus 2 different networks.

To better understand double spends let's try to implement a double spend attack ourselves! In doubleSpendTest.js the network has already been setup, but it's up to you to perform the double spend.

// Attempting to double spend!
// TODO: designate the node that will double spend
// TODO: designate the nodes that we will perform the attack on
// TODO: create 2 identical transactions that have different recipients
// TODO: broadcast both transaction to the network at the same time


Testing The Attack

You can run the network simulation at any time to check the results of your attack. This is done by running node doubleSpendTest.js in the 2.2 directory. As always, if you have questions or get stuck please hit up the community on the forum!

Throughout the rest of chapter 2 we will use slightly modified versions of doubleSpendTest.js to see how our different networks handle double spending

Last updated on 9/2/2019 by burrrata
← LectureLecture →
  • Double Spending
  • Testing The Attack
Course
Getting Started
Community
ForumContributors
More
BlogNewsletterGitHub
Copyright © 2019 Cryptoeconomics.Study