Working out ownership from the blockchain

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Working out ownership from the blockchain

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. How can you work out how much digital currency a person owns using the blockchain?
A Add up everything they received and subtract everything they sent
B Look up one number stored in a bank account
2. In which order should you read the blockchain records to work out a balance?
A Time order, from the oldest record to the newest
B Any order, because the total is always different
3. Ali receives 10 coins and later sends 4 coins. What is his balance?
A 14 coins
B 6 coins
4. Mia has these records: receives 8, sends 3, receives 5. What is her balance?
A 10 coins
B 16 coins
5. Ana sends 5 coins to Ben, then Ben sends 2 coins to Cai. Assuming they started with nothing else, what is Ben's balance?
A 7 coins
B 3 coins

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1balance = received - sent AA record showing that Ava sent 5 coins to Ben, so Ava's balance goes down by 5 and Ben's goes up by 5
2Ava -> Ben: 5 coins BAva: 10 - 4 = 6, Ben: 4
3Read the records in time order from the first one, starting every balance at 0 and updating after each record CWork out how much digital currency a person owns by adding up what they received and subtracting what they sent
4Worked example: Ava is paid 10 coins and then sends 4 coins to Ben, so Ava owns 6 and Ben owns 4 DMoney sent was added instead of taken away. The balance should be 10 - 4 = 6.
5Ava received 10 and sent 4, so balance = 10 + 4 = 14 Efor each record in time order: update balances
6Ben's balance = only the coins he received, ignoring the coins he sent FIgnoring the records where Ben is the sender. You must count all records, both money in and money out.

Definitions

balance

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
balance ← _ FOR EACH record IN blockchain OUTPUT record.amount
2.
IF record.to = "Ava" THEN balance ← balance _ record.amount ENDIF
3.
IF record.____ = "Ava" THEN balance ← balance - record.amount ENDIF
4.
ava ← 10 - 4 ben ← 0 + 4 - 1 cara ← 0 + _
5.
SORT blockchain BY _________ FOR EACH record IN blockchain OUTPUT record.from, record.to

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A moneyIn ← 0
B moneyOut ← 10
C FOR EACH t IN chain
D IF t.to = name THEN
E moneyIn ← moneyIn + t.amt
Question 2
A SORT chain BY amount
B balance ← 0
C FOR EACH t IN chain
D IF t.to = name THEN
E balance ← balance + t.amt
Question 3
A ana ← 10; bob ← 0; cy ← 0
B ana ← ana - 4; bob ← bob - 4
C bob ← bob - 3; cy ← cy + 3
D OUTPUT ana, bob, cy
Question 4
A balance ← 0
B FOR EACH t IN chain
C IF t.from = name THEN
D balance ← balance + t.amt
E ENDIF
Question 5
A owner ← lastRecord.to
B FOR EACH t IN rest
C IF t.coin = coinId THEN
D owner ← t.to

Answer Key

Working out ownership from the blockchain
Section A: Quick Questions
Q1
A — Add up everything they received and subtract everything they sent
Q2
A — Time order, from the oldest record to the newest
Q3
B — 6 coins
Q4
A — 10 coins
Q5
B — 3 coins
Section B: Match the Pairs
Q1
balance = received - sent → Work out how much digital currency a person owns by adding up what they received and subtracting what they sent
Q2
Ava -> Ben: 5 coins → A record showing that Ava sent 5 coins to Ben, so Ava's balance goes down by 5 and Ben's goes up by 5
Q3
Read the records in time order from the first one, starting every balance at 0 and updating after each record → for each record in time order: update balances
Q4
Worked example: Ava is paid 10 coins and then sends 4 coins to Ben, so Ava owns 6 and Ben owns 4 → Ava: 10 - 4 = 6, Ben: 4
Q5
Ava received 10 and sent 4, so balance = 10 + 4 = 14 → Money sent was added instead of taken away. The balance should be 10 - 4 = 6.
Q6
Ben's balance = only the coins he received, ignoring the coins he sent → Ignoring the records where Ben is the sender. You must count all records, both money in and money out.
Section C: Definitions
Q1
balance — The amount of digital currency a person owns, found by adding up all the money they received and taking away all the money they sent in the blockchain records, in time order.
Section D: Fill in the Blanks
Q1
balance ← 0 FOR EACH record IN blockchain OUTPUT record.amount
Q2
IF record.to = "Ava" THEN balance ← balance + record.amount ENDIF
Q3
IF record.from = "Ava" THEN balance ← balance - record.amount ENDIF
Q4
ava ← 10 - 4 ben ← 0 + 4 - 1 cara ← 0 + 1
Q5
SORT blockchain BY timestamp FOR EACH record IN blockchain OUTPUT record.from, record.to
Section E: Spot the Error
Q1
B — Money sent must start at 0 before the records are added up. Starting at 10 would wrongly take 10 coins off the balance. It should be moneyOut ← 0.
Q2
A — The records must be read in time order, so they are sorted by time-stamp. Sorting by amount puts them in the wrong order. It should be SORT chain BY timestamp.
Q3
B — When Ana sends 4 coins to Bob, Ana loses 4 and Bob gains 4. Bob's balance must go up. It should be bob ← bob + 4.
Q4
D — This record is one where the person sent money, so the amount must be taken away. It should be balance ← balance - t.amt.
Q5
A — Tracing a coin starts at the first record in time order, which gives its first owner. Then each later record changes the owner. It should be owner ← firstRecord.to.