5 ms·
Any good resources for proof-of-work pseudo-code? I am having trouble wrapping my head around the implementation, not theory, of blockchain (ledger entry based
by gm-conspiracy 8y ago
Any good resources for proof-of-work pseudo-code?
I am having trouble wrapping my head around the implementation, not theory, of blockchain (ledger entry based on previously hashed ledger entry).
Like, how is the beginning of the ledger created/determined? Is that just a nonce/IV?
How is each entry calculated and/or verified based on the previous entry?
- foepys 8y agoYou create a so called Genesis block on which everything is based. Maybe include a timestamp (in case of Bitcoin a newspaper headline) to prove that you didn't pre-mine and you are done. The Genesis block is then distributed with each implementation for bootstrapping the verification process. You calculate the hash of each block (which includes the hash of the previous block) and check if it matches the hash in the next block. Each block also includes the difficulty of the network at the time to prevent mining more than x block per hour. The difficulty describes the "format" of the hash of each block, e.g. the hash in hex format needs to have 50 times 0 at the beginning.
- gm-conspiracy 8y agoThank you for the response. So, fundamentally, is everything just how many zeros prepend the "unique" hex string (for proof-of-work)?
- arcticbull 8y agoYep, that's it as far as I know. Rather, the difficulty requirement sets forth how many leading zeroes the hash of the data plus the variable parameter must have.
- luckycharms810 8y agoWorked through this about a year ago, but at the time I wrote it, it worked interchangeably with Bitcoin blocks. https://github.com/ltavag/blocks/blob/master/block.py#L68 https://github.com/ltavag/blocks/blob/master/block.py#L68