Bitcoin Forum
May 04, 2024, 01:59:28 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Help with understanding Bitcoin script.  (Read 159 times)
evanlinjin (OP)
Newbie
*
Offline Offline

Activity: 2
Merit: 0


View Profile
August 30, 2020, 08:01:01 AM
 #1

I'm going through the book Mastering Bitcoin, and I have a query regarding the section on "Using Flow Control in Scripts".

So, there is an example of a redeem script as follows:

Code:
IF
  <Alice's PK> CHECKSIG
ELSE
  <Bob's PK> CHECKSIG
ENDIF

I'm wondering why it is structured in this manner, instead of the following:

Code:
IF
  <Alice's PK>
ELSE
  <Bob's PK>
ENDIF
CHECKSIG

Would the latter work? And if so, would it be the better version as it saves space by one opcode?

Thank you all in advance.
If you want to be a moderator, report many posts with accuracy. You will be noticed.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714831168
Hero Member
*
Offline Offline

Posts: 1714831168

View Profile Personal Message (Offline)

Ignore
1714831168
Reply with quote  #2

1714831168
Report to moderator
pooya87
Legendary
*
Offline Offline

Activity: 3444
Merit: 10546



View Profile
August 30, 2020, 09:06:37 AM
Merited by ABCbits (2), bob123 (2)
 #2

yes the second one works and essentially does the same thing as the first one but in a more efficient way. this example is probably like this to show how OP_IFs work otherwise there is a better way of defining this particular script which is using multi-sig.
Code:
1 <Alice's PK> <Bob's PK> 2 CHECMULTIKSIG

usually the conditional scripts like this are more complex and each expression could contain multiple pubkeys with a multi-sig OP or sometimes locktimes or other complications which has to be defined like the first script.
examples:
Code:
IF
  <Alice's PK> <Joe's PK> CHECMULTIKSIG
ELSE
  <Bob's PK> CHECKSIG
ENDIF
Code:
IF
  <somedatetimevalue> CheckLocktimeVerify DROP <Alice's PK> CHECKSIG
ELSE
  2 <Alice's PK> <Bob's PK> 2 CHECKMULTISIG
ENDIF

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
evanlinjin (OP)
Newbie
*
Offline Offline

Activity: 2
Merit: 0


View Profile
August 30, 2020, 10:19:08 AM
 #3

Awesome! Thank you for your help with clarifying Smiley
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!