A Python Implementation of GoofyCoin

A simple and useless cryptocurrency

Thiago Cardoso
Coinmonks
Published in
4 min readMar 26, 2021

--

Photo by Liam Read on Unsplash

1 — Introduction

GoofyCoin is about the simplest (and thus useless) cryptocurrency we can imagine. It is described in Chapter 1 of the book “Bitcoin and Cryptocurrency Technologies”, written by Arvind Narayanan, Joseph Bonneau, Edward Felten, Andrew Miller, Steven Goldfeder, and published by Princeton University Press in 2016. As a blockchain beginner, I tried to implement it in Python for learning purposes. I’m sure that my code contains mistakes and maybe my understanding of GoofyCoin rules, as described in the book, is not 100% accurate. If anyone finds any of those problems, feel free to comment here.

A jupyter notebook containing this introduction, explanation of GoofyCoin (as described in the book), and my code is available in the following GitHub: https://github.com/thiagoguimaraesdf/goofyCoinPython

2 — GoofyCoin rules and protocol

The two main GoofyCoin rules are:

The protocol for creating a new GoofyCoin is described below:

The protocol for transferring an existing coin is described below:

A more formal summary of GoofyCoin rules is described in the book:

3 — Implementation Code

3.1 — Library Import

The main libraries used here are ecdsa, for generating digital signatures, and Haslib, for employing Hash Function (SHA-3)

More info about ecdsa: https://pypi.org/project/ecdsa/

More info about hashlib: https://docs.python.org/3/library/hashlib.html

3.2 — Our random string generator

Defining a function to generate a random string with length n.
Note: There are probably more randomized algo’s for generating a random n length str. I’m employing here a very simple one.

3.3 — Creating Goofy Keys

We are going to create the real Goofy Signature and Public Keys outside our GoofyCoin class. I’m using here the ECDSA library (and algo) to generate and further verify Goofy private signature.
For more information about ECDSA algo: https://www.cs.miami.edu/home/burt/learning/Csc609.142/ecdsa-cert.pdf

3.4 — The GoofyCoin Class

The code for creating GoofyCoin class — which will enable us to (i) create a coin — only with Goofy Secret Signature, (ii) transfer a coin; and (iii) check if a coin is valid — is described and well commented below.

4 — Testing our Coin

I test here for the following cases:

# Test 1: Verifying a brand new coin

# Test 2: Trying to transfer an inexistent coin

# Test 3: Trying to create a new coin without Goofy Secret Key

# Test 4: Verifying a coin that was already transfered once

# Test 5: Verifying a coin that was already transfered twice

# Test 6: Verifying a fake coin transfered by Max

5 — Final remarks

Despite being a shitty coin, GoofyCoin guarantees a central authority (unfortunately Goofy in this case) the power to create coins and transfer them with a valid method of verification. Anyone receiving a coin can check if that coin is valid by following its “route” and checking if transferences were made by the right users.

The main problem with Goofy Coin is that anyone can double-spend its own coin. We don’t have a valid method to guarantee that a bad user won’t transfer his coin to two or more different persons. That’s why we call it Goofy Coin

--

--