Project Information
- Title: Building a Blockchain
- Tech: Rust
- Date: October 2020
- Code: Please reach out! Our professor asked that we keep the code private.
About
For an elective course on blockchain, my team of 4 built a blockchain in our language of choice. We chose Rust because we wanted to learn something new, but its strict memory safety, rules of ownership, and memory management made it quite a challenge. Looking back, coding in Go would've been a better choice.
The project itself involved keeping track of our ledger through a Merkle trie of blocks.
Each block contained:
- a hash of its data (with SHA256)
- a timestamp (for added "randomization")
- a difficulty target
- a nonce
- the data (bits from a specified file)
- a hash of the previous block
We had to manage difficulty with a bit of bit-twiddling. Since we wanted half of the maximum possible difficulty, we used 2^255 as our constant. (In reality, this was an array of 32 bits with the first bit as 0 and the rest as 255).
We also added functionality to serialize and store our blockchains. That way, our blockchains could be reloaded and validated after our code went offline.
My teammates were incredible at the bit-twiddling and actual implementation of this project. I was helpful with conceptualizing, but I wouldn't have gotten close to completing this project without them.