Skip to content

Commit 67879b7

Browse files
committed
Merge #11377: Disallow uncompressed pubkeys in bitcoin-tx [multisig] output adds
28d4542 Disallow uncompressed pubkeys in bitcoin-tx [multisig] output adds (Matt Corallo) Pull request description: Does what it says on the tin. Tree-SHA512: 324b8da8a9f9a35d3ade74f6c587f981894a085dfea9d64f78de745d5e6ec05c3a7bced487e9aad9c8a48151cd14969a0806f30f80b621edfce0da082fe6f4be
2 parents 8cf88b4 + 28d4542 commit 67879b7

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ EXTRA_DIST += \
249249
test/util/data/txcreatemultisig3.json \
250250
test/util/data/txcreatemultisig4.hex \
251251
test/util/data/txcreatemultisig4.json \
252+
test/util/data/txcreatemultisig5.json \
252253
test/util/data/txcreateoutpubkey1.hex \
253254
test/util/data/txcreateoutpubkey1.json \
254255
test/util/data/txcreateoutpubkey2.hex \

src/bitcoin-tx.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,9 @@ static void MutateTxAddOutPubKey(CMutableTransaction& tx, const std::string& str
310310
}
311311

312312
if (bSegWit) {
313+
if (!pubkey.IsCompressed()) {
314+
throw std::runtime_error("Uncompressed pubkeys are not useable for SegWit outputs");
315+
}
313316
// Call GetScriptForWitness() to build a P2WSH scriptPubKey
314317
scriptPubKey = GetScriptForWitness(scriptPubKey);
315318
}
@@ -375,6 +378,11 @@ static void MutateTxAddOutMultiSig(CMutableTransaction& tx, const std::string& s
375378
CScript scriptPubKey = GetScriptForMultisig(required, pubkeys);
376379

377380
if (bSegWit) {
381+
for (CPubKey& pubkey : pubkeys) {
382+
if (!pubkey.IsCompressed()) {
383+
throw std::runtime_error("Uncompressed pubkeys are not useable for SegWit outputs");
384+
}
385+
}
378386
// Call GetScriptForWitness() to build a P2WSH scriptPubKey
379387
scriptPubKey = GetScriptForWitness(scriptPubKey);
380388
}

test/util/data/bitcoin-util-test.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,13 @@
261261
"output_cmp": "txcreateoutpubkey3.json",
262262
"description": "Creates a new transaction with a single pay-to-pub-key output, wrapped in P2SH (output as json)"
263263
},
264+
{ "exec": "./bitcoin-tx",
265+
"args":
266+
["-json", "-create", "outpubkey=0:047d1368ba7ae01c94bc32293efd70bd7e3be7aa7912d07d0b1c659c1008d179b8642f5fb90f47580feb29f045e216ff5a4716d3a0fed36da414d332046303c44a:WS", "nversion=1"],
267+
"return_code": 1,
268+
"error_txt": "error: Uncompressed pubkeys are not useable for SegWit outputs",
269+
"description": "Creates a new transaction with a single pay-to-pub-key output, wrapped in P2SH (output as json)"
270+
},
264271
{ "exec": "./bitcoin-tx",
265272
"args":
266273
["-create",
@@ -388,5 +395,16 @@
388395
"args": ["-json", "-create", "outmultisig=1:2:3:02a5613bd857b7048924264d1e70e08fb2a7e6527d32b7ab1bb993ac59964ff397:021ac43c7ff740014c3b33737ede99c967e4764553d1b2b83db77c83b8715fa72d:02df2089105c77f266fa11a9d33f05c735234075f2e8780824c6b709415f9fb485:WS", "nversion=1"],
389396
"output_cmp": "txcreatemultisig4.json",
390397
"description": "Creates a new transaction with a single 2-of-3 multisig in a P2WSH output, wrapped in P2SH (output in json)"
398+
},
399+
{ "exec": "./bitcoin-tx",
400+
"args": ["-json", "-create", "outmultisig=1:2:3:02a5613bd857b7048924264d1e70e08fb2a7e6527d32b7ab1bb993ac59964ff397:021ac43c7ff740014c3b33737ede99c967e4764553d1b2b83db77c83b8715fa72d:047d1368ba7ae01c94bc32293efd70bd7e3be7aa7912d07d0b1c659c1008d179b8642f5fb90f47580feb29f045e216ff5a4716d3a0fed36da414d332046303c44a:S"],
401+
"output_cmp": "txcreatemultisig5.json",
402+
"description": "Uncompressed pubkeys should work just fine for non-witness outputs"
403+
},
404+
{ "exec": "./bitcoin-tx",
405+
"args": ["-json", "-create", "outmultisig=1:2:3:02a5613bd857b7048924264d1e70e08fb2a7e6527d32b7ab1bb993ac59964ff397:021ac43c7ff740014c3b33737ede99c967e4764553d1b2b83db77c83b8715fa72d:047d1368ba7ae01c94bc32293efd70bd7e3be7aa7912d07d0b1c659c1008d179b8642f5fb90f47580feb29f045e216ff5a4716d3a0fed36da414d332046303c44a:WS"],
406+
"return_code": 1,
407+
"error_txt": "error: Uncompressed pubkeys are not useable for SegWit outputs",
408+
"description": "Ensure adding witness outputs with uncompressed pubkeys fails"
391409
}
392410
]

test/util/data/txcreatemultisig5.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"txid": "813cf75e1f08debd242ef7c8192b7d478fb651355209369499a0de779ba7eb2f",
3+
"hash": "813cf75e1f08debd242ef7c8192b7d478fb651355209369499a0de779ba7eb2f",
4+
"version": 2,
5+
"size": 42,
6+
"vsize": 42,
7+
"locktime": 0,
8+
"vin": [
9+
],
10+
"vout": [
11+
{
12+
"value": 1.00000000,
13+
"n": 0,
14+
"scriptPubKey": {
15+
"asm": "OP_HASH160 a4051c02398868af83f28f083208fae99a769263 OP_EQUAL",
16+
"hex": "a914a4051c02398868af83f28f083208fae99a76926387",
17+
"reqSigs": 1,
18+
"type": "scripthash",
19+
"addresses": [
20+
"3GeGs1eHUxPz5YyuFe9WPpXid2UsUb5Jos"
21+
]
22+
}
23+
}
24+
],
25+
"hex": "02000000000100e1f5050000000017a914a4051c02398868af83f28f083208fae99a7692638700000000"
26+
}

0 commit comments

Comments
 (0)