Live data from Hacker News

A peek under Bitcoin’s hood: Writing a client that can create a transaction

samlewis.me

11–20 of 67 posts

Re: A peek under Bitcoin’s hood: Writing a client that can create a transaction

#11

Can someone explain why bitcoin adresses can be created (offline) without blockchain-validation for duplicates? Even if the chances are very small I mean...like....gone is gone...no bank to call for a false transaction.

https://bitcoin.stackexchange.com/questions/22/is-it-possibl...

doesn't answer my question.

(accepted answer includes) „...It may be "theoretically" possible...“

Re: A peek under Bitcoin’s hood: Writing a client that can create a transaction

#12

Can someone explain why bitcoin adresses can be created (offline) without blockchain-validation for duplicates? Even if the chances are very small I mean...like....gone is gone...no bank to call for a false transaction.

Bitcoin addresses are basically a public key, so you can generate them offline the same way you can generate pgp keys, openssl keys, SSH keys you use to access GitHub etc.

The chances of a collision are so astronomically low that our sun will probably run out of fuel and explode before two identical keys are generated.

Re: A peek under Bitcoin’s hood: Writing a client that can create a transaction

#13

Can someone explain why bitcoin adresses can be created (offline) without blockchain-validation for duplicates? Even if the chances are very small I mean...like....gone is gone...no bank to call for a false transaction.

Bitcoin addresses are basically a public key, so you can generate them offline the same way you can generate pgp keys, openssl keys, SSH keys you use to access GitHub etc. The chances of a collision are so astronomically low that our sun will probably run out of fuel and explode before two identical keys are generated.

With the comfort of a public blockchain at hand why not eliminate this case at address-creation time?

Re: A peek under Bitcoin’s hood: Writing a client that can create a transaction

#14

Can someone explain why bitcoin adresses can be created (offline) without blockchain-validation for duplicates? Even if the chances are very small I mean...like....gone is gone...no bank to call for a false transaction.

Addresses are created offline for scalability reasons, meaning that not having to interact with the blockchain is a feature, not a bug.

There are 2 levels of collision that are theoretically possible. The tldr is that both are really hard, way harder than mining itself, so you'd better spend your time mining that trying to find collisions in the address space.

The first level is that you can generate the same private key, i.e. guessing exactly 256 bit. Prob is 1/2^256.

The second level is that you find a collision in hashing the public key onto the address. Hash is a combination of sha256+rimemd160, but in fact it's a hash onto 160 bits, so the probability of finding a collision is 1/2^80 because of the birthday paradox.

When you generate a new address, you can certainly add an extra step and verifiy if it's used already in the blockchain. If you find a collision, though, please send it to me before discarding it :)

Re: A peek under Bitcoin’s hood: Writing a client that can create a transaction

#15

Earlier quoted context omitted.

Bitcoin addresses are basically a public key, so you can generate them offline the same way you can generate pgp keys, openssl keys, SSH keys you use to access GitHub etc. The chances of a collision are so astronomically low that our sun will probably run out of fuel and explode before two identical keys are generated.

With the comfort of a public blockchain at hand why not eliminate this case at address-creation time?

You could, but it's simply not necessary. I have not verified the numbers, but I think this answer gives a better idea of the scale we are talking about:

https://bitcoin.stackexchange.com/a/3205

Re: A peek under Bitcoin’s hood: Writing a client that can create a transaction

#16
This is an excellent writeup! If any readers are looking for an already-written and tested bitcoin client library and can use javascript, https://bitcoinjs.org/ is great. I wrapped a simple cli tool around the library to make the 'coindust' npm package to do simple operations with bitcoin addresses and public bitcoin APIs.

Re: A peek under Bitcoin’s hood: Writing a client that can create a transaction

#17

Earlier quoted context omitted.

Bitcoin addresses are basically a public key, so you can generate them offline the same way you can generate pgp keys, openssl keys, SSH keys you use to access GitHub etc. The chances of a collision are so astronomically low that our sun will probably run out of fuel and explode before two identical keys are generated.

With the comfort of a public blockchain at hand why not eliminate this case at address-creation time?

You clearly don't understand the scale, here.

Re: A peek under Bitcoin’s hood: Writing a client that can create a transaction

#18
I am actually really surprised it took a month for someone to swipe the BTC he sent to an address with a private key of 0xfacebeef. That could be found via an incremental search in under an hour of CPU search time on one computer.

I note that compressed public keys are not being used in these examples - it's highly recommended to use them, since they reduce transaction size and cost.

Regarding weak keys - there have been a lot of weak key generation techniques in bitcoin where hiding the public key won't do you any good.

Re: A peek under Bitcoin’s hood: Writing a client that can create a transaction

#19

Hi Sam, If you're reading the comments, can you do this treatment but for Ethereum and the smart contracts built on top of it? I find that your article gives a good explanation especially for beginner to understand from the code perspective.

FWIW, I was looking at eth code in the weekend and it's pretty accessible (I was looking at go -- I've read that eth python should be even more readable).

The address part is very similar, even simpler, than bitcoin. It's the same elliptic curve, same way to build private/public keys.

For the address, it uses a different hash function, Keccak256, and then it's just serialized in hex. Code here [1]. Pointers to key generation [2, 3].

[1] https://github.com/ethereum/go-ethereum/blob/release/1.6/cry...

[2] https://github.com/ethereum/go-ethereum/blob/release/1.6/acc...

[3] https://github.com/ethereum/go-ethereum/blob/release/1.6/acc...

Post reply on HN