<p>Yes, every opcode that inspects an element on the stack also pops it (OP_SIZE being an exception).</p>

CC BY-SA 3.0
2017-07-31T08:17:20.370Z
2017-07-31T08:17:20.370Z
Pieter Wuille
<p>e.g. the script for a P2SH is:</p>

<pre><code>OP_HASH160, P2SHAddress, OP_EQUAL
</code></pre>

<p>if whatever was on the stack, is hashed (OP_HASH160), the result of this operation is pushed back on the stack. Then the top two items on the stack are the result of the OP160 operation, and the P2SHAddress. These two are then compared. 
A good explanation is online here in Andreas' book "Mastering Bitcoin": <a href="http://chimera.labs.oreilly.com/books/1234000001802/ch05.html#p2sh" rel="nofollow noreferrer">http://chimera.labs.oreilly.com/books/1234000001802/ch05.html#p2sh</a></p>

CC BY-SA 3.0
2017-07-31T08:56:09.587Z
2017-07-31T08:56:09.587Z
pebwindkraft
<p>OP_HASH160 pops an item from the stack (it can be a public key or any arbitrary array of bytes), hashes it and pushes the result to the stack</p>

CC BY-SA 3.0
2017-07-31T08:17:43.687Z
2017-07-31T08:17:43.687Z
amaclin
<p>This guide <a href="https://bitcoin.org/en/developer-guide#p2pkh-script-validation" rel="nofollow noreferrer">https://bitcoin.org/en/developer-guide#p2pkh-script-validation</a> mentions
"The operation executed next, OP_HASH160, pushes onto the stack a hash of the data currently on top of it—in this case, Bob’s public key. This creates a hash of Bob’s public key."</p>

<p>Does the HASH160 operation pops the duplicated public key? If not, why keeping a duplication on the stack? what's the point?</p>

<p>Thanks.</p>

<p2pkh>
OP_HASH160 pops the public key from stack after hashing it?
John Smith
# OP_HASH160 pops the public key from stack after hashing it?

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

This guide <https://bitcoin.org/en/developer-guide#p2pkh-script-validation> mentions
"The operation executed next, OP\_HASH160, pushes onto the stack a hash of the data currently on top of it—in this case, Bob’s public key. This creates a hash of Bob’s public key."

Does the HASH160 operation pops the duplicated public key? If not, why keeping a duplication on the stack? what's the point?

Thanks.

**Tags:** p2pkh


---

## 3 answers

### Answer by username_1 on 2017-07-31. Score: 0 | Accepted answer

Yes, every opcode that inspects an element on the stack also pops it (OP\_SIZE being an exception).


---

### Answer by username_2 on 2017-07-31. Score: 1

e.g. the script for a P2SH is:

```
OP_HASH160, P2SHAddress, OP_EQUAL

```

if whatever was on the stack, is hashed (OP\_HASH160), the result of this operation is pushed back on the stack. Then the top two items on the stack are the result of the OP160 operation, and the P2SHAddress. These two are then compared.
A good explanation is online here in Andreas' book "Mastering Bitcoin": <http://chimera.labs.oreilly.com/books/1234000001802/ch05.html#p2sh>


---

### Answer by username_3 on 2017-07-31. Score: 1

OP\_HASH160 pops an item from the stack (it can be a public key or any arbitrary array of bytes), hashes it and pushes the result to the stack


---

