0% found this document useful (0 votes)
91 views

Internship Lab 1 RD

This document provides instructions for completing a lab assignment to create a basic cryptocurrency ledger (referred to as a "Scrooge Coin") in Java. It involves downloading prerequisite Java classes, then writing code to validate transactions by checking that: 1) inputs are unspent outputs, 2) signatures are valid, 3) outputs aren't double-spent, 4) values aren't negative, and 5) inputs >= outputs. Methods are outlined to validate the first 3 rules, and validate rules 4 and 5. The document concludes by noting the final method needed to process an array of transactions, accept valid ones, and update the UTXO pool.

Uploaded by

Rowan Briggs
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
91 views

Internship Lab 1 RD

This document provides instructions for completing a lab assignment to create a basic cryptocurrency ledger (referred to as a "Scrooge Coin") in Java. It involves downloading prerequisite Java classes, then writing code to validate transactions by checking that: 1) inputs are unspent outputs, 2) signatures are valid, 3) outputs aren't double-spent, 4) values aren't negative, and 5) inputs >= outputs. Methods are outlined to validate the first 3 rules, and validate rules 4 and 5. The document concludes by noting the final method needed to process an array of transactions, accept valid ones, and update the UTXO pool.

Uploaded by

Rowan Briggs
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Rowan Briggs

Lab 1: Scrooge Coin

Background: Coursera, Week 1 of Cryptocurrency class


Java I and II understanding preferred

Overview: Bitcoin has been gaining a lot of interest as of late. For this lab, we will be
creating a "Bitcoin." Specifically, we will be creating the ledger. The bitcoin
will be given to you in the transaction class. As was covered in the course, a
bitcoin needs to be able to have an input, output, and a signature. The ledger
needs to be able to verify a signature and check that the bitcoin is not being
double spent (there is enough bitcoin to pay the amount).

Material: Go to the following link to download the other classes that will be needed to
complete this lab. You will also need java in order to complete this lab. I
recommend using a program like Eclipse, but feel free to use any program that
you like.

Procedure:
Step 1:
Upload the precoded programs. This includes: UTXO.java, UTXOPool.java,
Tansaction.java, and Crypto.java.

Step 2: Download the Txhandler.java sample program.

Step 3: You will need the following imports:


import java.security.PublicKey;
import java.util.ArrayList;
import java.util.HashMap;

Step 4:
Here is the constructor. You will need to refer to the other java classes.
public TxHandler (UTXOPool utxoPool){
/** Creates a public ledger whose current UTXOPool (collection of unspent
* transaction outputs) is utxoPool. This should make a defensive copy of
* utxoPool by using the UTXOPool(UTXOPool uPool) constructor.
*/
}

Step 5:
Let's work on the TxHandler method:
What are the 5 things that the ledger will need to know from each Transaction?
1. All ______ claimed by tx are in the current UTXO pool
2. All ______ on each _____ of tx are valid.
3. No UTXO is claimed _____ times by tx
4. ALl tx's _____ values are _____ negative.
5. The sum of tx's _____ values are greater than or equal to the sum of its output values;
and _____ otherwise.
/** Returns true if
//1. All ______ claimed by tx are in the current UTXO pool
//2. All ______ on each _____ of tx are valid.
//3. No UTXO is claimed _____ times by tx
//4. ALl tx's _____ values are _____ negative.
//5. The sum of tx's _____ values is greater than or equal to the sum of its output
//values; and _____ otherwise.
*/
public boolean isValidTx (Transaction tx) {
//code
}
This method will call on other methods to check if these rules are followed. If these rules
are followed, then it will return ____ and if they are not followed, it will return _____.

Step 6:
Let’s write a method to check for the first 3 rules.

private boolean validateRuleNumber123(Transaction tx) {


HashMap<UTXO, Boolean > usedUTXO = new HashMap<UTXO, Boolean>();

for(int i = 0; i < tx.numInputs(); i++){


Transaction.Input input = tx.getInput(i);
if (input == null) {
return false;
}
UTXO utxo = new UTXO(input.prevTxHash, input.outputIndex);
//checks rule 1
//code

//checks rule 2
//code

//checks rule 3
//code

usedUTXO.put(utxo, true);
//saving this value for rule 5
this.totalInputSum += previousTxOutput.value;
}

//return some value


}

Step 7:
Now, we should validate rules 4 and 5.
private boolean validateRuleNumber45(Transaction tx) {
double outputSum = 0;
for (int i = 0; i < tx.numOutputs(); i++) {
Transaction.Output output = tx.getOutput(i);
if (output == null) {
//return what value?
}
if (output.value < 0) {
//return what value?
}

outputSum += output.value;
}
return this.totalInputSum >= outputSum;
}

Step 8:
Finally, let’s complete the last method.
/** Handles each epoch by receiving an unordered array of proposed
* transactions, checking each transaction for correctness,
* returning a mutually valid array of accepted transactions,
* and updating the current UTXO pool as appropriate.
*/
public Transaction[] handleTxs (Transaction[] possibleTxs){
//code
}

You might also like