Programming Assignments for Coursera Bitcoin and Cryptocurrency Technologies Course


Coursera’s forum engine didn’t let me write this longish post so that’s why I’m placing it here.

 

On the Preview Course page (https://www.coursera.org/learn/cryptocurrency/home/welcome ) there’s a Welcome intro by Mr.Narayanan from where you can follow a link (http://bitcoinbook.cs.princeton.edu/ ) to the Bitcoin and Cryptocurrency Technologies book.

Scroll down and there you’ll find the Programming Assignments section, which says “We are giving you grading scripts which you can use to check your solutions yourself.” Click the green button (https://docs.google.com/uc?id=0B4-bDFu_72BeblhsajRQZkRJNUk&export=download ) to download a ZIP archive, which indeed contains a bunch of JAR files and instructions how to run grading scripts.

Personally, I’m going to give it a spin somewhere next week.

Now, about how to develop the code for our programming assignments. I happened to be an Oracle Certified Professional and Oracle Certified Instructor who specializes in Java. Here’s the thing: to write Java programs, you’ll need the so-called JDK package installed on your computer. As for IDEs such as Intellij IDEA, Eclipse, NetBeans, Android Studio, BlueJ, etc., they are not strictly necessary; any Java code can be written in Notepad and then compiled and run from the command line.

To make your life easier, I would advise you to download and install the JDK + NetBeans combo straight from Oracle’s site ( http://www.oracle.com/technetwork/java/javase/downloads/jdk-netbeans-jsp-142931.html ).

And here’s one of my lectures that contains all necessary links to get you started: http://www.igor.host/coursera/JF_01_Basics_01_Getting_Ready_for_Java.ppt

I’m not sure how often I’ll be checking this Discussions page (or even whether I’m going to follow this course up to its end) so in case someone needs to ask me something you’re welcome to do it from my Contacts page on this site.

HTH.

FOLLOW UP:

Alright, here’s what I got by playing with the grading scripts on December 23, 2017:

Step 1. Unzip assignment_1 to a folder of your choice (in my case it was C:\Coursera\Bitcoin_and_Cryptocurrency_Technologies)

Step 2. Copy TxHandler.java from C:\Coursera\Bitcoin_and_Cryptocurrency_Technologies\assignment_1\grading\Reference folder to C:\Coursera\Bitcoin_and_Cryptocurrency_Technologies\assignment_1\grading folder.

Step 3. While holding down Windows key press R (or click Start) and then type cmd. Press Enter.

Step 4. Move into the folder that contains the ScroogeCoin-related classes by typing this command:

cd C:\Coursera\Bitcoin_and_Cryptocurrency_Technologies\assignment_1\grading

Step 5. Compile the classes with this command (also please note that the commands contained inside README are written for a *nix rig, that’s why I replaced colons with semicolons):

javac -cp scroogeCoinGrader.jar;rsa.jar;algs4.jar;. TestTxHandler.java

Step 6. Finally, run the tests with this command:

java -cp scroogeCoinGrader.jar;rsa.jar;algs4.jar;. TestTxHandler

Illustration (just the initial part):

And here’s entire output in the text format:

Running 7 total tests.

Test 1: test isValidTx() with valid transactions
==> passed

Test 2: test isValidTx() with transactions containing signatures of incorrect data
==> passed

Test 3: test isValidTx() with transactions containing signatures using incorrect private keys
==> passed

Test 4: test isValidTx() with transactions whose total output value exceeds total input value
==> passed

Test 5: test isValidTx() with transactions that claim outputs not in the current utxoPool
==> passed

Test 6: test isValidTx() with transactions that claim the same UTXO multiple times
==> passed

Test 7: test isValidTx() with transactions that contain a negative output value
==> passed


Total: 7/7 tests passed!

Running 8 total tests.

Test 1: test handleTransactions() with simple and valid transactions
Total Transactions = 2
Number of transactions returned valid by student = 2
Total Transactions = 50
Number of transactions returned valid by student = 50
Total Transactions = 100
Number of transactions returned valid by student = 100
==> passed

Test 2: test handleTransactions() with simple but some invalid transactions because of invalid signatures
Total Transactions = 2
Number of transactions returned valid by student = 0
Total Transactions = 50
Number of transactions returned valid by student = 1
Total Transactions = 100
Number of transactions returned valid by student = 1
==> passed

Test 3: test handleTransactions() with simple but some invalid transactions because of inputSum < outputSum
Total Transactions = 2
Number of transactions returned valid by student = 1
Total Transactions = 50
Number of transactions returned valid by student = 18
Total Transactions = 100
Number of transactions returned valid by student = 41
==> passed

Test 4: test handleTransactions() with simple and valid transactions with some double spends
Total Transactions = 2
Number of transactions returned valid by student = 1
Total Transactions = 50
Number of transactions returned valid by student = 23
Total Transactions = 100
Number of transactions returned valid by student = 43
==> passed

Test 5: test handleTransactions() with valid but some transactions are simple, some depend on other transactions
Total Transactions = 2
Number of transactions returned valid by student = 1
Total Transactions = 50
Number of transactions returned valid by student = 26
Total Transactions = 100
Number of transactions returned valid by student = 94
==> passed

Test 6: test handleTransactions() with valid and simple but some transactions take inputs from non-exisiting utxo's
Total Transactions = 2
Number of transactions returned valid by student = 1
Total Transactions = 50
Number of transactions returned valid by student = 10
Total Transactions = 100
Number of transactions returned valid by student = 59
==> passed

Test 7: test handleTransactions() with complex Transactions
Total Transactions = 2
Number of transactions returned valid by student = 0
Total Transactions = 50
Number of transactions returned valid by student = 12
Total Transactions = 100
Number of transactions returned valid by student = 20
==> passed

Test 8: test handleTransactions() with simple, valid transactions being called again to check for changes made in the pool
Total Transactions = 2
Number of transactions returned valid by student = 2
Total Transactions = 50
Number of transactions returned valid by student = 49
Total Transactions = 100
Number of transactions returned valid by student = 46
==> passed


Total: 8/8 tests passed!

 

Now, after I replaced the already implemented TxHandler.java with the dummy code we had been provided with, the tests failed as expected:

 

Apparently, the test harness from the Bitcoin and Cryptocurrency Technologies book works fine, and the TxHandler.java was implemented correctly — by whoever wrote that book. Now it’s our turn to fill in missing parts into the template we’ve been provided with, and see how well we fare.

ANOTHER FOLLOW-UP: Submitted & Passed (95 marks out of 100)

 

Grader Output

Running 15 tests
Test 1: test isValidTx() with valid transactions
==> passed

Test 2: test isValidTx() with transactions containing signatures of incorrect data
==> passed

Test 3: test isValidTx() with transactions containing signatures using incorrect private keys
==> passed

Test 4: test isValidTx() with transactions whose total output value exceeds total input value
==> passed

Test 5: test isValidTx() with transactions that claim outputs not in the current utxoPool
==> passed

Test 6: test isValidTx() with transactions that claim the same UTXO multiple times
==> passed

Test 7: test isValidTx() with transactions that contain a negative output value
==> passed


Test 8: test handleTransactions() with simple and valid transactions
Total Transactions = 2
Number of transactions returned valid by student = 2
Total Transactions = 50
Number of transactions returned valid by student = 50
Total Transactions = 100
Number of transactions returned valid by student = 100
==> passed

Test 9: test handleTransactions() with simple but some invalid transactions because of invalid signatures
Total Transactions = 2
Number of transactions returned valid by student = 0
Total Transactions = 50
Number of transactions returned valid by student = 2
Total Transactions = 100
Number of transactions returned valid by student = 1
==> passed

Test 10: test handleTransactions() with simple but some invalid transactions because of inputSum < outputSum
Total Transactions = 2
Number of transactions returned valid by student = 2
Total Transactions = 50
Number of transactions returned valid by student = 25
Total Transactions = 100
Number of transactions returned valid by student = 42
==> passed

Test 11: test handleTransactions() with simple and valid transactions with some double spends
Total Transactions = 2
Number of transactions returned valid by student = 1
Total Transactions = 50
Number of transactions returned valid by student = 21
Total Transactions = 100
Number of transactions returned valid by student = 43
==> passed

Test 12: test handleTransactions() with valid but some transactions are simple, some depend on other transactions
Total Transactions = 2
Number of transactions returned valid by student = 2
Total Transactions = 50
Number of transactions returned valid by student = 29
Total Transactions = 100
Number of transactions returned valid by student = 85
==> passed

Test 13: test handleTransactions() with valid and simple but some transactions take inputs from non-exisiting utxo's
Total Transactions = 2
Number of transactions returned valid by student = 1
Total Transactions = 50
Number of transactions returned valid by student = 12
Total Transactions = 100
Number of transactions returned valid by student = 57
==> passed

Test 14: test handleTransactions() with complex Transactions
Total Transactions = 2
Number of transactions returned valid by student = 2
Total Transactions = 50
Number of transactions returned valid by student = 10
Total Transactions = 100
Number of transactions returned valid by student = 30
==> passed

Test 15: test handleTransactions() with simple, valid transactions being called again to check for changes made in the pool
Total Transactions = 2
Number of transactions returned valid by student = 2
Total Transactions = 50
Number of transactions returned valid by student = 48
Total Transactions = 100
Number of transactions returned valid by student = 53
==> passed


Total:15/15 tests passed!

 

7 Comments

  1. Matt

    Thanks for the assignments.zip download… That doesn’t seem to be available anymore on their site.

    • Holy cow! Can’t believe it, lemme check… Yeap, you’re right Matt. They did remove all links. Well, in case they decide to mop up Google as well, here’s the same assignments archive on my site: http://www.igor.host/coursera/assignments.zip What’s more, all these files can be always found safe and sound on GitHub, thanks to those who went thru this course before us.

        • Sorry friend, I don’t have much experience with Macs… Anyways, the first step is always should be making sure that your Java environment has been set up correctly. Can you compile and run a Hello World-type of a program from your command line? Can you provide a screenshot of the error messages?

        • xie

          May be you should try to use “:” instead of “;” as path separator, like:
          javac -cp scroogeCoinGrader.jar:rsa.jar:algs4.jar:. TestTxHandler.java
          I make it work in Linux.

Leave Comment

Your email address will not be published.