diff --git a/src/crypto/clsag.cpp b/src/crypto/clsag.cpp index c4e1198f..352f4457 100644 --- a/src/crypto/clsag.cpp +++ b/src/crypto/clsag.cpp @@ -182,7 +182,7 @@ namespace crypto } bool verify_CLSAG_GGX(const hash& m, const std::vector& ring, const public_key& pseudo_out_amount_commitment, - const public_key& pseudo_out_asset_id, const key_image& ki, const CLSAG_GGX_signature& sig) + const public_key& pseudo_out_blinded_asset_id, const key_image& ki, const CLSAG_GGX_signature& sig) { return false; } diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index e990ac59..1d65917c 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -2578,7 +2578,7 @@ namespace currency return true; } - bool is_out_to_acc(const account_public_address& addr, const tx_out_zarcanum& zo, const crypto::key_derivation& derivation, size_t output_index, uint64_t& decoded_amount, + bool is_out_to_acc(const account_public_address& addr, const tx_out_zarcanum& zo, const crypto::key_derivation& derivation, size_t output_index, uint64_t& decoded_amount, crypto::public_key& decoded_asset_id, crypto::scalar_t& amount_blinding_mask, crypto::scalar_t& asset_id_blinding_mask) { crypto::scalar_t h; // = crypto::hash_helper_t::hs(reinterpret_cast(derivation), output_index); // h = Hs(8 * r * V, i) @@ -2604,11 +2604,11 @@ namespace currency asset_id_blinding_mask = crypto::hash_helper_t::hs(CRYPTO_HDS_OUT_ASSET_BLINDING_MASK, h); // f = Hs(domain_sep, d, i) - // crypto::point_t asset_id = blinded_asset_id - asset_id_blinding_mask * crypto::c_point_X; // H = T - s * X - + crypto::point_t asset_id = blinded_asset_id - asset_id_blinding_mask * crypto::c_point_X; // H = T - s * X + decoded_asset_id = asset_id.to_public_key(); return true; - } + } //--------------------------------------------------------------- bool lookup_acc_outs(const account_keys& acc, const transaction& tx, std::vector& outs, uint64_t& money_transfered, crypto::key_derivation& derivation) @@ -2724,14 +2724,17 @@ namespace currency VARIANT_SWITCH_END(); } VARIANT_CASE_CONST(tx_out_zarcanum, zo) + { uint64_t amount = 0; + crypto::public_key asset_id{}; crypto::scalar_t amount_blinding_mask = 0, asset_id_blinding_mask = 0; - if (is_out_to_acc(acc.account_address, zo, derivation, output_index, amount, amount_blinding_mask, asset_id_blinding_mask)) + if (is_out_to_acc(acc.account_address, zo, derivation, output_index, amount, asset_id, amount_blinding_mask, asset_id_blinding_mask)) { crypto::point_t asset_id_pt = crypto::point_t(zo.blinded_asset_id) - asset_id_blinding_mask * crypto::c_point_X; outs.emplace_back(output_index, amount, amount_blinding_mask, asset_id_blinding_mask, asset_id_pt.to_public_key()); money_transfered += amount; } + } VARIANT_SWITCH_END(); output_index++; } diff --git a/src/currency_core/currency_format_utils.h b/src/currency_core/currency_format_utils.h index 66fc0719..49ff7c3f 100644 --- a/src/currency_core/currency_format_utils.h +++ b/src/currency_core/currency_format_utils.h @@ -317,7 +317,7 @@ namespace currency crypto::hash get_multisig_out_id(const transaction& tx, size_t n); bool is_out_to_acc(const account_public_address& addr, const txout_to_key& out_key, const crypto::key_derivation& derivation, size_t output_index); bool is_out_to_acc(const account_public_address& addr, const txout_multisig& out_multisig, const crypto::key_derivation& derivation, size_t output_index); - bool is_out_to_acc(const account_public_address& addr, const tx_out_zarcanum& zo, const crypto::key_derivation& derivation, size_t output_index, uint64_t& decoded_amount, crypto::scalar_t& amount_blinding_mask, crypto::scalar_t& asset_id_blinding_mask); + bool is_out_to_acc(const account_public_address& addr, const tx_out_zarcanum& zo, const crypto::key_derivation& derivation, size_t output_index, uint64_t& decoded_amount, crypto::public_key& decoded_asset_id, crypto::scalar_t& amount_blinding_mask, crypto::scalar_t& asset_id_blinding_mask); bool lookup_acc_outs(const account_keys& acc, const transaction& tx, const crypto::public_key& tx_pub_key, std::vector& outs, uint64_t& money_transfered, crypto::key_derivation& derivation); bool lookup_acc_outs(const account_keys& acc, const transaction& tx, const crypto::public_key& tx_pub_key, std::vector& outs, uint64_t& money_transfered, crypto::key_derivation& derivation, std::list& htlc_info_list); bool lookup_acc_outs(const account_keys& acc, const transaction& tx, std::vector& outs, uint64_t& money_transfered, crypto::key_derivation& derivation); diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index a773dca5..a08aa2e2 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -1698,7 +1698,7 @@ std::string wallets_manager::reset_wallet_password(uint64_t wallet_id, const std else return API_RETURN_CODE_FAIL; } -std::string wallets_manager::add_custom_asset_id(uint64_t wallet_id, const crypto::hash& asset_id, currency::asset_descriptor_base& asset_descriptor) +std::string wallets_manager::add_custom_asset_id(uint64_t wallet_id, const crypto::public_key& asset_id, currency::asset_descriptor_base& asset_descriptor) { GET_WALLET_OPT_BY_ID(wallet_id, w); if(w.w->get()->add_custom_asset_id(asset_id, asset_descriptor)) @@ -1706,7 +1706,7 @@ std::string wallets_manager::add_custom_asset_id(uint64_t wallet_id, const crypt else return API_RETURN_CODE_FAIL; } -std::string wallets_manager::delete_custom_asset_id(uint64_t wallet_id, const crypto::hash& asset_id) +std::string wallets_manager::delete_custom_asset_id(uint64_t wallet_id, const crypto::public_key& asset_id) { GET_WALLET_OPT_BY_ID(wallet_id, w); if (w.w->get()->delete_custom_asset_id(asset_id)) diff --git a/src/wallet/wallets_manager.h b/src/wallet/wallets_manager.h index b5c2922f..b550857b 100644 --- a/src/wallet/wallets_manager.h +++ b/src/wallet/wallets_manager.h @@ -162,8 +162,8 @@ public: std::string get_qt_dev_tools_option() const { return m_qt_dev_tools; } void set_use_deffered_global_outputs(bool use) { m_use_deffered_global_outputs = use; } bool set_use_tor(bool use_tor); - std::string add_custom_asset_id(uint64_t wallet_id, const crypto::hash& asset_id, currency::asset_descriptor_base& asset_descriptor); - std::string delete_custom_asset_id(uint64_t wallet_id, const crypto::hash& asset_id); + std::string add_custom_asset_id(uint64_t wallet_id, const crypto::public_key& asset_id, currency::asset_descriptor_base& asset_descriptor); + std::string delete_custom_asset_id(uint64_t wallet_id, const crypto::public_key& asset_id); private: void main_worker(const po::variables_map& vm); diff --git a/tests/core_tests/chaingen.cpp b/tests/core_tests/chaingen.cpp index 2196792f..4412213f 100644 --- a/tests/core_tests/chaingen.cpp +++ b/tests/core_tests/chaingen.cpp @@ -463,7 +463,7 @@ bool test_generator::build_wallets(const blockchain_vector& blockchain, if (amount == 0 && out_v.type() == typeid(tx_out_zarcanum)) { const tx_out_zarcanum& out_zc = boost::get(out_v); - rsp_entry.outs.emplace_back(gindex, out_zc.stealth_address, out_zc.amount_commitment, out_zc.concealing_point); + rsp_entry.outs.emplace_back(gindex, out_zc.stealth_address, out_zc.amount_commitment, out_zc.concealing_point, out_zc.blinded_asset_id); } else if (amount != 0 && out_v.type() == typeid(tx_out_bare)) { @@ -1040,18 +1040,20 @@ bool test_generator::construct_pow_block_with_alias_info_in_coinbase(const accou struct output_index { const currency::tx_out_v out_v; - uint64_t amount; // actual amount (decoded, cannot be zero) - size_t tx_no; // index of transaction in block - size_t out_no; // index of out in transaction - size_t idx; // global index - bool spent; // was it spent? - bool zc_out; // is it a ZC output? - const currency::block *p_blk; - const currency::transaction *p_tx; - crypto::scalar_t blinding_mask; // zc outs only + uint64_t amount = 0; // actual amount (decoded, cannot be zero) + size_t tx_no = 0; // index of transaction in block + size_t out_no = 0; // index of out in transaction + size_t idx = 0; // global index + bool spent = false; // was it spent? + bool zc_out = false; // is it a ZC output? + const currency::block *p_blk = 0; + const currency::transaction *p_tx = 0; + crypto::scalar_t amount_blinding_mask = 0; // zc outs only + crypto::scalar_t asset_id_blinding_mask = 0; // zc outs only + crypto::public_key asset_id = currency::native_coin_asset_id; output_index(const currency::tx_out_v &_out_v, uint64_t _a, size_t tno, size_t ono, const currency::block *_pb, const currency::transaction *_pt) - : out_v(_out_v), amount(_a), tx_no(tno), out_no(ono), idx(0), spent(false), zc_out(false), p_blk(_pb), p_tx(_pt), blinding_mask(0) + : out_v(_out_v), amount(_a), tx_no(tno), out_no(ono), p_blk(_pb), p_tx(_pt) {} output_index(const output_index &other) = default; @@ -1062,10 +1064,11 @@ struct output_index ss << "output_index{" << " tx_no=" << tx_no << " out_no=" << out_no - << " amount=" << amount + << " amount=" << currency::print_money_brief(amount) << " idx=" << idx << " spent=" << spent << " zc_out=" << zc_out + << " asset=" << (asset_id == currency::native_coin_asset_id ? std::string("native") : print16(asset_id)) << "}"; return ss.str(); } @@ -1144,11 +1147,14 @@ bool init_output_indices(map_output_idx_t& outs, map_output_t& outs_mine, const outs_vec.emplace_back(std::move(oi)); uint64_t decoded_amount = 0; - crypto::scalar_t decoded_blinding_mask{}; - if (is_out_to_acc(acc_keys.account_address, out, derivation, j, decoded_amount, decoded_blinding_mask)) + crypto::public_key decoded_asset_id{}; + crypto::scalar_t decoded_amount_blinding_mask{}, decoded_asset_id_blinding_mask{}; + if (is_out_to_acc(acc_keys.account_address, out, derivation, j, decoded_amount, decoded_asset_id, decoded_amount_blinding_mask, decoded_asset_id_blinding_mask)) { - outs_vec.back().amount = decoded_amount; - outs_vec.back().blinding_mask = decoded_blinding_mask; + outs_vec.back().amount = decoded_amount; + outs_vec.back().amount_blinding_mask = decoded_amount_blinding_mask; + outs_vec.back().asset_id = decoded_asset_id; + outs_vec.back().asset_id_blinding_mask = decoded_asset_id_blinding_mask; outs_mine[0].push_back(out_global_idx); } VARIANT_SWITCH_END() @@ -1282,7 +1288,7 @@ bool fill_output_entries(const std::vector& out_indices, size_t re output_entries.emplace_back(out_ref_v, otk.key); VARIANT_SWITCH_END() VARIANT_CASE_CONST(tx_out_zarcanum, ozc) - output_entries.emplace_back(out_ref_v, ozc.stealth_address, ozc.concealing_point, ozc.amount_commitment); + output_entries.emplace_back(out_ref_v, ozc.stealth_address, ozc.concealing_point, ozc.amount_commitment, ozc.blinded_asset_id); VARIANT_SWITCH_END() } } @@ -1392,8 +1398,10 @@ bool fill_tx_sources(std::vector& sources, const std: currency::tx_source_entry ts = AUTO_VAL_INIT(ts); + ts.asset_id = oi.asset_id; ts.amount = oi.amount; - ts.real_out_amount_blinding_mask = oi.blinding_mask; + ts.real_out_asset_id_blinding_mask = oi.asset_id_blinding_mask; + ts.real_out_amount_blinding_mask = oi.amount_blinding_mask; ts.real_output_in_tx_index = oi.out_no; ts.real_out_tx_key = get_tx_pub_key_from_extra(*oi.p_tx); // source tx public key if (!fill_output_entries(outs[o.first], sender_out, nmix, check_for_unlocktime, use_ref_by_id, next_block_height, head_block_ts, ts.real_output, ts.outputs)) diff --git a/tests/core_tests/multiassets_test.cpp b/tests/core_tests/multiassets_test.cpp index 8bc70f08..a1d4e7f9 100644 --- a/tests/core_tests/multiassets_test.cpp +++ b/tests/core_tests/multiassets_test.cpp @@ -73,17 +73,17 @@ bool multiassets_basic_test::c1(currency::core& c, size_t ev_index, const std::v std::vector destinations(2); destinations[0].addr.push_back(miner_wlt->get_account().get_public_address()); destinations[0].amount = AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC; - destinations[0].asset_id = currency::ffff_hash; + destinations[0].asset_id = currency::ffff_pkey; destinations[1].addr.push_back(alice_wlt->get_account().get_public_address()); destinations[1].amount = AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC; - destinations[1].asset_id = currency::ffff_hash; + destinations[1].asset_id = currency::ffff_pkey; LOG_PRINT_MAGENTA("destinations[0].asset_id:" << destinations[0].asset_id, LOG_LEVEL_0); LOG_PRINT_MAGENTA("destinations[1].asset_id:" << destinations[1].asset_id, LOG_LEVEL_0); - LOG_PRINT_MAGENTA("currency::ffff_hash:" << currency::ffff_hash, LOG_LEVEL_0); + LOG_PRINT_MAGENTA("currency::ffff_pkey: " << currency::ffff_pkey, LOG_LEVEL_0); currency::transaction tx = AUTO_VAL_INIT(tx); - crypto::hash asset_id = currency::null_hash; + crypto::public_key asset_id = currency::null_pkey; miner_wlt->publish_new_asset(adb, destinations, tx, asset_id); LOG_PRINT_L0("Published new asset: " << asset_id << ", tx_id: " << currency::get_transaction_hash(tx)); @@ -95,11 +95,11 @@ bool multiassets_basic_test::c1(currency::core& c, size_t ev_index, const std::v miner_wlt->refresh(); alice_wlt->refresh(); uint64_t mined = 0; - std::unordered_map balances; + std::unordered_map balances; miner_wlt->balance(balances, mined); auto it_asset = balances.find(asset_id); - auto it_native = balances.find(currency::null_hash); + auto it_native = balances.find(currency::native_coin_asset_id); CHECK_AND_ASSERT_MES(it_asset != balances.end() && it_native != balances.end(), false, "Failed to find needed asset in result balances"); @@ -111,7 +111,7 @@ bool multiassets_basic_test::c1(currency::core& c, size_t ev_index, const std::v alice_wlt->balance(balances, mined); it_asset = balances.find(asset_id); - it_native = balances.find(currency::null_hash); + it_native = balances.find(currency::native_coin_asset_id); CHECK_AND_ASSERT_MES(it_asset != balances.end(), false, "Failed to find needed asset in result balances"); CHECK_AND_ASSERT_MES(it_native == balances.end(), false, "Failed to find needed asset in result balances"); diff --git a/tests/performance_tests/is_out_to_acc.h b/tests/performance_tests/is_out_to_acc.h index 60e7fd33..5a2a9e11 100644 --- a/tests/performance_tests/is_out_to_acc.h +++ b/tests/performance_tests/is_out_to_acc.h @@ -18,6 +18,9 @@ public: bool test() { const currency::txout_to_key& tx_out = boost::get(boost::get(m_tx.vout[0]).target); - return currency::is_out_to_acc(m_bob.get_keys(), tx_out, m_tx_pub_key, 0); + + crypto::key_derivation derivation; + generate_key_derivation(m_tx_pub_key, m_bob.get_keys().view_secret_key, derivation); + return currency::is_out_to_acc(m_bob.get_public_address(), tx_out, derivation, 0); } }; diff --git a/tests/unit_tests/basic_struct_packing.cpp b/tests/unit_tests/basic_struct_packing.cpp index 7d75ff8d..41b16705 100644 --- a/tests/unit_tests/basic_struct_packing.cpp +++ b/tests/unit_tests/basic_struct_packing.cpp @@ -113,6 +113,9 @@ TEST(tx_signatures_packing, 1) ASSERT_EQ(82178, get_object_blobsize(sigs)); } + // the following tests cases should be redone + // TODO @#@# + { // empty ZC_sig // v(1) + (1 + 32 + 32 + (1 + 10*32) + 32) = 99 @@ -136,7 +139,7 @@ TEST(tx_signatures_packing, 1) // 128 10-ring ZC_sigs // v(128) + 128 * (1 + 32 + 32 + (v(10) + 10*32) + 32) = 53506 (97 + (v(10) + 10*32)) ZC_sig zc = AUTO_VAL_INIT(zc); - zc.clsags_gg.r.resize(10); + //zc.clsags_gg.r.resize(10); sigs.clear(); for(size_t i = 0; i < 128; ++i) sigs.emplace_back(zc);