Merge pull request #1246 from delta1/issue-1245

fix: getnewaddress - don't blind bech32 addresses
This commit is contained in:
Pablo Greco 2023-07-19 12:18:30 -03:00 committed by GitHub
commit 6802564be5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 15 deletions

View file

@ -294,7 +294,9 @@ static RPCHelpMan getnewaddress()
label = LabelFromValue(request.params[0]);
OutputType output_type = pwallet->m_default_address_type;
bool force_blind = false;
// default blinding to the blindedaddresses setting
bool add_blinding_key = gArgs.GetBoolArg("-blindedaddresses", g_con_elementsmode);
if (!request.params[1].isNull()) {
if (!ParseOutputType(request.params[1].get_str(), output_type)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Unknown address type '%s'", request.params[1].get_str()));
@ -302,15 +304,17 @@ static RPCHelpMan getnewaddress()
if (output_type == OutputType::BECH32M && pwallet->GetLegacyScriptPubKeyMan()) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Legacy wallets cannot provide bech32m addresses");
}
// Special case for "blech32" when `-blindedaddresses=0` in the config.
if (request.params[1].get_str() == "blech32") {
force_blind = true;
// always blind for "blech32" even if `-blindedaddresses=0` in the config.
add_blinding_key = true;
} else if (request.params[1].get_str() == "bech32") {
// never blind for "bech32"
add_blinding_key = false;
}
}
CTxDestination dest;
std::string error;
bool add_blinding_key = force_blind || gArgs.GetBoolArg("-blindedaddresses", g_con_elementsmode);
if (!pwallet->GetNewDestination(output_type, label, dest, error, add_blinding_key)) {
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, error);
}

View file

@ -164,13 +164,13 @@ class CTTest (BitcoinTestFramework):
self.test_wallet_recovery()
print("Test blech32 python roundtrip")
# blech/bech are aliased, both are blech32
for addrtype in ["bech32", "blech32"]:
addr_to_rt = self.nodes[0].getnewaddress("", addrtype)
hrp = addr_to_rt[:2]
assert_equal(hrp, "el")
(witver, witprog) = decode(hrp, addr_to_rt)
assert_equal(encode(hrp, witver, witprog), addr_to_rt)
# test only blech32, since getnewaddress for bech32 was changed to return an unblinded address
addr_to_rt = self.nodes[0].getnewaddress("", "blech32")
hrp = addr_to_rt[:2]
assert_equal(hrp, "el")
(witver, witprog) = decode(hrp, addr_to_rt)
assert_equal(encode(hrp, witver, witprog), addr_to_rt)
# Test that "blech32" gives a blinded segwit address.
blech32_addr = self.nodes[0].getnewaddress("", "blech32")

View file

@ -130,7 +130,7 @@ class SighashRangeproofTest(BitcoinTestFramework):
struct.pack("<B", len(signature)) + signature
+ struct.pack("<B", len(pubkey.get_bytes())) + pubkey.get_bytes()
)
elif address_type == "bech32" or address_type == "p2sh-segwit":
elif address_type == "blech32" or address_type == "p2sh-segwit":
assert signed_tx.wit.vtxinwit[0].scriptWitness.stack[1] == pubkey.get_bytes()
pubkeyhash = hash160(pubkey.get_bytes())
script = get_p2pkh_script(pubkeyhash)
@ -217,7 +217,7 @@ class SighashRangeproofTest(BitcoinTestFramework):
def run_test(self):
util.node_fastmerkle = self.nodes[0]
ADDRESS_TYPES = ["legacy", "bech32", "p2sh-segwit"]
ADDRESS_TYPES = ["legacy", "blech32", "p2sh-segwit"]
# Different test scenarios.
# - before activation, using the flag is non-standard
@ -280,4 +280,3 @@ class SighashRangeproofTest(BitcoinTestFramework):
if __name__ == '__main__':
SighashRangeproofTest().main()

View file

@ -357,7 +357,7 @@ class SignRawTransactionsTest(BitcoinTestFramework):
4) The signature of signrawtransactionwithwallet by inputs and
the signature of signrawtransactionwithwallet by utxos are equal.
5) The signed transaction can broadcast."""
utxo_address = self.nodes[2].getnewaddress('', 'bech32')
utxo_address = self.nodes[2].getnewaddress('', 'blech32')
utxo_address_info = self.nodes[2].getaddressinfo(utxo_address)
uc_addr = utxo_address_info['unconfidential']
utxo_address_privkey = self.nodes[2].dumpprivkey(uc_addr)