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.

0

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

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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