sapio_miniscript/miniscript/
limits.rs

1//! Miscellaneous constraints imposed by Bitcoin.
2//! These constraints can be either Consensus or Policy (standardness) rules, for either Segwitv0
3//! or Legacy scripts.
4
5/// Maximum operations per script
6// https://github.com/bitcoin/bitcoin/blob/875e1ccc9fe01e026e564dfd39a64d9a4b332a89/src/script/script.h#L26
7pub const MAX_OPS_PER_SCRIPT: usize = 201;
8/// Maximum p2wsh initial stack items
9// https://github.com/bitcoin/bitcoin/blob/875e1ccc9fe01e026e564dfd39a64d9a4b332a89/src/policy/policy.h#L40
10pub const MAX_STANDARD_P2WSH_STACK_ITEMS: usize = 100;
11/// Maximum script size allowed by consensus rules
12// https://github.com/bitcoin/bitcoin/blob/42b66a6b814bca130a9ccf0a3f747cf33d628232/src/script/script.h#L32
13pub const MAX_SCRIPT_SIZE: usize = 10_000;
14/// Maximum script size allowed by standardness rules
15// https://github.com/bitcoin/bitcoin/blob/283a73d7eaea2907a6f7f800f529a0d6db53d7a6/src/policy/policy.h#L44
16pub const MAX_STANDARD_P2WSH_SCRIPT_SIZE: usize = 3600;
17/// The Threshold for deciding whether `nLockTime` is interpreted as
18/// time or height.
19// https://github.com/bitcoin/bitcoin/blob/9ccaee1d5e2e4b79b0a7c29aadb41b97e4741332/src/script/script.h#L39
20pub const HEIGHT_TIME_THRESHOLD: u32 = 500_000_000;
21
22/// Bit flag for deciding whether sequence number is
23/// interpreted as height or time
24/* If nSequence encodes a relative lock-time and this flag
25 * is set, the relative lock-time has units of 512 seconds,
26 * otherwise it specifies blocks with a granularity of 1. */
27// https://github.com/bitcoin/bips/blob/master/bip-0112.mediawiki
28pub const SEQUENCE_LOCKTIME_TYPE_FLAG: u32 = 1 << 22;
29
30/// Disable flag for sequence locktime
31/* Below flags apply in the context of BIP 68*/
32/* If this flag set, nSequence is NOT interpreted as a
33 * relative lock-time. For future soft-fork compatibility*/
34// https://github.com/bitcoin/bips/blob/master/bip-0112.mediawiki
35pub const SEQUENCE_LOCKTIME_DISABLE_FLAG: u32 = 1 << 31;
36
37/// Maximum script element size allowed by consensus rules
38// https://github.com/bitcoin/bitcoin/blob/42b66a6b814bca130a9ccf0a3f747cf33d628232/src/script/script.h#L23
39pub const MAX_SCRIPT_ELEMENT_SIZE: usize = 520;
40/// Maximum script sig size allowed by standardness rules
41// https://github.com/bitcoin/bitcoin/blob/42b66a6b814bca130a9ccf0a3f747cf33d628232/src/policy/policy.cpp#L102
42pub const MAX_SCRIPTSIG_SIZE: usize = 1650;
43/// Maximum items during stack execution
44// This limits also applies for initial stack satisfaction
45// https://github.com/bitcoin/bitcoin/blob/3af495d6972379b07530a5fcc2665aa626d01621/src/script/script.h#L35
46pub const MAX_STACK_SIZE: usize = 1000;
47/** The maximum allowed weight for a block, see BIP 141 (network rule) */
48pub const MAX_BLOCK_WEIGHT: usize = 4000000;
49
50/// Maximum pubkeys as arguments to CHECKMULTISIG
51// https://github.com/bitcoin/bitcoin/blob/6acda4b00b3fc1bfac02f5de590e1a5386cbc779/src/script/script.h#L30
52pub const MAX_PUBKEYS_PER_MULTISIG: usize = 20;