mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-19 14:53:43 +01:00
Merge bitcoin/bitcoin#24147: Miniscript integration
2da94a4c6ffuzz: add a fuzz target for Miniscript decoding from Script (Antoine Poinsot)f8369996e7Miniscript: ops limit and stack size computation (Pieter Wuille)2e55e88f86Miniscript: conversion from script (Pieter Wuille)1ddaa66eaeMiniscript: type system, script creation, text notation, tests (Pieter Wuille)4fe29368c0script: expose getter for CScriptNum, add a BuildScript helper (Antoine Poinsot)f4e289f384script: move CheckMinimalPush from interpreter to script.h (Antoine Poinsot)31ec6ae92ascript: make IsPushdataOp non-static (Antoine Poinsot) Pull request description: Miniscript is a language for writing (a subset of) Bitcoin Scripts in a structured way. Miniscript permits: - To safely extend the Output Descriptor language to many more scripting features thanks to the typing system (composition). - Statical analysis of spending conditions, maximum spending cost of each branch, security properties, third-party malleability. - General satisfaction of any correctly typed ("valid" [0]) Miniscript. The satisfaction itself is also analyzable. - To extend the possibilities of external signers, because of all of the above and since it carries enough metadata. Miniscript guarantees: - That for any statically-analyzed as "safe" [0] Script, a witness can be constructed in the bounds of the consensus and standardness rules (standardness complete). - That unless the conditions of the Miniscript are met, no witness can be created for the Script (consensus sound). - Third-party malleability protection for the satisfaction of a sane Miniscript, which is too complex to summarize here. For more details around Miniscript (including the specifications), please refer to the [website](https://bitcoin.sipa.be/miniscript/). Miniscript was designed by Pieter Wuille, Andrew Poelstra and Sanket Kanjalkar. This PR is an updated and rebased version of #16800. See [the commit history of the Miniscript repository](https://github.com/sipa/miniscript/commits/master) for details about the changes made since September 2019 (TL;DR: bugfixes, introduction of timelock conflicts in the type system, `pk()` and `pkh()` aliases, `thresh_m` renamed to `multi`, all recursive algorithms were made non-recursive). This PR is also the first in a series of 3: - The first one (here) integrates the backbone of Miniscript. - The second one (#24148) introduces support for Miniscript in Output Descriptors, allowing for watch-only support of Miniscript Descriptors in the wallet. - The third one (#24149) implements signing for these Miniscript Descriptors, using Miniscript's satisfaction algorithm. Note to reviewers: - Miniscript is currently defined only for P2WSH. No Taproot yet. - Miniscript is different from the policy language (a high-level logical representation of a spending policy). A policy->Miniscript compiler is not included here. - The fuzz target included here is more interestingly extended in the 3rd PR to check a script's satisfaction against `VerifyScript`. I think it could be further improved by having custom mutators as we now have for multisig (see https://github.com/bitcoin/bitcoin/issues/23105). A minified corpus of Miniscript Scripts is available at https://github.com/bitcoin-core/qa-assets/pull/85. [0] We call "valid" any correctly-typed Miniscript. And "safe" any sane Miniscript, ie one whose satisfaction isn't malleable, which requires a key for any spending path, etc.. ACKs for top commit: jb55: ACK2da94a4c6flaanwj: Light code review ACK2da94a4c6f(mostly reviewed the changes to the existing code and build system) Tree-SHA512: d3ef558436cfcc699a50ad13caf1e776f7d0addddb433ee28ef38f66ea5c3e581382d8c748ccac9b51768e4b95712ed7a6112b0e3281a6551e0f325331de9167
This commit is contained in:
@@ -225,31 +225,6 @@ bool static CheckPubKeyEncoding(const valtype &vchPubKey, unsigned int flags, co
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CheckMinimalPush(const valtype& data, opcodetype opcode) {
|
||||
// Excludes OP_1NEGATE, OP_1-16 since they are by definition minimal
|
||||
assert(0 <= opcode && opcode <= OP_PUSHDATA4);
|
||||
if (data.size() == 0) {
|
||||
// Should have used OP_0.
|
||||
return opcode == OP_0;
|
||||
} else if (data.size() == 1 && data[0] >= 1 && data[0] <= 16) {
|
||||
// Should have used OP_1 .. OP_16.
|
||||
return false;
|
||||
} else if (data.size() == 1 && data[0] == 0x81) {
|
||||
// Should have used OP_1NEGATE.
|
||||
return false;
|
||||
} else if (data.size() <= 75) {
|
||||
// Must have used a direct push (opcode indicating number of bytes pushed + those bytes).
|
||||
return opcode == data.size();
|
||||
} else if (data.size() <= 255) {
|
||||
// Must have used OP_PUSHDATA.
|
||||
return opcode == OP_PUSHDATA1;
|
||||
} else if (data.size() <= 65535) {
|
||||
// Must have used OP_PUSHDATA2.
|
||||
return opcode == OP_PUSHDATA2;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int FindAndDelete(CScript& script, const CScript& b)
|
||||
{
|
||||
int nFound = 0;
|
||||
|
||||
Reference in New Issue
Block a user