OP_HASH160 pops the public key from stack after hashing it?

0

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.

John Smith

Posted 2017-07-31T08:13:56.357

Reputation: 261

Answers

0

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

Pieter Wuille

Posted 2017-07-31T08:13:56.357

Reputation: 54 032

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

amaclin

Posted 2017-07-31T08:13:56.357

Reputation: 5 763

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

pebwindkraft

Posted 2017-07-31T08:13:56.357

Reputation: 4 568