confidential assets: global refactoring WIP (now everything is in compilable state, including tests)

This commit is contained in:
sowle 2023-02-13 21:42:31 +01:00
parent 7652a117cd
commit a813484a4f
No known key found for this signature in database
GPG key ID: C07A24B2D89D49FC
9 changed files with 55 additions and 38 deletions

View file

@ -182,7 +182,7 @@ namespace crypto
}
bool verify_CLSAG_GGX(const hash& m, const std::vector<CLSAG_GGX_input_ref_t>& 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;
}

View file

@ -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<const crypto::public_key&>(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<wallet_out_info>& 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++;
}

View file

@ -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<wallet_out_info>& 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<wallet_out_info>& outs, uint64_t& money_transfered, crypto::key_derivation& derivation, std::list<htlc_info>& htlc_info_list);
bool lookup_acc_outs(const account_keys& acc, const transaction& tx, std::vector<wallet_out_info>& outs, uint64_t& money_transfered, crypto::key_derivation& derivation);

View file

@ -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))

View file

@ -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);

View file

@ -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<tx_out_zarcanum>(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<output_index>& 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<currency::tx_source_entry>& 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))

View file

@ -73,17 +73,17 @@ bool multiassets_basic_test::c1(currency::core& c, size_t ev_index, const std::v
std::vector<currency::tx_destination_entry> 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<crypto::hash, tools::wallet_public::asset_balance_entry_base> balances;
std::unordered_map<crypto::public_key, tools::wallet_public::asset_balance_entry_base> 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");

View file

@ -18,6 +18,9 @@ public:
bool test()
{
const currency::txout_to_key& tx_out = boost::get<currency::txout_to_key>(boost::get<currency::tx_out_bare>(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);
}
};

View file

@ -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);