Skip to content

fix: getnewaddress - don't blind bech32 addresses #1246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,23 +294,27 @@ 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()));
}
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);
}
Expand Down
14 changes: 7 additions & 7 deletions test/functional/feature_confidential_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,13 @@ def run_test(self):
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")
Expand Down
5 changes: 2 additions & 3 deletions test/functional/feature_sighash_rangeproof.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def prepare_tx_signed_with_sighash(self, address_type, sighash_rangeproof_aware,
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)
Expand Down Expand Up @@ -217,7 +217,7 @@ def assert_tx_valid(self, tx, assert_valid=True):

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
Expand Down Expand Up @@ -280,4 +280,3 @@ def run_test(self):

if __name__ == '__main__':
SighashRangeproofTest().main()

2 changes: 1 addition & 1 deletion test/functional/rpc_signrawtransaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ def witness_blind_pubkey_test(self):
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)
Expand Down