Practical Task Verifying Transaction Integrity Using Merkle
Practical Task Verifying Transaction Integrity Using Merkle
1. Guide participants through the process of constructing a Merkle tree using the
generated transactions.
2. Explain the concept of a Merkle tree and how it allows for efficient verification of
transaction integrity.
Step 4: Verifying Transaction Integrity
1. Once the verifier receives the transaction data, they should request the Merkle
proof from the prover.
2. The prover must generate the necessary Merkle proof for the transaction by
providing the path from the transaction leaf to the Merkle root.
1. The verifier should use the provided Merkle proof to verify the integrity of the
transaction.
2. Guide participants through the verification process, emphasizing how the Merkle
proof ensures that the transaction data has not been tampered with.
1. After each verification, rotate the roles of the participants, allowing everyone to act
as both verifier and prover.
2. Repeat steps 4 to 6 until all participants have had the opportunity to verify a
transaction's integrity.
Final Outcome
Participants should submit a report summarizing their experience in verifying transaction
integrity using Merkle trees. The report should include:
Additionally, participants should submit any code or scripts they developed during the
task, if applicable.
import hashlib
return tree
def get_root(self):
return self.tree[-1][0] if self.tree else None
def get_proof(self, transaction):
proof = []
index = self.transactions.index(transaction)
for level in self.tree[:-1]:
pair_index = index ^ 1
if pair_index < len(level):
proof.append(level[pair_index])
index //= 2
return proof
Example Usage
transactions = ["tx1", "tx2", "tx3", "tx4"] merkle_tree = MerkleTree(transactions)
Prover
transaction = "tx1" proof = merkle_tree.get_proof(transaction) root = merkle_tree.get_root()
Verifier
is_valid = merkle_tree.verify_proof(transaction, proof, root) print(f"Transaction is valid:
{is_valid}")