blvm_consensus/script/flags.rs
1//! Script verification flags (Orange Paper §5.2; BIP62/BIP66/BIP147/BIP341).
2//!
3//! These constants map to consensus `SCRIPT_VERIFY_*` flag bits.
4//! Divergence from the Orange Paper values is a consensus bug.
5
6/// No flags — bare pubkey / standard evaluation.
7pub const SCRIPT_VERIFY_NONE: u32 = 0;
8
9/// Evaluate P2SH subscripts (BIP16).
10pub const SCRIPT_VERIFY_P2SH: u32 = 1 << 0; // 0x0001
11
12/// Require DER-encoded signatures (BIP66 stricter encoding).
13pub const SCRIPT_VERIFY_STRICTENC: u32 = 1 << 1; // 0x0002
14
15/// Enforce strict DER signature encoding (BIP66).
16pub const SCRIPT_VERIFY_DERSIG: u32 = 1 << 2; // 0x0004
17
18/// Enforce low-S signature requirement (BIP62).
19pub const SCRIPT_VERIFY_LOW_S: u32 = 1 << 3; // 0x0008
20
21/// OP_CHECKMULTISIG dummy element must be OP_0 (BIP147).
22pub const SCRIPT_VERIFY_NULLDUMMY: u32 = 1 << 4; // 0x0010
23
24/// Require only push opcodes in scriptSig.
25pub const SCRIPT_VERIFY_SIGPUSHONLY: u32 = 1 << 5; // 0x0020
26
27/// Require minimal encoding for pushdata (BIP62 rule 3 & 4).
28pub const SCRIPT_VERIFY_MINIMALDATA: u32 = 1 << 6; // 0x0040
29
30/// NOPs 1–10 are reserved; treat them as invalid if a future soft-fork hasn't defined them.
31pub const SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS: u32 = 1 << 7; // 0x0080
32
33/// Require clean stack after script evaluation (BIP62).
34pub const SCRIPT_VERIFY_CLEANSTACK: u32 = 1 << 8; // 0x0100
35
36/// Enable OP_CHECKLOCKTIMEVERIFY (BIP65).
37pub const SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY: u32 = 1 << 9; // 0x0200
38
39/// Enable OP_CHECKSEQUENCEVERIFY (BIP112).
40pub const SCRIPT_VERIFY_CHECKSEQUENCEVERIFY: u32 = 1 << 10; // 0x0400
41
42/// Enable Segregated Witness evaluation (BIP141/143).
43pub const SCRIPT_VERIFY_WITNESS: u32 = 1 << 11; // 0x0800
44
45/// Reject unknown witness program versions (allows future soft-forks).
46pub const SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_WITNESS_PROGRAM: u32 = 1 << 12; // 0x1000
47
48/// Require minimal IF argument (BIP342 and pre-taproot cleanups).
49pub const SCRIPT_VERIFY_MINIMALIF: u32 = 1 << 13; // 0x2000
50
51/// Require empty sig on CHECKSIG failure (BIP342 null-fail rule).
52pub const SCRIPT_VERIFY_NULLFAIL: u32 = 1 << 14; // 0x4000
53
54/// Require compressed public keys in witness programs (BIP143).
55pub const SCRIPT_VERIFY_WITNESS_PUBKEYTYPE: u32 = 1 << 15; // 0x8000
56
57/// Signature hash must not hash the script code after a CODESEPARATOR (BIP143 §4).
58pub const SCRIPT_VERIFY_CONST_SCRIPTCODE: u32 = 1 << 16; // 0x10000
59
60/// Enable Taproot/Tapscript evaluation (BIP341/342).
61///
62/// WARNING: This is 0x20000 (bit 17), NOT 0x8000 (bit 15, which is WITNESS_PUBKEYTYPE).
63/// Confusing the two disables Taproot validation entirely.
64pub const SCRIPT_VERIFY_TAPROOT: u32 = 1 << 17; // 0x20000
65
66/// Reject unknown Taproot leaf versions (allows future soft-forks).
67pub const SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_TAPROOT_VERSION: u32 = 1 << 18; // 0x40000
68
69/// Reject OP_SUCCESS opcodes that are not re-defined by a known Tapscript upgrade.
70pub const SCRIPT_VERIFY_DISCOURAGE_OP_SUCCESS: u32 = 1 << 19; // 0x80000
71
72/// Reject unknown pubkey types in Tapscript (allows future soft-forks).
73pub const SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_PUBKEYTYPE: u32 = 1 << 20; // 0x100000
74
75/// Standard mandatory flags for segwit-v0 transactions (pre-Taproot).
76pub const SEGWIT_STANDARD_FLAGS: u32 =
77 SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_WITNESS | SCRIPT_VERIFY_WITNESS_PUBKEYTYPE;
78
79/// Full Taproot activation flag set (P2SH + SegWit + Taproot).
80///
81/// Use this as the baseline when verifying Taproot outputs.
82pub const TAPROOT_STANDARD_FLAGS: u32 = SCRIPT_VERIFY_P2SH
83 | SCRIPT_VERIFY_WITNESS
84 | SCRIPT_VERIFY_WITNESS_PUBKEYTYPE
85 | SCRIPT_VERIFY_TAPROOT;