Skip to main content

blvm_consensus/script/
flags.rs

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