Crypto/Script/Opcode.pm

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