2

How does Bitcoin prevent replay-attacks for P2PKH transactions?

As far as I understand, when a transaction is made to pay bitcoins to another account, the P2PKH script is used.

scriptPubKey: OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG
scriptSig: <sig> <pubKey>

Now, even though I may not know what the private key of the person who sends the scriptSig is, I still know how a valid signature from him looks for this very transaction.

So, if I simply copy the transaction with the same data, the check for the signature should still be all valid. So, if someone pays me coins, what prevents me sending the same transaction over and over again, effectively draining all his coins?

1
  • I agree that they're duplicates, but to be honest, I'd rather close them in the other direction, as this question here is much better researched. ;)
    – Murch
    Commented Jul 11, 2017 at 5:42

1 Answer 1

3

A transaction contains a reference to the output that it is spending from. So all you would be doing is just rebroadcasting the same transaction over and over again. Since transactions are identified by the hash of the transaction, the transaction you are rebroadcasting is exactly the same thing as the one already broadcast, and all nodes will treat it as the same transaction, one that they have already seen.

Not the answer you're looking for? Browse other questions tagged or ask your own question.