Private keys work on the basis of proving that you own the one and only privatekkey and the messages you write with it are indeed your own. But in blockchain, there is nothing hidden so the blockchain cannot verify using a private key. So how does it do that? How does it ensure the transaction uses the right key?
For each transaction, there are outputs created. These output have specific requirements for it to be spendable. For those in P2PKH, the requirement is for the public key to be able to be hashed to the address.
For every transaction, it contains both the public key and the signature. The nodes can verify that the public key can hash to the address and the signature is signed by that public key.
Even straight up brute forcing it, it's still possible right? Just not practical because it would take ages or tonnes of computer power.
You can probably crack address but not to the extent of forging transactions. Bitcoin is designed in such a way that every transaction is linked until the block which has generated it. Nodes do not trust anyone but themselves.
For a transaction to be valid,
- It has to conform to the protocol rules.
- The inputs can be referenced to a previous transaction.
- The signature on it is valid.
If you can't fulfill any of this, you can't forge transactions.
Just out of curiosity though, if you poured the 1000s of THashes of computing involved in mining to crack a private key, how long do you reckon it would take?
Possibly way after the sun dies. Generating addresses aren't measured in the terahashes. They are measured in the number of keys per second. Current ASIC cannot work to crack private keys.
Also, what would happen if you flooded the system (neighboring bitcoin nodes) with 1000s of random guesses?
Sorry for the tonnes of questions...
Random guesses? After several invalid transactions, they would've banned you.
But I'm still getting my head around the verification process for checking signatures. How can everyone verify the signature without SIGNIFICANTLY reducing the number of guesses required to find the private key?
Public key cryptography allows anyone to verify the validity of a signature using only a public key.
Wouldn't that slow down the other nodes? couldn't you just write all the false transactions and have other nodes verify them?
Honestly, no. Bitcoin Core obviously doesn't let you spam them forever and the resources it takes isn't that much either.