-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Description
Importing a 1-of-2 multisig p2sh address into 0.19.0.1 testnet, the following script dies with a segfault:
#!/bin/bash
echo running createwallet
./bitcoin-0.19.0.1/bin/bitcoin-cli -testnet createwallet "whynokeys"
#sleep 4
echo running importprivkey 1
./bitcoin-0.19.0.1/bin/bitcoin-cli -testnet -rpcwallet=whynokeys importprivkey "cQkx6d2rpRJgrsAUT6sfctTbxSPD1CaTQ5Q6XMQojjZXK1ntjCvo" "addr1" false
#sleep 4
echo running importprivkey 2
./bitcoin-0.19.0.1/bin/bitcoin-cli -testnet -rpcwallet=whynokeys importprivkey "cPaQ8eEdhYbtSLX6t86eoWePqZcKB7ibAqH8zhqnA936k8ML8F1H" "addr2" false
#sleep 4
echo running importmulti
./bitcoin-0.19.0.1/bin/bitcoin-cli -testnet -rpcwallet=whynokeys importmulti \
'[
{
"scriptPubKey": { "address": "2NBeG2myyAwSUCv1L21kTHAA3SdMELxdspi" },
"timestamp":1578787441,
"redeemscript":"512103b7e7e3dacb0ad6f1e2bee28a7a5e8842152a8232f36be55bba66243aee77b95c21039dd05437b699bf98ea32ed3217d0aeb5a5a5fd76a343bebeec6e56968aa9bf0d52ae"
}]'
#sleep 4
echo running listunspent
./bitcoin-0.19.0.1/bin/bitcoin-cli -testnet -rpcwallet=whynokeys listunspent
echo all done
Results:
user@host:~$ ./badimport.sh
running createwallet
{
"name": "whynokeys",
"warning": ""
}
running importprivkey 1
running importprivkey 2
running importmulti
error: Could not connect to the server 127.0.0.1:18332 (error code 1 - "EOF reached")
Make sure the bitcoind server is running and that you are connecting to the correct RPC port.
running listunspent
error: Could not connect to the server 127.0.0.1:18332
Make sure the bitcoind server is running and that you are connecting to the correct RPC port.
all done
[1]+ Segmentation fault ./bitcoin-0.19.0.1/bin/bitcoin-qt -server
Though sometimes the importmulti completes and the segfault doesn't occur until the listunspent.
If you uncomment all the sleep 4
lines, this works every time without segfault, however the importmulti gives a bogus warning:
running createwallet
{
"name": "whynokeys",
"warning": ""
}
running importprivkey 1
running importprivkey 2
running importmulti
[
{
"success": true,
"warnings": [
"Some private keys are missing, outputs will be considered watchonly. If this is intentional, specify the watchonly flag."
]
}
]
running listunspent
[
{
"txid": "d322f58c03fab2526d9cd32baa3ab5e1719a6841a59b92494aa58d2fd2447be1",
"vout": 1,
"address": "2NBeG2myyAwSUCv1L21kTHAA3SdMELxdspi",
"label": "",
"redeemScript": "512103b7e7e3dacb0ad6f1e2bee28a7a5e8842152a8232f36be55bba66243aee77b95c21039dd05437b699bf98ea32ed3217d0aeb5a5a5fd76a343bebeec6e56968aa9bf0d52ae",
"scriptPubKey": "a914c9cd895fba08d0cfb13510fd8a4c6be8ad70bd6c87",
"amount": 0.02100000,
"confirmations": 80,
"spendable": true,
"solvable": true,
"desc": "sh(multi(1,[c9d3ec21]03b7e7e3dacb0ad6f1e2bee28a7a5e8842152a8232f36be55bba66243aee77b95c,[5e88ca09]039dd05437b699bf98ea32ed3217d0aeb5a5a5fd76a343bebeec6e56968aa9bf0d))#z2pgdmn0",
"safe": true
}
]
all done
I doublechecked that the two privkeys imported do match the pubkeys in the redeem script. Also notice that listunspent claims they are spendable and solvable, as expected. Therefore the warning about missing private keys is bogus.
Expected behavior
- No segfault
- No warning from importmulti
Actual behavior
- Segfault
- (after adding delays to script) bogus warning from importmulti
To reproduce
See above script. Segfault is not 100% reliable but probably 90%. The bogus warning is 100% reproducible.
System information
Running Bitcoin Core 0.19.0.1 on Whonix 14. First noticed on my own build of 0.19.0.1, also reproduced on official download of bitcoin-0.19.0.1-x86_64-linux-gnu.tar.gz.
Debug log from (successful, non-segfaulting) importmulti:
2020-01-12T04:24:07Z Using BerkeleyDB version Berkeley DB 4.8.30: (April 9, 2010)
2020-01-12T04:24:07Z Using wallet /home/user/.bitcoin/testnet3/whynokeys
2020-01-12T04:24:07Z BerkeleyEnvironment::Open: LogDir=/home/user/.bitcoin/testnet3/whynokeys/database ErrorFile=
/home/user/.bitcoin/testnet3/whynokeys/db.log
2020-01-12T04:24:07Z init message: Loading wallet...
2020-01-12T04:24:07Z BerkeleyEnvironment::Open: LogDir=/home/user/.bitcoin/testnet3/whynokeys/database ErrorFile=/home/user/.bitcoin/testnet3/whynokeys/db.log
2020-01-12T04:24:07Z [whynokeys] Wallet File Version = 10500
2020-01-12T04:24:07Z [whynokeys] Keys: 0 plaintext, 0 encrypted, 0 w/ metadata, 0 total. Unknown wallet records: 0
2020-01-12T04:24:07Z [whynokeys] Performing wallet upgrade to 169900
2020-01-12T04:24:08Z [whynokeys] keypool added 2000 keys (1000 internal), size=2000 (1000 internal)
2020-01-12T04:24:08Z [whynokeys] Wallet completed loading in 1476ms
2020-01-12T04:24:08Z [whynokeys] setKeyPool.size() = 2000
2020-01-12T04:24:08Z [whynokeys] mapWallet.size() = 0
2020-01-12T04:24:08Z [whynokeys] mapAddressBook.size() = 0
2020-01-12T04:24:08Z New outbound peer connected: version: 70015, blocks=1659728, peer=7 (full-relay)
2020-01-12T04:24:09Z New outbound peer connected: version: 70015, blocks=1659728, peer=8 (full-relay)
2020-01-12T04:24:09Z P2P peers available. Skipped DNS seeding.
2020-01-12T04:24:09Z dnsseed thread exit
2020-01-12T04:24:12Z [whynokeys] Already have script 0014c9d3ec21d7a7667dd8317255d9b604ca0a3b73d5, skipping
2020-01-12T04:24:16Z [whynokeys] Already have script 00145e88ca0914a704056bc79b25a958d2d543900ef2, skipping
2020-01-12T04:24:20Z [whynokeys] RescanFromTime: Rescanning last 140 blocks
2020-01-12T04:24:20Z [whynokeys] Rescan started from block 00000000000007d256a92bfb67e59ecda20fc5728ce36f7404a2bc7c34853378...
2020-01-12T04:24:20Z [whynokeys] AddToWallet d322f58c03fab2526d9cd32baa3ab5e1719a6841a59b92494aa58d2fd2447be1 new
2020-01-12T04:24:20Z [whynokeys] Rescan completed in 32ms