1
0
Fork 0
forked from lthn/blockchain

fixes against recent changes over tx_source_entry::output_entry

This commit is contained in:
cryptozoidberg 2022-07-13 17:17:04 +02:00
parent 6b4bfee7d9
commit be5766f266
No known key found for this signature in database
GPG key ID: 22DEB97A54C6FDEC
8 changed files with 56 additions and 44 deletions

View file

@ -1676,7 +1676,6 @@ namespace currency
NLSAG_sources.push_back(&src_entr);
}
}
}
if (ins_zc.elements.size())

View file

@ -27,6 +27,13 @@ namespace currency
crypto::public_key stealth_address; // a.k.a output's one-time public key
crypto::public_key concealing_point; // only for zarcaum outputs
crypto::public_key amount_commitment; // only for zarcaum outputs
BEGIN_SERIALIZE_OBJECT()
FIELD(out_reference)
FIELD(stealth_address)
FIELD(concealing_point)
FIELD(amount_commitment)
END_SERIALIZE()
};
//typedef serializable_pair<txout_ref_v, crypto::public_key> output_entry; // txout_ref_v is either global output index or ref_by_id; public_key - is output's stealth address

View file

@ -3263,7 +3263,7 @@ void wallet2::submit_transfer(const std::string& signed_tx_blob, currency::trans
const auto& src = ft.ftp.sources[i];
THROW_IF_FALSE_WALLET_INT_ERR_EX(src.real_output < src.outputs.size(), "src.real_output is out of bounds: " << src.real_output);
const crypto::public_key& out_key = src.outputs[src.real_output].second;
const crypto::public_key& out_key = src.outputs[src.real_output].stealth_address;
tri_ki_to_be_added.push_back(std::make_pair(src.transfer_index, ki));
pk_ki_to_be_added.push_back(std::make_pair(out_key, ki));
@ -4654,9 +4654,9 @@ bool wallet2::prepare_tx_sources(size_t fake_outputs_count, std::vector<currency
{
if (td.m_global_output_index == daemon_oe.global_amount_index)
continue;
tx_output_entry oe;
oe.first = daemon_oe.global_amount_index;
oe.second = daemon_oe.out_key;
tx_output_entry oe = AUTO_VAL_INIT(oe);
oe.out_reference = daemon_oe.global_amount_index;
oe.stealth_address = daemon_oe.out_key;
src.outputs.push_back(oe);
if (src.outputs.size() >= fake_outputs_count)
break;
@ -4666,22 +4666,22 @@ bool wallet2::prepare_tx_sources(size_t fake_outputs_count, std::vector<currency
//paste real transaction to the random index
auto it_to_insert = std::find_if(src.outputs.begin(), src.outputs.end(), [&](const tx_output_entry& a)
{
if (a.first.type().hash_code() == typeid(uint64_t).hash_code())
return boost::get<uint64_t>(a.first) >= td.m_global_output_index;
if (a.out_reference.type().hash_code() == typeid(uint64_t).hash_code())
return static_cast<bool>(boost::get<uint64_t>(a.out_reference) >= td.m_global_output_index);
return false; // TODO: implement deterministics real output placement in case there're ref_by_id outs
});
//size_t real_index = src.outputs.size() ? (rand() % src.outputs.size() ):0;
tx_output_entry real_oe;
real_oe.first = td.m_global_output_index; // TODO: use ref_by_id when neccessary
tx_output_entry real_oe = AUTO_VAL_INIT(real_oe);
real_oe.out_reference = td.m_global_output_index; // TODO: use ref_by_id when neccessary
//@#@
VARIANT_SWITCH_BEGIN(td.m_ptx_wallet_info->m_tx.vout[td.m_internal_output_index]);
VARIANT_CASE_CONST(tx_out_bare, o)
{
VARIANT_SWITCH_BEGIN(o.target);
VARIANT_CASE_CONST(txout_to_key, o)
real_oe.second = o.key;
real_oe.stealth_address = o.key;
VARIANT_CASE_CONST(txout_htlc, htlc)
real_oe.second = htlc.pkey_refund;
real_oe.stealth_address = htlc.pkey_refund;
VARIANT_CASE_OTHER()
{
WLT_THROW_IF_FALSE_WITH_CODE(false,
@ -4774,8 +4774,8 @@ bool wallet2::prepare_tx_sources_htlc(crypto::hash htlc_tx_id, const std::string
sources.push_back(AUTO_VAL_INIT(currency::tx_source_entry()));
currency::tx_source_entry& src = sources.back();
tx_output_entry real_oe = AUTO_VAL_INIT(real_oe);
real_oe.first = td.m_global_output_index; // TODO: use ref_by_id when necessary
real_oe.second = htlc_out.pkey_redeem;
real_oe.out_reference = td.m_global_output_index; // TODO: use ref_by_id when necessary
real_oe.stealth_address = htlc_out.pkey_redeem;
src.outputs.push_back(real_oe); //m_global_output_index should be prefetched
src.amount = found_money = td.amount();
src.real_output_in_tx_index = td.m_internal_output_index;
@ -5380,7 +5380,7 @@ uint64_t wallet2::get_tx_expiration_median() const
void wallet2::print_source_entry(const currency::tx_source_entry& src) const
{
std::ostringstream indexes;
std::for_each(src.outputs.begin(), src.outputs.end(), [&](const currency::tx_source_entry::output_entry& s_e) { indexes << s_e.first << " "; });
std::for_each(src.outputs.begin(), src.outputs.end(), [&](const currency::tx_source_entry::output_entry& s_e) { indexes << s_e.out_reference << " "; });
WLT_LOG_L0("amount=" << currency::print_money(src.amount) << ", real_output=" << src.real_output << ", real_output_in_tx_index=" << src.real_output_in_tx_index << ", indexes: " << indexes.str());
}
//----------------------------------------------------------------------------------------------------
@ -5860,8 +5860,8 @@ void wallet2::sweep_below(size_t fake_outs_count, const currency::account_public
if (td.m_global_output_index == daemon_oe.global_amount_index)
continue;
tx_output_entry oe;
oe.first = daemon_oe.global_amount_index;
oe.second = daemon_oe.out_key;
oe.out_reference = daemon_oe.global_amount_index;
oe.stealth_address = daemon_oe.out_key;
src.outputs.push_back(oe);
if (src.outputs.size() >= fake_outs_count)
break;
@ -5871,17 +5871,17 @@ void wallet2::sweep_below(size_t fake_outs_count, const currency::account_public
// insert real output into src.outputs
auto it_to_insert = std::find_if(src.outputs.begin(), src.outputs.end(), [&](const tx_output_entry& a)
{
if (a.first.type().hash_code() == typeid(uint64_t).hash_code())
return boost::get<uint64_t>(a.first) >= td.m_global_output_index;
if (a.out_reference.type().hash_code() == typeid(uint64_t).hash_code())
return static_cast<bool>(boost::get<uint64_t>(a.out_reference) >= td.m_global_output_index);
return false; // TODO: implement deterministics real output placement in case there're ref_by_id outs
});
tx_output_entry real_oe;
real_oe.first = td.m_global_output_index;
tx_output_entry real_oe = AUTO_VAL_INIT(real_oe);
real_oe.out_reference = td.m_global_output_index;
//@#@
if(td.m_ptx_wallet_info->m_tx.vout[td.m_internal_output_index].type() != typeid(tx_out_bare))
continue;
const tx_out_bare& out_b = boost::get<tx_out_bare>(td.m_ptx_wallet_info->m_tx.vout[td.m_internal_output_index]);
real_oe.second = boost::get<txout_to_key>(out_b.target).key;
real_oe.stealth_address = boost::get<txout_to_key>(out_b.target).key;
auto inserted_it = src.outputs.insert(it_to_insert, real_oe);
src.real_out_tx_key = get_tx_pub_key_from_extra(td.m_ptx_wallet_info->m_tx);
src.real_output = inserted_it - src.outputs.begin();

View file

@ -312,7 +312,10 @@ bool gen_block_miner_tx_has_2_in::generate(std::vector<test_event_entry>& events
tx_source_entry se = AUTO_VAL_INIT(se);
se.amount = boost::get<currency::tx_out_bare>(blk_0.miner_tx.vout[0]).amount;
se.outputs.push_back(make_serializable_pair<txout_ref_v, crypto::public_key>(0, boost::get<txout_to_key>(boost::get<currency::tx_out_bare>(blk_0.miner_tx.vout[0]).target).key));
currency::tx_source_entry::output_entry oe = AUTO_VAL_INIT(oe);
oe.out_reference = 0;
oe.stealth_address = boost::get<txout_to_key>(boost::get<currency::tx_out_bare>(blk_0.miner_tx.vout[0]).target).key;
se.outputs.push_back(oe);
se.real_output = 0;
se.real_out_tx_key = get_tx_pub_key_from_extra(blk_0.miner_tx);
se.real_output_in_tx_index = 0;
@ -357,7 +360,10 @@ bool gen_block_miner_tx_with_txin_to_key::generate(std::vector<test_event_entry>
tx_source_entry se = AUTO_VAL_INIT(se);
se.amount = boost::get<currency::tx_out_bare>(blk_1.miner_tx.vout[0]).amount;
se.outputs.push_back(make_serializable_pair<txout_ref_v, crypto::public_key>(0, boost::get<txout_to_key>(boost::get<currency::tx_out_bare>(blk_1.miner_tx.vout[0]).target).key));
currency::tx_source_entry::output_entry oe = AUTO_VAL_INIT(oe);
oe.out_reference = 0;
oe.stealth_address = boost::get<txout_to_key>(boost::get<currency::tx_out_bare>(blk_1.miner_tx.vout[0]).target).key;
se.outputs.push_back(oe);
se.real_output = 0;
se.real_out_tx_key = get_tx_pub_key_from_extra(blk_1.miner_tx);
se.real_output_in_tx_index = 0;

View file

@ -779,11 +779,11 @@ bool construct_broken_tx(const currency::account_keys& sender_account_keys, cons
return false;
//check that derivated key is equal with real output key
if (!(in_ephemeral.pub == src_entr.outputs[src_entr.real_output].second))
if (!(in_ephemeral.pub == src_entr.outputs[src_entr.real_output].stealth_address))
{
LOG_ERROR("derived public key missmatch with output public key! " << ENDL << "derived_key:"
<< epst::pod_to_hex(in_ephemeral.pub) << ENDL << "real output_public_key:"
<< epst::pod_to_hex(src_entr.outputs[src_entr.real_output].second));
<< epst::pod_to_hex(src_entr.outputs[src_entr.real_output].stealth_address));
return false;
}
@ -794,7 +794,7 @@ bool construct_broken_tx(const currency::account_keys& sender_account_keys, cons
//fill outputs array and use relative offsets
BOOST_FOREACH(const currency::tx_source_entry::output_entry& out_entry, src_entr.outputs)
input_to_key.key_offsets.push_back(out_entry.first);
input_to_key.key_offsets.push_back(out_entry.out_reference);
input_to_key.key_offsets = currency::absolute_output_offsets_to_relative(input_to_key.key_offsets);
tx.vin.push_back(input_to_key);
@ -842,8 +842,8 @@ bool construct_broken_tx(const currency::account_keys& sender_account_keys, cons
std::vector<const crypto::public_key*> keys_ptrs;
BOOST_FOREACH(const currency::tx_source_entry::output_entry& o, src_entr.outputs)
{
keys_ptrs.push_back(&o.second);
ss_ring_s << o.second << ENDL;
keys_ptrs.push_back(&o.stealth_address);
ss_ring_s << o.stealth_address << ENDL;
}
tx.signatures.push_back(currency::NLSAG_sig());

View file

@ -60,28 +60,28 @@ bool test_transaction_generation_and_ring_signature()
src.amount = 70368744177663;
{
tx_output_entry oe;
oe.first = 0;
oe.second = boost::get<txout_to_key>(boost::get<currency::tx_out_bare>(tx_mine_1.vout[0]).target).key;
oe.out_reference = 0;
oe.stealth_address = boost::get<txout_to_key>(boost::get<currency::tx_out_bare>(tx_mine_1.vout[0]).target).key;
src.outputs.push_back(oe);
oe.first = 1;
oe.second = boost::get<txout_to_key>(boost::get<currency::tx_out_bare>(tx_mine_2.vout[0]).target).key;
oe.out_reference = 1;
oe.stealth_address = boost::get<txout_to_key>(boost::get<currency::tx_out_bare>(tx_mine_2.vout[0]).target).key;
src.outputs.push_back(oe);
oe.first = 2;
oe.second = boost::get<txout_to_key>(boost::get<currency::tx_out_bare>(tx_mine_3.vout[0]).target).key;
oe.out_reference = 2;
oe.stealth_address = boost::get<txout_to_key>(boost::get<currency::tx_out_bare>(tx_mine_3.vout[0]).target).key;
src.outputs.push_back(oe);
oe.first = 3;
oe.second = boost::get<txout_to_key>(boost::get<currency::tx_out_bare>(tx_mine_4.vout[0]).target).key;
oe.out_reference = 3;
oe.stealth_address = boost::get<txout_to_key>(boost::get<currency::tx_out_bare>(tx_mine_4.vout[0]).target).key;
src.outputs.push_back(oe);
oe.first = 4;
oe.second = boost::get<txout_to_key>(boost::get<currency::tx_out_bare>(tx_mine_5.vout[0]).target).key;
oe.out_reference = 4;
oe.stealth_address = boost::get<txout_to_key>(boost::get<currency::tx_out_bare>(tx_mine_5.vout[0]).target).key;
src.outputs.push_back(oe);
oe.first = 5;
oe.second = boost::get<txout_to_key>(boost::get<currency::tx_out_bare>(tx_mine_6.vout[0]).target).key;
oe.out_reference = 5;
oe.stealth_address = boost::get<txout_to_key>(boost::get<currency::tx_out_bare>(tx_mine_6.vout[0]).target).key;
src.outputs.push_back(oe);
crypto::public_key tx_pub_key = null_pkey;

View file

@ -35,7 +35,7 @@ struct tx_builder
// fill outputs array and use relative offsets
for(const currency::tx_source_entry::output_entry& out_entry : src_entr.outputs)
input_to_key.key_offsets.push_back(out_entry.first);
input_to_key.key_offsets.push_back(out_entry.out_reference);
input_to_key.key_offsets = currency::absolute_output_offsets_to_relative(input_to_key.key_offsets);
m_tx.vin.push_back(input_to_key);
@ -106,7 +106,7 @@ struct tx_builder
std::vector<const crypto::public_key*> keys_ptrs;
for(const currency::tx_source_entry::output_entry& o : src_entr.outputs)
{
keys_ptrs.push_back(&o.second);
keys_ptrs.push_back(&o.stealth_address);
}
m_tx.signatures.push_back(currency::NLSAG_sig());

View file

@ -273,7 +273,7 @@ bool gen_tx_key_offest_points_to_foreign_key::generate(std::vector<test_event_en
builder.step1_init();
builder.step2_fill_inputs(bob_account.get_keys(), sources_bob);
txin_to_key& in_to_key = boost::get<txin_to_key>(builder.m_tx.vin.front());
in_to_key.key_offsets.front() = sources_alice.front().outputs.front().first;
in_to_key.key_offsets.front() = sources_alice.front().outputs.front().out_reference;
builder.step3_fill_outputs(destinations_bob);
builder.step4_calc_hash();
builder.step5_sign(sources_bob);
@ -329,7 +329,7 @@ bool gen_tx_mixed_key_offest_not_exist::generate(std::vector<test_event_entry>&
std::vector<tx_destination_entry> destinations;
fill_tx_sources_and_destinations(events, blk_2, bob_account, miner_account, MK_TEST_COINS(1), TESTS_DEFAULT_FEE, 1, sources, destinations);
sources.front().outputs[(sources.front().real_output + 1) % 2].first = std::numeric_limits<uint64_t>::max();
sources.front().outputs[(sources.front().real_output + 1) % 2].out_reference = std::numeric_limits<uint64_t>::max();
tx_builder builder;
builder.step1_init();