Crypto/Script/Opcode.pm

filter: Statementstmt 98.5% 612 / 621 Branchbran 68.4% 141 / 206 Conditioncond 78.8% 67 / 85 MC/DCmcdc 56.8% 29 / 51 Subroutinesub 98.2% 166 / 169 Podpod 50.0% 3 / 6 totaltotal 89.4% 1018 / 1138 CC 136 SCAR 16.3
CC
136
Cov
90%
__ANON__
29.7
__checksig
11.0
__ANON__
9.0
CRAP 5.1
« Crypto/Role/PSBT/Combiner.pm ↑ Summary Crypto/Role/Key.pm »
1 package Bitcoin::Crypto::Script::Opcode;
2 68 $Bitcoin::Crypto::Script::Opcode::VERSION = '4.006';
3 68 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 68 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 68 ▶use Mooish::Base -standard;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 68 ▶use Crypt::Digest::RIPEMD160 qw(ripemd160);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 68 ▶use Crypt::Digest::SHA256 qw(sha256);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 68 ▶use Crypt::Digest::SHA1 qw(sha1);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 68 ▶use List::Util qw(notall);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 68 ▶use Feature::Compat::Try;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 68 ▶use Bitcoin::Crypto qw(btc_pub);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 68 ▶use Bitcoin::Crypto::Constants qw(:script :sighash :transaction);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 68 ▶use Bitcoin::Crypto::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 68 ▶use Bitcoin::Crypto::Types -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 68 ▶use Bitcoin::Crypto::Util::Internal qw(hash160 hash256);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 use Bitcoin::Crypto::Helpers
20 68 ▶ qw(standard_push check_strict_public_key check_strict_der_signature die_no_trace check_sighash);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 68 ▶use Bitcoin::Crypto::Transaction::Input;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 68 has param 'name' => (
24 isa => Str,
25 );
26  
27 68 has param 'code' => (
28 isa => IntMaxBits [8],
29 );
30  
31 68 has param 'needs_transaction' => (
32 isa => Bool,
33 default => 0,
34 );
35  
36 68 has param 'pushop' => (
37 isa => Bool,
38 default => 0,
39 );
40  
41 68 has param 'sigop' => (
42 isa => Bool,
43 default => 0,
44 );
45  
46 # args for coderef are:
47 # - Bitcoin::Crypto::Script::Compiler instance
48 # - Compiled opcode (array from compile method in Runner)
49 # - Compilation context (hashref)
50 68 has option 'on_compilation' => (
51 isa => CodeRef,
52 );
53  
54 # args for coderef are:
55 # - Bitcoin::Crypto::Script::Runner instance
56 # (additional args are possible depending on opcode type)
57 68 has option 'runner' => (
58 isa => CodeRef,
59 predicate => 'implemented',
60 );
61  
62 sub _verify_stack
63 1002 ▶{
Subroutine _verify_stack: called CC=2 SCAR=7.2
64 1002 my $class = shift;
65 1002 my $runner = shift;
66  
67 1002 ▶ if (@{$runner->stack} + @{$runner->alt_stack} > SCRIPT_MAX_STACK_ELEMENTS) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$runner->stack;} + @{$runner->alt_stack;} > 1000) 0 1002 1002
68 0 $runner->_invalid_script('maximum stack size exceeded');
69 }
70 }
71  
72 sub _compile_OP_NUM
73 1548 ▶{
Subroutine _compile_OP_NUM: called CC=2 SCAR=6.9
74 1548 my ($class, $num) = @_;
75  
76 # avoid cyclical uses
77 1548 require Bitcoin::Crypto::Script::Runner;
78 1548 ▶ my $to_push = $num == 0 ? '' : Bitcoin::Crypto::Script::Runner->from_int($num);
Branch: 1 branch
BranchTrueFalseTotal
$num == 0 ? : 86 1462 1548
79  
80 720 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
81 720 my ($compiler, $op, $context) = @_;
82  
83 720 push @$op, $to_push;
84 1548 };
85 }
86  
87 sub _compile_OP_PUSH
88 6450 ▶{
Subroutine _compile_OP_PUSH: called CC=1 SCAR=0.0
89 6450 my ($class, $size) = @_;
90  
91 929 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
92 929 my ($compiler, $op, $context) = @_;
93  
94 929 push @$op, $compiler->_compile_data_push($context, $size);
95 929 $op->[1] .= $op->[2];
96 6450 };
97 }
98  
99 sub _compile_OP_PUSHDATA
100 258 ▶{
Subroutine _compile_OP_PUSHDATA: called CC=2 SCAR=6.9
101 258 my ($class, $length) = @_;
102  
103 258 state $formats = {
104 1 => 'C',
105 2 => 'v',
106 4 => 'V',
107 };
108  
109 258 ▶ my $format = $formats->{$length}
Condition50%1/2
$formats->{$length} // die("bad pushdata length")
l!l
2580
MC/DC0%0/1
$formats->{$length} // die("bad pushdata length")
$formats->{$length}
Truth table50%1/2
A
A= $formats->{$length}
Aresult
11
00
110 // die 'bad pushdata length';
111  
112 15 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
113 15 my ($compiler, $op, $context) = @_;
114  
115 15 my $raw_size = substr $context->{serialized}, $context->{offset}, $length;
116 15 my $size = unpack $format, $raw_size;
117 15 $context->{offset} += $length;
118  
119 15 push @$op, $compiler->_compile_data_push($context, $size);
120 14 $op->[1] .= $raw_size . $op->[2];
121 258 };
122 }
123  
124 sub _compile_OP_IF
125 172 ▶{
Subroutine _compile_OP_IF: called CC=1 SCAR=0.0
126 172 my ($class) = @_;
127  
128 32 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
129 32 my ($compiler, $op, $context) = @_;
130  
131 32 ▶ if ($context->{branch}{if}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($context->{"branch"}{"if"}) 8 24 32
132 8 my $prev = {%{$context->{branch}}};
133 $context->{branch} = {
134 8 previous => $prev,
135 };
136 }
137  
138 32 $context->{branch}{if} = $op;
139 32 $context->{branch}{execution_chain} = [$op];
140 172 };
141 }
142  
143 sub _compile_OP_ELSE
144 86 ▶{
Subroutine _compile_OP_ELSE: called CC=1 SCAR=0.0
145 86 my ($class) = @_;
146  
147 27 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
148 27 my ($compiler, $op, $context) = @_;
149  
150 $compiler->_invalid_script(
151 'OP_ELSE found but no previous OP_IF or OP_NOTIF'
152 27 ▶ ) if !$context->{branch}{if};
Branch: 1 branch
BranchTrueFalseTotal
unless $context->{"branch"}{"if"} 1 26 27
153  
154 # set up jump point for previous else
155 26 my $chain = $context->{branch}{execution_chain};
156 26 push @{$chain->[-1]}, $context->{position};
157  
158 # save else for later
159 26 push @{$chain}, $op;
160 86 };
161 }
162  
163 sub _compile_OP_ENDIF
164 86 ▶{
Subroutine _compile_OP_ENDIF: called CC=1 SCAR=0.0
165 86 my ($class) = @_;
166  
167 32 ▶ return sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
168 32 my ($compiler, $op, $context) = @_;
169  
170 $compiler->_invalid_script(
171 'OP_ENDIF found but no previous OP_IF or OP_NOTIF'
172 32 ▶ ) if !$context->{branch}{if};
Branch: 1 branch
BranchTrueFalseTotal
unless $context->{"branch"}{"if"} 1 31 32
173  
174 # set up jump point for last execution element (if or else)
175 31 my $chain = $context->{branch}{execution_chain};
176 31 push @{$chain->[-1]}, $context->{position};
177  
178 31 ▶ if ($context->{branch}{previous}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($context->{'branch'}{'previous'}) { } 8 23 31
179 8 $context->{branch} = $context->{branch}{previous};
180 }
181 else {
182 23 delete $context->{branch};
183 }
184 86 };
185 }
186  
187 sub _compile_OP_VERIF
188 172 ▶{
Subroutine _compile_OP_VERIF: called CC=1 SCAR=0.0
189 172 my ($class) = @_;
190  
191 180 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
192 180 my ($compiler, $op, $context) = @_;
193  
194 180 $compiler->_invalid_script('OP_VERIF encountered');
195 172 };
196 }
197  
198 sub _compile_disabled
199 1290 ▶{
Subroutine _compile_disabled: called CC=1 SCAR=0.0
200 1290 my ($class) = @_;
201  
202 15 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
203 15 my ($compiler, $op, $context) = @_;
204  
205 15 $compiler->_invalid_script($op->[0]->name . ' is disabled');
206 1290 };
207 }
208  
209 sub __checksig
210 151 ▶{
Subroutine __checksig: called CC=11 SCAR=24.0
211 151 my ($runner, $sig, $hashtype, $raw_pubkey, $preimage) = @_;
212  
213 151 ▶ if (defined $hashtype) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hashtype) 142 9 151
214 142 ▶ $runner->_invalid_script('bad sighash')
Branch: 1 branch
BranchTrueFalseTotal
if $runner->flags->strict_encoding and not check_sighash($hashtype) 1 141 142
Condition100%3/3
$runner->flags->strict_encoding and not check_sighash($hashtype)
!ll&&!rl&&r
13381
MC/DC100%2/2
$runner->flags->strict_encoding and not check_sighash($hashtype)
$runner->flags->strict_encoding not check_sighash($hashtype)
Truth table100%3/3
A and not(B)
A= $runner->flags->strict_encodingB= not check_sighash($hashtype)
ABresult
0X0
100
111
215 if $runner->flags->strict_encoding
216 && !check_sighash($hashtype);
217  
218 141 ▶ $runner->_invalid_script('non-strict DER signature')
Branch: 1 branch
BranchTrueFalseTotal
if $runner->flags->strict_signatures and not check_strict_der_signature($sig) 4 137 141
Condition100%3/3
$runner->flags->strict_signatures and not check_strict_der_signature($sig)
!ll&&!rl&&r
51324
MC/DC100%2/2
$runner->flags->strict_signatures and not check_strict_der_signature($sig)
$runner->flags->strict_signatures not check_strict_der_signature($sig)
Truth table100%3/3
A and not(B)
A= $runner->flags->strict_signaturesB= not check_strict_der_signature($sig)
ABresult
0X0
100
111
219 if $runner->flags->strict_signatures
220 && !check_strict_der_signature($sig);
221 }
222  
223 146 ▶ $runner->_invalid_script('non-strict pubkey')
Branch: 1 branch
BranchTrueFalseTotal
if $runner->flags->strict_encoding and not check_strict_public_key($raw_pubkey) 1 145 146
Condition100%3/3
$runner->flags->strict_encoding and not check_strict_public_key($raw_pubkey)
!ll&&!rl&&r
13871
MC/DC100%2/2
$runner->flags->strict_encoding and not check_strict_public_key($raw_pubkey)
$runner->flags->strict_encoding not check_strict_public_key($raw_pubkey)
Truth table100%3/3
A and not(B)
A= $runner->flags->strict_encodingB= not check_strict_public_key($raw_pubkey)
ABresult
0X0
100
111
224 if $runner->flags->strict_encoding && !check_strict_public_key($raw_pubkey);
225  
226 145 my $pubkey;
227 145 try {
228 145 $pubkey = btc_pub->from_serialized($raw_pubkey)
229 }
230 catch ($e) {
231 0 return !!0;
232 }
233  
234 145 ▶ $runner->_script_error('public keys must be compressed')
Branch: 1 branch
BranchTrueFalseTotal
if $runner->flags->compressed_pubkeys and $runner->transaction->is_segwit and not $pubkey->compressed 1 144 145
Condition100%6/6
$runner->flags->compressed_pubkeys and $runner->transaction->is_segwit and not $pubkey->compressed
!ll&&!rl&&r
13951
$runner->flags->compressed_pubkeys and $runner->transaction->is_segwit
!ll&&!rl&&r
13726
MC/DC100%3/3
$runner->flags->compressed_pubkeys and $runner->transaction->is_segwit and not $pubkey->compressed
$runner->flags->compressed_pubkeys $runner->transaction->is_segwit not $pubkey->compressed
Truth table100%4/4
A and B and not(C)
A= $runner->flags->compressed_pubkeysB= $runner->transaction->is_segwitC= not $pubkey->compressed
ABCresult
0XX0
10X0
1100
1111
235 if $runner->flags->compressed_pubkeys
236 && $runner->transaction->is_segwit
237 && !$pubkey->compressed;
238  
239 144 return $pubkey->verify_message($preimage, $sig, flags => $runner->flags);
240 }
241  
242 sub _OP_PUSHDATA
243 8256 ▶{
Subroutine _OP_PUSHDATA: called CC=1 SCAR=0.0
244 8256 my ($class, $opcode_name) = @_;
245  
246 946 ▶ return sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
247 946 my ($runner, $bytes) = @_;
248  
249 946 ▶ $runner->_invalid_script("push opcode for data is not minimal in $opcode_name")
Branch: 1 branch
BranchTrueFalseTotal
if $runner->flags->minimal_data and not standard_push($opcode_name, $bytes) 1 945 946
Condition100%3/3
$runner->flags->minimal_data and not standard_push($opcode_name, $bytes)
!ll&&!rl&&r
912331
MC/DC100%2/2
$runner->flags->minimal_data and not standard_push($opcode_name, $bytes)
$runner->flags->minimal_data not standard_push($opcode_name, $bytes)
Truth table100%3/3
A and not(B)
A= $runner->flags->minimal_dataB= not standard_push($opcode_name, $bytes)
ABresult
0X0
100
111
250 if $runner->flags->minimal_data && !standard_push($opcode_name, $bytes);
251  
252 945 push @{$runner->stack}, $bytes;
253 945 $class->_verify_stack($runner);
254 8256 };
255 }
256  
257 sub _OP_RESERVED
258 260 ▶{
Subroutine _OP_RESERVED: called CC=1 SCAR=0.0
259 260 my ($class) = @_;
260  
261 6 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
262 6 my $runner = shift;
263 6 $runner->_invalid_script;
264 260 };
265 }
266  
267 # does nothing
268 sub _OP_NOP
269 172 ▶{
Subroutine _OP_NOP: called CC=1 SCAR=0.0
270 172 my ($class) = @_;
271  
272 172 ▶ return sub { };
Subroutine __ANON__: called CC=1 SCAR=0.0
273 }
274  
275 sub _OP_NOP_UPGRADEABLE
276 688 ▶{
Subroutine _OP_NOP_UPGRADEABLE: called CC=1 SCAR=0.0
277 688 my ($class) = @_;
278  
279 18 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
280 18 my $runner = shift;
281  
282 18 ▶ $runner->_invalid_script('upgradeable NOP encountered')
Branch: 1 branch
BranchTrueFalseTotal
if $runner->flags->illegal_upgradeable_nops 1 17 18
283 if $runner->flags->illegal_upgradeable_nops;
284 688 };
285 }
286  
287 sub _OP_VER
288 86 ▶{
Subroutine _OP_VER: called CC=1 SCAR=0.0
289 86 my ($class) = @_;
290  
291 2 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
292 2 my $runner = shift;
293 2 $runner->_invalid_script;
294 86 };
295 }
296  
297 sub _OP_IF
298 172 ▶{
Subroutine _OP_IF: called CC=1 SCAR=0.0
299 172 my ($class, $inverted) = @_;
300  
301 28 ▶ return sub {
Subroutine __ANON__: called CC=9 SCAR=22.0
302 28 my ($runner, $next_else_or_endif) = @_;
303 28 my $stack = $runner->stack;
304  
305 28 ▶ $runner->_stack_error unless @$stack >= 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= 1 0 28 28
306 28 my $value = pop @$stack;
307  
308 28 ▶ my $minimal_if = $runner->is_tapscript
Condition100%9/9
$runner->is_tapscript || $runner->has_transaction && $runner->transaction->is_segwit && $runner->flags->minimal_if
l!l&&r!l&&!r
3124
$runner->has_transaction and $runner->transaction->is_segwit and $runner->flags->minimal_if
!ll&&!rl&&r
1771
$runner->has_transaction and $runner->transaction->is_segwit
!ll&&!rl&&r
1438
MC/DC100%4/4
$runner->is_tapscript || $runner->has_transaction && $runner->transaction->is_segwit && $runner->flags->minimal_if
$runner->is_tapscript $runner->has_transaction $runner->transaction->is_segwit $runner->flags->minimal_if
Truth table100%5/5
A || B and C and D
A= $runner->is_tapscriptB= $runner->has_transactionC= $runner->transaction->is_segwitD= $runner->flags->minimal_if
ABCDresult
1XXX1
01111
00XX0
010X0
01100
309 || ($runner->has_transaction && $runner->transaction->is_segwit && $runner->flags->minimal_if);
310  
311 28 ▶ $value = $minimal_if ? $runner->to_minimal_bool($value) : $runner->to_bool($value);
Branch: 1 branch
BranchTrueFalseTotal
$minimal_if ? : 4 24 28
312 28 ▶ $runner->_invalid_script('OP_IF argument is not minimal') unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 2 26 28
313  
314 26 ▶ $value = !$value if $inverted;
Branch: 1 branch
BranchTrueFalseTotal
if $inverted 8 18 26
315  
316 26 ▶ $runner->_set_pos($next_else_or_endif)
Branch: 1 branch
BranchTrueFalseTotal
unless $value 8 18 26
317 unless $value;
318 }
319 172 }
320  
321 # should only get called when IF branch ops are depleted
322 sub _OP_ELSE
323 86 ▶{
Subroutine _OP_ELSE: called CC=1 SCAR=0.0
324 86 my ($class) = @_;
325  
326 12 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
327 12 my ($runner, $next_else_or_endif) = @_;
328  
329 12 $runner->_set_pos($next_else_or_endif);
330 86 };
331 }
332  
333 # should only get called when IF or ELSE branch ops are depleted
334 # nothing to do here, will step to the next op
335 sub _OP_ENDIF
336 86 ▶{
Subroutine _OP_ENDIF: called CC=1 SCAR=0.0
337 86 my ($class) = @_;
338  
339 86 return $class->_OP_NOP;
340 }
341  
342 sub _OP_VERIFY
343 466 ▶{
Subroutine _OP_VERIFY: called CC=1 SCAR=0.0
344 466 my ($class) = @_;
345  
346 56 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
347 56 my $runner = shift;
348 56 my $stack = $runner->stack;
349  
350 56 ▶ $runner->_invalid_script unless $runner->to_bool($stack->[-1]);
Branch: 1 branch
BranchTrueFalseTotal
unless $runner->to_bool($stack->[-1]) 4 52 56
351  
352 # pop later so that problematic value can be seen on the stack
353 52 pop @$stack;
354 466 };
355 }
356  
357 sub _OP_RETURN
358 86 ▶{
Subroutine _OP_RETURN: called CC=1 SCAR=0.0
359 86 my ($class) = @_;
360  
361 1 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
362 1 my $runner = shift;
363 1 $runner->_invalid_script;
364 86 };
365 }
366  
367 sub _OP_TOALTSTACK
368 86 ▶{
Subroutine _OP_TOALTSTACK: called CC=1 SCAR=0.0
369 86 my ($class) = @_;
370  
371 2 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
372 2 my $runner = shift;
373 2 my $stack = $runner->stack;
374  
375 2 ▶ $runner->_stack_error unless @$stack >= 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= 1 0 2 2
376 2 push @{$runner->alt_stack}, pop @$stack;
377 86 };
378 }
379  
380 sub _OP_FROMALTSTACK
381 86 ▶{
Subroutine _OP_FROMALTSTACK: called CC=1 SCAR=0.0
382 86 my ($class) = @_;
383  
384 1 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
385 1 my $runner = shift;
386 1 my $alt = $runner->alt_stack;
387  
388 1 ▶ $runner->_stack_error unless @$alt >= 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @$alt >= 1 0 1 1
389 1 push @{$runner->stack}, pop @$alt;
390 86 };
391 }
392  
393 sub _OP_2DROP
394 86 ▶{
Subroutine _OP_2DROP: called CC=1 SCAR=0.0
395 86 my ($class) = @_;
396  
397 2 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
398 2 my $runner = shift;
399 2 my $stack = $runner->stack;
400  
401 2 ▶ $runner->_stack_error unless @$stack >= 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= 2 0 2 2
402 2 splice @$stack, -2, 2;
403 86 };
404 }
405  
406 sub _OP_2DUP
407 86 ▶{
Subroutine _OP_2DUP: called CC=1 SCAR=0.0
408 86 my ($class) = @_;
409  
410 1 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
411 1 my $runner = shift;
412 1 my $stack = $runner->stack;
413  
414 1 ▶ $runner->_stack_error unless @$stack >= 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= 2 0 1 1
415 1 push @$stack, @$stack[-2, -1];
416 1 $class->_verify_stack($runner);
417 86 };
418 }
419  
420 sub _OP_3DUP
421 86 ▶{
Subroutine _OP_3DUP: called CC=1 SCAR=0.0
422 86 my ($class) = @_;
423  
424 1 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
425 1 my $runner = shift;
426 1 my $stack = $runner->stack;
427  
428 1 ▶ $runner->_stack_error unless @$stack >= 3;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= 3 0 1 1
429 1 push @$stack, @$stack[-3, -2, -1];
430 1 $class->_verify_stack($runner);
431 86 };
432 }
433  
434 sub _OP_2OVER
435 86 ▶{
Subroutine _OP_2OVER: called CC=1 SCAR=0.0
436 86 my ($class) = @_;
437  
438 1 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
439 1 my $runner = shift;
440 1 my $stack = $runner->stack;
441  
442 1 ▶ $runner->_stack_error unless @$stack >= 4;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= 4 0 1 1
443 1 push @$stack, @$stack[-4, -3];
444 1 $class->_verify_stack($runner);
445 86 };
446 }
447  
448 sub _OP_2ROT
449 86 ▶{
Subroutine _OP_2ROT: called CC=1 SCAR=0.0
450 86 my ($class) = @_;
451  
452 1 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
453 1 my $runner = shift;
454 1 my $stack = $runner->stack;
455  
456 1 ▶ $runner->_stack_error unless @$stack >= 6;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= 6 0 1 1
457 1 push @$stack, splice @$stack, -6, 2;
458 86 };
459 }
460  
461 sub _OP_2SWAP
462 86 ▶{
Subroutine _OP_2SWAP: called CC=1 SCAR=0.0
463 86 my ($class) = @_;
464  
465 1 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
466 1 my $runner = shift;
467 1 my $stack = $runner->stack;
468  
469 1 ▶ $runner->_stack_error unless @$stack >= 4;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= 4 0 1 1
470 1 push @$stack, splice @$stack, -4, 2;
471 86 };
472 }
473  
474 sub _OP_IFDUP
475 86 ▶{
Subroutine _OP_IFDUP: called CC=1 SCAR=0.0
476 86 my ($class) = @_;
477  
478 3 ▶ return sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
479 3 my $runner = shift;
480 3 my $stack = $runner->stack;
481  
482 3 ▶ $runner->_stack_error unless @$stack >= 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= 1 0 3 3
483 3 ▶ if ($runner->to_bool($stack->[-1])) {
Branch: 1 branch
BranchTrueFalseTotal
if ($runner->to_bool($stack->[-1])) 1 2 3
484 1 push @$stack, $stack->[-1];
485 1 $class->_verify_stack($runner);
486 }
487 86 };
488 }
489  
490 sub _OP_DEPTH
491 86 ▶{
Subroutine _OP_DEPTH: called CC=1 SCAR=0.0
492 86 my ($class) = @_;
493  
494 1 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
495 1 my $runner = shift;
496 1 my $stack = $runner->stack;
497  
498 1 push @$stack, $runner->from_int(scalar @$stack);
499 1 $class->_verify_stack($runner);
500 86 };
501 }
502  
503 sub _OP_DROP
504 86 ▶{
Subroutine _OP_DROP: called CC=1 SCAR=0.0
505 86 my ($class) = @_;
506  
507 1 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
508 1 my $runner = shift;
509 1 my $stack = $runner->stack;
510  
511 1 ▶ $runner->_stack_error unless @$stack >= 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= 1 0 1 1
512 1 pop @$stack;
513 86 };
514 }
515  
516 sub _OP_DUP
517 86 ▶{
Subroutine _OP_DUP: called CC=1 SCAR=0.0
518 86 my ($class) = @_;
519  
520 49 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
521 49 my $runner = shift;
522 49 my $stack = $runner->stack;
523  
524 49 ▶ $runner->_stack_error unless @$stack >= 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= 1 1 48 49
525 48 push @$stack, $stack->[-1];
526 48 $class->_verify_stack($runner);
527 86 };
528 }
529  
530 sub _OP_NIP
531 86 ▶{
Subroutine _OP_NIP: called CC=1 SCAR=0.0
532 86 my ($class) = @_;
533  
534 1 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
535 1 my $runner = shift;
536 1 my $stack = $runner->stack;
537  
538 1 ▶ $runner->_stack_error unless @$stack >= 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= 2 0 1 1
539 1 splice @$stack, -2, 1;
540 86 };
541 }
542  
543 sub _OP_OVER
544 86 ▶{
Subroutine _OP_OVER: called CC=1 SCAR=0.0
545 86 my ($class) = @_;
546  
547 1 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
548 1 my $runner = shift;
549 1 my $stack = $runner->stack;
550  
551 1 ▶ $runner->_stack_error unless @$stack >= 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= 2 0 1 1
552 1 push @$stack, $stack->[-2];
553 1 $class->_verify_stack($runner);
554 86 };
555 }
556  
557 sub _OP_PICK
558 86 ▶{
Subroutine _OP_PICK: called CC=1 SCAR=0.2
559 86 my ($class) = @_;
560  
561 1 ▶ return sub {
Subroutine __ANON__: called CC=4 SCAR=14.8
562 1 my $runner = shift;
563 1 my $stack = $runner->stack;
564  
565 1 ▶ $runner->_stack_error unless @$stack >= 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= 2 0 1 1
566  
567 1 my $n = $runner->to_int(pop @$stack);
568 1 ▶ $runner->_stack_error if $n < 0 || $n >= @$stack;
Branch: 1 branch
BranchTrueFalseTotal
if $n < 0 or $n >= @$stack 0 1 1
Condition33%1/3
$n < 0 or $n >= @$stack
l!l&&r!l&&!r
001
MC/DC0%0/2
$n < 0 or $n >= @$stack
$n < 0 $n >= @$stack
Truth table33%1/3
A or B
A= $n < 0B= $n >= @$stack
ABresult
1X1
011
000
569  
570 1 push @$stack, $stack->[-1 * ($n + 1)];
571 1 $class->_verify_stack($runner);
572 86 };
573 }
574  
575 sub _OP_ROLL
576 86 ▶{
Subroutine _OP_ROLL: called CC=1 SCAR=0.2
577 86 my ($class) = @_;
578  
579 1 ▶ return sub {
Subroutine __ANON__: called CC=4 SCAR=15.0
580 1 my $runner = shift;
581 1 my $stack = $runner->stack;
582  
583 1 ▶ $runner->_stack_error unless @$stack >= 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= 2 0 1 1
584  
585 1 my $n = $runner->to_int(pop @$stack);
586 1 ▶ $runner->_stack_error if $n < 0 || $n >= @$stack;
Branch: 1 branch
BranchTrueFalseTotal
if $n < 0 or $n >= @$stack 0 1 1
Condition33%1/3
$n < 0 or $n >= @$stack
l!l&&r!l&&!r
001
MC/DC0%0/2
$n < 0 or $n >= @$stack
$n < 0 $n >= @$stack
Truth table33%1/3
A or B
A= $n < 0B= $n >= @$stack
ABresult
1X1
011
000
587  
588 1 push @$stack, splice @$stack, -1 * ($n + 1), 1;
589 86 };
590 }
591  
592 sub _OP_ROT
593 86 ▶{
Subroutine _OP_ROT: called CC=1 SCAR=0.0
594 86 my ($class) = @_;
595  
596 1 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
597 1 my $runner = shift;
598 1 my $stack = $runner->stack;
599  
600 1 ▶ $runner->_stack_error unless @$stack >= 3;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= 3 0 1 1
601 1 push @$stack, splice @$stack, -3, 1;
602 86 };
603 }
604  
605 sub _OP_SWAP
606 86 ▶{
Subroutine _OP_SWAP: called CC=1 SCAR=3.5
607 86 my ($class) = @_;
608  
609 0 ▶ return sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
610 0 my $runner = shift;
611 0 my $stack = $runner->stack;
612  
613 0 ▶ $runner->_stack_error unless @$stack >= 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= 2 0 0 0
614 0 push @$stack, splice @$stack, -2, 1;
615 86 };
616 }
617  
618 sub _OP_TUCK
619 86 ▶{
Subroutine _OP_TUCK: called CC=1 SCAR=0.0
620 86 my ($class) = @_;
621  
622 1 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
623 1 my $runner = shift;
624 1 my $stack = $runner->stack;
625  
626 1 ▶ $runner->_stack_error unless @$stack >= 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= 2 0 1 1
627 1 splice @$stack, -2, 0, $stack->[-1];
628 1 $class->_verify_stack($runner);
629 86 };
630 }
631  
632 sub _OP_SIZE
633 86 ▶{
Subroutine _OP_SIZE: called CC=1 SCAR=0.0
634 86 my ($class) = @_;
635  
636 1 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
637 1 my $runner = shift;
638 1 my $stack = $runner->stack;
639  
640 1 ▶ $runner->_stack_error unless @$stack >= 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= 1 0 1 1
641 1 push @$stack, $runner->from_int(length $stack->[-1]);
642 1 $class->_verify_stack($runner);
643 86 };
644 }
645  
646 sub _OP_EQUAL
647 172 ▶{
Subroutine _OP_EQUAL: called CC=1 SCAR=0.0
648 172 my ($class) = @_;
649  
650 118 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
651 118 my $runner = shift;
652 118 my $stack = $runner->stack;
653  
654 118 ▶ $runner->_stack_error unless @$stack >= 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= 2 0 118 118
655 118 push @$stack, $runner->from_bool(pop(@$stack) eq pop(@$stack));
656 172 };
657 }
658  
659 sub _OP_EQUALVERIFY
660 86 ▶{
Subroutine _OP_EQUALVERIFY: called CC=1 SCAR=0.0
661 86 my ($class) = @_;
662  
663 86 my $op_equal = $class->_OP_EQUAL;
664 86 my $op_verify = $class->_OP_VERIFY;
665  
666 49 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
667 49 $op_equal->(@_);
668 49 $op_verify->(@_);
669 86 };
670 }
671  
672 sub _OP_1ADD
673 86 ▶{
Subroutine _OP_1ADD: called CC=1 SCAR=0.0
674 86 my ($class) = @_;
675  
676 2 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
677 2 my $runner = shift;
678 2 my $stack = $runner->stack;
679  
680 2 ▶ $runner->_stack_error unless @$stack >= 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= 1 0 2 2
681 2 push @$stack, $runner->from_int($runner->to_int(pop @$stack) + 1);
682 86 };
683 }
684  
685 sub _OP_1SUB
686 86 ▶{
Subroutine _OP_1SUB: called CC=1 SCAR=0.0
687 86 my ($class) = @_;
688  
689 1 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
690 1 my $runner = shift;
691 1 my $stack = $runner->stack;
692  
693 1 ▶ $runner->_stack_error unless @$stack >= 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= 1 0 1 1
694 1 push @$stack, $runner->from_int($runner->to_int(pop @$stack) - 1);
695 86 };
696 }
697  
698 sub _OP_NEGATE
699 86 ▶{
Subroutine _OP_NEGATE: called CC=1 SCAR=0.0
700 86 my ($class) = @_;
701  
702 6 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
703 6 my $runner = shift;
704 6 my $stack = $runner->stack;
705  
706 6 ▶ $runner->_stack_error unless @$stack >= 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= 1 0 6 6
707 6 push @$stack, $runner->from_int($runner->to_int(pop @$stack) * -1);
708 86 };
709 }
710  
711 sub _OP_ABS
712 86 ▶{
Subroutine _OP_ABS: called CC=1 SCAR=0.0
713 86 my ($class) = @_;
714  
715 2 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
716 2 my $runner = shift;
717 2 my $stack = $runner->stack;
718  
719 2 ▶ $runner->_stack_error unless @$stack >= 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= 1 0 2 2
720 2 push @$stack, $runner->from_int(abs $runner->to_int(pop @$stack));
721 86 };
722 }
723  
724 sub _OP_NOT
725 86 ▶{
Subroutine _OP_NOT: called CC=1 SCAR=0.0
726 86 my ($class) = @_;
727  
728 5 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
729 5 my $runner = shift;
730 5 my $stack = $runner->stack;
731  
732 5 ▶ $runner->_stack_error unless @$stack >= 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= 1 0 5 5
733 5 push @$stack, $runner->from_bool($runner->to_int(pop @$stack) == 0);
734 86 };
735 }
736  
737 sub _OP_0NOTEQUAL
738 86 ▶{
Subroutine _OP_0NOTEQUAL: called CC=1 SCAR=0.0
739 86 my ($class) = @_;
740  
741 2 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
742 2 my $runner = shift;
743 2 my $stack = $runner->stack;
744  
745 2 ▶ $runner->_stack_error unless @$stack >= 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= 1 0 2 2
746 2 push @$stack, $runner->from_bool($runner->to_int(pop @$stack) != 0);
747 86 };
748 }
749  
750 sub _OP_ADD
751 86 ▶{
Subroutine _OP_ADD: called CC=1 SCAR=0.0
752 86 my ($class) = @_;
753  
754 4 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
755 4 my $runner = shift;
756 4 my $stack = $runner->stack;
757  
758 4 ▶ $runner->_stack_error unless @$stack >= 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= 2 0 4 4
759 4 push @$stack, $runner->from_int(
760 $runner->to_int(pop @$stack)
761 + $runner->to_int(pop @$stack)
762 );
763 86 };
764 }
765  
766 sub _OP_SUB
767 86 ▶{
Subroutine _OP_SUB: called CC=1 SCAR=0.0
768 86 my ($class) = @_;
769  
770 3 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
771 3 my $runner = shift;
772 3 my $stack = $runner->stack;
773  
774 3 ▶ $runner->_stack_error unless @$stack >= 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= 2 0 3 3
775 3 push @$stack, $runner->from_int(
776 -1 * $runner->to_int(pop @$stack)
777 + $runner->to_int(pop @$stack)
778 );
779 86 };
780 }
781  
782 sub _OP_BOOLAND
783 86 ▶{
Subroutine _OP_BOOLAND: called CC=1 SCAR=0.0
784 86 my ($class) = @_;
785  
786 5 ▶ return sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
787 5 my $runner = shift;
788 5 my $stack = $runner->stack;
789  
790 5 ▶ $runner->_stack_error unless @$stack >= 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= 2 0 5 5
791  
792 5 my $second = $runner->to_int(pop @$stack) != 0;
793 5 ▶ push @$stack, $runner->from_bool(
Condition100%3/3
$runner->to_int(pop @$stack) != 0 && $second
!ll&&!rl&&r
212
MC/DC100%2/2
$runner->to_int(pop @$stack) != 0 && $second
$runner->to_int(pop @$stack) != 0 $second
Truth table100%3/3
A && B
A= $runner->to_int(pop @$stack) != 0B= $second
ABresult
0X0
100
111
794 $runner->to_int(pop @$stack) != 0
795 && $second
796 );
797 86 };
798 }
799  
800 sub _OP_BOOLOR
801 86 ▶{
Subroutine _OP_BOOLOR: called CC=1 SCAR=0.0
802 86 my ($class) = @_;
803  
804 4 ▶ return sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
805 4 my $runner = shift;
806 4 my $stack = $runner->stack;
807  
808 4 ▶ $runner->_stack_error unless @$stack >= 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= 2 0 4 4
809  
810 4 my $second = $runner->to_int(pop @$stack) != 0;
811 4 ▶ push @$stack, $runner->from_bool(
Condition100%3/3
$runner->to_int(pop @$stack) != 0 || $second
l!l&&r!l&&!r
211
MC/DC100%2/2
$runner->to_int(pop @$stack) != 0 || $second
$runner->to_int(pop @$stack) != 0 $second
Truth table100%3/3
A || B
A= $runner->to_int(pop @$stack) != 0B= $second
ABresult
1X1
011
000
812 $runner->to_int(pop @$stack) != 0
813 || $second
814 );
815 86 };
816 }
817  
818 sub _OP_NUMEQUAL
819 172 ▶{
Subroutine _OP_NUMEQUAL: called CC=1 SCAR=0.0
820 172 my ($class) = @_;
821  
822 15 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
823 15 my $runner = shift;
824 15 my $stack = $runner->stack;
825  
826 15 ▶ $runner->_stack_error unless @$stack >= 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= 2 1 14 15
827 14 push @$stack, $runner->from_bool(
828 $runner->to_int(pop @$stack)
829 == $runner->to_int(pop @$stack)
830 );
831 172 };
832 }
833  
834 sub _OP_NUMEQUALVERIFY
835 86 ▶{
Subroutine _OP_NUMEQUALVERIFY: called CC=1 SCAR=0.0
836 86 my ($class) = @_;
837  
838 86 my $op_numequal = $class->_OP_NUMEQUAL;
839 86 my $op_verify = $class->_OP_VERIFY;
840  
841 5 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
842 5 $op_numequal->(@_);
843 4 $op_verify->(@_);
844 86 };
845 }
846  
847 sub _OP_NUMNOTEQUAL
848 86 ▶{
Subroutine _OP_NUMNOTEQUAL: called CC=1 SCAR=0.0
849 86 my ($class) = @_;
850  
851 4 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
852 4 my $runner = shift;
853 4 my $stack = $runner->stack;
854  
855 4 ▶ $runner->_stack_error unless @$stack >= 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= 2 0 4 4
856 4 push @$stack, $runner->from_bool(
857 $runner->to_int(pop @$stack)
858 != $runner->to_int(pop @$stack)
859 );
860 86 };
861 }
862  
863 sub _OP_LESSTHAN
864 86 ▶{
Subroutine _OP_LESSTHAN: called CC=1 SCAR=0.0
865 86 my ($class) = @_;
866  
867 3 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
868 3 my $runner = shift;
869 3 my $stack = $runner->stack;
870  
871 3 ▶ $runner->_stack_error unless @$stack >= 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= 2 0 3 3
872 3 push @$stack, $runner->from_bool(
873 $runner->to_int(pop @$stack)
874 > $runner->to_int(pop @$stack)
875 );
876 86 };
877 }
878  
879 sub _OP_GREATERTHAN
880 86 ▶{
Subroutine _OP_GREATERTHAN: called CC=1 SCAR=0.0
881 86 my ($class) = @_;
882  
883 3 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
884 3 my $runner = shift;
885 3 my $stack = $runner->stack;
886  
887 3 ▶ $runner->_stack_error unless @$stack >= 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= 2 0 3 3
888 3 push @$stack, $runner->from_bool(
889 $runner->to_int(pop @$stack)
890 < $runner->to_int(pop @$stack)
891 );
892 86 };
893 }
894  
895 sub _OP_LESSTHANOREQUAL
896 86 ▶{
Subroutine _OP_LESSTHANOREQUAL: called CC=1 SCAR=0.0
897 86 my ($class) = @_;
898  
899 3 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
900 3 my $runner = shift;
901 3 my $stack = $runner->stack;
902  
903 3 ▶ $runner->_stack_error unless @$stack >= 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= 2 0 3 3
904 3 push @$stack, $runner->from_bool(
905 $runner->to_int(pop @$stack)
906 >= $runner->to_int(pop @$stack)
907 );
908 86 };
909 }
910  
911 sub _OP_GREATERTHANOREQUAL
912 86 ▶{
Subroutine _OP_GREATERTHANOREQUAL: called CC=1 SCAR=0.0
913 86 my ($class) = @_;
914  
915 3 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
916 3 my $runner = shift;
917 3 my $stack = $runner->stack;
918  
919 3 ▶ $runner->_stack_error unless @$stack >= 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= 2 0 3 3
920 3 push @$stack, $runner->from_bool(
921 $runner->to_int(pop @$stack)
922 <= $runner->to_int(pop @$stack)
923 );
924 86 };
925 }
926  
927 sub _OP_MIN
928 86 ▶{
Subroutine _OP_MIN: called CC=1 SCAR=0.0
929 86 my ($class) = @_;
930  
931 2 ▶ return sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
932 2 my $runner = shift;
933 2 my $stack = $runner->stack;
934  
935 2 ▶ $runner->_stack_error unless @$stack >= 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= 2 0 2 2
936 2 my ($first, $second) = map { $runner->to_int($_) } splice @$stack, -2, 2;
937 2 ▶ my $smaller = $first < $second ? $first : $second;
Branch: 1 branch
BranchTrueFalseTotal
$first < $second ? : 1 1 2
938 2 push @$stack, $runner->from_int($smaller);
939 86 };
940 }
941  
942 sub _OP_MAX
943 86 ▶{
Subroutine _OP_MAX: called CC=1 SCAR=0.0
944 86 my ($class) = @_;
945  
946 2 ▶ return sub {
Subroutine __ANON__: called CC=3 SCAR=11.2
947 2 my $runner = shift;
948 2 my $stack = $runner->stack;
949  
950 2 ▶ $runner->_stack_error unless @$stack >= 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= 2 0 2 2
951 2 my ($first, $second) = map { $runner->to_int($_) } splice @$stack, -2, 2;
952 2 ▶ my $larger = $first > $second ? $first : $second;
Branch: 1 branch
BranchTrueFalseTotal
$first > $second ? : 2 0 2
953 2 push @$stack, $runner->from_int($larger);
954 86 };
955 }
956  
957 sub _OP_WITHIN
958 86 ▶{
Subroutine _OP_WITHIN: called CC=1 SCAR=0.0
959 86 my ($class) = @_;
960  
961 4 ▶ return sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
962 4 my $runner = shift;
963 4 my $stack = $runner->stack;
964  
965 4 ▶ $runner->_stack_error unless @$stack >= 3;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= 3 0 4 4
966 4 my ($first, $second, $third) = map { $runner->to_int($_) } splice @$stack, -3, 3;
967 4 ▶ push @$stack, $runner->from_bool($first >= $second && $first < $third);
Condition100%3/3
$first >= $second && $first < $third
!ll&&!rl&&r
112
MC/DC100%2/2
$first >= $second && $first < $third
$first >= $second $first < $third
Truth table100%3/3
A && B
A= $first >= $secondB= $first < $third
ABresult
0X0
100
111
968 86 };
969 }
970  
971 sub _OP_RIPEMD160
972 86 ▶{
Subroutine _OP_RIPEMD160: called CC=1 SCAR=0.0
973 86 my ($class) = @_;
974  
975 1 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
976 1 my $runner = shift;
977 1 my $stack = $runner->stack;
978  
979 1 ▶ $runner->_stack_error unless @$stack >= 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= 1 0 1 1
980 1 push @$stack, ripemd160(pop @$stack);
981 86 };
982 }
983  
984 sub _OP_SHA1
985 86 ▶{
Subroutine _OP_SHA1: called CC=1 SCAR=0.0
986 86 my ($class) = @_;
987  
988 1 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
989 1 my $runner = shift;
990 1 my $stack = $runner->stack;
991  
992 1 ▶ $runner->_stack_error unless @$stack >= 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= 1 0 1 1
993 1 push @$stack, sha1(pop @$stack);
994 86 };
995 }
996  
997 sub _OP_SHA256
998 86 ▶{
Subroutine _OP_SHA256: called CC=1 SCAR=0.0
999 86 my ($class) = @_;
1000  
1001 25 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
1002 25 my $runner = shift;
1003 25 my $stack = $runner->stack;
1004  
1005 25 ▶ $runner->_stack_error unless @$stack >= 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= 1 0 25 25
1006 25 push @$stack, sha256(pop @$stack);
1007 86 };
1008 }
1009  
1010 sub _OP_HASH160
1011 86 ▶{
Subroutine _OP_HASH160: called CC=1 SCAR=0.0
1012 86 my ($class) = @_;
1013  
1014 82 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
1015 82 my $runner = shift;
1016 82 my $stack = $runner->stack;
1017  
1018 82 ▶ $runner->_stack_error unless @$stack >= 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= 1 0 82 82
1019 82 push @$stack, hash160(pop @$stack);
1020 86 };
1021 }
1022  
1023 sub _OP_HASH256
1024 86 ▶{
Subroutine _OP_HASH256: called CC=1 SCAR=0.0
1025 86 my ($class) = @_;
1026  
1027 1 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
1028 1 my $runner = shift;
1029 1 my $stack = $runner->stack;
1030  
1031 1 ▶ $runner->_stack_error unless @$stack >= 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= 1 0 1 1
1032 1 push @$stack, hash256(pop @$stack);
1033 86 };
1034 }
1035  
1036 sub _OP_CODESEPARATOR
1037 86 ▶{
Subroutine _OP_CODESEPARATOR: called CC=1 SCAR=0.0
1038 86 my ($class) = @_;
1039  
1040 14 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
1041 14 my $runner = shift;
1042 14 $runner->_register_codeseparator;
1043 86 };
1044 }
1045  
1046 sub _OP_CHECKSIG
1047 100 ▶{
Subroutine _OP_CHECKSIG: called CC=1 SCAR=0.0
1048 100 my ($class) = @_;
1049  
1050 88 ▶ return sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
1051 88 my $runner = shift;
1052  
1053 88 my $stack = $runner->stack;
1054 88 ▶ $runner->_stack_error unless @$stack >= 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= 2 1 87 88
1055  
1056 87 my $raw_pubkey = pop @$stack;
1057 87 my $sig = pop @$stack;
1058 87 my $sig_orig = $sig;
1059  
1060 87 my $hashtype = unpack 'C', substr $sig, -1, 1, '';
1061  
1062 87 my $preimage = $runner->transaction->get_digest(
1063 signatures => [$sig_orig],
1064 sighash => $hashtype,
1065 );
1066  
1067 86 my $result = __checksig($runner, $sig, $hashtype, $raw_pubkey, $preimage);
1068  
1069 81 ▶ $runner->_script_error('non-empty signature verification failed')
Branch: 1 branch
BranchTrueFalseTotal
if not $result and $runner->flags->null_fail and $sig_orig ne "" 3 78 81
Condition83%5/6
not $result and $runner->flags->null_fail and $sig_orig ne ""
!ll&&!rl&&r
7803
not $result and $runner->flags->null_fail
!ll&&!rl&&r
6993
MC/DC66%2/3
not $result and $runner->flags->null_fail and $sig_orig ne ""
not $result $runner->flags->null_fail $sig_orig ne ""
Truth table75%3/4
not(A) and B and C
A= not $resultB= $runner->flags->null_failC= $sig_orig ne ""
ABCresult
0XX0
10X0
1100
1111
1070 if !$result && $runner->flags->null_fail && $sig_orig ne '';
1071  
1072 78 push @$stack, $runner->from_bool($result);
1073 100 };
1074 }
1075  
1076 sub _OP_CHECKSIGVERIFY
1077 86 ▶{
Subroutine _OP_CHECKSIGVERIFY: called CC=1 SCAR=0.0
1078 86 my ($class) = @_;
1079  
1080 86 my $op_checksig = $class->_OP_CHECKSIG;
1081 86 my $op_verify = $class->_OP_VERIFY;
1082  
1083 3 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
1084 3 $op_checksig->(@_);
1085 3 $op_verify->(@_);
1086 86 };
1087 }
1088  
1089 sub _OP_CHECKMULTISIG
1090 100 ▶{
Subroutine _OP_CHECKMULTISIG: called CC=1 SCAR=0.1
1091 100 my ($class) = @_;
1092  
1093 35 ▶ return sub {
Subroutine __ANON__: called CC=25 SCAR=33.9
1094 35 my $runner = shift;
1095 35 my $stack = $runner->stack;
1096  
1097 35 ▶ $runner->_stack_error unless @$stack >= 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= 1 0 35 35
1098 35 my $pubkeys_num = $runner->to_int(pop @$stack);
1099 35 ▶ $runner->_stack_error unless @$stack >= $pubkeys_num;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= $pubkeys_num 0 35 35
1100 35 ▶ $runner->_script_error('OP_CHECKMULTISIG negative number of public keys')
Branch: 1 branch
BranchTrueFalseTotal
if $pubkeys_num < 0 0 35 35
1101 if $pubkeys_num < 0;
1102 35 ▶ $runner->_script_error('OP_CHECKMULTISIG maximum number of public keys exceeded')
Branch: 1 branch
BranchTrueFalseTotal
if $pubkeys_num > 20 0 35 35
1103 if $pubkeys_num > SCRIPT_MAX_MULTISIG_PUBKEYS;
1104 35 $runner->_increment_opcode_count($pubkeys_num);
1105 35 ▶ my @pubkeys = $pubkeys_num ? splice @$stack, -$pubkeys_num : ();
Branch: 1 branch
BranchTrueFalseTotal
$pubkeys_num ? : 35 0 35
1106  
1107 35 ▶ $runner->_stack_error unless @$stack >= 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= 1 0 35 35
1108 35 my $signatures_num = $runner->to_int(pop @$stack);
1109 35 ▶ $runner->_stack_error unless @$stack >= $signatures_num;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= $signatures_num 1 34 35
1110 34 ▶ $runner->_script_error('OP_CHECKMULTISIG negative number of signatures')
Branch: 1 branch
BranchTrueFalseTotal
if $signatures_num < 0 0 34 34
1111 if $signatures_num < 0;
1112 34 ▶ $runner->_script_error('OP_CHECKMULTISIG number of signatures exceeds the number of public keys')
Branch: 1 branch
BranchTrueFalseTotal
if $signatures_num > $pubkeys_num 0 34 34
1113 if $signatures_num > $pubkeys_num;
1114 34 ▶ my @signatures = $signatures_num ? splice @$stack, -$signatures_num : ();
Branch: 1 branch
BranchTrueFalseTotal
$signatures_num ? : 34 0 34
1115 34 my @signatures_left = @signatures;
1116  
1117 # Remove extra unused value from the stack
1118 34 ▶ $runner->_stack_error unless @$stack >= 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= 1 1 33 34
1119 33 my $unused = pop @$stack;
1120 33 ▶ $runner->_script_error('OP_CHECKMULTISIG dummy argument must be empty')
Branch: 1 branch
BranchTrueFalseTotal
if $runner->flags->null_dummy and length $unused 1 32 33
Condition100%3/3
$runner->flags->null_dummy and length $unused
!ll&&!rl&&r
1311
MC/DC100%2/2
$runner->flags->null_dummy and length $unused
$runner->flags->null_dummy length $unused
Truth table100%3/3
A and B
A= $runner->flags->null_dummyB= length $unused
ABresult
0X0
100
111
1121 if $runner->flags->null_dummy && length $unused;
1122  
1123 32 my $found = !!1;
1124 32 my %digests;
1125 32 ▶ while (defined(my $sig = pop @signatures_left)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $sig = pop @signatures_left)) 59 26 85
1126 59 my $hashtype = unpack 'C', substr $sig, -1, 1, '';
1127  
1128 59 ▶ my $preimage = $digests{$hashtype // ''} //= $runner->transaction->get_digest(
Condition80%4/5
$digests{$hashtype // ""} //= $runner->transaction->get_digest("signatures", \@signatures, "sighash", $hashtype)
l!l&&r!l&&!r
19400
$hashtype // ""
l!l
563
MC/DC0%0/2
$digests{$hashtype // ""} //= $runner->transaction->get_digest("signatures", \@signatures, "sighash", $hashtype)
$digests{$hashtype // ""} $runner->transaction->get_digest("signatures", \@signatures, "sighash", $hashtype)
MC/DC100%1/1
$hashtype // ""
$hashtype
Truth table66%2/3
A //= B
A= $digests{$hashtype // ""}B= $runner->transaction->get_digest("signatures", \@signatures, "sighash", $hashtype)
ABresult
1X1
011
000
Truth table100%2/2
A
A= $hashtype
Aresult
11
00
1129 signatures => \@signatures,
1130 sighash => $hashtype,
1131 );
1132  
1133 59 $found = !!0;
1134 59 ▶ while (defined(my $raw_pubkey = pop @pubkeys)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $raw_pubkey = pop @pubkeys)) 65 0 65
1135 65 $found = __checksig($runner, $sig, $hashtype, $raw_pubkey, $preimage);
1136 63 ▶ last if $found || @signatures_left + 1 > @pubkeys;
Branch: 1 branch
BranchTrueFalseTotal
if $found or @signatures_left + 1 > @pubkeys 57 6 63
Condition100%3/3
$found or @signatures_left + 1 > @pubkeys
l!l&&r!l&&!r
5346
MC/DC100%2/2
$found or @signatures_left + 1 > @pubkeys
$found @signatures_left + 1 > @pubkeys
Truth table100%3/3
A or B
A= $foundB= @signatures_left + 1 > @pubkeys
ABresult
1X1
011
000
1137 }
1138  
1139 57 ▶ last if !$found;
Branch: 1 branch
BranchTrueFalseTotal
unless $found 4 53 57
1140 }
1141  
1142 # checking is correct if we have no more signatures to check and the
1143 # last one was found correctly
1144 30 ▶ my $result = $found && !@signatures_left;
Condition66%2/3
$found && !@signatures_left
!ll&&!rl&&r
4026
MC/DC50%1/2
$found && !@signatures_left
$found !@signatures_left
Truth table66%2/3
A && not(B)
A= $foundB= !@signatures_left
ABresult
0X0
100
111
1145 $runner->_script_error('non-empty signature verification failed')
1146 0 ▶ if !$result && $runner->flags->null_fail && notall { $_ eq '' } @signatures;
Subroutine __ANON__: not called CC=1 SCAR=1.2
Branch: 1 branch
BranchTrueFalseTotal
if not $result and $runner->flags->null_fail and &notall(sub { $_ eq ""; } , @signatures) 0 30 30
Condition50%3/6
not $result and $runner->flags->null_fail and &notall(sub { $_ eq ""; } , @signatures)
!ll&&!rl&&r
3000
not $result and $runner->flags->null_fail
!ll&&!rl&&r
2640
MC/DC0%0/3
not $result and $runner->flags->null_fail and &notall(sub { $_ eq ""; } , @signatures)
not $result $runner->flags->null_fail &notall(sub { $_ eq ""; } , @signatures)
Truth table50%2/4
not(A) and B and C
A= not $resultB= $runner->flags->null_failC= &notall(sub { $_ eq ""; } , @signatures)
ABCresult
0XX0
10X0
1100
1111
1147  
1148 30 push @$stack, $runner->from_bool($result);
1149 100 };
1150 }
1151  
1152 sub _OP_CHECKMULTISIGVERIFY
1153 122 ▶{
Subroutine _OP_CHECKMULTISIGVERIFY: called CC=1 SCAR=0.4
1154 122 my ($class) = @_;
1155  
1156 122 my $checkmultisig = $class->_OP_CHECKMULTISIG;
1157 122 my $verify = $class->_OP_VERIFY;
1158  
1159 0 ▶ return sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1160 0 $checkmultisig->(@_);
1161 0 $verify->(@_);
1162 122 };
1163 }
1164  
1165 sub _OP_CHECKLOCKTIMEVERIFY
1166 86 ▶{
Subroutine _OP_CHECKLOCKTIMEVERIFY: called CC=1 SCAR=0.0
1167 86 my ($class) = @_;
1168  
1169 10 ▶ return sub {
Subroutine __ANON__: called CC=7 SCAR=19.5
1170 10 my $runner = shift;
1171 10 my $transaction = $runner->transaction;
1172  
1173 # NOP if no consensus rule
1174 10 ▶ return unless $runner->flags->checklocktimeverify;
Branch: 1 branch
BranchTrueFalseTotal
unless $runner->flags->checklocktimeverify 1 9 10
1175  
1176 9 my $stack = $runner->stack;
1177 9 ▶ $runner->_stack_error unless @$stack >= 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= 1 0 9 9
1178  
1179 9 my $c1 = $runner->to_int($stack->[-1], 5);
1180 9 my $c2 = $runner->transaction->locktime;
1181  
1182 9 ▶ $runner->_invalid_script('negative number')
Branch: 1 branch
BranchTrueFalseTotal
if $c1 < 0 1 8 9
1183 if $c1 < 0;
1184  
1185 8 my $c1_is_height = $c1 < LOCKTIME_HEIGHT_THRESHOLD;
1186 8 my $c2_is_height = $c2 < LOCKTIME_HEIGHT_THRESHOLD;
1187  
1188 8 ▶ $runner->_invalid_script('type mismatch')
Branch: 1 branch
BranchTrueFalseTotal
unless !!$c1_is_height == !!$c2_is_height 2 6 8
1189 unless !!$c1_is_height == !!$c2_is_height;
1190  
1191 6 ▶ $runner->_invalid_script
Branch: 1 branch
BranchTrueFalseTotal
if $c1 > $c2 3 3 6
1192 if $c1 > $c2;
1193  
1194 3 ▶ $runner->_invalid_script('maximum sequence in input')
Branch: 1 branch
BranchTrueFalseTotal
if $transaction->this_input->sequence_no == 4294967295 0 3 3
1195 if $transaction->this_input->sequence_no == MAX_SEQUENCE_NO;
1196 86 };
1197 }
1198  
1199 sub _OP_CHECKSEQUENCEVERIFY
1200 86 ▶{
Subroutine _OP_CHECKSEQUENCEVERIFY: called CC=1 SCAR=0.0
1201 86 my ($class) = @_;
1202  
1203 12 ▶ return sub {
Subroutine __ANON__: called CC=9 SCAR=22.0
1204 12 my $runner = shift;
1205 12 my $transaction = $runner->transaction;
1206  
1207 # NOP if no consensus rule
1208 12 ▶ return unless $runner->flags->checksequenceverify;
Branch: 1 branch
BranchTrueFalseTotal
unless $runner->flags->checksequenceverify 1 11 12
1209  
1210 11 my $stack = $runner->stack;
1211 11 ▶ $runner->_stack_error unless @$stack >= 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @$stack >= 1 0 11 11
1212  
1213 11 my $c1 = $runner->to_int($stack->[-1], 5);
1214  
1215 11 ▶ $runner->_invalid_script('negative number')
Branch: 1 branch
BranchTrueFalseTotal
if $c1 < 0 1 10 11
1216 if $c1 < 0;
1217  
1218 10 ▶ if (!($c1 & (1 << 31))) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $c1 & 2147483648) 9 1 10
1219 9 ▶ $runner->_invalid_script('bad transaction version')
Branch: 1 branch
BranchTrueFalseTotal
if $transaction->version < 2 1 8 9
1220 if $transaction->version < 2;
1221  
1222 8 my $c2 = $transaction->this_input->sequence_no;
1223  
1224 8 ▶ $runner->_invalid_script("no mask in input's sequence")
Branch: 1 branch
BranchTrueFalseTotal
if $c2 & 2147483648 0 8 8
1225 if $c2 & (1 << 31);
1226  
1227 8 my $c1_is_time = $c1 & (1 << 22);
1228 8 my $c2_is_time = $c2 & (1 << 22);
1229  
1230 8 ▶ $runner->_invalid_script('type mismatch')
Branch: 1 branch
BranchTrueFalseTotal
if !!$c1_is_time ne !!$c2_is_time 2 6 8
1231 if !!$c1_is_time ne !!$c2_is_time;
1232  
1233 6 ▶ $runner->_invalid_script
Branch: 1 branch
BranchTrueFalseTotal
if ($c1 & 65535) > ($c2 & 65535) 2 4 6
1234 if ($c1 & 0x0000ffff) > ($c2 & 0x0000ffff);
1235 }
1236 86 };
1237 }
1238  
1239 sub _build_opcodes
1240 86 ▶{
Subroutine _build_opcodes: called CC=4 SCAR=13.9
1241 86 my ($class) = @_;
1242  
1243 86 my %opcodes = (
1244 OP_0 => {
1245 code => 0x00,
1246 pushop => !!1,
1247 on_compilation => $class->_compile_OP_NUM(0),
1248 runner => $class->_OP_PUSHDATA,
1249 },
1250 OP_PUSHDATA1 => {
1251 code => 0x4c,
1252 pushop => !!1,
1253 on_compilation => $class->_compile_OP_PUSHDATA(1),
1254 runner => $class->_OP_PUSHDATA('OP_PUSHDATA1'),
1255 },
1256 OP_PUSHDATA2 => {
1257 code => 0x4d,
1258 pushop => !!1,
1259 on_compilation => $class->_compile_OP_PUSHDATA(2),
1260 runner => $class->_OP_PUSHDATA('OP_PUSHDATA2'),
1261 },
1262 OP_PUSHDATA4 => {
1263 code => 0x4e,
1264 pushop => !!1,
1265 on_compilation => $class->_compile_OP_PUSHDATA(4),
1266 runner => $class->_OP_PUSHDATA('OP_PUSHDATA4'),
1267 },
1268 OP_1NEGATE => {
1269 code => 0x4f,
1270 pushop => !!1,
1271 on_compilation => $class->_compile_OP_NUM(-1),
1272 runner => $class->_OP_PUSHDATA,
1273 },
1274 OP_RESERVED => {
1275 code => 0x50,
1276 runner => $class->_OP_RESERVED,
1277 },
1278 OP_NOP => {
1279 code => 0x61,
1280 runner => $class->_OP_NOP,
1281 },
1282 OP_VER => {
1283 code => 0x62,
1284 runner => $class->_OP_VER,
1285 },
1286 OP_IF => {
1287 code => 0x63,
1288 on_compilation => $class->_compile_OP_IF,
1289 runner => $class->_OP_IF,
1290 },
1291 OP_NOTIF => {
1292 code => 0x64,
1293 on_compilation => $class->_compile_OP_IF,
1294 runner => $class->_OP_IF(!!1),
1295 },
1296 OP_VERIF => {
1297 code => 0x65,
1298 on_compilation => $class->_compile_OP_VERIF,
1299 },
1300 OP_VERNOTIF => {
1301 code => 0x66,
1302 on_compilation => $class->_compile_OP_VERIF,
1303 },
1304 OP_ELSE => {
1305 code => 0x67,
1306 on_compilation => $class->_compile_OP_ELSE,
1307 runner => $class->_OP_ELSE,
1308 },
1309 OP_ENDIF => {
1310 code => 0x68,
1311 on_compilation => $class->_compile_OP_ENDIF,
1312 runner => $class->_OP_ENDIF,
1313 },
1314 OP_VERIFY => {
1315 code => 0x69,
1316 runner => $class->_OP_VERIFY,
1317 },
1318 OP_RETURN => {
1319 code => 0x6a,
1320 runner => $class->_OP_RETURN,
1321 },
1322 OP_TOALTSTACK => {
1323 code => 0x6b,
1324 runner => $class->_OP_TOALTSTACK,
1325 },
1326 OP_FROMALTSTACK => {
1327 code => 0x6c,
1328 runner => $class->_OP_FROMALTSTACK,
1329 },
1330 OP_2DROP => {
1331 code => 0x6d,
1332 runner => $class->_OP_2DROP,
1333 },
1334 OP_2DUP => {
1335 code => 0x6e,
1336 runner => $class->_OP_2DUP,
1337 },
1338 OP_3DUP => {
1339 code => 0x6f,
1340 runner => $class->_OP_3DUP,
1341 },
1342 OP_2OVER => {
1343 code => 0x70,
1344 runner => $class->_OP_2OVER,
1345 },
1346 OP_2ROT => {
1347 code => 0x71,
1348 runner => $class->_OP_2ROT,
1349 },
1350 OP_2SWAP => {
1351 code => 0x72,
1352 runner => $class->_OP_2SWAP,
1353 },
1354 OP_IFDUP => {
1355 code => 0x73,
1356 runner => $class->_OP_IFDUP,
1357 },
1358 OP_DEPTH => {
1359 code => 0x74,
1360 runner => $class->_OP_DEPTH,
1361 },
1362 OP_DROP => {
1363 code => 0x75,
1364 runner => $class->_OP_DROP,
1365 },
1366 OP_DUP => {
1367 code => 0x76,
1368 runner => $class->_OP_DUP,
1369 },
1370 OP_NIP => {
1371 code => 0x77,
1372 runner => $class->_OP_NIP,
1373 },
1374 OP_OVER => {
1375 code => 0x78,
1376 runner => $class->_OP_OVER,
1377 },
1378 OP_PICK => {
1379 code => 0x79,
1380 runner => $class->_OP_PICK,
1381 },
1382 OP_ROLL => {
1383 code => 0x7a,
1384 runner => $class->_OP_ROLL,
1385 },
1386 OP_ROT => {
1387 code => 0x7b,
1388 runner => $class->_OP_ROT,
1389 },
1390 OP_SWAP => {
1391 code => 0x7c,
1392 runner => $class->_OP_SWAP,
1393 },
1394 OP_TUCK => {
1395 code => 0x7d,
1396 runner => $class->_OP_TUCK,
1397 },
1398 OP_CAT => {
1399 code => 0x7e,
1400 on_compilation => $class->_compile_disabled,
1401 },
1402 OP_SUBSTR => {
1403 code => 0x7f,
1404 on_compilation => $class->_compile_disabled,
1405 },
1406 OP_LEFT => {
1407 code => 0x80,
1408 on_compilation => $class->_compile_disabled,
1409 },
1410 OP_RIGHT => {
1411 code => 0x81,
1412 on_compilation => $class->_compile_disabled,
1413 },
1414 OP_SIZE => {
1415 code => 0x82,
1416 runner => $class->_OP_SIZE,
1417 },
1418 OP_INVERT => {
1419 code => 0x83,
1420 on_compilation => $class->_compile_disabled,
1421 },
1422 OP_AND => {
1423 code => 0x84,
1424 on_compilation => $class->_compile_disabled,
1425 },
1426 OP_OR => {
1427 code => 0x85,
1428 on_compilation => $class->_compile_disabled,
1429 },
1430 OP_XOR => {
1431 code => 0x86,
1432 on_compilation => $class->_compile_disabled,
1433 },
1434 OP_EQUAL => {
1435 code => 0x87,
1436 runner => $class->_OP_EQUAL,
1437 },
1438 OP_EQUALVERIFY => {
1439 code => 0x88,
1440 runner => $class->_OP_EQUALVERIFY
1441 },
1442 OP_RESERVED1 => {
1443 code => 0x89,
1444 runner => $class->_OP_RESERVED,
1445 },
1446 OP_RESERVED2 => {
1447 code => 0x8a,
1448 runner => $class->_OP_RESERVED,
1449 },
1450 OP_1ADD => {
1451 code => 0x8b,
1452 runner => $class->_OP_1ADD,
1453 },
1454 OP_1SUB => {
1455 code => 0x8c,
1456 runner => $class->_OP_1SUB,
1457 },
1458 OP_2MUL => {
1459 code => 0x8d,
1460 on_compilation => $class->_compile_disabled,
1461 },
1462 OP_2DIV => {
1463 code => 0x8e,
1464 on_compilation => $class->_compile_disabled,
1465 },
1466 OP_NEGATE => {
1467 code => 0x8f,
1468 runner => $class->_OP_NEGATE,
1469 },
1470 OP_ABS => {
1471 code => 0x90,
1472 runner => $class->_OP_ABS,
1473 },
1474 OP_NOT => {
1475 code => 0x91,
1476 runner => $class->_OP_NOT,
1477 },
1478 OP_0NOTEQUAL => {
1479 code => 0x92,
1480 runner => $class->_OP_0NOTEQUAL,
1481 },
1482 OP_ADD => {
1483 code => 0x93,
1484 runner => $class->_OP_ADD,
1485 },
1486 OP_SUB => {
1487 code => 0x94,
1488 runner => $class->_OP_SUB,
1489 },
1490 OP_MUL => {
1491 code => 0x95,
1492 on_compilation => $class->_compile_disabled,
1493 },
1494 OP_DIV => {
1495 code => 0x96,
1496 on_compilation => $class->_compile_disabled,
1497 },
1498 OP_MOD => {
1499 code => 0x97,
1500 on_compilation => $class->_compile_disabled,
1501 },
1502 OP_LSHIFT => {
1503 code => 0x98,
1504 on_compilation => $class->_compile_disabled,
1505 },
1506 OP_RSHIFT => {
1507 code => 0x99,
1508 on_compilation => $class->_compile_disabled,
1509 },
1510 OP_BOOLAND => {
1511 code => 0x9a,
1512 runner => $class->_OP_BOOLAND,
1513 },
1514 OP_BOOLOR => {
1515 code => 0x9b,
1516 runner => $class->_OP_BOOLOR,
1517 },
1518 OP_NUMEQUAL => {
1519 code => 0x9c,
1520 runner => $class->_OP_NUMEQUAL,
1521 },
1522 OP_NUMEQUALVERIFY => {
1523 code => 0x9d,
1524 runner => $class->_OP_NUMEQUALVERIFY,
1525 },
1526 OP_NUMNOTEQUAL => {
1527 code => 0x9e,
1528 runner => $class->_OP_NUMNOTEQUAL,
1529 },
1530 OP_LESSTHAN => {
1531 code => 0x9f,
1532 runner => $class->_OP_LESSTHAN,
1533 },
1534 OP_GREATERTHAN => {
1535 code => 0xa0,
1536 runner => $class->_OP_GREATERTHAN,
1537 },
1538 OP_LESSTHANOREQUAL => {
1539 code => 0xa1,
1540 runner => $class->_OP_LESSTHANOREQUAL,
1541 },
1542 OP_GREATERTHANOREQUAL => {
1543 code => 0xa2,
1544 runner => $class->_OP_GREATERTHANOREQUAL,
1545 },
1546 OP_MIN => {
1547 code => 0xa3,
1548 runner => $class->_OP_MIN,
1549 },
1550 OP_MAX => {
1551 code => 0xa4,
1552 runner => $class->_OP_MAX,
1553 },
1554 OP_WITHIN => {
1555 code => 0xa5,
1556 runner => $class->_OP_WITHIN,
1557 },
1558 OP_RIPEMD160 => {
1559 code => 0xa6,
1560 runner => $class->_OP_RIPEMD160,
1561 },
1562 OP_SHA1 => {
1563 code => 0xa7,
1564 runner => $class->_OP_SHA1,
1565 },
1566 OP_SHA256 => {
1567 code => 0xa8,
1568 runner => $class->_OP_SHA256,
1569 },
1570 OP_HASH160 => {
1571 code => 0xa9,
1572 runner => $class->_OP_HASH160,
1573 },
1574 OP_HASH256 => {
1575 code => 0xaa,
1576 runner => $class->_OP_HASH256,
1577 },
1578 OP_CODESEPARATOR => {
1579 code => 0xab,
1580 needs_transaction => !!1,
1581 runner => $class->_OP_CODESEPARATOR,
1582 },
1583 OP_CHECKSIG => {
1584 code => 0xac,
1585 needs_transaction => !!1,
1586 sigop => !!1,
1587 runner => $class->_OP_CHECKSIG,
1588 },
1589 OP_CHECKSIGVERIFY => {
1590 code => 0xad,
1591 needs_transaction => !!1,
1592 sigop => !!1,
1593 runner => $class->_OP_CHECKSIGVERIFY
1594 },
1595 OP_CHECKMULTISIG => {
1596 code => 0xae,
1597 needs_transaction => !!1,
1598 sigop => !!1,
1599 runner => $class->_OP_CHECKMULTISIG,
1600 },
1601 OP_CHECKMULTISIGVERIFY => {
1602 code => 0xaf,
1603 needs_transaction => !!1,
1604 sigop => !!1,
1605 runner => $class->_OP_CHECKMULTISIGVERIFY
1606 },
1607 OP_CHECKLOCKTIMEVERIFY => {
1608 code => 0xb1,
1609 needs_transaction => !!1,
1610 runner => $class->_OP_CHECKLOCKTIMEVERIFY,
1611 },
1612 OP_CHECKSEQUENCEVERIFY => {
1613 code => 0xb2,
1614 needs_transaction => !!1,
1615 runner => $class->_OP_CHECKSEQUENCEVERIFY,
1616 },
1617 );
1618  
1619 86 for my $num (1 .. 75) {
1620 6450 $opcodes{"OP_PUSH$num"} = {
1621 name => 'OP_PUSH',
1622 code => $num,
1623 pushop => !!1,
1624 on_compilation => $class->_compile_OP_PUSH($num),
1625 runner => $class->_OP_PUSHDATA('OP_PUSH'),
1626 };
1627 }
1628  
1629 86 for my $num (1 .. 16) {
1630 1376 $opcodes{"OP_$num"} = {
1631 code => 0x50 + $num,
1632 pushop => !!1,
1633 on_compilation => $class->_compile_OP_NUM($num),
1634 runner => $class->_OP_PUSHDATA,
1635 };
1636 }
1637  
1638 86 for my $num (1, 4 .. 10) {
1639 688 $opcodes{"OP_NOP$num"} = {
1640 code => 0xaf + $num,
1641 runner => $class->_OP_NOP_UPGRADEABLE,
1642 };
1643 }
1644  
1645 # aliases - prefixed with underscore
1646 86 $opcodes{_OP_FALSE} = $opcodes{OP_0};
1647 86 $opcodes{_OP_TRUE} = $opcodes{OP_1};
1648  
1649 86 return %opcodes;
1650 }
1651  
1652 sub opcodes
1653 1917 ▶{
Subroutine opcodes: called CC=2 SCAR=6.9
Pod undocumented
1654 1917 my ($class) = @_;
1655  
1656 1917 state $maps = {};
1657 1917 ▶ return $maps->{$class} //= do {
Condition66%2/3
$maps->{$class} //= do { my(%opcodes) = $class->_build_opcodes; +{map({my $name = $_; $name =~ s/^_//u; $_, $class->new("name", $name, %{$opcodes{$_};});} keys %opcodes)} }
l!l&&r!l&&!r
1831860
MC/DC0%0/2
$maps->{$class} //= do { my(%opcodes) = $class->_build_opcodes; +{map({my $name = $_; $name =~ s/^_//u; $_, $class->new("name", $name, %{$opcodes{$_};});} keys %opcodes)} }
$maps->{$class} do { my(%opcodes) = $class->_build_opcodes; +{map({my $name = $_; $name =~ s/^_//u; $_, $class->new("name", $name, %{$opcodes{$_};});} keys %opcodes)} }
Truth table66%2/3
A //= B
A= $maps->{$class}B= do { my(%opcodes) = $class->_build_opcodes; +{map({my $name = $_; $name =~ s/^_//u; $_, $class->new("name", $name, %{$opcodes{$_};});} keys %opcodes)} }
ABresult
1X1
011
000
1658 86 my %opcodes = $class->_build_opcodes;
1659 +{
1660 map {
1661 86 my $name = $_;
1662 18652 $name =~ s/^_//;
1663 18652 $_, $class->new(name => $name, %{$opcodes{$_}})
1664 } keys %opcodes
1665 };
1666 };
1667 }
1668  
1669 sub opcodes_reverse
1670 631 ▶{
Subroutine opcodes_reverse: called CC=2 SCAR=6.9
Pod undocumented
1671 631 my ($class) = @_;
1672  
1673 631 state $maps = {};
1674 631 ▶ return $maps->{$class} //= do {
Condition66%2/3
$maps->{$class} //= do { my(%codes) = %{$class->opcodes;}; +{map({$codes{$_}{"code"}, $codes{$_};} grep({not $_ =~ /^_/u;} keys %codes))} }
l!l&&r!l&&!r
570610
MC/DC0%0/2
$maps->{$class} //= do { my(%codes) = %{$class->opcodes;}; +{map({$codes{$_}{"code"}, $codes{$_};} grep({not $_ =~ /^_/u;} keys %codes))} }
$maps->{$class} do { my(%codes) = %{$class->opcodes;}; +{map({$codes{$_}{"code"}, $codes{$_};} grep({not $_ =~ /^_/u;} keys %codes))} }
Truth table66%2/3
A //= B
A= $maps->{$class}B= do { my(%codes) = %{$class->opcodes;}; +{map({$codes{$_}{"code"}, $codes{$_};} grep({not $_ =~ /^_/u;} keys %codes))} }
ABresult
1X1
011
000
1675 61 my %codes = %{$class->opcodes};
1676 61 +{map { $codes{$_}{code}, $codes{$_} } grep { $_ !~ /^_/ } keys %codes};
1677 };
1678 }
1679  
1680 # this is how Bitcoin Core classifies opcodes as "push opcode"
1681 sub non_push_opcode
1682 2867 ▶{
Subroutine non_push_opcode: called CC=1 SCAR=0.0
Pod undocumented
1683 2867 $_[0]->code > 0x60;
1684 }
1685  
1686 sub execute
1687 1619 ▶{
Subroutine execute: called CC=2 SCAR=7.0
Pod documented
1688 1619 my $self = shift;
1689  
1690 1619 my $runner = $self->runner;
1691 1619 ▶ die_no_trace $self->name . ' is not implemented'
Branch: 1 branch
BranchTrueFalseTotal
unless $runner 0 1619 1619
1692 unless $runner;
1693  
1694 1619 goto $runner;
1695 }
1696  
1697 sub _make_unknown
1698 2 ▶{
Subroutine _make_unknown: called CC=1 SCAR=0.0
1699 2 my ($self, $code) = @_;
1700  
1701 2 return $self->new(
1702 name => 'UNKNOWN',
1703 code => $code,
1704 runner => $self->_OP_RESERVED,
1705 );
1706 }
1707  
1708 sub get_opcode_by_code
1709 631 ▶{
Subroutine get_opcode_by_code: called CC=2 SCAR=7.1
Pod documented
1710 631 my ($self, $code) = @_;
1711  
1712 631 ▶ return $self->opcodes_reverse->{$code}
Condition66%2/3
$self->opcodes_reverse->{$code} // $self->_make_unknown($code)
l!l&&r!l&&!r
62920
MC/DC0%0/2
$self->opcodes_reverse->{$code} // $self->_make_unknown($code)
$self->opcodes_reverse->{$code} $self->_make_unknown($code)
Truth table66%2/3
A // B
A= $self->opcodes_reverse->{$code}B= $self->_make_unknown($code)
ABresult
1X1
011
000
1713 // $self->_make_unknown($code);
1714 }
1715  
1716 sub get_opcode_by_name
1717 1856 ▶{
Subroutine get_opcode_by_name: called CC=4 SCAR=15.9
Pod documented
1718 1856 my ($self, $name) = @_;
1719 1856 my $hash = $self->opcodes;
1720  
1721 1856 ▶ my $opcode = $hash->{$name} || $hash->{"_$name"};
Condition66%2/3
$hash->{$name} || $$hash{"_$name"}
l!l&&r!l&&!r
1840160
MC/DC0%0/2
$hash->{$name} || $$hash{"_$name"}
$hash->{$name} $$hash{"_$name"}
Truth table66%2/3
A || B
A= $hash->{$name}B= $$hash{"_$name"}
ABresult
1X1
011
000
1722  
1723 1856 ▶ Bitcoin::Crypto::Exception::ScriptOpcode->raise(
Branch: 1 branch
BranchTrueFalseTotal
unless $opcode 0 1856 1856
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
1724 sprintf "unknown opcode %s (%s)", $name, ref $self || $self
1725 ) unless $opcode;
1726  
1727 1856 return $opcode;
1728 }
1729  
1730 68 1;
1731  
1732 __END__
« Crypto/Role/PSBT/Combiner.pm ↑ Summary Crypto/Role/Key.pm »