Skip to content

Commit fd9bed0

Browse files
committed
miniscript: update the source from Bitcoin Core master branch
1 parent be0655f commit fd9bed0

File tree

4 files changed

+335
-181
lines changed

4 files changed

+335
-181
lines changed

bitcoin/script/miniscript.cpp

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2019 The Bitcoin Core developers
1+
// Copyright (c) 2019-2022 The Bitcoin Core developers
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

@@ -172,8 +172,8 @@ Type ComputeType(Fragment fragment, Type x, Type y, Type z, const std::vector<Ty
172172
(y & "B"_mst).If(x << "Bdu"_mst) | // B=B_y*B_x*d_x*u_x
173173
(x & "o"_mst).If(y << "z"_mst) | // o=o_x*z_y
174174
(x & y & "m"_mst).If(x << "e"_mst && (x | y) << "s"_mst) | // m=m_x*m_y*e_x*(s_x+s_y)
175-
(x & y & "zes"_mst) | // z=z_x*z_y, e=e_x*e_y, s=s_x*s_y
176-
(y & "ufd"_mst) | // u=u_y, f=f_y, d=d_y
175+
(x & y & "zs"_mst) | // z=z_x*z_y, s=s_x*s_y
176+
(y & "ufde"_mst) | // u=u_y, f=f_y, d=d_y, e=e_y
177177
"x"_mst | // x
178178
((x | y) & "ghij"_mst) | // g=g_x+g_y, h=h_x+h_y, i=i_x+i_y, j=j_x+j_y
179179
(x & y & "k"_mst); // k=k_x*k_y
@@ -201,7 +201,7 @@ Type ComputeType(Fragment fragment, Type x, Type y, Type z, const std::vector<Ty
201201
(y & z & "u"_mst) | // u=u_y*u_z
202202
(z & "f"_mst).If((x << "s"_mst) || (y << "f"_mst)) | // f=(s_x+f_y)*f_z
203203
(z & "d"_mst) | // d=d_z
204-
(x & z & "e"_mst).If(x << "s"_mst || y << "f"_mst) | // e=e_x*e_z*(s_x+f_y)
204+
(z & "e"_mst).If(x << "s"_mst || y << "f"_mst) | // e=e_z*(s_x+f_y)
205205
(x & y & z & "m"_mst).If(x << "e"_mst && (x | y | z) << "s"_mst) | // m=m_x*m_y*m_z*e_x*(s_x+s_y+s_z)
206206
(z & (x | y) & "s"_mst) | // s=s_z*(s_x+s_y)
207207
"x"_mst | // x
@@ -245,7 +245,6 @@ Type ComputeType(Fragment fragment, Type x, Type y, Type z, const std::vector<Ty
245245
}
246246
}
247247
assert(false);
248-
return ""_mst;
249248
}
250249

251250
size_t ComputeScriptLen(Fragment fragment, Type sub0typ, size_t subsize, uint32_t k, size_t n_subs, size_t n_keys) {
@@ -260,7 +259,7 @@ size_t ComputeScriptLen(Fragment fragment, Type sub0typ, size_t subsize, uint32_
260259
case Fragment::SHA256: return 4 + 2 + 33;
261260
case Fragment::HASH160:
262261
case Fragment::RIPEMD160: return 4 + 2 + 21;
263-
case Fragment::MULTI: return 3 + (n_keys > 16) + (k > 16) + 34 * n_keys;
262+
case Fragment::MULTI: return 1 + BuildScript(n_keys).size() + BuildScript(k).size() + 34 * n_keys;
264263
case Fragment::AND_V: return subsize;
265264
case Fragment::WRAP_V: return subsize + (sub0typ << "x"_mst);
266265
case Fragment::WRAP_S:
@@ -278,10 +277,9 @@ size_t ComputeScriptLen(Fragment fragment, Type sub0typ, size_t subsize, uint32_
278277
case Fragment::THRESH: return subsize + n_subs + BuildScript(k).size();
279278
}
280279
assert(false);
281-
return 0;
282280
}
283281

284-
InputStack& InputStack::Available(Availability avail) {
282+
InputStack& InputStack::SetAvailable(Availability avail) {
285283
available = avail;
286284
if (avail == Availability::NO) {
287285
stack.clear();
@@ -293,37 +291,37 @@ InputStack& InputStack::Available(Availability avail) {
293291
return *this;
294292
}
295293

296-
InputStack& InputStack::WithSig() {
294+
InputStack& InputStack::SetWithSig() {
297295
has_sig = true;
298296
return *this;
299297
}
300298

301-
InputStack& InputStack::NonCanon() {
299+
InputStack& InputStack::SetNonCanon() {
302300
non_canon = true;
303301
return *this;
304302
}
305303

306-
InputStack& InputStack::Malleable(bool x) {
304+
InputStack& InputStack::SetMalleable(bool x) {
307305
malleable = x;
308306
return *this;
309307
}
310308

311309
InputStack operator+(InputStack a, InputStack b) {
312310
a.stack = Cat(std::move(a.stack), std::move(b.stack));
313-
a.size += b.size;
311+
if (a.available != Availability::NO && b.available != Availability::NO) a.size += b.size;
314312
a.has_sig |= b.has_sig;
315313
a.malleable |= b.malleable;
316314
a.non_canon |= b.non_canon;
317315
if (a.available == Availability::NO || b.available == Availability::NO) {
318-
a.Available(Availability::NO);
316+
a.SetAvailable(Availability::NO);
319317
} else if (a.available == Availability::MAYBE || b.available == Availability::MAYBE) {
320-
a.Available(Availability::MAYBE);
318+
a.SetAvailable(Availability::MAYBE);
321319
}
322320
return a;
323321
}
324322

325323
InputStack operator|(InputStack a, InputStack b) {
326-
// If only one (or neither) is valid, pick the other one.
324+
// If only one is invalid, pick the other one. If both are invalid, pick an arbitrary one.
327325
if (a.available == Availability::NO) return b;
328326
if (b.available == Availability::NO) return a;
329327
// If only one of the solutions has a signature, we must pick the other one.
@@ -351,9 +349,9 @@ InputStack operator|(InputStack a, InputStack b) {
351349
}
352350
}
353351

354-
std::optional<std::vector<std::pair<opcodetype, std::vector<unsigned char>>>> DecomposeScript(const CScript& script)
352+
std::optional<std::vector<Opcode>> DecomposeScript(const CScript& script)
355353
{
356-
std::vector<std::pair<opcodetype, std::vector<unsigned char>>> out;
354+
std::vector<Opcode> out;
357355
CScript::const_iterator it = script.begin(), itend = script.end();
358356
while (it != itend) {
359357
std::vector<unsigned char> push_data;
@@ -387,7 +385,7 @@ std::optional<std::vector<std::pair<opcodetype, std::vector<unsigned char>>>> De
387385
return out;
388386
}
389387

390-
std::optional<int64_t> ParseScriptNumber(const std::pair<opcodetype, std::vector<unsigned char>>& in) {
388+
std::optional<int64_t> ParseScriptNumber(const Opcode& in) {
391389
if (in.first == OP_0) {
392390
return 0;
393391
}

0 commit comments

Comments
 (0)