Bitcoin Forum
July 02, 2024, 08:27:25 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Question about the lock script  (Read 100 times)
coinesel (OP)
Newbie
*
Offline Offline

Activity: 3
Merit: 0


View Profile
December 08, 2022, 06:57:27 AM
 #1

Hi there,

usually I see that lock script: "OP_DUP OP_HASH160 <key> OP_EQUALVERIFY OP_CHECKSIG" and the type of the transaction is "pubkeyhash"

Now I have this lock script: "OP_HASH160 <key> OP_EQUAL" and the transaction type is "scripthash".


How is it possible to spend this UTXO?

Thanks a lot!
pooya87
Legendary
*
Offline Offline

Activity: 3500
Merit: 10695



View Profile
December 08, 2022, 08:16:24 AM
 #2

usually I see that lock script: "OP_DUP OP_HASH160 <key> OP_EQUALVERIFY OP_CHECKSIG" and the type of the transaction is "pubkeyhash"
It is not a "key" in that script it is a hash or more specifically a 160-bit hash. It is also called pay to pubkey hash or P2PKH for short.

Quote
Now I have this lock script: "OP_HASH160 <key> OP_EQUAL" and the transaction type is "scripthash".
Same as above it is a hash not a key and it is called pay to script hash or P2SH for short.

Quote
How is it possible to spend this UTXO?
P2SH scripts are a special case that were added many years ago through a soft fork that is explained in BIP-16[1]. The way these scripts are evaluated is a two step process.
First step is what is normally done in any other script (run signature script then run pubkey script) but a copy of the top stack element before running the pubkey (or locking) script is stored for next step.
Second step is evaluating that item we duplicated before (the top stack element) as a script called Redeem Script. Then run that script too using the existing items in the stack the rest is the same (eg. push some data to the stack, pop data, run CheckSig ops, etc.).

Keep in mind that the Redeem Script can be anything from a simple OP_TRUE to complex nested conditionals with locktimes and the common multi-sig scripts with multiple public keys inside.

[1] https://github.com/bitcoin/bips/blob/master/bip-0016.mediawiki

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
baro77
Member
**
Offline Offline

Activity: 90
Merit: 91


View Profile WWW
December 08, 2022, 11:04:31 AM
 #3

How is it possible to spend this UTXO?
Thanks a lot!

Check if this infographic about simplest locking/unlocking script can help you:
https://github.com/baro77/btcUnlockingLockingScriptCS/raw/master/(Un)lockingScriptsCheatsheet20190911.pdf

coinesel (OP)
Newbie
*
Offline Offline

Activity: 3
Merit: 0


View Profile
December 08, 2022, 12:59:40 PM
 #4

Great! That was very helpful. Thanks a lot!!
NotATether
Legendary
*
Offline Offline

Activity: 1652
Merit: 6937


In memory of o_e_l_e_o


View Profile WWW
December 08, 2022, 05:53:30 PM
 #5

Now I have this lock script: "OP_HASH160 <key> OP_EQUAL" and the transaction type is "scripthash".

How is it possible to spend this UTXO?

You would have to put the public key in the stack and the hash of that key in the script at the part that says <key>.

It's the same as the first, conventional script you posted, but it doesn't verify the signature, which is a bad idea.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
DannyHamilton
Legendary
*
Offline Offline

Activity: 3430
Merit: 4681



View Profile
December 08, 2022, 11:56:51 PM
 #6

It's the same as the first, conventional script you posted, but it doesn't verify the signature, which is a bad idea.

That doesn't sound right.  Isn't this a P2SH output?

If it is P2SH, then both the locking script AND the unlocking script are provided by the spender at the time that the output is spent.  While it is possible that the locking script might not require a signature (it's impossible to know just from the hash, you'd have to see the actual script to know), it's FAR more common that the locking script will be a typical signature-requiring script (most often segWit).
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!