Readit News logoReadit News
msgilligan · 4 years ago
This is reminds me of Ken Shirriff's 2014 "Bitcoins the Hard Way" blog post that also used Python to build a Bitcoin transaction from scratch: http://www.righto.com/2014/02/bitcoins-hard-way-using-raw-bi...

(The subtitle of the blog is "Computer history, restoring vintage computers, IC reverse engineering, and whatever" and it is full of fascinating articles, several of which have been featured here on HN)

kens · 4 years ago
Thanks for the nice mention of my blog. I was wondering if anyone remembered my old bitcoin article :-)
arthurcolle · 4 years ago
It's a classic. You will be forever remembered for your timeless contributions to the collective consciousness!
audiometry · 4 years ago
The retro-computing stuff I see you guys doing on CuriousMarc's youtube channel blows my mind.
martindale · 4 years ago
I go back to it twice yearly
ngcc_hk · 4 years ago
We do
samlewis · 4 years ago
Shameless self-promotion but there's also this post I wrote in 2017 if anyone interested in a slightly different take (but a very similar write up to the OP): https://www.samlewis.me/2017/06/a-peek-under-bitcoins-hood/

Cool that this article implements the cryptography primitives, though!

e: Funnily, like the article, I also stored some BTC in a wallet and challenged people to (manually) take/steal it. At the time it was worth $10 USD.. now it's worth $123 USD!

westurner · 4 years ago
> The 'dumbcoin' jupyter notebook is also a good reference: "Dumbcoin - An educational python implementation of a bitcoin-like blockchain" https://nbviewer.jupyter.org/github/julienr/ipynb_playground...

https://github.com/yjjnls/awesome-blockchain#implementation-... and https://github.com/openblockchains/awesome-blockchains#pytho... list a few more ~"blockchain from scratch" [in Python] examples.

... FWIU, Ethereum has the better Python story. There was a reference implementation of Ethereum in Python? https://ethereum.org/en/developers/docs/programming-language...

NextHendrix · 4 years ago
Ken's blog is great, as well as his work with CuriousMarc. Here's when he tried mining bitcoins by hand.

http://www.righto.com/2014/09/mining-bitcoin-with-pencil-and...

animex · 4 years ago
No, the hardest way is using pencil and paper to mine a block :)

https://gizmodo.com/mining-bitcoin-with-pencil-and-paper-164...

alpb · 4 years ago
That's basically just a SHA256 hashing on pen and paper, doesn't have much to do with how bitcoin works.
rantwasp · 4 years ago
technically it said “the hard way” not “the hardest way”. also, computing a hash != mining. mining needs forming the block and computing the hash
Saig6 · 4 years ago
Same guy, Ken Shirriff
kozak · 4 years ago
I'm amazed that he has time for this kind of hobby work.
yellow_lead · 4 years ago
For others: Andrej Karpathy is the director of artificial intelligence and Autopilot Vision at Tesla.

Was on front page yesterday for a presentation on Tesla's Autopilot / Autonomous features: https://www.youtube.com/watch?v=NSDTZQdo6H8

meekaaku · 4 years ago
He was doing this kind of hobby work well before. I learnt solving Rubik's cube from his page[0].

[0] http://badmephisto.com

isaacimagine · 4 years ago
Woah, he's him? Same here!
perfect_wave · 4 years ago
I think I still have my printouts of the PLL algorithms somewhere…

Cool to learn this is the same guy.

andai · 4 years ago
"If you want something done quickly, give it to the busiest person."
delaaxe · 4 years ago
“I choose a lazy person to do a hard job. Because a lazy person will find an easy way to do it.”

― Bill Gates

christophergs · 4 years ago
A lot of busy, smart people have seemingly random side-projects. For example, Von Neumann:

"A professor of Byzantine history at Princeton once said that von Neumann had greater expertise in Byzantine history than he did" [1]

I don't know for sure why, but I think two possibilities are likely: (1) An extremely strong, natural intellectual curiosity and/or (2) Working on other things allows them to bring fresh ideas/insights to their "main" work, and in this sense is also rejuvenating.

[1] https://en.m.wikipedia.org/wiki/John_von_Neumann

natmaka · 4 years ago
From this point of view intelligence and memory may be just like muscle: the more you use (train) it, the more is grows (performs well).

Deleted Comment

spoonjim · 4 years ago
He’s smart enough to do the job he has because he has done this hobby work his whole life. See also Peter Norvig.
boringg · 4 years ago
Probably helps his boss is the "tecnoking" and cfo is the "master of coin".

