Block Chain
Block Chain
a) A symmetric-key cryptosystem consists of three functions: a key generator GG, an encryption function
EE, and a decryption function DD. For any pair of users, say Alice (A) and Bob (B), GG takes as input a
string of random bits and produces as output a shared key KABK_{AB}. Either Alice or Bob can take a
plaintext message xx and produce a ciphertext message y=E(x,KAB)y = E(x, K_{AB}). The ciphertext yy
can be sent over an insecure channel, and the recipient can recover x=D(y,KAB)x = D(y, K_{AB}).
Answer:
i. Basic requirements for security:
1. Key Confidentiality: The shared key KABK_{AB} must remain secret between Alice and Bob to
prevent unauthorized access.
2. Message Confidentiality: The ciphertext y=E(x,KAB)y = E(x, K_{AB}) should not reveal any
information about the plaintext xx without the key.
3. Message Integrity: The system must ensure that the decrypted ciphertext D(y,KAB)D(y, K_{AB})
matches the original plaintext xx, ensuring no tampering during transmission.
1. Scalability Issues: Managing unique keys for every pair of communicating entities is impractical for
large-scale systems.
2. Key Distribution Problem: Securely sharing and managing keys over insecure channels is
challenging.
3. No Non-repudiation: Since both parties share the same key, it’s impossible to prove who sent a
particular message.
b) List and explain factors that gas usage depends on in transactions and how is the transaction fee
calculated?
Answer:
Factors affecting gas usage:
2. Storage Requirements: Writing data to the blockchain consumes more gas than reading it.
3. Network Congestion: High traffic can increase the gas price due to supply and demand dynamics.
Transaction Fee=Gas Used×Gas Price\text{Transaction Fee} = \text{Gas Used} \times \text{Gas Price}
2. Efficient Data Sharing: Facilitates real-time access to healthcare data among authorized
stakeholders.
d) A liquidity pool operated by an automated market maker contains 3000 Ether (ETH) and 9,000,000
Tether (USDT). You want to exchange 50,000 USDT into ETH. How many ETH can you take out of the
pool?
Answer:
Using the constant product formula x⋅y=kx \cdot y = k:
e) Identify two major properties of a blockchain network and state their properties.
Answer:
1. Decentralization: The system is distributed across nodes, eliminating the need for a central
authority.
2. Immutability: Data once written cannot be altered, ensuring the integrity of the blockchain.
while (uint256(sha3(x)) != y) {
x++;
Assume you know an xx and yy for which this function never terminates. Explain how a malicious miner
can use this function to waste other miners' resources without spending any of its own resources.
Answer:
A malicious miner can run the wasted function with values of xx and yy that never satisfy the condition
sha3(x)=ysha3(x) = y. This creates an infinite loop, consuming computational resources of competing
miners while the malicious miner focuses on executing valid transactions or solving the block, giving them
an unfair advantage.
a) Cryptocurrencies like Bitcoin use wallets. Explain how a wallet works related to public and private
keys.
Answer:
A cryptocurrency wallet consists of a private key and a public key.
The private key is used to sign transactions, proving ownership and authorization to spend the
associated cryptocurrency.
The public key is derived from the private key and is used to generate wallet addresses that others
can use to send funds.
Transactions are verified on the blockchain using the public key without exposing the private key.
Answer:
2. Healthcare
3. Voting Systems
c) Create a Merkle tree below for the following transactions: A, B, C, D, E, F, G. Show the entire tree from
the transaction level and all leaf/hash levels until you are at the root.
Answer:
2. Intermediate Nodes:
o Level 1: H1=Hash(Hash(A)+Hash(B)),H2=Hash(Hash(C)+Hash(D)),H3=Hash(Hash(E)
+Hash(F))H_1 = Hash(Hash(A) + Hash(B)), H_2 = Hash(Hash(C) + Hash(D)), H_3 =
Hash(Hash(E) + Hash(F))
3a) Your company is considering blockchain technology to support a collaborative energy production
organization.
Permissioned Blockchain: Ensures only verified participants (e.g., energy producers and
consumers) can interact, offering better scalability and privacy.
Proof of Authority (PoA): Ensures quick and energy-efficient transaction validation by trusted
nodes, suitable for private energy networks.
Stakeholders: Energy producers, consumers, IoT device manufacturers, grid operators, regulators.
Diagram: Illustrates interactions such as energy transactions, data flow from IoT devices, and
payments.
iv. Why is the difficulty of Bitcoin's proof of work set to ten minutes? What would go wrong if changed
to 12 seconds?
Reason: A 10-minute interval balances the trade-off between fast confirmation and network
security.
Problem with 12 seconds: Frequent block generation increases stale blocks and forks, reducing
network stability and security.
Answer:
1. Block Header
3. Transaction List
4. Merkle Root
c) Explain three attacks resulting from a 51% attack.
d) Explain why Paxos uses a majority vote among 2f+12f + 1 nodes to ensure consistency.
A majority ensures at least one overlapping node between conflicting views, preserving agreement
and preventing inconsistencies.
Answer:
Answer:
Definition: A Merkle tree is a binary tree where each leaf node represents a transaction hash, and
non-leaf nodes represent the combined hash of their child nodes.
Role in Blockchain:
o Reduces the amount of data needed for validation by storing only the root hash.
Answer:
The Merkle root is the topmost hash of a Merkle tree, summarizing all transactions in a block. It ensures
data integrity; any change in the transaction data will alter the Merkle root, making tampering detectable.
3. Other nodes verify the solution and add the block to their chain.
Answer:
Smart contracts are self-executing programs stored on the blockchain. They execute predefined actions
automatically when certain conditions are met.
Uses:
c) Provide three reasons why blockchain is an improvement to the current system of data security and
transfer.
Answer:
Answer:
Stakeholders vote to elect a small group of trusted nodes to validate transactions, making the
process faster and more energy-efficient.
ii. Proof-of-Stake (PoS)
Validators are chosen based on the number of coins they hold (stake). It is energy-efficient
compared to PoW.
MD5 is a cryptographic hash function producing a 128-bit hash value. While fast, it is now
considered insecure due to vulnerabilities in collision resistance.
Answer:
class Blockchain:
def __init__(self):
self.chain = []
self.generate_genesis_block()
def generate_genesis_block(self):
previous_block_hash = self.last_block.block_hash
self.chain.append(GeekCoinBlock(previous_block_hash, transaction_list))
def display_chain(self):
for i in range(len(self.chain)):
@property
def last_block(self):
return self.chain[-1]
i. self.chain
ii. generate_genesis_block
Creates the first block in the blockchain with a placeholder value for previous hash and predefined
data.
iii. create_block_from_transaction
Generates a new block using the previous block's hash and a list of transactions.
iv. display_chain
d) List any three costs involved with implementing a blockchain solution within an organization.
Answer:
2. Development Costs: Building and testing smart contracts and blockchain applications.
a) What does the gas usage in a transaction depend on and how is the transaction fee calculated? (3
Marks)
Answer:
1. Complexity of the Operations: Simple operations like transfers require less gas, while
complex operations like loops or storing data require more.
2. Storage Costs: Writing or updating storage on the blockchain consumes more gas than
reading data.
Transaction Fee=Gas Used×Gas Price\text{Transaction Fee} = \text{Gas Used} \times \text{Gas Price}
b) Explain what constitutes a blockchain network, including a main property of that network. (5 Marks)
Answer:
A blockchain network consists of nodes (participants), a shared ledger, consensus algorithms, and smart
contracts for automation.
Main Property:
Decentralization: Data is distributed across all nodes, reducing the risk of single-point failures and
ensuring trust without intermediaries.
c) If I provide you with a SHA256-hash of my name, would it be in principle possible for you to verify
whether the hash is indeed the output of my name? (4 Marks)
Answer:
Yes, it is possible to verify the hash by applying the SHA256 algorithm to your name and comparing the
resulting hash to the one provided. However, without access to your name, verification is not feasible.
d) Identify two major benefits of using blockchain in supply chain management. (5 Marks)
Answer:
1. Traceability: Real-time tracking of goods and transparent recording of their journey across the
supply chain.
e) A liquidity pool operated by an automated market maker contains 3000 Ether (ETH) and 9,000,000
Tether (USDT). You want to exchange 50,000 USDT into ETH. How many ETH can you take out of the
pool? (3 Marks)
Answer:
Using the constant product formula:
x⋅y=kx \cdot y = k
where xx and yy are the reserves for ETH and USDT respectively, and kk is constant.
Initial state:
xnew=kynewx_{\text{new}} = \frac{k}{y_{\text{new}}}
f) Identify two major properties of a blockchain network and state their significance. (4 Marks)
Answer:
1. Immutability: Data recorded on the blockchain cannot be altered, ensuring trust and integrity.
// SPDX-License-Identifier: MIT
contract SimpleStorage {
uint storedData;
storedData = x;
return storedData;
Answer:
2. contract SimpleStorage
Defines the contract SimpleStorage.
3. uint storedData;
Declares an unsigned integer variable storedData to store data.
a) Identify some relatively any four areas where blockchain might have applications. (8 Marks)
Answer:
1. Healthcare: Secure storage and sharing of medical records and patient data.
2. Finance: Transparent and tamper-proof transaction records for banking and lending.
b) Define a Merkle hash tree and describe its role in blockchain. (3 Marks)
Answer:
A Merkle tree is a data structure that uses hashes to summarize and verify the integrity of large data sets
efficiently.
Role in Blockchain:
It organizes transactions into a tree structure, where the root hash (Merkle root) represents all
transactions in the block. This ensures data integrity and quick verification.
ii. Study the output of the Merkle tree graph below and interpret how the data structure works. (6
Marks)
Answer:
Pairs of hashes are combined and hashed recursively to form parent nodes.
This process continues until a single hash, the Merkle root, is obtained at the top.
Any modification in a transaction alters the corresponding hash, invalidating the Merkle root.
3a) The company you work for is considering introducing blockchain technology to support a
collaborative energy production organization.
i. Which blockchain will you use to support this project? (4 Marks)
Answer:
Reason: Ethereum supports smart contracts, enabling automation of energy exchanges and
payments without intermediaries.
ii. Choose a transaction validation strategy and justify your choice. (4 Marks)
Answer:
Justification: PoS consumes less energy and provides scalability, which is crucial for IoT devices
and frequent energy transactions.
iii. Identify the blockchain organization and potential new partners using the Deloitte stack. For each
partner, identify the value they provide. (4 Marks)
Answer:
3. IoT Device Manufacturers: Supply smart devices for monitoring energy production/consumption.
c) Why is the difficulty of the proof of work in Bitcoin set to 10 minutes? What would go wrong if it was
changed to 12 seconds? (4 Marks)
Answer:
10 Minutes: Ensures network stability by providing sufficient time for nodes to propagate new
blocks and reach consensus.
At 12 Seconds: Higher risks of orphaned blocks (conflicting versions of the blockchain) and
reduced network security due to rapid block creation.
2. Consensus Mechanism: Protocols like Proof of Work or Proof of Stake to achieve agreement
among nodes.
4. Smart Contracts: Automated programs that execute specific actions when conditions are met.
b) List the four fields on how you can identify a block. (4 Marks)
Answer:
1. Block Header: Contains metadata, including the previous block hash and timestamp.
d) Consensus algorithm like Byzantine Generals Problem. Why is it sufficient in Paxos to use a majority
vote among 2f + 1 nodes to ensure consistency? (5 Marks)
Answer:
In a system with f faulty nodes, 2f + 1 ensures that even if f nodes act maliciously, the remaining f + 1
honest nodes form a majority to reach consensus. This ensures both fault tolerance and consistency.
e) Ignoring packet headers, if the system uses 1KB chunks and uses the 160-bit SHA-1 hash to compute
chunk IDs, what is the minimum percentage of the size of the original data stream that this system could
send with completely redundant traffic? (4 Marks)
Answer:
Calculation:
a) Explain what constitutes a blockchain network, including a main property of that network. (4 Marks)
Answer:
A blockchain network consists of nodes that share, verify, and maintain a distributed ledger.
Main Property:
Immutability: Once data is written to a blockchain, it cannot be altered, ensuring trust and transparency.
b) List several differences between a public and a private blockchain. Provide examples. (6 Marks)
Answer:
1. Access:
3. Transaction Speed:
c) Identify two major benefits of using blockchain in supply chain management. (4 Marks)
Answer:
How It Works:
i. Using modulo 9 as the hash function h(x) = x mod 9, show the contents of the hash table after the
following values are stored: 5, 11, 25, 40, 23.
Answer:
5 mod 9 = 5
11 mod 9 = 2
25 mod 9 = 7
40 mod 9 = 4
23 mod 9 = 5
Hash Table:
Index 2: 11
Index 4: 40
Index 5: 5, 23
Index 7: 25
e) Identify two major properties of a blockchain network. And state their properties. (4 Marks)
Answer:
1. Decentralization: No single point of control; nodes maintain the network collectively.
14. What is the difference between a blockchain and a distributed ledger? (4 Marks)
Answer:
Blockchain: A specific type of distributed ledger that organizes data into blocks linked in a chain. It
uses cryptography to secure the data and typically operates with a consensus mechanism like
Proof of Work or Proof of Stake.
Distributed Ledger: A broader concept that refers to a decentralized database distributed across
multiple nodes. It may or may not use a blockchain structure.
1. Block Header: Contains metadata such as the previous block’s hash, timestamp, and nonce.
3. Hash: A unique identifier for the block generated using cryptographic hashing.
Roles:
17. What is the difference between Proof of Work (PoW) and Proof of Stake (PoS)? (6 Marks)
Answer:
Calculation:
Gas Price: The price users are willing to pay per gas unit (in Gwei).
20. What is the difference between a hard fork and a soft fork? (5 Marks)
Answer:
Hard Fork: A radical protocol change that is not backward compatible, creating two separate
blockchains (e.g., Bitcoin vs. Bitcoin Cash).
Soft Fork: A minor protocol change that is backward compatible, where non-upgraded nodes can
still process transactions under new rules.
Private Key: A confidential key used to sign transactions and access blockchain assets.
Public Key: A publicly shared key used to verify the signature or encrypt data.
23. What are the challenges in integrating blockchain with IoT? (6 Marks)
Answer:
3. Energy Consumption: IoT devices often have limited energy, incompatible with energy-intensive
blockchain processes.
4. Interoperability: Ensuring seamless communication between IoT devices and blockchain networks.