1
0
mirror of https://github.com/bitcoinbook/bitcoinbook synced 2025-03-24 19:35:43 +00:00

Merge pull request #497 from theStack/twofewerops

script opcode count IF vs. VERIFY: diff is two ops
This commit is contained in:
Andreas M. Antonopoulos 2018-02-14 14:56:16 -06:00 committed by GitHub
commit 678f2f3c2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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.