<p>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.</p>

CC BY-SA 3.0
2017-07-10T06:19:49.063Z
2017-07-10T06:19:49.063Z
Ava Chow
<p>How does Bitcoin prevent replay-attacks for P2PKH transactions?</p>

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

<pre><code>scriptPubKey: OP_DUP OP_HASH160 &lt;pubKeyHash&gt; OP_EQUALVERIFY OP_CHECKSIG
scriptSig: &lt;sig&gt; &lt;pubKey&gt;
</code></pre>

<p>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.</p>

<p>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?</p>

CC BY-SA 3.0
2017-07-11T05:42:58.063Z
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
<replay-attack><p2pkh>
How does Bitcoin prevent replay-attacks?
user2762996
# How does Bitcoin prevent replay-attacks?

(Asked by: username_0 on 2017-07-09)

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?

**Tags:** replay-attack, p2pkh

> **Comments:**
> **username_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. ;)  

---

## 1 answers

### Answer by username_2 on 2017-07-10. Score: 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.


---

