# the bitcoin algorithm
<!-- Put the link to this slide here so people can follow -->
slide: https://hackmd.io/@amirulabu/thebitcoinalgorithm
---
## Who am I?
- a guy
- bitcoin hodler (a story for another time)
---
# what is bitcoin?
---
- bitcoin: virtual currency
- Bitcoin: decentralised network and systems that manages bitcoin
- decentralised ledger
- transactions linked by blockchain
- incentive for people maintaining the network
---
# what is a ledger?
---

---

---
# what is blockchain?
---
a system that link blocks of data using their hash
Hashes are cryptographic codes created by special algorithms.
demo 1: https://xorbin.com/tools/sha256-hash-calculator
---
```
data: Epstein didn't kill himself
previous hash: 0000
```
## block 1
---
```
data: Area 51 contains cat girls
previous hash: d11f69bfc9457b4b768511c73fec8e3fd240aec47e36088ed4416dbc86554505
```
## block 2
---
```
data: Antarctica is where they store the aliens
previous hash:
9c6bab6c7bc1f7f63a2631eab2caae78f9df0eed0d5f2dbe123649454872f4bf
```
## block 3
---

---

---

---
# what is a bitcoin mining?
---
- a way to incentivise people maintaining the network
---
remember this?
```
data: Antarctica is where they store the aliens
previous hash:
9c6bab6c7bc1f7f63a2631eab2caae78f9df0eed0d5f2dbe123649454872f4bf
```
---
now you need to answer a quiz to submit the block
```
data: Antarctica is where they store the aliens
quiz-answer: 12312
previous hash:
9c6bab6c7bc1f7f63a2631eab2caae78f9df0eed0d5f2dbe123649454872f4bf
```
---
# what is a SHA-256?
---
- A one-way hash can be generated from any piece of data, but the data cannot be generated from the hash.
<a href="https://imgbb.com/"><img src="https://i.ibb.co/3cCfdrP/9604874-orig.jpg" alt="9604874-orig" border="0"></a>
---
# what is exactly bitcoin mining?
---
to answer the quiz, is to find what alphanumeric combination to produce the hash with n-zeros in front
demo 2: https://xorbin.com/tools/sha256-hash-calculator
```
data: Antarctica is where they store the aliens
quiz-answer: 12312
previous hash:
9c6bab6c7bc1f7f63a2631eab2caae78f9df0eed0d5f2dbe123649454872f4bf
```
---
- https://analysis.null.place/how-do-the-bitcoin-mining-algorithms-work/#form4
---
# what are other applications using cryptographic hash function?
---

---
# how is password stored in the database?
---
demo 3: https://xorbin.com/tools/sha256-hash-calculator
```
hunter2
```
---
# why can't we store the password as-is?
---
- in case that a person gets access to the database, they can get the password
https://security.blogoverflow.com/2011/11/why-passwords-should-be-hashed/
---
# end 🎉
---
### Wrap up
- bitcoin uses cryptographic hash function as a way to make transactions immutable
- bitcoin also uses cryptographic hash function as a way to identify people doing work algorithmically
- saving password in a database also uses cryptographic hash function to encrypt password
---
### Thank you! :sailboat:
---
# bonus: why SHA-256 is not preferred for passwords anymore
---
https://security.stackexchange.com/questions/133239/what-is-the-specific-reason-to-prefer-bcrypt-or-pbkdf2-over-sha256-crypt-in-pass
{"metaMigratedAt":"2023-06-15T14:27:46.847Z","metaMigratedFrom":"YAML","title":"the bitcoin algorithm","breaks":false,"description":"View the slide with \"Slide Mode\".","contributors":"[{\"id\":\"a5f8019e-0673-4dcc-9de7-50a212465f06\",\"add\":7409,\"del\":3622}]"}