Crypto/Script/Runner.pm

filter: Statementstmt 99.5% 204 / 205 Branchbran 84.1% 69 / 82 Conditioncond 61.0% 36 / 59 MC/DCmcdc 20.5% 7 / 34 Subroutinesub 97.5% 40 / 41 Podpod 100% 11 / 11 totaltotal 84.9% 367 / 432 CC 65 SCAR 16.7
CC
65
Cov
89%
success
12.0
_subscript_legacy
11.3
to_int
9.2
CRAP 5.3
« Crypto/Block.pm ↑ Summary Crypto/Script/Opcode.pm »
1 package Bitcoin::Crypto::Script::Runner;
2 65 $Bitcoin::Crypto::Script::Runner::VERSION = '4.004';
3 65 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 65 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 65 ▶use Mooish::Base -standard;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 65 ▶use Types::Common -sigs;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 65 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 65 ▶use List::Util qw(any);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 65 ▶use Bitcoin::Crypto::Types -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 65 ▶use Bitcoin::Crypto::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 65 ▶use Bitcoin::Crypto::Helpers qw(pad_hex ensure_length standard_push die_no_trace);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 65 ▶use Bitcoin::Crypto::Script::Transaction;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 65 ▶use Bitcoin::Crypto::Transaction::Flags;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 65 ▶use Bitcoin::Crypto::Constants qw(:script USE_BIGINTS);
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 65 has field 'script' => (
20 isa => InstanceOf ['Bitcoin::Crypto::Script'],
21 writer => 1,
22 handles => [qw(_compiler)],
23 );
24  
25 65 has option 'transaction' => (
26 coerce => (InstanceOf ['Bitcoin::Crypto::Script::Transaction'])
27 ->plus_coercions(
28 InstanceOf ['Bitcoin::Crypto::Transaction'],
29 q{Bitcoin::Crypto::Script::Transaction->new(transaction => $_)}
30 ),
31 trigger => 1,
32 writer => 1,
33 clearer => 1,
34 );
35  
36 65 has param 'flags' => (
37 coerce => (InstanceOf ['Bitcoin::Crypto::Transaction::Flags'])
38 ->plus_coercions(
39 Undef, q{Bitcoin::Crypto::Transaction::Flags->new}
40 ),
41 writer => 1,
42 default => undef,
43 );
44  
45 65 has field 'stack' => (
46 isa => ArrayRef [ByteStr],
47 writer => -hidden,
48 );
49  
50 65 has field 'alt_stack' => (
51 isa => ArrayRef [ByteStr],
52 writer => -hidden,
53 );
54  
55 65 has field 'pos' => (
56 isa => PositiveOrZeroInt,
57 writer => -hidden,
58 );
59  
60 65 has field 'codeseparator' => (
61 isa => PositiveOrZeroInt,
62 writer => -hidden,
63 clearer => -hidden,
64 );
65  
66 65 has field '_opcode_count' => (
67 isa => Int,
68 writer => 1,
69 );
70  
71 # shortcut for quick access
72 1926 ▶sub operations { $_[0]->_compiler->operations }
Subroutine operations: called CC=1 SCAR=0.0
Pod documented
73  
74 sub _trigger_transaction
75 {
76 160 ▶ my ($self) = @_;
Subroutine _trigger_transaction: called CC=1 SCAR=0.0
77  
78 160 $self->transaction->set_runner($self);
79 }
80  
81 sub _stack_error
82 {
83 5 ▶ die_no_trace 'stack error';
Subroutine _stack_error: called CC=1 SCAR=0.0
84 }
85  
86 sub _invalid_script
87 {
88 37 ▶ my ($self, $msg) = @_;
Subroutine _invalid_script: called CC=2 SCAR=6.9
89 37 ▶ $msg = defined $msg ? ": $msg" : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $msg ? : 19 18 37
90  
91 37 $self->_script_error('transaction was marked as invalid' . $msg);
92 }
93  
94 sub _script_error
95 {
96 41 ▶ my ($self, $error) = @_;
Subroutine _script_error: called CC=1 SCAR=0.0
97  
98 41 Bitcoin::Crypto::Exception::TransactionScript->raise($error);
99 }
100  
101 sub to_int
102 {
103 656 ▶ my ($self, $bytes, $max_bytes) = @_;
Subroutine to_int: called CC=9 SCAR=22.2
Pod documented
104 656 ▶ $max_bytes //= 4;
Condition100%2/2
$max_bytes //= 4
l!l
20636
MC/DC100%1/1
$max_bytes //= 4
$max_bytes
Truth table100%2/2
A
A= $max_bytes
Aresult
11
00
105  
106 # too big vector cannot be interpreted as a number - see CScriptNum
107 656 ▶ die_no_trace 'script numeric value too big to be interpreted as a number'
Branch: 1 branch
BranchTrueFalseTotal
if length $bytes > $max_bytes 0 656 656
108 if length $bytes > $max_bytes;
109  
110 656 ▶ return 0 if !length $bytes;
Branch: 1 branch
BranchTrueFalseTotal
unless length $bytes 379 277 656
111  
112 277 my $negative = !!0;
113 277 my $last = substr $bytes, -1, 1;
114 277 my $ord = ord $last;
115 277 ▶ if ($ord >= 0x80) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ord >= 128) 15 262 277
116 15 $negative = !!1;
117 15 substr $bytes, -1, 1, chr($ord - 0x80);
118 }
119  
120 277 my $value;
121 277 if (USE_BIGINTS) {
122 $value = Math::BigInt->from_bytes(scalar reverse $bytes);
123 $value->bneg if $negative;
124 }
125 else {
126 277 my $bytes = ensure_length scalar(reverse $bytes), 8;
127 277 my ($higher, $lower) = unpack 'NN', $bytes;
128 277 $value = ($higher << 32) + $lower;
129 277 ▶ $value = -$value if $negative;
Branch: 1 branch
BranchTrueFalseTotal
if $negative 15 262 277
130 }
131  
132 277 ▶ die_no_trace 'number is not minimally encoded'
Branch: 1 branch
BranchTrueFalseTotal
if ref $self and $self->flags->minimal_data and $bytes ne $self->from_int($value) 0 277 277
Condition50%3/6
ref $self and $self->flags->minimal_data and $bytes ne $self->from_int($value)
!ll&&!rl&&r
27700
ref $self and $self->flags->minimal_data
!ll&&!rl&&r
752020
MC/DC0%0/3
ref $self and $self->flags->minimal_data and $bytes ne $self->from_int($value)
ref $self $self->flags->minimal_data $bytes ne $self->from_int($value)
Truth table50%2/4
A and B and C
A= ref $selfB= $self->flags->minimal_dataC= $bytes ne $self->from_int($value)
ABCresult
0XX0
10X0
1100
1111
133 if ref $self && $self->flags->minimal_data && $bytes ne $self->from_int($value);
134  
135 277 return $value;
136 }
137  
138 sub from_int
139 {
140 2658 ▶ my ($self, $value) = @_;
Subroutine from_int: called CC=6 SCAR=17.9
Pod documented
141  
142 2658 my $bytes;
143 my $negative;
144 2658 if (USE_BIGINTS) {
145 if (!blessed $value) {
146 $value = Math::BigInt->new($value);
147 }
148  
149 return '' if $value == 0;
150  
151 $negative = $value < 0;
152 $value->babs if $negative;
153  
154 $bytes = reverse pack 'H*', pad_hex($value->to_hex);
155 }
156 else {
157 2658 ▶ return '' if $value == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $value == 0 142 2516 2658
158 2516 $negative = $value < 0;
159 2516 ▶ $value = abs $value if $negative;
Branch: 1 branch
BranchTrueFalseTotal
if $negative 61 2455 2516
160  
161 2516 $bytes = pack 'V', $value & 0xffffffff;
162 2516 $bytes .= pack 'V', $value >> 32;
163  
164 2516 $bytes =~ s/\x00+$//;
165 }
166  
167 2516 my $last = substr $bytes, -1, 1;
168 2516 my $ord = ord $last;
169 2516 ▶ if ($ord >= 0x80) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ord >= 128) { } 8 2508 2516
elsif ($negative) { } 60 2448 2508
170 8 ▶ if ($negative) {
Branch: 1 branch
BranchTrueFalseTotal
if ($negative) { } 1 7 8
171 1 $bytes .= "\x80";
172 }
173 else {
174 7 $bytes .= "\x00";
175 }
176 }
177 elsif ($negative) {
178 60 substr $bytes, -1, 1, chr($ord + 0x80);
179 }
180  
181 2516 return $bytes;
182 }
183  
184 sub to_bool
185 {
186 218 ▶ my ($self, $bytes) = @_;
Subroutine to_bool: called CC=4 SCAR=14.3
Pod documented
187 218 ▶ $bytes //= '';
Condition50%1/2
$bytes //= ""
l!l
2180
MC/DC0%0/1
$bytes //= ""
$bytes
Truth table50%1/2
A
A= $bytes
Aresult
11
00
188  
189 218 my $len = length $bytes;
190 218 ▶ return !!0 if $len == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $len == 0 19 199 218
191  
192 199 my $substr = "\x00" x ($len - 1);
193 199 ▶ return $bytes ne $substr . "\x00"
Condition33%1/3
$bytes ne $substr . "\000" && $bytes ne $substr . "\200"
!ll&&!rl&&r
00199
MC/DC0%0/2
$bytes ne $substr . "\000" && $bytes ne $substr . "\200"
$bytes ne $substr . "\000" $bytes ne $substr . "\200"
Truth table33%1/3
A && B
A= $bytes ne $substr . "\000"B= $bytes ne $substr . "\200"
ABresult
0X0
100
111
194 && $bytes ne $substr . "\x80";
195 }
196  
197 sub to_minimal_bool
198 {
199 4 ▶ my ($self, $bytes) = @_;
Subroutine to_minimal_bool: called CC=4 SCAR=13.9
Pod documented
200 4 ▶ $bytes //= '';
Condition50%1/2
$bytes //= ""
l!l
40
MC/DC0%0/1
$bytes //= ""
$bytes
Truth table50%1/2
A
A= $bytes
Aresult
11
00
201  
202 4 ▶ return undef unless $bytes eq "\x01" or $bytes eq '';
Branch: 1 branch
BranchTrueFalseTotal
unless $bytes eq "\1" or $bytes eq "" 2 2 4
Condition100%3/3
$bytes eq "\1" or $bytes eq ""
l!l&&r!l&&!r
112
MC/DC100%2/2
$bytes eq "\1" or $bytes eq ""
$bytes eq "\1" $bytes eq ""
Truth table100%3/3
A or B
A= $bytes eq "\1"B= $bytes eq ""
ABresult
1X1
011
000
203 2 return length $bytes == 1;
204 }
205  
206 sub from_bool
207 {
208 287 ▶ my ($self, $value) = @_;
Subroutine from_bool: called CC=2 SCAR=6.9
Pod documented
209  
210 287 ▶ return !!$value ? "\x01" : '';
Branch: 1 branch
BranchTrueFalseTotal
!!$value ? : 239 48 287
211 }
212  
213 sub _register_codeseparator
214 {
215 14 ▶ my ($self) = @_;
Subroutine _register_codeseparator: called CC=1 SCAR=0.0
216  
217 14 $self->_set_codeseparator($self->pos);
218 14 return;
219 }
220  
221 sub _increment_opcode_count
222 {
223 605 ▶ my ($self, $number) = @_;
Subroutine _increment_opcode_count: called CC=3 SCAR=11.3
224  
225 # numify from bigint
226 605 $number = "$number";
227  
228 605 $self->_set_opcode_count($self->_opcode_count + $number);
229  
230 605 ▶ $self->_script_error('script non-push opcode count exceeded')
Branch: 1 branch
BranchTrueFalseTotal
if not $self->is_tapscript and $self->_opcode_count > 201 0 605 605
Condition66%2/3
not $self->is_tapscript and $self->_opcode_count > 201
!ll&&!rl&&r
1374680
MC/DC0%0/2
not $self->is_tapscript and $self->_opcode_count > 201
not $self->is_tapscript $self->_opcode_count > 201
Truth table66%2/3
not(A) and B
A= not $self->is_tapscriptB= $self->_opcode_count > 201
ABresult
0X0
100
111
231 if !$self->is_tapscript
232 && $self->_opcode_count > SCRIPT_MAX_OPCODES;
233 }
234  
235 sub stack_serialized
236 {
237 62 ▶ my ($self) = @_;
Subroutine stack_serialized: called CC=2 SCAR=6.9
Pod documented
238  
239 return join '',
240 124 ▶ map { length $_ == 0 ? "\x00" : $_ }
Branch: 1 branch
BranchTrueFalseTotal
length $_ == 0 ? : 34 90 124
241 62 @{$self->stack};
242 }
243  
244 65 signature_for execute => (
245 method => !!1,
246 positional => [BitcoinScript, ArrayRef [ByteStr], {default => []}],
247 );
248  
249 sub execute
250 {
251 549 ▶ my ($self, $script, $initial_stack) = @_;
Subroutine execute: called CC=3 SCAR=11.0
252  
253 549 $self->start($script, $initial_stack);
254 525 ▶ if (!$self->success) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->success) 438 87 525
255 438 my $stepper = $self->_step;
256  
257 # optimization: a lot of operations may want to check bytestrings here, but
258 # all bytestrings were already checked and accepted
259 438 local $Bitcoin::Crypto::Types::CHECK_BYTESTRINGS = !!0;
260  
261 438 ▶ 1 while $stepper->();
Branch: 1 branch
BranchTrueFalseTotal
&$stepper() and do { '???' } 1139 393 1532
262 }
263  
264 480 return $self;
265 }
266  
267 65 signature_for start => (
268 method => !!1,
269 positional => [BitcoinScript, ArrayRef [ByteStr], {default => []}],
270 );
271  
272 sub start
273 {
274 599 ▶ my ($self, $script, $initial_stack) = @_;
Subroutine start: called CC=5 SCAR=16.4
275  
276 599 $self->set_script($script);
277 599 $self->_set_alt_stack([]);
278 599 $self->_set_pos(0);
279 599 $self->_clear_codeseparator;
280  
281 599 my $compiler = $self->_compiler;
282 599 my $is_tapscript = $self->is_tapscript;
283 599 $compiler->assert_valid;
284  
285 575 ▶ Bitcoin::Crypto::Exception::ScriptRuntime->raise(
Branch: 1 branch
BranchTrueFalseTotal
if $is_tapscript and not $self->flags->taproot 0 575 575
Condition66%2/3
$is_tapscript and not $self->flags->taproot
!ll&&!rl&&r
4381370
MC/DC0%0/2
$is_tapscript and not $self->flags->taproot
$is_tapscript not $self->flags->taproot
Truth table66%2/3
A and not(B)
A= $is_tapscriptB= not $self->flags->taproot
ABresult
0X0
100
111
286 'cannot run tapscript without taproot flag'
287 ) if $is_tapscript && !$self->flags->taproot;
288  
289 # set and increment opcode count. Incrementing is checking for too many
290 # opcodes (SCRIPT_MAX_OPCODES)
291 575 $self->_set_opcode_count(0);
292 575 ▶ $self->_increment_opcode_count($compiler->opcode_count // 0);
Condition50%1/2
$compiler->opcode_count // 0
l!l
5750
MC/DC0%0/1
$compiler->opcode_count // 0
$compiler->opcode_count
Truth table50%1/2
A
A= $compiler->opcode_count
Aresult
11
00
293  
294 # run this ONLY if the script was not marked as "unconditionally valid"
295 575 ▶ if (!$compiler->unconditionally_valid) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($compiler->unconditionally_valid) 488 87 575
296 Bitcoin::Crypto::Exception::ScriptRuntime->trap_into(
297 sub {
298 488 ▶ die_no_trace 'script size exceeded'
Subroutine __ANON__: called CC=4 SCAR=14.3
Branch: 1 branch
BranchTrueFalseTotal
if not $is_tapscript and length $script->to_serialized > 10000 0 488 488
Condition66%2/3
not $is_tapscript and length $script->to_serialized > 10000
!ll&&!rl&&r
504380
MC/DC0%0/2
not $is_tapscript and length $script->to_serialized > 10000
not $is_tapscript length $script->to_serialized > 10000
Truth table66%2/3
not(A) and B
A= not $is_tapscriptB= length $script->to_serialized > 10000
ABresult
0X0
100
111
299 if !$is_tapscript
300 && length $script->to_serialized > SCRIPT_MAX_SIZE;
301  
302 die_no_trace 'maximum stack element size exceeded'
303 488 ▶ if any { $_->[0]->pushop && length $_->[2] > SCRIPT_MAX_ELEMENT_SIZE } @{$self->operations};
Subroutine __ANON__: called CC=2 SCAR=7.0
Branch: 2 branches
BranchTrueFalseTotal
if &any(sub { $_->[0]->pushop and length $_->[2] > 520; } , @{$self->operations;}) 0 488 488
$_->[0]->pushop and length $_->[2] > 520 854 652 1506
304 }
305 488 );
306  
307 Bitcoin::Crypto::Exception::ScriptPush->trap_into(
308 sub {
309 488 ▶ die_no_trace 'maximum initial stack element count exceeded'
Subroutine __ANON__: called CC=4 SCAR=14.6
Branch: 1 branch
BranchTrueFalseTotal
if $is_tapscript and @$initial_stack > 1000 0 488 488
Condition66%2/3
$is_tapscript and @$initial_stack > 1000
!ll&&!rl&&r
438500
MC/DC0%0/2
$is_tapscript and @$initial_stack > 1000
$is_tapscript @$initial_stack > 1000
Truth table66%2/3
A and B
A= $is_tapscriptB= @$initial_stack > 1000
ABresult
0X0
100
111
310 if $is_tapscript && @$initial_stack > SCRIPT_MAX_STACK_ELEMENTS;
311  
312 die_no_trace 'maximum initial stack element size exceeded'
313 488 ▶ if any { length $_ > SCRIPT_MAX_ELEMENT_SIZE } @$initial_stack;
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
if &any(sub { length $_ > 520; } , @$initial_stack) 0 488 488
314  
315 488 $self->_set_stack($initial_stack);
316 }
317 488 );
318 }
319  
320 575 return $self;
321 }
322  
323 sub _step
324 {
325 632 ▶ my ($self) = @_;
Subroutine _step: called CC=2 SCAR=7.0
326  
327 # if pos is undefined, execution was not yet started
328 632 my $pos = $self->pos;
329 0 ▶ return sub { !!0 }
Subroutine __ANON__: not called CC=1 SCAR=6.9
330 632 ▶ unless defined $pos;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pos 0 632 632
331  
332 632 my $operations = $self->operations;
333 632 my $has_transaction = $self->has_transaction;
334  
335 return sub {
336 1771 ▶ my $compiled_op = $operations->[$pos];
Subroutine __ANON__: called CC=4 SCAR=13.9
337  
338 # out of operations
339 1771 ▶ return !!0 unless defined $compiled_op;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $compiled_op 395 1376 1771
340 1376 my ($op, $raw_op, @args) = @{$compiled_op};
341  
342 1376 ▶ Bitcoin::Crypto::Exception::TransactionScript->raise(
Branch: 1 branch
BranchTrueFalseTotal
if $op->needs_transaction and not $has_transaction 0 1376 1376
Condition66%2/3
$op->needs_transaction and not $has_transaction
!ll&&!rl&&r
11831930
MC/DC0%0/2
$op->needs_transaction and not $has_transaction
$op->needs_transaction not $has_transaction
Truth table66%2/3
A and not(B)
A= $op->needs_transactionB= not $has_transaction
ABresult
0X0
100
111
343 'no transaction is set for the script runner'
344 ) if $op->needs_transaction && !$has_transaction;
345  
346 Bitcoin::Crypto::Exception::ScriptRuntime->trap_into(
347 sub {
348 1376 ▶ $op->execute($self, @args);
Subroutine __ANON__: called CC=1 SCAR=0.0
349 },
350 1376 "error at pos $pos (" . $op->name . ")"
351 );
352  
353 # cannot trust $pos anymore. Jumps in script could've happened
354 1328 $pos = $self->pos + 1;
355 1328 $self->_set_pos($pos);
356 1328 return !!1;
357 632 };
358 }
359  
360 sub step
361 {
362 194 ▶ my ($self) = @_;
Subroutine step: called CC=1 SCAR=0.0
Pod documented
363  
364 194 return $self->_step->();
365 }
366  
367 sub _subscript_legacy
368 {
369 64 ▶ my ($self, $sigs) = @_;
Subroutine _subscript_legacy: called CC=11 SCAR=24.2
370  
371 64 ▶ my $start = ($self->codeseparator // -1) + 1;
Condition100%2/2
$self->codeseparator // -1
l!l
757
MC/DC100%1/1
$self->codeseparator // -1
$self->codeseparator
Truth table100%2/2
A
A= $self->codeseparator
Aresult
11
00
372 64 my $operations = $self->operations;
373  
374 64 ▶ my %sigs_lookup = map { $_ => 1 } grep { length $_ // '' } @{$sigs // []};
Condition75%3/4
length $_ // ""
l!l
640
$sigs // []
l!l
5212
MC/DC0%0/1
length $_ // ""
length $_
MC/DC100%1/1
$sigs // []
$sigs
Truth table50%1/2
A
A= length $_
Aresult
11
00
Truth table100%2/2
A
A= $sigs
Aresult
11
00
375  
376 64 my $result = '';
377 64 foreach my $operation (@{$operations}[$start .. $#$operations]) {
378 270 my ($op, $raw_op, $pushop_data) = @$operation;
379  
380 270 my $name = $op->name;
381 270 ▶ next if $name eq 'OP_CODESEPARATOR';
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "OP_CODESEPARATOR" 4 266 270
382 266 ▶ next if $op->pushop && $sigs_lookup{$pushop_data} && standard_push($name, $pushop_data);
Branch: 1 branch
BranchTrueFalseTotal
if $op->pushop and $sigs_lookup{$pushop_data} and standard_push($name, $pushop_data) 0 266 266
Condition50%3/6
$op->pushop and $sigs_lookup{$pushop_data} and standard_push($name, $pushop_data)
!ll&&!rl&&r
26600
$op->pushop and $sigs_lookup{$pushop_data}
!ll&&!rl&&r
1411250
MC/DC0%0/3
$op->pushop and $sigs_lookup{$pushop_data} and standard_push($name, $pushop_data)
$op->pushop $sigs_lookup{$pushop_data} standard_push($name, $pushop_data)
Truth table50%2/4
A and B and C
A= $op->pushopB= $sigs_lookup{$pushop_data}C= standard_push($name, $pushop_data)
ABCresult
0XX0
10X0
1100
1111
383  
384 266 $result .= $raw_op;
385 }
386  
387 64 ▶ if ($self->flags->const_script) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->flags->const_script) 2 62 64
388 2 my $orig = $self->script->to_serialized;
389 2 ▶ $self->_invalid_script('script is not constant')
Branch: 1 branch
BranchTrueFalseTotal
if $result ne $orig 1 1 2
390 if $result ne $orig;
391 }
392  
393 63 return $result;
394 }
395  
396 sub _subscript_segwit
397 {
398 127 ▶ my $self = shift;
Subroutine _subscript_segwit: called CC=2 SCAR=6.9
399  
400 127 my $codeseparator = $self->codeseparator;
401  
402 127 ▶ return $self->script->to_serialized
Branch: 1 branch
BranchTrueFalseTotal
unless defined $codeseparator 117 10 127
403 unless defined $codeseparator;
404  
405 10 my $operations = $self->operations;
406 10 return join '', map { $_->[1] } @{$operations}[$codeseparator + 1 .. $#$operations];
407 }
408  
409 sub subscript
410 {
411 191 ▶ goto \&_subscript_segwit
Subroutine subscript: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]->transaction->this_input->is_segwit 127 64 191
412 if $_[0]->transaction->this_input->is_segwit;
413  
414 64 goto \&_subscript_legacy;
415 }
416  
417 sub success
418 {
419 764 ▶ my ($self) = @_;
Subroutine success: called CC=11 SCAR=24.8
Pod documented
420  
421 764 ▶ return !!1 if $self->_compiler->unconditionally_valid;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_compiler->unconditionally_valid 174 590 764
422 590 ▶ return !!0 if $self->pos != @{$self->operations};
Branch: 1 branch
BranchTrueFalseTotal
if $self->pos != @{$self->operations;} 434 156 590
423  
424 156 my $stack = $self->stack;
425 156 ▶ return !!0 if !$stack;
Branch: 1 branch
BranchTrueFalseTotal
unless $stack 0 156 156
426 156 ▶ return !!0 if !$stack->[-1];
Branch: 1 branch
BranchTrueFalseTotal
unless $stack->[-1] 8 148 156
427 148 ▶ return !!0 if !$self->to_bool($stack->[-1]);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->to_bool($stack->[-1]) 0 148 148
428  
429 # NOTE: clean_stack rule does not check altstack, because altstack can only
430 # be manipulated by the script itself, so there is no chance for witness
431 # malleability
432 148 ▶ if (@$stack > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$stack > 1) 17 131 148
433 17 ▶ my $segwit = $self->has_transaction && $self->transaction->is_native_segwit;
Condition33%1/3
$self->has_transaction && $self->transaction->is_native_segwit
!ll&&!rl&&r
0170
MC/DC0%0/2
$self->has_transaction && $self->transaction->is_native_segwit
$self->has_transaction $self->transaction->is_native_segwit
Truth table33%1/3
A && B
A= $self->has_transactionB= $self->transaction->is_native_segwit
ABresult
0X0
100
111
434 17 ▶ return !!0 if $segwit || $self->is_tapscript || $self->flags->clean_stack;
Branch: 1 branch
BranchTrueFalseTotal
if $segwit or $self->is_tapscript or $self->flags->clean_stack 1 16 17
Condition50%3/6
$segwit or $self->is_tapscript or $self->flags->clean_stack
l!l&&r!l&&!r
0116
$segwit or $self->is_tapscript
l!l&&r!l&&!r
0017
MC/DC33%1/3
$segwit or $self->is_tapscript or $self->flags->clean_stack
$segwit $self->is_tapscript $self->flags->clean_stack
Truth table50%2/4
A or B or C
A= $segwitB= $self->is_tapscriptC= $self->flags->clean_stack
ABCresult
1XX1
01X1
0011
0000
435 }
436  
437 147 return !!1;
438 }
439  
440 sub is_tapscript
441 {
442 1249 ▶ my $script = shift->script;
Subroutine is_tapscript: called CC=2 SCAR=7.1
Pod documented
443 1249 ▶ return $script && $script->isa('Bitcoin::Crypto::Tapscript');
Condition66%2/3
$script && $script->isa('Bitcoin::Crypto::Tapscript')
!ll&&!rl&&r
0972277
MC/DC50%1/2
$script && $script->isa('Bitcoin::Crypto::Tapscript')
$script $script->isa('Bitcoin::Crypto::Tapscript')
Truth table66%2/3
A && B
A= $scriptB= $script->isa('Bitcoin::Crypto::Tapscript')
ABresult
0X0
100
111
444 }
445  
446 65 1;
447  
448 __END__
« Crypto/Block.pm ↑ Summary Crypto/Script/Opcode.pm »