Crypto/Script/Runner.pm

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