Skip to content

Commit 5e1e2e5

Browse files
committed
Normalize the flag names
1 parent 833c41d commit 5e1e2e5

7 files changed

Lines changed: 130 additions & 82 deletions

File tree

Changes

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@ Revision history for Perl extension Bitcoin::Crypto.
1515
- Bitcoin::Crypto::Transaction::Flags:
1616
- added new_full method
1717
- renamed strict_signatures flag to der_signatures
18+
- renamed nulldummy flag to null_dummy
1819
- added strict_sigantures method
1920
- added signature_pushes_only flag
20-
- added minimalif flag
21+
- added minimal_if flag
2122
- added compressed_pubkeys flag
2223
- added strict_encoding flag
2324
- added low_s_signatures flag
24-
- added minimaldata flag
25-
- added nullfail flag
26-
- added cleanstack flag
25+
- added minimal_data flag
26+
- added null_fail flag
27+
- added clean_stack flag
2728
- added const_script flag
2829
- added known_witness flag
2930
- added illegal_upgradeable_nops flag

lib/Bitcoin/Crypto/Script/Opcode.pm

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ sub _OP_PUSHDATA
257257
my ($runner, $bytes) = @_;
258258

259259
$runner->_invalid_script("push opcode for data is not minimal in $opcode_name")
260-
if $runner->flags->minimaldata && !standard_push($opcode_name, $bytes);
260+
if $runner->flags->minimal_data && !standard_push($opcode_name, $bytes);
261261

262262
push @{$runner->stack}, $bytes;
263263
$class->_verify_stack($runner);
@@ -315,10 +315,10 @@ sub _OP_IF
315315
$runner->_stack_error unless @$stack >= 1;
316316
my $value = pop @$stack;
317317

318-
my $minimalif = $runner->is_tapscript
319-
|| ($runner->has_transaction && $runner->transaction->is_segwit && $runner->flags->minimalif);
318+
my $minimal_if = $runner->is_tapscript
319+
|| ($runner->has_transaction && $runner->transaction->is_segwit && $runner->flags->minimal_if);
320320

321-
$value = $minimalif ? $runner->to_minimal_bool($value) : $runner->to_bool($value);
321+
$value = $minimal_if ? $runner->to_minimal_bool($value) : $runner->to_bool($value);
322322
$runner->_invalid_script('OP_IF argument is not minimal') unless defined $value;
323323

324324
$value = !$value if $inverted;
@@ -1076,7 +1076,7 @@ sub _OP_CHECKSIG
10761076
my $result = __checksig($runner, $sig, $hashtype, $raw_pubkey, $preimage);
10771077

10781078
$runner->_script_error('non-empty signature verification failed')
1079-
if !$result && $runner->flags->nullfail && $sig ne '';
1079+
if !$result && $runner->flags->null_fail && $sig ne '';
10801080

10811081
push @$stack, $runner->from_bool($result);
10821082
};
@@ -1127,7 +1127,7 @@ sub _OP_CHECKMULTISIG
11271127
$runner->_stack_error unless @$stack >= 1;
11281128
my $unused = pop @$stack;
11291129
$runner->_script_error('OP_CHECKMULTISIG dummy argument must be empty')
1130-
if $runner->flags->nulldummy && length $unused;
1130+
if $runner->flags->null_dummy && length $unused;
11311131

11321132
my $found = !!1;
11331133
my %digests;
@@ -1152,7 +1152,7 @@ sub _OP_CHECKMULTISIG
11521152
# last one was found correctly
11531153
my $result = $found && !@signatures_left;
11541154
$runner->_script_error('non-empty signature verification failed')
1155-
if !$result && $runner->flags->nullfail && notall { $_ eq '' } @signatures;
1155+
if !$result && $runner->flags->null_fail && notall { $_ eq '' } @signatures;
11561156

11571157
push @$stack, $runner->from_bool($result);
11581158
};

lib/Bitcoin/Crypto/Script/Runner.pm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ sub to_int
130130
}
131131

132132
die_no_trace 'number is not minimally encoded'
133-
if ref $self && $self->flags->minimaldata && $bytes ne $self->from_int($value);
133+
if ref $self && $self->flags->minimal_data && $bytes ne $self->from_int($value);
134134

135135
return $value;
136136
}
@@ -410,12 +410,12 @@ sub success
410410
return !!0 if !$stack->[-1];
411411
return !!0 if !$self->to_bool($stack->[-1]);
412412

413-
# NOTE: cleanstack rule does not check altstack, because altstack can only
413+
# NOTE: clean_stack rule does not check altstack, because altstack can only
414414
# be manipulated by the script itself, so there is no chance for witness
415415
# malleability
416416
if (@$stack > 1) {
417417
my $segwit = $self->has_transaction && $self->transaction->is_native_segwit;
418-
return !!0 if $segwit || $self->is_tapscript || $self->flags->cleanstack;
418+
return !!0 if $segwit || $self->is_tapscript || $self->flags->clean_stack;
419419
}
420420

