Bitcoin Forum
May 11, 2024, 08:19:29 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 160 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.
1715458769
Hero Member
*
Offline Offline

Posts: 1715458769

View Profile Personal Message (Offline)

Ignore
1715458769
Reply with quote  #2

1715458769
Report to moderator
I HATE TABLES I HATE TABLES I HA(╯°□°)╯︵ ┻━┻ TABLES I HATE TABLES I HATE TABLES
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715458769
Hero Member
*
Offline Offline

Posts: 1715458769

View Profile Personal Message (Offline)

Ignore
1715458769
Reply with quote  #2

1715458769
Report to moderator
1715458769
Hero Member
*
Offline Offline

Posts: 1715458769

View Profile Personal Message (Offline)

Ignore
1715458769
Reply with quote  #2

1715458769
Report to moderator
pooya87
Legendary
*
Offline Offline

Activity: 3444
Merit: 10558



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!