Agreed though - impressive he has that kind of sidebar time or is so capable he doesn't need that much time to figure it out.

woah · 4 years ago
This stuff isn't that hard to figure out, given the number of specifications and tutorials already out there. What's impressive is the fact that he thought of a reasonably sized task, and (presumably) executed it efficiently and completely without getting stuck or distracted.
roystonvassey · 4 years ago
I think he’s a natural teacher - someone who loves sharing what he’s learnt with others - and it pleases to me know such people exist.

Everything I learned about deep neural networks, enough to apply it in a live product, was essentially all his notes, videos and exercises. And it’s all out there for free!

Thanks Andrej and keep doing cool stuff!

actinium226 · 4 years ago
I know right? I had to do a double take when I saw the link, and then had to click it to confirm it was that Karpathy
mlcrypto · 4 years ago
Maybe most of his job is hype & marketing without delivering much
ketamine__ · 4 years ago
FSD rollout has been delayed many times. He's underperforming.
toxik · 4 years ago
If you, like me, were curious about what the secret key 1 is on the mainnet, then here you are:

       1 1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH https://www.blockchain.com/btc/address/1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH
Some others:

       2 1cMh228HTCiwS8ZsaakH8A8wze1JR5ZsP  https://www.blockchain.com/btc/address/1cMh228HTCiwS8ZsaakH8A8wze1JR5ZsP
       3 1CUNEBjYrCn2y1SdiUMohaKUi4wpP326Lb https://www.blockchain.com/btc/address/1CUNEBjYrCn2y1SdiUMohaKUi4wpP326Lb
      42 1EMxdcJsfN5jwtZRVRvztDns1LgquGUTwi https://www.blockchain.com/btc/address/1EMxdcJsfN5jwtZRVRvztDns1LgquGUTwi
    1337 1DN76uuAUDY1DLxABD3JAyunhhAreJbCjT https://www.blockchain.com/btc/address/1DN76uuAUDY1DLxABD3JAyunhhAreJbCjT

zikduruqe · 4 years ago
If you are really curious, all the secrets are out there.

https://keys.lol/bitcoin/22486853933768128433444208678976948...

Finding one with a balance is the hard part.

delaaxe · 4 years ago
I was wondering if monitoring those starter addresses could be lucrative... They've transacted quite a lot
delaaxe · 4 years ago
Thanks, I was wondering the same but too lazy to figure out the addresses!
halotrope · 4 years ago
Implementing things from scratch is probably the ultimate test of thorough understanding. Chapeau! On another note I am amused that Mr. Karphathys name describes exactly what he is doing in his day job.
ijlx · 4 years ago
An excellent example of nominative determinism!
yerwhat01010 · 4 years ago
I don't get it. What does the word "Karpathy" mean or sound like?
davidhowlett · 4 years ago
"car path ey" sounds like a thing connected to finding paths for cars.
aaronax · 4 years ago
Car pathing, as in getting cars to drive along a path.
sombremesa · 4 years ago
Sometimes implementing things from scratch is the ultimate proof of thorough misunderstanding.
delaaxe · 4 years ago
That's very true, I don't know why you're getting downvoted
Cantinflas · 4 years ago
"NIST publishes recommendations on which ones to use, but people prefer to use other curves (like secp256k1) that are less likely to have backdoors built into them"

Does this make any sense? How is a curve going to have backdoors on it? Or he means a specific implementation? Or is this a joke? I'm confused

inter_netuser · 4 years ago
ECC NIST curves were proposed by the NSA. They have some unusual hand-selected constants that nobody quite understands exactly why they were selected.

https://miracl.com/blog/backdoors-in-nist-elliptic-curves/

“Working in collaboration with the NSA, NIST included three sets of recommended elliptic curves in FIPS 186-2 that were generated using the algorithms in the American National Standard (ANS) X9.62 standard and Institute of Electrical and Electronics Engineers (IEEE) P1363 standards.”: What exactly is NIST’s justification for making claims regarding the method that NSA used to generate these curves? The fact that a hash matches is publicly verifiable, but the distribution of “random” inputs is not. I have heard NSA employees claiming that the “random” inputs were actually generated as hashes of English text chosen (and later forgotten) by Jerry Solinas."

https://csrc.nist.gov/CSRC/media/Publications/sp/800-186/dra...

It's all quite public.

