| 1 | package Bitcoin::Crypto::Script::Runner; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 65 | $Bitcoin::Crypto::Script::Runner::VERSION = '4.005'; | |||||||||||||||||||||||||||||||||||||||||
| 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 | 1948 | ▶ | sub operations { $_[0]->_compiler->operations } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
operations: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | sub _trigger_transaction | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 161 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_trigger_transaction: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 161 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 161 | $self->transaction->set_runner($self); | |||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | sub _stack_error | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 5 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_stack_error: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 5 | die_no_trace 'stack error'; | |||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | sub _invalid_script | ||||||||||||||||||||||||||||||||||||||||||
| 87 | 37 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_invalid_script: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | 37 | my ($self, $msg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 89 | 37 | ▶ | $msg = defined $msg ? ": $msg" : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | 37 | $self->_script_error('transaction was marked as invalid' . $msg); | |||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | sub _script_error | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 41 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_script_error: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | 41 | my ($self, $error) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 41 | Bitcoin::Crypto::Exception::TransactionScript->raise($error); | |||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | sub to_int | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 661 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_int: called CC=9 SCAR=22.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 661 | my ($self, $bytes, $max_bytes) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 104 | 661 | ▶ | $max_bytes //= 4; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$max_bytes //= 4
MC/DC100%1/1
$max_bytes //= 4
$max_bytes
Truth table100%2/2
A
A= $max_bytes
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | # too big vector cannot be interpreted as a number - see CScriptNum | ||||||||||||||||||||||||||||||||||||||||||
| 107 | 661 | ▶ | die_no_trace 'script numeric value too big to be interpreted as a number' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | if length $bytes > $max_bytes; | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 661 | ▶ | return 0 if !length $bytes; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 282 | my $negative = !!0; | |||||||||||||||||||||||||||||||||||||||||
| 113 | 282 | my $last = substr $bytes, -1, 1; | |||||||||||||||||||||||||||||||||||||||||
| 114 | 282 | my $ord = ord $last; | |||||||||||||||||||||||||||||||||||||||||
| 115 | 282 | ▶ | if ($ord >= 0x80) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 15 | $negative = !!1; | |||||||||||||||||||||||||||||||||||||||||
| 117 | 15 | substr $bytes, -1, 1, chr($ord - 0x80); | |||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | 282 | my $value; | |||||||||||||||||||||||||||||||||||||||||
| 121 | 282 | if (USE_BIGINTS) { | |||||||||||||||||||||||||||||||||||||||||
| 122 | $value = Math::BigInt->from_bytes(scalar reverse $bytes); | ||||||||||||||||||||||||||||||||||||||||||
| 123 | $value->bneg if $negative; | ||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||
| 125 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 126 | 282 | my $bytes = ensure_length scalar(reverse $bytes), 8; | |||||||||||||||||||||||||||||||||||||||||
| 127 | 282 | my ($higher, $lower) = unpack 'NN', $bytes; | |||||||||||||||||||||||||||||||||||||||||
| 128 | 282 | $value = ($higher << 32) + $lower; | |||||||||||||||||||||||||||||||||||||||||
| 129 | 282 | ▶ | $value = -$value if $negative; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | 282 | ▶ | die_no_trace 'number is not minimally encoded' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
ref $self and $self->flags->minimal_data and $bytes ne $self->from_int($value)
ref $self and $self->flags->minimal_data
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)
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | if ref $self && $self->flags->minimal_data && $bytes ne $self->from_int($value); | ||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | 282 | return $value; | |||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | sub from_int | ||||||||||||||||||||||||||||||||||||||||||
| 139 | 2659 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
from_int: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | 2659 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | 2659 | my $bytes; | |||||||||||||||||||||||||||||||||||||||||
| 143 | my $negative; | ||||||||||||||||||||||||||||||||||||||||||
| 144 | 2659 | 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 | 2659 | ▶ | return '' if $value == 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 2517 | $negative = $value < 0; | |||||||||||||||||||||||||||||||||||||||||
| 159 | 2517 | ▶ | $value = abs $value if $negative; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | 2517 | $bytes = pack 'V', $value & 0xffffffff; | |||||||||||||||||||||||||||||||||||||||||
| 162 | 2517 | $bytes .= pack 'V', $value >> 32; | |||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | 2517 | $bytes =~ s/\x00+$//; | |||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | 2517 | my $last = substr $bytes, -1, 1; | |||||||||||||||||||||||||||||||||||||||||
| 168 | 2517 | my $ord = ord $last; | |||||||||||||||||||||||||||||||||||||||||
| 169 | 2517 | ▶ | if ($ord >= 0x80) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 8 | ▶ | if ($negative) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | 2517 | return $bytes; | |||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | sub to_bool | ||||||||||||||||||||||||||||||||||||||||||
| 185 | 221 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_bool: called CC=4 SCAR=14.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | 221 | my ($self, $bytes) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 187 | 221 | ▶ | $bytes //= ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$bytes //= ""
MC/DC0%0/1
$bytes //= ""
$bytes
Truth table50%1/2
A
A= $bytes
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | 221 | my $len = length $bytes; | |||||||||||||||||||||||||||||||||||||||||
| 190 | 221 | ▶ | return !!0 if $len == 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | 202 | my $substr = "\x00" x ($len - 1); | |||||||||||||||||||||||||||||||||||||||||
| 193 | 202 | ▶ | return $bytes ne $substr . "\x00" | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$bytes ne $substr . "\000" && $bytes ne $substr . "\200"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | && $bytes ne $substr . "\x80"; | ||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||
| 197 | sub to_minimal_bool | ||||||||||||||||||||||||||||||||||||||||||
| 198 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_minimal_bool: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | 4 | my ($self, $bytes) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 200 | 4 | ▶ | $bytes //= ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$bytes //= ""
MC/DC0%0/1
$bytes //= ""
$bytes
Truth table50%1/2
A
A= $bytes
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | 4 | ▶ | return undef unless $bytes eq "\x01" or $bytes eq ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$bytes eq "\1" or $bytes eq ""
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 ""
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | 2 | return length $bytes == 1; | |||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | sub from_bool | ||||||||||||||||||||||||||||||||||||||||||
| 207 | 291 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
from_bool: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | 291 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | 291 | ▶ | return !!$value ? "\x01" : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | sub _register_codeseparator | ||||||||||||||||||||||||||||||||||||||||||
| 214 | 14 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_register_codeseparator: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | 14 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | 14 | $self->_set_codeseparator($self->pos); | |||||||||||||||||||||||||||||||||||||||||
| 218 | 14 | return; | |||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | sub _increment_opcode_count | ||||||||||||||||||||||||||||||||||||||||||
| 222 | 612 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_increment_opcode_count: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||||||||||||||||
| 223 | 612 | my ($self, $number) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||
| 225 | # numify from bigint | ||||||||||||||||||||||||||||||||||||||||||
| 226 | 612 | $number = "$number"; | |||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||
| 228 | 612 | $self->_set_opcode_count($self->_opcode_count + $number); | |||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||
| 230 | 612 | ▶ | $self->_script_error('script non-push opcode count exceeded') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $self->is_tapscript and $self->_opcode_count > 201
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
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | if !$self->is_tapscript | ||||||||||||||||||||||||||||||||||||||||||
| 232 | && $self->_opcode_count > SCRIPT_MAX_OPCODES; | ||||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||
| 235 | sub stack_serialized | ||||||||||||||||||||||||||||||||||||||||||
| 236 | 62 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stack_serialized: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 237 | 62 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | return join '', | ||||||||||||||||||||||||||||||||||||||||||
| 240 | 124 | ▶ | map { length $_ == 0 ? "\x00" : $_ } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | 554 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
execute: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 251 | 554 | my ($self, $script, $initial_stack) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||
| 253 | 554 | $self->start($script, $initial_stack); | |||||||||||||||||||||||||||||||||||||||||
| 254 | 530 | ▶ | if (!$self->success) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 255 | 443 | 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 | 443 | local $Bitcoin::Crypto::Types::CHECK_BYTESTRINGS = !!0; | |||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | 443 | ▶ | 1 while $stepper->(); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | 485 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | 65 | signature_for start => ( | |||||||||||||||||||||||||||||||||||||||||
| 268 | method => !!1, | ||||||||||||||||||||||||||||||||||||||||||
| 269 | positional => [BitcoinScript, ArrayRef [ByteStr], {default => []}], | ||||||||||||||||||||||||||||||||||||||||||
| 270 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||
| 272 | sub start | ||||||||||||||||||||||||||||||||||||||||||
| 273 | 604 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
start: called CC=5 SCAR=16.4
| |||||||||||||||||||||||||||||||||||||||||||
| 274 | 604 | my ($self, $script, $initial_stack) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||
| 276 | 604 | $self->set_script($script); | |||||||||||||||||||||||||||||||||||||||||
| 277 | 604 | $self->_set_alt_stack([]); | |||||||||||||||||||||||||||||||||||||||||
| 278 | 604 | $self->_set_pos(0); | |||||||||||||||||||||||||||||||||||||||||
| 279 | 604 | $self->_clear_codeseparator; | |||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||
| 281 | 604 | my $compiler = $self->_compiler; | |||||||||||||||||||||||||||||||||||||||||
| 282 | 604 | my $is_tapscript = $self->is_tapscript; | |||||||||||||||||||||||||||||||||||||||||
| 283 | 604 | $compiler->assert_valid; | |||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||
| 285 | 580 | ▶ | Bitcoin::Crypto::Exception::ScriptRuntime->raise( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$is_tapscript and not $self->flags->taproot
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | 580 | $self->_set_opcode_count(0); | |||||||||||||||||||||||||||||||||||||||||
| 292 | 580 | ▶ | $self->_increment_opcode_count($compiler->opcode_count // 0); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$compiler->opcode_count // 0
MC/DC0%0/1
$compiler->opcode_count // 0
$compiler->opcode_count
Truth table50%1/2
A
A= $compiler->opcode_count
| |||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||
| 294 | # run this ONLY if the script was not marked as "unconditionally valid" | ||||||||||||||||||||||||||||||||||||||||||
| 295 | 580 | ▶ | if (!$compiler->unconditionally_valid) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 296 | Bitcoin::Crypto::Exception::ScriptRuntime->trap_into( | ||||||||||||||||||||||||||||||||||||||||||
| 297 | 493 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.3
| |||||||||||||||||||||||||||||||||||||||||||
| 298 | 493 | ▶ | die_no_trace 'script size exceeded' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $is_tapscript and length $script->to_serialized > 10000
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
| |||||||||||||||||||||||||||||||||||||||||||
| 299 | if !$is_tapscript | ||||||||||||||||||||||||||||||||||||||||||
| 300 | && length $script->to_serialized > SCRIPT_MAX_SIZE; | ||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||
| 302 | die_no_trace 'maximum stack element size exceeded' | ||||||||||||||||||||||||||||||||||||||||||
| 303 | 493 | ▶ | if any { $_->[0]->pushop && length $_->[2] > SCRIPT_MAX_ELEMENT_SIZE } @{$self->operations}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||
| 305 | 493 | ); | |||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | Bitcoin::Crypto::Exception::ScriptPush->trap_into( | ||||||||||||||||||||||||||||||||||||||||||
| 308 | 493 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.6
| |||||||||||||||||||||||||||||||||||||||||||
| 309 | 493 | ▶ | die_no_trace 'maximum initial stack element count exceeded' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$is_tapscript and @$initial_stack > 1000
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
| |||||||||||||||||||||||||||||||||||||||||||
| 310 | if $is_tapscript && @$initial_stack > SCRIPT_MAX_STACK_ELEMENTS; | ||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||
| 312 | die_no_trace 'maximum initial stack element size exceeded' | ||||||||||||||||||||||||||||||||||||||||||
| 313 | 493 | ▶ | if any { length $_ > SCRIPT_MAX_ELEMENT_SIZE } @$initial_stack; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||
| 315 | 493 | $self->_set_stack($initial_stack); | |||||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||||
| 317 | 493 | ); | |||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||
| 320 | 580 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||
| 323 | sub _step | ||||||||||||||||||||||||||||||||||||||||||
| 324 | 637 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_step: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 325 | 637 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||
| 327 | # if pos is undefined, execution was not yet started | ||||||||||||||||||||||||||||||||||||||||||
| 328 | 637 | my $pos = $self->pos; | |||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | ▶ | return sub { !!0 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 330 | 637 | ▶ | unless defined $pos; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||
| 332 | 637 | my $operations = $self->operations; | |||||||||||||||||||||||||||||||||||||||||
| 333 | 637 | my $has_transaction = $self->has_transaction; | |||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||
| 335 | 1796 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 336 | 1796 | my $compiled_op = $operations->[$pos]; | |||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||
| 338 | # out of operations | ||||||||||||||||||||||||||||||||||||||||||
| 339 | 1796 | ▶ | return !!0 unless defined $compiled_op; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 340 | 1396 | my ($op, $raw_op, @args) = @{$compiled_op}; | |||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||
| 342 | 1396 | ▶ | Bitcoin::Crypto::Exception::TransactionScript->raise( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$op->needs_transaction and not $has_transaction
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | 1396 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 348 | 1396 | $op->execute($self, @args); | |||||||||||||||||||||||||||||||||||||||||
| 349 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 350 | 1396 | "error at pos $pos (" . $op->name . ")" | |||||||||||||||||||||||||||||||||||||||||
| 351 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||
| 353 | # cannot trust $pos anymore. Jumps in script could've happened | ||||||||||||||||||||||||||||||||||||||||||
| 354 | 1349 | $pos = $self->pos + 1; | |||||||||||||||||||||||||||||||||||||||||
| 355 | 1349 | $self->_set_pos($pos); | |||||||||||||||||||||||||||||||||||||||||
| 356 | 1349 | return !!1; | |||||||||||||||||||||||||||||||||||||||||
| 357 | 637 | }; | |||||||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||
| 360 | sub step | ||||||||||||||||||||||||||||||||||||||||||
| 361 | 194 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
step: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 362 | 194 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||
| 364 | 194 | return $self->_step->(); | |||||||||||||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||
| 367 | sub _subscript_legacy | ||||||||||||||||||||||||||||||||||||||||||
| 368 | 68 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_subscript_legacy: called CC=11 SCAR=24.2
| |||||||||||||||||||||||||||||||||||||||||||
| 369 | 68 | my ($self, $sigs) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||
| 371 | 68 | ▶ | my $start = ($self->codeseparator // -1) + 1; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->codeseparator // -1
MC/DC100%1/1
$self->codeseparator // -1
$self->codeseparator
Truth table100%2/2
A
A= $self->codeseparator
| |||||||||||||||||||||||||||||||||||||||||||
| 372 | 68 | my $operations = $self->operations; | |||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||
| 374 | 68 | ▶ | my %sigs_lookup = map { $_ => 1 } grep { length $_ // '' } @{$sigs // []}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition75%3/4
length $_ // ""
$sigs // []
MC/DC0%0/1
length $_ // ""
length $_
MC/DC100%1/1
$sigs // []
$sigs
Truth table50%1/2
A
A= length $_
Truth table100%2/2
A
A= $sigs
| |||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||
| 376 | 68 | my $result = ''; | |||||||||||||||||||||||||||||||||||||||||
| 377 | 68 | foreach my $operation (@{$operations}[$start .. $#$operations]) { | |||||||||||||||||||||||||||||||||||||||||
| 378 | 290 | my ($op, $raw_op, $pushop_data) = @$operation; | |||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||
| 380 | 290 | my $name = $op->name; | |||||||||||||||||||||||||||||||||||||||||
| 381 | 290 | ▶ | next if $name eq 'OP_CODESEPARATOR'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 382 | 286 | ▶ | next if $op->pushop && $sigs_lookup{$pushop_data} && standard_push($name, $pushop_data); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$op->pushop and $sigs_lookup{$pushop_data} and standard_push($name, $pushop_data)
$op->pushop and $sigs_lookup{$pushop_data}
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)
| |||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||
| 384 | 286 | $result .= $raw_op; | |||||||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||
| 387 | 68 | ▶ | if ($self->flags->const_script) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 388 | 2 | my $orig = $self->script->to_serialized; | |||||||||||||||||||||||||||||||||||||||||
| 389 | 2 | ▶ | $self->_invalid_script('script is not constant') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 390 | if $result ne $orig; | ||||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||
| 393 | 67 | return $result; | |||||||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||
| 396 | sub _subscript_segwit | ||||||||||||||||||||||||||||||||||||||||||
| 397 | 127 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_subscript_segwit: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 398 | 127 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||
| 400 | 127 | my $codeseparator = $self->codeseparator; | |||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||
| 402 | 127 | ▶ | return $self->script->to_serialized | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | 195 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
subscript: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 411 | 195 | ▶ | goto \&_subscript_segwit | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 412 | if $_[0]->transaction->this_input->is_segwit; | ||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||
| 414 | 68 | goto \&_subscript_legacy; | |||||||||||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||
| 417 | sub success | ||||||||||||||||||||||||||||||||||||||||||
| 418 | 772 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
success: called CC=11 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 419 | 772 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||
| 421 | 772 | ▶ | return !!1 if $self->_compiler->unconditionally_valid; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 422 | 598 | ▶ | return !!0 if $self->pos != @{$self->operations}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||
| 424 | 159 | my $stack = $self->stack; | |||||||||||||||||||||||||||||||||||||||||
| 425 | 159 | ▶ | return !!0 if !$stack; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 426 | 159 | ▶ | return !!0 if !$stack->[-1]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 427 | 151 | ▶ | return !!0 if !$self->to_bool($stack->[-1]); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | 151 | ▶ | if (@$stack > 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 433 | 17 | ▶ | my $segwit = $self->has_transaction && $self->transaction->is_native_segwit; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->has_transaction && $self->transaction->is_native_segwit
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
| |||||||||||||||||||||||||||||||||||||||||||
| 434 | 17 | ▶ | return !!0 if $segwit || $self->is_tapscript || $self->flags->clean_stack; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$segwit or $self->is_tapscript or $self->flags->clean_stack
$segwit or $self->is_tapscript
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
| |||||||||||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||
| 437 | 150 | return !!1; | |||||||||||||||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||
| 440 | sub is_tapscript | ||||||||||||||||||||||||||||||||||||||||||
| 441 | 1261 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_tapscript: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 442 | 1261 | my $script = shift->script; | |||||||||||||||||||||||||||||||||||||||||
| 443 | 1261 | ▶ | return $script && $script->isa('Bitcoin::Crypto::Tapscript'); | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$script && $script->isa('Bitcoin::Crypto::Tapscript')
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')
| |||||||||||||||||||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||||
| 446 | 65 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||
| 448 | __END__ | ||||||||||||||||||||||||||||||||||||||||||