Bit by Bitcoin

Watch the video below on how bitcoin, a “cryptocurrency,” works, up through 00:21:54.

  1. (2 points.) What, in your own words, is a blockchain? How does bitcoin use a blockchain?

  2. (2 points.) What, in your own words, is a cryptographic hash function?

  3. (2 points.) Consider the hash function, below, which calls ord. Assume that s is a string of length 1 or greater.

     def hash(s):
         return ord(s[0]) % 50
    

    Why is this implementation of hash unsuitable as a cryptographic hash function?

  1. (4 points.) Although a block in an actual blockchain represents multiple transactions, assume for simplicity that a block represents only one and that each block thus has, among other fields:
    • a unique identifier for the transaction itself,
    • a unique identifier for the transaction’s sender,
    • a unique identifier for the transaction’s recipient,
    • the transaction’s amount,
    • a digital signature from the sender, and
    • a proof of work.

    Suppose we have a type blockchain defined as

     typedef block *blockchain;
    

    where a blockchain is a pointer to a value of type block.

    Implement a type called block in a manner consistent with the video and specifications above. Assume that digest is a type with which you can represent SHA256 digests.