421421
return !!1;
@@ -666,7 +666,7 @@ machines.
666666
=head3 from_bool
667667
668668
These methods encode and decode booleans in format which is used on L</stack>.
669-
C<to_minimal_bool> variant is used to enforce MINIMALIF rule.
669+
C<to_minimal_bool> variant is used to enforce L<Bitcoin::Crypto::Transaction::Flags/minimal_if>.
670670
671671
=head3 stack_serialized
672672

lib/Bitcoin/Crypto/Transaction/Flags.pm

Lines changed: 100 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@ has param 'p2sh' => (
1212
writer => 1,
1313
);
1414

15-
has param 'signature_pushes_only' => (
16-
coerce => Bool,
17-
default => 1,
18-
writer => 1,
19-
);
20-
2115
# BIP65
2216
has param 'checklocktimeverify' => (
2317
coerce => Bool,
@@ -47,7 +41,7 @@ has param 'segwit' => (
4741
);
4842

4943
# BIP147
50-
has param 'nulldummy' => (
44+
has param 'null_dummy' => (
5145
coerce => Bool,
5246
default => 1,
5347
writer => 1,
@@ -62,8 +56,14 @@ has param 'taproot' => (
6256

6357
# optional standardness rules below
6458

59+
has param 'signature_pushes_only' => (
60+
coerce => Bool,
61+
default => 0,
62+
writer => 1,
63+
);
64+
6565
# segwit only
66-
has param 'minimalif' => (
66+
has param 'minimal_if' => (
6767
coerce => Bool,
6868
default => 0,
6969
writer => 1,
@@ -88,19 +88,19 @@ has param 'low_s_signatures' => (
8888
writer => 1,
8989
);
9090

91-
has param 'minimaldata' => (
91+
has param 'minimal_data' => (
9292
coerce => Bool,
9393
default => 0,
9494
writer => 1,
9595
);
9696

97-
has param 'nullfail' => (
97+
has param 'null_fail' => (
9898
coerce => Bool,
9999
default => 0,
100100
writer => 1,
101101
);
102102

103-
has param 'cleanstack' => (
103+
has param 'clean_stack' => (
104104
coerce => Bool,
105105
default => 0,
106106
writer => 1,
@@ -130,12 +130,11 @@ sub new_empty
130130

131131
return $self->new(
132132
p2sh => !!0,
133-
signature_pushes_only => !!0,
134133
checklocktimeverify => !!0,
135134
der_signatures => !!0,
136135
checksequenceverify => !!0,
137136
segwit => !!0,
138-
nulldummy => !!0,
137+
null_dummy => !!0,
139138
taproot => !!0,
140139
%args,
141140
);
@@ -146,13 +145,14 @@ sub new_full
146145
my ($self, %args) = @_;
147146

148147
return $self->new(
149-
minimalif => !!1,
148+
signature_pushes_only => !!1,
149+
minimal_if => !!1,
150150
compressed_pubkeys => !!1,
151151
strict_encoding => !!1,
152152
low_s_signatures => !!1,
153-
minimaldata => !!1,
154-
nullfail => !!1,
155-
cleanstack => !!1,
153+
minimal_data => !!1,
154+
null_fail => !!1,
155+
clean_stack => !!1,
156156
const_script => !!1,
157157
known_witness => !!1,
158158
illegal_upgradeable_nops => !!1,
@@ -185,7 +185,7 @@ Bitcoin::Crypto::Transaction::Flags - Consensus flags
185185
186186
# disable some flags (those not passed are active)
187187
my $some_flags = Bitcoin::Crypto::Transaction::Flags->new(
188-
strict_signatures => !!0,
188+
der_signatures => !!0,
189189
);
190190
191191
# use flags in transaction verification
@@ -197,85 +197,118 @@ This is a class that represents a set of consensus rules used in transaction
197197
verification and associated systems. Each attribute of this class represents a
198198
single rule.
199199
200-
By default, all implemented consensus rules are active. As Bitcoin
201-
and this module progress, more rules may be added all enabled by default on
202-
arrival. Since Bitcoin is extended through softforks (implemented in a
200+
By default, all implemented consensus rules are active, and all implemented
201+
standardness rules are inactive when calling L</new>. As Bitcoin and this
202+
module progress, more rules may be added all enabled by default on arrival.
203+
Since Bitcoin is extended through softforks (implemented in a
203204
backward-compatible manner), this should rarely pose a problem with
204205
Bitcoin::Crypto code. If you want to be extra sure, see L</new_empty>.
205206
206207
=head1 INTERFACE
207208
208-
=head2 Attributes
209+
All the following flags are attributes available in the constructor of the
210+
object. They have writer methods named C<set_X>.
209211
210-
=head3 p2sh
212+
=head2 Consensus flags
213+
214+
All consensus flags are active by default.
211215
212-
I<Available in the constructor>.
216+
=head3 p2sh
213217
214218
Whether P2SH verification defined in
215219
L<BIP16|https://github.com/bitcoin/bips/blob/master/bip-0016.mediawiki> should
216220
be used.
217221
218-
I<writer:> C<set_p2sh>
219-
220-
=head3 strict_signatures
221-
222-
I<Available in the constructor>.
222+
=head3 der_signatures
223223
224224
Whether strict DER signature verification defined in
225225
L<BIP66|https://github.com/bitcoin/bips/blob/master/bip-0066.mediawiki> should
226226
be used.
227227
228-
I<writer:> C<set_strict_signatures>
229-
230228
=head3 checklocktimeverify
231229
232-
I<Available in the constructor>.
233-
234230
Whether C<OP_CHECKLOCKTIMEVERIFY> opcode defined in
235231
L<BIP65|https://github.com/bitcoin/bips/blob/master/bip-0065.mediawiki> should
236232
be used.
237233
238-
I<writer:> C<set_checklocktimeverify>
239-
240234
=head3 checksequenceverify
241235
242-
I<Available in the constructor>.
243-
244236
Whether C<OP_CHECKSEQUENCEVERIFY> opcode defined in
245237
L<BIP112|https://github.com/bitcoin/bips/blob/master/bip-0112.mediawiki> should
246238
be used.
247239
248-
I<writer:> C<set_checksequenceverify>
240+
=head3 null_dummy
249241
250-
=head3 nulldummy
251-
252-
I<Available in the constructor>.
253-
254-
Whether C<OP_CHECKMULTISIG> nulldummy verification defined in
242+
Whether C<OP_CHECKMULTISIG> null dummy verification defined in
255243
L<BIP147|https://github.com/bitcoin/bips/blob/master/bip-0147.mediawiki> should
256244
be used.
257245
258-
I<writer:> C<set_nulldummy>
259-
260246
=head3 segwit
261247
262-
I<Available in the constructor>.
263-
264248
Whether segwit-specific verification defined in
265249
L<BIP141|https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki> should
266250
be used.
267251
268-
I<writer:> C<set_segwit>
269-
270252
=head3 taproot
271253
272-
I<Available in the constructor>.
273-
274254
Whether taproot-specific verification defined in
275255
L<BIP341|https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki> should
276256
be used.
277257
278-
I<writer:> C<set_taproot>
258+
=head2 Standardness flags
259+
260+
All standardness flags are inactive by default.
261+
262+
=head3 signature_pushes_only
263+
264+
Disallows non-push opcodes in signature scripts of inputs for legacy non-P2SH
265+
transactions. Automatically active for P2SH.
266+
267+
=head3 minimal_if
268+
269+
Whether the argument to C<OP_IF> must be minimal (C<OP_1> or C<OP_0>). Only
270+
applicable to Segregated Witness scripts.
271+
272+
=head3 compressed_pubkeys
273+
274+
Whether public keys used is signature-checking scripts must be compressed. Only
275+
applicable to Segregated Witness scripts.
276+
277+
=head3 strict_encoding
278+
279+
Disallows non-strictly encoded DER signatures and public keys.
280+
281+
=head3 low_s_signatures
282+
283+
Disallows signatures encoded with low S.
284+
285+
=head3 minimal_data
286+
287+
When active, data pushed by push opcodes must be minimally encoded.
288+
289+
=head3 null_fail
290+
291+
Causes non-taproot signature-checking opcodes to stop script execution on
292+
failure, unless the signature is empty.
293+
294+
=head3 clean_stack
295+
296+
Requires script stack to have exactly one element at the end of execution to
297+
consider the execution successful.
298+
299+
=head3 const_script
300+
301+
Causes the script to fail if C<OP_CODESEPARATOR> or a signature is encoded in a
302+
pre-SegWit script.
303+
304+
=head3 known_witness
305+
306+
Causes the transaction verification to fail if unknown version of Segregated
307+
Witness program is encountered.
308+
309+
=head3 illegal_upgradeable_nops
310+
311+
Disallows the use of C<OP_NOPX> opcodes (but not C<OP_NOP>).
279312
280313
=head2 Methods
281314
@@ -284,7 +317,7 @@ I<writer:> C<set_taproot>
284317
$object = $class->new(%args)
285318
286319
This is a standard Moo constructor, which can be used to create the object. It
287-
takes arguments specified in L</Attributes>.
320+
takes arguments specified in L</Consensus flags> and L</Standardness flags>.
288321
289322
Returns a class instance.
290323
@@ -294,6 +327,20 @@ Returns a class instance.
294327
295328
Same as L</new>, but assumes all flags unspecified in C<%args> are disabled.
296329
330+
=head3 new_full
331+
332+
$object = $class->new_full(%args)
333+
334+
Same as L</new>, but assumes all flags unspecified in C<%args> are enabled.
335+
336+
=head3 strict_signatures
337+
338+
$bool = $object->strict_signatures()
339+
340+
Return true if any one of L</strict_encoding>, L</der_signatures> or
341+
L</low_s_signatures> are enabled. Having either one of these flags in effect is
342+
the same as having L</der_signatures> enabled.
343+
297344
=head1 SEE ALSO
298345
299346
=over

lib/Bitcoin/Crypto/Transaction/Signer.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ sub finalize_multisignature
225225
'not on multisignature opcode'
226226
) unless $self->_multisigop;
227227

228-
# add mandatory nulldummy element
228+
# add mandatory null dummy element
229229
$self->add_bytes('');
230230
$self->_step_over_sigop;
231231

0 commit comments

Comments
 (0)