rkagerer · 4 years ago
https://services.math.duke.edu/~bray/Courses/89s-MOU/2016/Pa...

Quoting from the paper:

The standard given by the NIST gives a list of explicit parameters ... describing the elliptic curve behind the algorithm.

Examining the points P and Q here, it is obvious why cryptographers were suspicious of the Dual EC ... once the scalar k is known, it is a “simple matter to determine the secret internal state s of the pseudo-random bit generator” [6], by observing as few as 32 bytes of output.

It goes on to quote one of the NSA contractors who admitted that instead of being randomly chosen, "Q is (in essence) the public key for some random private key."

"It could also be generated like a(nother) canonical G, but NSA kyboshed this idea, and I was not allowed to publicly discuss it, just in case you may think of going there."

Straying from the prescribed points was discouraged, and NIST only provided FIPS validation to clients using the original P and Q.

More recently, GPRS was also shown to have been intentionally weakened - presumably to pass export controls - although in this case I think it was the algorithm and not a "cherry picked" curve: https://eprint.iacr.org/2021/819.pdf

scoofy · 4 years ago
Here's a computerphile video that explains it very simply: https://youtu.be/nybVFJVXbww
sundarurfriend · 4 years ago
> But then the Snowden leaks came along, and it looks even more suspicious.

> Money was changing hands between the NSA and companies, to have them install this as their standard for number generation. That's deeply suspicious.

(-from the video)

That's one piece of information I didn't know, and doesn't usually get mentioned in the discussions I've seen about this.

Cantinflas · 4 years ago
Thanks! Thanks to the other answers too. Amazing stuff!
stcredzero · 4 years ago
There's been a history of mathematical information used in cryptography produced by the NSA, for which it's later revealed, they had pre-developed an attack. Example: the s-boxes of DES.
foo92691 · 4 years ago
Except NSA strengthened DES against this not-yet-known-to-the-public attack (differential cryptanalysis).

https://en.wikipedia.org/wiki/Data_Encryption_Standard#NSA's...

https://en.wikipedia.org/wiki/Differential_cryptanalysis#His...

21eleven · 4 years ago
Looks like the exercise left to the reader has been completed: https://www.blockchain.com/btc-testnet/tx/182bf9202649ded3a6...
counternotions · 4 years ago
> steal my bitcoins from my 3rd identity wallet (mgh4VjZx5MpkHRis9mDsF2ZcKLdXoP3oQ4) to your own wallet ;) If done successfully, the 3rd wallet will show “Final Balance” of 0. At the time of writing this is 0.00095000 BTC, as we intended and expected.

Can someone explain how this was executed?

meowface · 4 years ago
Guessing it's because the private key is right in the code:

>secret_key3 = int.from_bytes(b"Andrej's Super Secret 3rd Wallet", 'big') # or just random.randrange(1, bitcoin_gen.n)

(Obviously a private key intended for actual use generally wouldn't just be some ASCII bytes of an English phrase and wouldn't be posted publicly. Though, of course, there have been instances of both...)

toxik · 4 years ago
You have the secret key, just sign away the txouts.
noxer · 4 years ago
0.00090000 BTC moved 0.00005000 BTC Fees Thats 5.55%

On the test net! On the real net it would be like 20% or more in fees.

bogota · 4 years ago
Fees are dictated by the user and the time they have for the transaction to take place. The fee could have been much lower.

I think we are well past the point of debating if bitcoin layer one will be used for day to day transactions however. A custodial service or lighting will have to be used for that. Additionally most people treat bitcoin closer to gold than a dollar currently.

sethgecko · 4 years ago
I’ve made something similar in order to learn how everything works and made it into a python library. Everything is in pure python with no dependencies, only std lib. I’ve implemented all the crypto stuff, address generation including HD, transaction serialization and even the bitcoin script. https://github.com/mcdallas/cryptotools
mountainboy · 4 years ago
respect.
jaycroft · 4 years ago
One little nitpick: the checksum error probability should be more like 9 nines. The checksum contains 4 bytes, not 4 bits, and so the false positive rate should be about 1 in 2^32, not 1 in 2^4.

"The raw 25 bytes of our address though contain 1 byte for a Version (the Bitcoin “main net” is b'\x00', while the Bitcoin “test net” uses b'\x6f'), then the 20 bytes from the hash digest, and finally 4 bytes for a checksum so we can throw an error with 1 - 1/2*4 = 93.75% probability in case a user messes up typing in their Bitcoin address into some textbox."