-
Notifications
You must be signed in to change notification settings - Fork 129
taproot/script limits; default unknown-witness off; BIP8 stub #222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 29.x-knots
Are you sure you want to change the base?
Changes from all commits
4582579
4ab41d5
65e4bd0
ef9ad50
9369191
312f14d
46e9deb
9b891c1
6de2837
b960a57
45599f5
1870ad6
54a587c
6b17603
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| # BIP-0444 Policy Changes (Taproot and Script Limits) | ||
|
|
||
| ## Summary | ||
|
|
||
| This release introduces policy-level enforcement of BIP-0444 to prevent large arbitrary-data inscriptions and reduce UTXO/script bloat. These changes are active immediately as relay/mempool policy defaults; consensus enforcement will follow after BIP8 activation (parameters TBD). | ||
|
|
||
| ## Policy Changes (Active Now) | ||
|
|
||
| ### scriptPubKey Limits | ||
| - **Non-NULL_DATA scriptPubKey size cap**: Transactions with non-NULL_DATA outputs exceeding 34 bytes are rejected (`scriptpubkey-size-34`). | ||
| - **scriptPubKey push length cap**: Any single push operation in a scriptPubKey exceeding 256 bytes is rejected (`scriptpubkey-pushlen`). | ||
|
|
||
| ### Taproot/Tapscript Limits | ||
| - **Control block size cap**: Taproot control blocks exceeding 257 bytes (33-byte base + 7 merkle path nodes) are rejected (`taproot-controlblock-size`). | ||
| - **Per-input witness size cap**: Segwit v1 inputs with total witness data exceeding 1024 bytes are rejected (`taproot-perinput-witness`). Configurable via `-v1perinputwitnesslimit` (min 128, max 8192). | ||
| - **Tapscript IF ban**: OP_IF and OP_NOTIF opcodes are disallowed in Tapscript leaves (`taproot-if-disallowed`). | ||
| - **Tapscript push-only run cap**: Contiguous push-only regions in Tapscript leaves exceeding 256 bytes total payload are rejected (`taproot-pushrun`). | ||
| - **Tapscript IF-body cap**: Push-only IF/NOTIF branch bodies exceeding 80 bytes total payload are rejected (`taproot-if-pushonly`). | ||
|
|
||
| ### Unknown Witness Versions | ||
| - **Default reject unknown witness**: The default for `-acceptunknownwitness` is now `false`. Transactions sending to undefined witness program versions are rejected by default unless explicitly allowed via `-acceptunknownwitness=1`. | ||
|
|
||
| ## Configuration Options | ||
|
|
||
| - `-v1perinputwitnesslimit=<n>`: Set maximum total witness bytes per segwit v1 input (default: 1024; min 128, max 8192). | ||
| - `-acceptunknownwitness=<bool>`: Allow relay of transactions to unknown/future witness versions (default: 0). | ||
|
|
||
| ## Rationale | ||
|
|
||
| These policy defaults target the common inscription vectors (Taproot witness/script abuse) while preserving legitimate usage: | ||
| - Standard P2TR/P2WSH outputs remain valid (≤34 bytes). | ||
| - Normal signatures, keys, and small scripts are unaffected. | ||
| - Taproot key-path spends are unaffected. | ||
| - The limits are conservative and tunable for advanced use cases. | ||
|
|
||
| ## Deployment | ||
|
|
||
| BIP-0444 includes a soft-fork component with BIP8 activation (parameters TBD). Policy enforcement is active immediately; consensus rules will activate after the signaling period and delayed activation height. | ||
|
|
||
| For testing on regtest/testnet/signet, use `-vbparams=taproot_script_limits:start:end[:min_activation_height]` to override deployment parameters. | ||
|
|
||
| ## Compatibility | ||
|
|
||
| - **Wallets**: Avoid creating transactions with oversized scriptPubKeys, large push payloads, or Tapscript leaves using OP_IF/NOTIF. | ||
| - **Contracts**: Multi-party protocols with large witness data (e.g., complex lightning channels, vaults) may need to tune `-v1perinputwitnesslimit` or split across multiple inputs. | ||
| - **Unknown witness versions**: If your application relies on future witness versions, set `-acceptunknownwitness=1`. | ||
|
|
||
| ## References | ||
|
|
||
| - BIP-0444: https://github.com/bitcoin/bips/blob/master/bip-0444.mediawiki (pending merge) | ||
| - Discussion: https://gnusha.org/pi/bitcoindev/CALeFGL0PDjtRt2rfbY4gTkoc+5oNQ0mn_obraE7PrtHuNYFpQw@mail.gmail.com/T/#mb71350c5dfb119efeb92c5ee738b6c8225bf15b6 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -717,6 +717,7 @@ void SetupServerArgs(ArgsManager& argsman, bool can_listen_ipc) | |
| strprintf("Maximum size of data in data carrier transactions we relay and mine, in bytes (default: %u)", | ||
| MAX_OP_RETURN_RELAY), | ||
| ArgsManager::ALLOW_ANY, OptionsCategory::NODE_RELAY); | ||
| argsman.AddArg("-v1perinputwitnesslimit", "Set maximum total witness bytes per segwit v1 input for policy (default: 1024; min 128, max 8192)", ArgsManager::ALLOW_ANY, OptionsCategory::NODE_RELAY); | ||
| argsman.AddArg("-maxscriptsize", strprintf("Maximum size of scripts (including the entire witness stack) we relay and mine, in bytes (default: %s)", DEFAULT_SCRIPT_SIZE_POLICY_LIMIT), ArgsManager::ALLOW_ANY, OptionsCategory::NODE_RELAY); | ||
| argsman.AddArg("-maxtxlegacysigops", | ||
| strprintf("Maximum number of legacy sigops allowed in transactions we relay and mine, as measured by BIP54 (default: %s)", | ||
|
|
@@ -866,6 +867,8 @@ void InitParameterInteraction(ArgsManager& args) | |
| args.SoftSetArg("-blockmaxweight", "4000000"); | ||
| } | ||
|
|
||
|
|
||
justinfilip marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Empty lines added without purpose. Remove. |
||
|
|
||
| // when specifying an explicit binding address, you want to listen on it | ||
| // even when -connect or -proxy is specified | ||
| if (!args.GetArgs("-bind").empty()) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,7 +41,7 @@ static constexpr bool DEFAULT_ACCEPT_NON_STD_DATACARRIER{false}; | |
| /** Default for -acceptnonstdtxn */ | ||
| static constexpr bool DEFAULT_ACCEPT_NON_STD_TXN{false}; | ||
| /** Default for -acceptunknownwitness */ | ||
| static constexpr bool DEFAULT_ACCEPTUNKNOWNWITNESS{true}; | ||
| static constexpr bool DEFAULT_ACCEPTUNKNOWNWITNESS{false}; | ||
justinfilip marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| namespace kernel { | ||
| /** | ||
|
|
@@ -95,6 +95,8 @@ struct MemPoolOptions { | |
| bool permitephemeral_send{DEFAULT_PERMITEPHEMERAL_SEND}; | ||
| bool permitephemeral_dust{DEFAULT_PERMITEPHEMERAL_DUST}; | ||
| bool persist_v1_dat{DEFAULT_PERSIST_V1_DAT}; | ||
| // Policy to limit inscription-like data in witnesses/tapscripts | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "inscription-like data" is vague. Be more specific: "Total witness bytes per v1 input to prevent witness stuffing/inscription abuse." |
||
| unsigned int policy_max_v1_perinput_witness{1024}; | ||
justinfilip marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| MemPoolLimits limits{}; | ||
|
|
||
| ValidationSignals* signals{nullptr}; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -307,6 +307,15 @@ util::Result<void> ApplyArgsManOptions(const ArgsManager& argsman, const CChainP | |
|
|
||
| mempool_opts.persist_v1_dat = argsman.GetBoolArg("-persistmempoolv1", mempool_opts.persist_v1_dat); | ||
|
|
||
| // Policy flags to constrain per-input witness size for segwit v1 | ||
| if (auto lim = argsman.GetIntArg("-v1perinputwitnesslimit")) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. User sets Should log when clamping occurs or return error for out-of-range values. |
||
| // Enforce reasonable bounds to avoid footguns | ||
| unsigned val = *lim; | ||
| if (val < 128) val = 128; | ||
| if (val > 8192) val = 8192; | ||
| mempool_opts.policy_max_v1_perinput_witness = val; | ||
| } | ||
|
|
||
| ApplyArgsManOptions(argsman, mempool_opts.limits); | ||
|
|
||
| return {}; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BIP-0444 link shows "(pending merge)" but links to non-existent file (404).
Update when BIP number is assigned or remove until finalized.