# Cryptographic hash functions and Cryptocurrency ## Hash properties - Collision-free - Hiding - Puzzle-friendly About the same as [Properties of hash function](/Lq9U6xg3RzuSvfGOznxM4w) ## Hash function used in Bitcoin - SHA-256 ![](https://i.imgur.com/EHbJgjP.png) ## Data structure with hash pointers - Tamper-evident log ![](https://i.imgur.com/9Dj908Y.png) - Merkel tree ![](https://i.imgur.com/xE86UaJ.png) - proving membership: $O(log\ n)$ time - ![](https://i.imgur.com/Ql1XYEF.png) - variant: sorted Merkel tree - prove non-membership in $O(log\ n)$ - show items before, after missing one ## API for digital signature $(sk, pk):=generateKeys(keysize)$ > sk: private (secret) key > pk: public key > $sig:=sign(sk, message)$ $isValid=verify(pk, message, sig)$ ## Practical digital signature - Bitcoin uses *ECDSA* standard - Elliptic Curve Digital Signature Algorithm ## Public key == identity A address that sees $sig$ and can say $verify(pk, msg, sig) == true$ must have a matching $sk$ ## First try: GoofyCoin ![](https://i.imgur.com/WJJodfg.jpg) - Simple but can't prevent ***double spending attack*** ![](https://i.imgur.com/KGyD0Ci.png) ## Second try: ScroogeCoin - Every transaction has a pointer to all history - Double spending doesn't work here, since we can look into the history and figure out ![](https://i.imgur.com/BYMKTSr.jpg) ### PayCoins transaction #### Conditions of a valid PayCoins transaction - cousumed coins are valid - not already consumed - total vale out == total value in - signed by owners of all consumed coins ![](https://i.imgur.com/KwJla8z.jpg) #### Immutable coins - Coins can't be transfered, subdivided, or combined - But you can get the same effects with transactions