From 41fbc555216ab7d410acc369c0c9b269f9c93a35 Mon Sep 17 00:00:00 2001 From: Paul Shapiro Date: Tue, 13 Nov 2018 13:25:11 -0600 Subject: [PATCH] added bridge__mainnet_pubKeyDerivations test case to verify output ownership in generated txs; monero_transfer_utils / serial_bridge_index: exposed tx_pub_key retVal .. one possible addtl retVal would be the output pub keys.. but is there a use in non-test envs for that data? --- src/monero_transfer_utils.cpp | 14 ++++++-- src/monero_transfer_utils.hpp | 2 ++ src/serial_bridge_index.cpp | 1 + src/serial_bridge_index.hpp | 1 + test/test_all.cpp | 65 ++++++++++++++++++++++++++++++++++- 5 files changed, 80 insertions(+), 3 deletions(-) diff --git a/src/monero_transfer_utils.cpp b/src/monero_transfer_utils.cpp index 234e13c..591ed4f 100644 --- a/src/monero_transfer_utils.cpp +++ b/src/monero_transfer_utils.cpp @@ -430,6 +430,7 @@ void monero_transfer_utils::send_step2__try_create_transaction( retVals.signed_serialized_tx_string = std::move(*(create_tx__retVals.signed_serialized_tx_string)); retVals.tx_hash_string = std::move(*(create_tx__retVals.tx_hash_string)); retVals.tx_key_string = std::move(*(create_tx__retVals.tx_key_string)); + retVals.tx_pub_key_string = std::move(*(create_tx__retVals.tx_pub_key_string)); } // // @@ -787,14 +788,23 @@ void monero_transfer_utils::convenience__create_transaction( // signed serialized tx retVals.signed_serialized_tx_string = epee::string_tools::buff_to_hex_nodelimer(cryptonote::tx_to_blob(*actualCall_retVals.tx)); // (concatenated) tx key - ostringstream oss; { + ostringstream oss; oss << epee::string_tools::pod_to_hex(*actualCall_retVals.tx_key); for (size_t i = 0; i < (*actualCall_retVals.additional_tx_keys).size(); ++i) { oss << epee::string_tools::pod_to_hex((*actualCall_retVals.additional_tx_keys)[i]); } + retVals.tx_key_string = oss.str(); + } + { + ostringstream oss; + oss << epee::string_tools::pod_to_hex(get_tx_pub_key_from_extra(*actualCall_retVals.tx)); + retVals.tx_pub_key_string = oss.str(); } - retVals.tx_key_string = oss.str(); retVals.tx = *actualCall_retVals.tx; // for calculating block weight; FIXME: std::move? + // +// cout << "out 0: " << string_tools::pod_to_hex(boost::get((*(actualCall_retVals.tx)).vout[0].target).key) << endl; +// cout << "out 1: " << string_tools::pod_to_hex(boost::get((*(actualCall_retVals.tx)).vout[1].target).key) << endl; + // retVals.txBlob_byteLength = txBlob_byteLength; } diff --git a/src/monero_transfer_utils.hpp b/src/monero_transfer_utils.hpp index 20f57d4..25da931 100644 --- a/src/monero_transfer_utils.hpp +++ b/src/monero_transfer_utils.hpp @@ -210,6 +210,7 @@ namespace monero_transfer_utils optional signed_serialized_tx_string; optional tx_hash_string; optional tx_key_string; // this includes additional_tx_keys + optional tx_pub_key_string; // from get_tx_pub_key_from_extra() }; void send_step2__try_create_transaction( Send_Step2_RetVals &retVals, @@ -241,6 +242,7 @@ namespace monero_transfer_utils optional signed_serialized_tx_string; optional tx_hash_string; optional tx_key_string; // this includes additional_tx_keys + optional tx_pub_key_string; // from get_tx_pub_key_from_extra() optional tx; // for block weight optional txBlob_byteLength; }; diff --git a/src/serial_bridge_index.cpp b/src/serial_bridge_index.cpp index 8463599..a41cfd8 100644 --- a/src/serial_bridge_index.cpp +++ b/src/serial_bridge_index.cpp @@ -614,6 +614,7 @@ string serial_bridge::send_step2__try_create_transaction(const string &args_stri root.put(ret_json_key__send__serialized_signed_tx(), std::move(*(retVals.signed_serialized_tx_string))); root.put(ret_json_key__send__tx_hash(), std::move(*(retVals.tx_hash_string))); root.put(ret_json_key__send__tx_key(), std::move(*(retVals.tx_key_string))); + root.put(ret_json_key__send__tx_pub_key(), std::move(*(retVals.tx_pub_key_string))); } } return ret_json_from_root(root); diff --git a/src/serial_bridge_index.hpp b/src/serial_bridge_index.hpp index 4211baf..e13c9dd 100644 --- a/src/serial_bridge_index.hpp +++ b/src/serial_bridge_index.hpp @@ -93,6 +93,7 @@ namespace serial_bridge static inline string ret_json_key__send__serialized_signed_tx() { return "serialized_signed_tx"; } static inline string ret_json_key__send__tx_hash() { return "tx_hash"; } static inline string ret_json_key__send__tx_key() { return "tx_key"; } + static inline string ret_json_key__send__tx_pub_key() { return "tx_pub_key"; } // // - - decode_address, etc static inline string ret_json_key__paymentID_string() { return "paymentID_string"; } // optional diff --git a/test/test_all.cpp b/test/test_all.cpp index f33b964..7c73c54 100644 --- a/test/test_all.cpp +++ b/test/test_all.cpp @@ -332,7 +332,7 @@ BOOST_AUTO_TEST_CASE(bridge__transfers__send__amountWOnlyDusty) // ^--- expecting needMoreMoneyThanFound } string DG_postsweep__unspent_outs_json = "{\"unspent_outs\":[{\"amount\":\"3000000000\",\"public_key\":\"41be1978f58cabf69a9bed5b6cb3c8d588621ef9b67602328da42a213ee42271\",\"index\":1,\"global_index\":7611174,\"rct\":\"86a2c9f1f8e66848cd99bfda7a14d4ac6c3525d06947e21e4e55fe42a368507eb5b234ccdd70beca8b1fc8de4f2ceb1374e0f1fd8810849e7f11316c2cc063060008ffa5ac9827b776993468df21af8c963d12148622354f950cbe1369a92a0c\",\"tx_id\":5334971,\"tx_hash\":\"9d37c7fdeab91abfd1e7e120f5c49eac17b7ac04a97a0c93b51c172115df21ea\",\"tx_pub_key\":\"bd703d7f37995cc7071fb4d2929594b5e2a4c27d2b7c68a9064500ca7bc638b8\"}]}"; -string DG_postsweep__rand_outs_json = "{\"mix_outs\":[{\"amount\":\"0\",\"outputs\":[{\"global_index\":\"7453099\",\"public_key\":\"31f3a7fec0f6f09067e826b6c2904fd4b1684d7893dcf08c5b5d22e317e148bb\",\"rct\":\"ea6bcb193a25ce2787dd6abaaeef1ee0c924b323c6a5873db1406261e86145fc\"},{\"global_index\":\"7500097\",\"public_key\":\"f9d923500671da05a1bf44b932b872f0c4a3c88e6b3d4bf774c8be915e25f42b\",\"rct\":\"dcae4267a6c382bcd71fd1af4d2cbceb3749d576d7a3acc473dd579ea9231a52\"},{\"global_index\":\"7548483\",\"public_key\":\"839cbbb73685654b93e824c4843e745e8d5f7742e83494932307bf300641c480\",\"rct\":\"aa99d492f1d6f1b20dcd95b8fff8f67a219043d0d94b4551759016b4888573e7\"},{\"global_index\":\"7554755\",\"public_key\":\"b8860f0697988c8cefd7b4285fbb8bec463f136c2b9a9cadb3e57cebee10717f\",\"rct\":\"327f9b07bee9c4c25b5a990123cd2444228e5704ebe32016cd632866710279b5\"},{\"global_index\":\"7561477\",\"public_key\":\"561d734cb90bc4a64d49d37f85ea85575243e2ed749a3d6dcb4d27aa6bec6e88\",\"rct\":\"b5393e038df95b94bfda62b44a29141cac9e356127270af97193460d51949841\"},{\"global_index\":\"7567062\",\"public_key\":\"db1024ef67e7e73608ef8afab62f49e2402c8da3dc3197008e3ba720ad3c94a8\",\"rct\":\"1fedf95621881b77f823a70aa83ece26aef62974976d2b8cd87ed4862a4ec92c\"},{\"global_index\":\"7567508\",\"public_key\":\"6283f3cd2f050bba90276443fe04f6076ad2ad46a515bf07b84d424a3ba43d27\",\"rct\":\"10e16bb8a8b7b0c8a4b193467b010976b962809c9f3e6c047335dba09daa351f\"},{\"global_index\":\"7568716\",\"public_key\":\"7a7deb4eef81c1f5ce9cbd0552891cb19f1014a03a5863d549630824c7c7c0d3\",\"rct\":\"735d059dc3526334ac705ddc44c4316bb8805d2426dcea9544cde50cf6c7a850\"},{\"global_index\":\"7571196\",\"public_key\":\"535208e354cae530ed7ce752935e555d630cf2edd7f91525024ed9c332b2a347\",\"rct\":\"c3cf838faa14e993536c5581ca582fb0d96b70f713cf88f7f15c89336e5853ec\"},{\"global_index\":\"7571333\",\"public_key\":\"e73f27b7eb001aa7eac13df82814cda65b42ceeb6ef36227c25d5cbf82f6a5e4\",\"rct\":\"5f45f33c6800cdae202b37abe6d87b53d6873e7b30f3527161f44fa8db3104b6\"},{\"global_index\":\"7571335\",\"public_key\":\"fce982db8e7a6b71a1e632c7de8c5cbf54e8bacdfbf250f1ffc2a8d2f7055ce3\",\"rct\":\"407bdcc48e70eb3ef2cc22cefee6c6b5a3c59fd17bde12fda5f1a44a0fb39d14\"}]}]}"; +string DG_postsweep__rand_outs_json = "{\"mix_outs\":[{\"amount\":\"0\",\"outputs\":[{\"global_index\":\"7453099\",\"public_key\":\"31f3a7fec0f6f09067e826b6c2904fd4b1684d7893dcf08c5b5d22e317e148bb\",\"rct\":\"ea6bcb193a25ce2787dd6abaaeef1ee0c924b323c6a5873db1406261e86145fc\"},{\"global_index\":\"7500097\",\"public_key\":\"f9d923500671da05a1bf44b932b872f0c4a3c88e6b3d4bf774c8be915e25f42b\",\"rct\":\"dcae4267a6c382bcd71fd1af4d2cbceb3749d576d7a3acc473dd579ea9231a52\"},{\"global_index\":\"7548483\",\"public_key\":\"839cbbb73685654b93e824c4843e745e8d5f7742e83494932307bf300641c480\",\"rct\":\"aa99d492f1d6f1b20dcd95b8fff8f67a219043d0d94b4551759016b4888573e7\"},{\"global_index\":\"7554755\",\"public_key\":\"b8860f0697988c8cefd7b4285fbb8bec463f136c2b9a9cadb3e57cebee10717f\",\"rct\":\"327f9b07bee9c4c25b5a990123cd2444228e5704ebe32016cd632866710279b5\"},{\"global_index\":\"7561477\",\"public_key\":\"561d734cb90bc4a64d49d37f85ea85575243e2ed749a3d6dcb4d27aa6bec6e88\",\"rct\":\"b5393e038df95b94bfda62b44a29141cac9e356127270af97193460d51949841\"},{\"global_index\":\"7567062\",\"public_key\":\"db1024ef67e7e73608ef8afab62f49e2402c8da3dc3197008e3ba720ad3c94a8\",\"rct\":\"1fedf95621881b77f823a70aa83ece26aef62974976d2b8cd87ed4862a4ec92c\"},{\"global_index\":\"7567508\",\"public_key\":\"6283f3cd2f050bba90276443fe04f6076ad2ad46a515bf07b84d424a3ba43d27\",\"rct\":\"10e16bb8a8b7b0c8a4b193467b010976b962809c9f3e6c047335dba09daa351f\"},{\"global_index\":\"7568716\",\"public_key\":\"7a7deb4eef81c1f5ce9cbd0552891cb19f1014a03a5863d549630824c7c7c0d3\",\"rct\":\"735d059dc3526334ac705ddc44c4316bb8805d2426dcea9544cde50cf6c7a850\"},{\"global_index\":\"7571196\",\"public_key\":\"535208e354cae530ed7ce752935e555d630cf2edd7f91525024ed9c332b2a347\",\"rct\":\"c3cf838faa14e993536c5581ca582fb0d96b70f713cf88f7f15c89336e5853ec\"},{\"global_index\":\"7571333\",\"public_key\":\"e73f27b7eb001aa7eac13df82814cda65b42ceeb6ef36227c25d5cbf82f6a5e4\",\"rct\":\"5f45f33c6800cdae202b37abe6d87b53d6873e7b30f3527161f44fa8db3104b6\"},{\"global_index\":\"7571335\",\"public_key\":\"fce982dbz8e7a6b71a1e632c7de8c5cbf54e8bacdfbf250f1ffc2a8d2f7055ce3\",\"rct\":\"407bdcc48e70eb3ef2cc22cefee6c6b5a3c59fd17bde12fda5f1a44a0fb39d14\"}]}]}"; BOOST_AUTO_TEST_CASE(bridge__transfers__send__amount) { @@ -448,6 +448,7 @@ BOOST_AUTO_TEST_CASE(bridge__transfers__send__amount) { boost::property_tree::ptree root; root.put("final_total_wo_fee", *final_total_wo_fee_string); + cout << "change_amount_string: " << *change_amount_string << endl; root.put("change_amount", *change_amount_string); // from step1 root.put("fee_amount", *using_fee_string); // from step1 root.add_child("using_outs", using_outs); // from step1 @@ -488,6 +489,7 @@ BOOST_AUTO_TEST_CASE(bridge__transfers__send__amount) } optional tx_hash = ret_tree.get_optional(ret_json_key__send__tx_hash()); optional tx_key_string = ret_tree.get_optional(ret_json_key__send__tx_key()); + optional tx_pub_key_string = ret_tree.get_optional(ret_json_key__send__tx_pub_key()); optional serialized_signed_tx = ret_tree.get_optional(ret_json_key__send__serialized_signed_tx()); BOOST_REQUIRE(serialized_signed_tx != none); BOOST_REQUIRE((*serialized_signed_tx).size() > 0); @@ -498,6 +500,9 @@ BOOST_AUTO_TEST_CASE(bridge__transfers__send__amount) BOOST_REQUIRE(tx_key_string != none); BOOST_REQUIRE((*tx_key_string).size() > 0); cout << "bridge__transfers__send__amount: tx_key_string: " << *tx_key_string << endl; + BOOST_REQUIRE(tx_pub_key_string != none); + BOOST_REQUIRE((*tx_pub_key_string).size() > 0); + cout << "bridge__transfers__send__amount: tx_pub_key_string: " << *tx_pub_key_string << endl; } } } @@ -996,6 +1001,64 @@ BOOST_AUTO_TEST_CASE(bridged__generate_key_derivation) cout << "bridged__generate_key_derivation: derivation: " << *derivation << endl; } // +BOOST_AUTO_TEST_CASE(bridge__mainnet_pubKeyDerivations) +{ + using namespace serial_bridge; + // + string arg__txPubKey = "5b7bc9532af303b7742dfceb04a5a3989f2433caa0ca75f58df4eaa1a4422d96"; + string arg__secViewKey = "7bea1907940afdd480eff7c4bcadb478a0fbb626df9e3ed74ae801e18f53e104"; + string arg__pubSpendKey = "3eb884d3440d71326e27cc07a861b873e72abd339feb654660c36a008a0028b3"; + // + string arg__TxOwnOutIdx = "0"; + string arg__TxOwnOutPubKey = "f43366980f7b0c2094023171cf8275210e7d0dae03cca0e8161a2f0aa4625e63"; + // + cout << "bridge__mainnet_pubKeyDerivations: arg__TxOwnOutPubKey " << arg__TxOwnOutPubKey << endl; + // + optional key_derivation = none; // to derive + { + boost::property_tree::ptree root; + root.put("pub", arg__txPubKey); + root.put("sec", arg__secViewKey); + // + auto ret_string = serial_bridge::generate_key_derivation(args_string_from_root(root)); + stringstream ret_stream; + ret_stream << ret_string; + boost::property_tree::ptree ret_tree; + boost::property_tree::read_json(ret_stream, ret_tree); + optional err_string = ret_tree.get_optional(ret_json_key__any__err_msg()); + if (err_string != none) { + BOOST_REQUIRE_MESSAGE(false, *err_string); + } + key_derivation = ret_tree.get_optional(ret_json_key__generic_retVal()); + BOOST_REQUIRE(key_derivation != none); + BOOST_REQUIRE((*key_derivation).size() > 0); + cout << "bridge__mainnet_pubKeyDerivations: key_derivation " << *key_derivation << endl; + } + { + boost::property_tree::ptree root; + root.put("derivation", *key_derivation); + root.put("out_index", arg__TxOwnOutIdx); + root.put("pub", arg__pubSpendKey); + // + auto ret_string = serial_bridge::derive_public_key(args_string_from_root(root)); + stringstream ret_stream; + ret_stream << ret_string; + boost::property_tree::ptree ret_tree; + boost::property_tree::read_json(ret_stream, ret_tree); + optional err_string = ret_tree.get_optional(ret_json_key__any__err_msg()); + if (err_string != none) { + BOOST_REQUIRE_MESSAGE(false, *err_string); + } + optional derived_pub_key = ret_tree.get_optional(ret_json_key__generic_retVal()); + BOOST_REQUIRE(derived_pub_key != none); + BOOST_REQUIRE((*derived_pub_key).size() > 0); + cout << "bridge__mainnet_pubKeyDerivations: Derived pub key " << *derived_pub_key << endl; + // + // The critical tests + BOOST_REQUIRE(*derived_pub_key == arg__TxOwnOutPubKey); + } +} +// BOOST_AUTO_TEST_CASE(bridged__decodeRct) { using namespace serial_bridge;