From 40a62a151da8be6a9bbc5fc4631c7ce58a100028 Mon Sep 17 00:00:00 2001 From: Gregory Sanders Date: Thu, 4 Apr 2019 11:46:00 -0400 Subject: [PATCH 1/4] DestinationEncoder: don't assert when a parent destination is unblinded --- src/key_io.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/key_io.cpp b/src/key_io.cpp index 9ee053bdbe..897d816079 100644 --- a/src/key_io.cpp +++ b/src/key_io.cpp @@ -33,7 +33,6 @@ public: std::string operator()(const PKHash& id) const { if (id.blinding_pubkey.IsFullyValid()) { - assert(!for_parent); std::vector data = m_params.Base58Prefix(CChainParams::BLINDED_ADDRESS); // Blinded addresses have the actual address type prefix inside the payload. std::vector prefix = m_params.Base58Prefix(CChainParams::PUBKEY_ADDRESS); @@ -52,7 +51,6 @@ public: std::string operator()(const ScriptHash& id) const { if (id.blinding_pubkey.IsFullyValid()) { - assert(!for_parent); std::vector data = m_params.Base58Prefix(CChainParams::BLINDED_ADDRESS); // Blinded addresses have the actual address type prefix inside the payload. std::vector prefix = m_params.Base58Prefix(CChainParams::SCRIPT_ADDRESS); From 894d76e7c8083a32b3a797351a3eeb0004f9d3b6 Mon Sep 17 00:00:00 2001 From: Gregory Sanders Date: Thu, 4 Apr 2019 09:36:09 -0400 Subject: [PATCH 2/4] test all single-key pegout address types --- test/functional/feature_fedpeg.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/test/functional/feature_fedpeg.py b/test/functional/feature_fedpeg.py index 3a1b538abd..2b3c778ffe 100755 --- a/test/functional/feature_fedpeg.py +++ b/test/functional/feature_fedpeg.py @@ -15,8 +15,8 @@ from test_framework.util import ( ) from decimal import Decimal -def get_new_unconfidential_address(node): - addr = node.getnewaddress() +def get_new_unconfidential_address(node, addr_type="p2sh-segwit"): + addr = node.getnewaddress("", addr_type) val_addr = node.getaddressinfo(addr) if 'unconfidential' in val_addr: return val_addr['unconfidential'] @@ -148,6 +148,8 @@ class FedPegTest(BitcoinTestFramework): pegout_tested = True break assert pegout_tested + sidechain.generatetoaddress(1, sidechain.getnewaddress()) + assert_equal(sidechain.gettransaction(pegout_txid)["confirmations"], 1) def run_test(self): parent = self.nodes[0] @@ -289,8 +291,10 @@ class FedPegTest(BitcoinTestFramework): if "confirmations" not in tx or tx["confirmations"] == 0: raise Exception("Peg-in confirmation has failed.") - print("Test pegout") - self.test_pegout(get_new_unconfidential_address(parent), sidechain) + print("Test pegouts") + self.test_pegout(get_new_unconfidential_address(parent, "legacy"), sidechain) + self.test_pegout(get_new_unconfidential_address(parent, "p2sh-segwit"), sidechain) + self.test_pegout(get_new_unconfidential_address(parent, "bech32"), sidechain) print("Test pegout P2SH") parent_chain_addr = get_new_unconfidential_address(parent) From 9e56c87ec5334744789275073b5bed57ccfdd33d Mon Sep 17 00:00:00 2001 From: Gregory Sanders Date: Thu, 4 Apr 2019 10:25:39 -0400 Subject: [PATCH 3/4] have validateaddress give useful parent chain addr info --- src/rpc/misc.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index de233ddfa5..8130a725a5 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -56,6 +56,12 @@ static UniValue validateaddress(const JSONRPCRequest& request) " \"witness_program\" : \"hex\" (string, optional) The hex value of the witness program\n" " \"confidential_key\" : \"hex\", (string) The hex value of the raw blinding public key for that address, if any. \"\" if none.\n" " \"unconfidential\" : \"address\", (string) The address without confidentiality key.\n" + " \"parent_address_info\": (obj) If the address isvalid_parent, this object contains details about the parent address type.\n" + " {\n" + " \"address\" : \"address\",\n" + " \"scriptPubKey\" : \"hex\",\n" + " ...\n" + " }\n" "}\n" "\nExamples:\n" + HelpExampleCli("validateaddress", "\"1PSSGeFHDnKNxiEyFrD1wcEaHr9hrQDDWc\"") @@ -82,6 +88,20 @@ static UniValue validateaddress(const JSONRPCRequest& request) UniValue blind_detail = DescribeBlindAddress(dest); ret.pushKVs(blind_detail); } + if (is_valid_parent) { + UniValue parent_info(UniValue::VOBJ); + std::string currentAddress = EncodeParentDestination(parent_dest); + parent_info.pushKV("address", currentAddress); + + CScript scriptPubKey = GetScriptForDestination(parent_dest); + parent_info.pushKV("scriptPubKey", HexStr(scriptPubKey.begin(), scriptPubKey.end())); + + UniValue detail = DescribeAddress(parent_dest); + parent_info.pushKVs(detail); + UniValue blind_detail = DescribeBlindAddress(parent_dest); + parent_info.pushKVs(blind_detail); + ret.pushKV("parent_address_info", parent_info); + } return ret; } From 30eb323e9bf5cdf6b777ec50b474a20c74c97adf Mon Sep 17 00:00:00 2001 From: Gregory Sanders Date: Thu, 4 Apr 2019 10:26:02 -0400 Subject: [PATCH 4/4] ensure pak wallet is returning right kind of addresses --- test/functional/feature_pak.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/test/functional/feature_pak.py b/test/functional/feature_pak.py index 2e0e83bdc7..dfc6bc614f 100755 --- a/test/functional/feature_pak.py +++ b/test/functional/feature_pak.py @@ -33,9 +33,8 @@ pak2 = [("03767a74373b7207c5ae1214295197a88ec2abdf92e9e2a29daf024c322fae9fcb", " ("02f4a7445f9c48ee8590a930d3fc4f0f5763e3d1d003fdf5fc822e7ba18f380632", "036b3786f029751ada9f02f519a86c7e02fb2963a7013e7e668eb5f7ec069b9e7e")] # Args that will be re-used in slightly different ways across runs -# TODO remove lol once parent chain hrp default is changed -args = [["-acceptnonstdtxn=0", "-initialfreecoins=100000000", "-parent_bech32_hrp=lol"]] \ - + [["-acceptnonstdtxn=0", "-enforce_pak=1", "-initialfreecoins=100000000", "-parent_bech32_hrp=lol"]]*4 +args = [["-acceptnonstdtxn=0", "-initialfreecoins=100000000", "-parent_bech32_hrp=lol", "-pubkeyprefix=112", "-scriptprefix=197"]] \ + + [["-acceptnonstdtxn=0", "-enforce_pak=1", "-initialfreecoins=100000000", "-parent_bech32_hrp=lol", "-pubkeyprefix=112", "-scriptprefix=197"]]*4 args[i_reject] = args[i_reject] + ['-pak=reject'] # Novalidate has pak entry, should not act on it ever args[i_novalidate] = args[i_novalidate] + pak_to_option(pak1) @@ -220,6 +219,11 @@ class PAKTest (BitcoinTestFramework): assert_equal(init_results[i]["liquid_pak_address"], info_results[i]["liquid_pak_address"]) assert_equal(info_results[i]["bitcoin_descriptor"], xpub_desc) assert_equal(info_results[i]["bip32_counter"], "0") + validata = self.nodes[i].validateaddress(init_results[i]["address_lookahead"][0]) + assert not validata["isvalid"] + assert validata["isvalid_parent"] + assert not validata["parent_address_info"]["isscript"] + assert not validata["parent_address_info"]["iswitness"] # Use custom derivation counter values, check if stored correctly, # address lookahead looks correct and that new liquid_pak was chosen @@ -349,12 +353,20 @@ class PAKTest (BitcoinTestFramework): validata = self.nodes[i_pak1].validateaddress(wpkh_stmc["bitcoin_address"]) assert(not validata["isvalid"]) assert(validata["isvalid_parent"]) + assert(not validata["parent_address_info"]["isscript"]) + assert(validata["parent_address_info"]["iswitness"]) assert_equal(wpkh_pak_info["bip32_counter"], wpkh_stmc["bip32_counter"]) assert_equal(wpkh_pak_info["bitcoin_descriptor"], wpkh_stmc["bitcoin_descriptor"]) sh_wpkh_desc = "sh(wpkh("+xpub+"/0/1/*))" sh_wpkh_info = self.nodes[i_pak1].initpegoutwallet(sh_wpkh_desc) + validata = self.nodes[i_pak1].validateaddress(sh_wpkh_info["address_lookahead"][0]) + assert(not validata["isvalid"]) + assert(validata["isvalid_parent"]) + assert(validata["parent_address_info"]["isscript"]) + assert(not validata["parent_address_info"]["iswitness"]) + # Add to pak list for pak1, restart self.stop_nodes() extra_args = copy.deepcopy(args) @@ -396,5 +408,7 @@ class PAKTest (BitcoinTestFramework): raise Exception("Found unexpected peg-out output") assert(peg_out_found) + # TODO: create rawsendtomainchain to do transaction surgery for testing + if __name__ == '__main__': PAKTest ().main ()