Skip to content

Commit

Permalink
Merge pull request bitcoinbook#497 from theStack/twofewerops
Browse files Browse the repository at this point in the history
script opcode count IF vs. VERIFY: diff is two ops
  • Loading branch information
aantonop authored Feb 14, 2018
2 parents bf4e865 + cf87bad commit 678f2f3
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion ch07.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ Bob's unlocking script is identical:
<Bob's Sig> <hash pre-image>
----

The script with +IF+ does the same thing as using an opcode with a +VERIFY+ suffix; they both operate as guard clauses. However, the +VERIFY+ construction is more efficient, using one fewer opcode.
The script with +IF+ does the same thing as using an opcode with a +VERIFY+ suffix; they both operate as guard clauses. However, the +VERIFY+ construction is more efficient, using two fewer opcodes.

So, when do we use +VERIFY+ and when do we use +IF+? If all we are trying to do is to attach a precondition (guard clause), then +VERIFY+ is better. If, however, we want to have more than one execution path (flow control), then we need an +IF...ELSE+ flow control clause.

Expand Down

0 comments on commit 678f2f3

Please sign in to comment.