forked from lthn/blockchain
1) outputs_generation_context is now part of finalize_tx_params; 2) outputs_generation_context -> tx_generation_context
This commit is contained in:
parent
f1815da106
commit
a9ac0a24eb
14 changed files with 124 additions and 90 deletions
|
|
@ -1432,7 +1432,7 @@ bool blockchain_storage::create_block_template(const account_public_address& min
|
|||
block& b,
|
||||
wide_difficulty_type& diffic,
|
||||
uint64_t& height,
|
||||
outputs_generation_context* miner_tx_ogc_ptr /* = nullptr */) const
|
||||
tx_generation_context* miner_tx_tgc_ptr /* = nullptr */) const
|
||||
{
|
||||
create_block_template_params params = AUTO_VAL_INIT(params);
|
||||
params.miner_address = miner_address;
|
||||
|
|
@ -1447,8 +1447,8 @@ bool blockchain_storage::create_block_template(const account_public_address& min
|
|||
b = resp.b;
|
||||
diffic = resp.diffic;
|
||||
height = resp.height;
|
||||
if (miner_tx_ogc_ptr)
|
||||
*miner_tx_ogc_ptr = resp.miner_tx_ogc;
|
||||
if (miner_tx_tgc_ptr)
|
||||
*miner_tx_tgc_ptr = resp.miner_tx_tgc;
|
||||
return r;
|
||||
}
|
||||
|
||||
|
|
@ -1533,7 +1533,7 @@ bool blockchain_storage::create_block_template(const create_block_template_param
|
|||
CURRENCY_MINER_TX_MAX_OUTS,
|
||||
pos,
|
||||
pe,
|
||||
&resp.miner_tx_ogc);
|
||||
&resp.miner_tx_tgc);
|
||||
CHECK_AND_ASSERT_MES(r, false, "Failed to construc miner tx, first chance");
|
||||
uint64_t coinbase_size = get_object_blobsize(b.miner_tx);
|
||||
// "- 100" - to reserve room for PoS additions into miner tx
|
||||
|
|
|
|||
|
|
@ -261,7 +261,7 @@ namespace currency
|
|||
|
||||
|
||||
bool create_block_template(const account_public_address& miner_address, const blobdata& ex_nonce, block& b, wide_difficulty_type& di, uint64_t& height) const;
|
||||
bool create_block_template(const account_public_address& miner_address, const account_public_address& stakeholder_address, const blobdata& ex_nonce, bool pos, const pos_entry& pe, fill_block_template_func_t custom_fill_block_template_func, block& b, wide_difficulty_type& di, uint64_t& height, outputs_generation_context* miner_tx_ogc_ptr = nullptr) const;
|
||||
bool create_block_template(const account_public_address& miner_address, const account_public_address& stakeholder_address, const blobdata& ex_nonce, bool pos, const pos_entry& pe, fill_block_template_func_t custom_fill_block_template_func, block& b, wide_difficulty_type& di, uint64_t& height, tx_generation_context* miner_tx_tgc_ptr = nullptr) const;
|
||||
bool create_block_template(const create_block_template_params& params, create_block_template_response& resp) const;
|
||||
|
||||
bool have_block(const crypto::hash& id) const;
|
||||
|
|
|
|||
|
|
@ -146,7 +146,7 @@ namespace currency
|
|||
block b;
|
||||
wide_difficulty_type diffic;
|
||||
uint64_t height;
|
||||
outputs_generation_context miner_tx_ogc; // bad design, a lot of copying, consider redesign -- sowle
|
||||
tx_generation_context miner_tx_tgc; // bad design, a lot of copying, consider redesign -- sowle
|
||||
};
|
||||
|
||||
typedef std::unordered_map<crypto::hash, transaction> transactions_map;
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ namespace currency
|
|||
return true;
|
||||
}
|
||||
//--------------------------------------------------------------------------------
|
||||
bool generate_asset_surjection_proof(const crypto::hash& context_hash, bool has_non_zc_inputs, outputs_generation_context& ogc, zc_asset_surjection_proof& result)
|
||||
bool generate_asset_surjection_proof(const crypto::hash& context_hash, bool has_non_zc_inputs, tx_generation_context& ogc, zc_asset_surjection_proof& result)
|
||||
{
|
||||
bool r = false;
|
||||
size_t outs_count = ogc.blinded_asset_ids.size();
|
||||
|
|
@ -196,11 +196,11 @@ namespace currency
|
|||
return true;
|
||||
}
|
||||
//--------------------------------------------------------------------------------
|
||||
bool generate_zc_outs_range_proof(const crypto::hash& context_hash, size_t out_index_start, const outputs_generation_context& outs_gen_context,
|
||||
bool generate_zc_outs_range_proof(const crypto::hash& context_hash, size_t out_index_start, const tx_generation_context& outs_gen_context,
|
||||
const std::vector<tx_out_v>& vouts, zc_outs_range_proof& result)
|
||||
{
|
||||
size_t outs_count = outs_gen_context.amounts.size();
|
||||
// TODO @#@# reconsider this check CHECK_AND_ASSERT_MES(outs_gen_context.check_sizes(outs_count), false, "");
|
||||
// TODO @#@# reconsider this check CHECK_AND_ASSERT_MES(gen_context.check_sizes(outs_count), false, "");
|
||||
CHECK_AND_ASSERT_MES(out_index_start + outs_count == vouts.size(), false, "");
|
||||
|
||||
// prepare data for aggregation proof
|
||||
|
|
@ -260,7 +260,7 @@ namespace currency
|
|||
return diff;
|
||||
}
|
||||
//------------------------------------------------------------------
|
||||
bool generate_tx_balance_proof(const transaction &tx, const crypto::hash& tx_id, const outputs_generation_context& ogc, uint64_t block_reward_for_miner_tx, currency::zc_balance_proof& proof)
|
||||
bool generate_tx_balance_proof(const transaction &tx, const crypto::hash& tx_id, const tx_generation_context& ogc, uint64_t block_reward_for_miner_tx, currency::zc_balance_proof& proof)
|
||||
{
|
||||
CHECK_AND_ASSERT_MES(tx.version > TRANSACTION_VERSION_PRE_HF4, false, "unsupported tx.version: " << tx.version);
|
||||
CHECK_AND_ASSERT_MES(count_type_in_variant_container<zc_balance_proof>(tx.proofs) == 0, false, "zc_balance_proof is already present");
|
||||
|
|
@ -362,7 +362,7 @@ namespace currency
|
|||
size_t max_outs /* = CURRENCY_MINER_TX_MAX_OUTS */,
|
||||
bool pos /* = false */,
|
||||
const pos_entry& pe /* = pos_entry() */, // only pe.stake_unlock_time and pe.stake_amount are used now, TODO: consider refactoring -- sowle
|
||||
outputs_generation_context* ogc_ptr /* = nullptr */,
|
||||
tx_generation_context* ogc_ptr /* = nullptr */,
|
||||
const keypair* tx_one_time_key_to_use /* = nullptr */
|
||||
)
|
||||
{
|
||||
|
|
@ -469,7 +469,8 @@ namespace currency
|
|||
}
|
||||
|
||||
// fill outputs
|
||||
outputs_generation_context outs_gen_context(zc_ins_count, destinations.size()); // auxiliary data for each output
|
||||
tx_generation_context tx_gen_context{};
|
||||
tx_gen_context.resize(zc_ins_count, destinations.size()); // auxiliary data for each output
|
||||
uint64_t output_index = 0;
|
||||
for (auto& d : destinations)
|
||||
{
|
||||
|
|
@ -477,14 +478,14 @@ namespace currency
|
|||
finalized_tx result = AUTO_VAL_INIT(result);
|
||||
uint8_t tx_outs_attr = 0;
|
||||
r = construct_tx_out(d, txkey.sec, output_index, tx, deriv_cache, account_keys(),
|
||||
outs_gen_context.asset_id_blinding_masks[output_index], outs_gen_context.amount_blinding_masks[output_index],
|
||||
outs_gen_context.blinded_asset_ids[output_index], outs_gen_context.amount_commitments[output_index], result, tx_outs_attr);
|
||||
tx_gen_context.asset_id_blinding_masks[output_index], tx_gen_context.amount_blinding_masks[output_index],
|
||||
tx_gen_context.blinded_asset_ids[output_index], tx_gen_context.amount_commitments[output_index], result, tx_outs_attr);
|
||||
CHECK_AND_ASSERT_MES(r, false, "construct_tx_out failed, output #" << output_index << ", amount: " << print_money_brief(d.amount));
|
||||
outs_gen_context.amounts[output_index] = d.amount;
|
||||
outs_gen_context.asset_ids[output_index] = crypto::point_t(d.asset_id);
|
||||
outs_gen_context.asset_id_blinding_mask_x_amount_sum += outs_gen_context.asset_id_blinding_masks[output_index] * d.amount;
|
||||
outs_gen_context.amount_blinding_masks_sum += outs_gen_context.amount_blinding_masks[output_index];
|
||||
outs_gen_context.amount_commitments_sum += outs_gen_context.amount_commitments[output_index];
|
||||
tx_gen_context.amounts[output_index] = d.amount;
|
||||
tx_gen_context.asset_ids[output_index] = crypto::point_t(d.asset_id);
|
||||
tx_gen_context.asset_id_blinding_mask_x_amount_sum += tx_gen_context.asset_id_blinding_masks[output_index] * d.amount;
|
||||
tx_gen_context.amount_blinding_masks_sum += tx_gen_context.amount_blinding_masks[output_index];
|
||||
tx_gen_context.amount_commitments_sum += tx_gen_context.amount_commitments[output_index];
|
||||
++output_index;
|
||||
}
|
||||
|
||||
|
|
@ -498,7 +499,7 @@ namespace currency
|
|||
}
|
||||
|
||||
if (ogc_ptr)
|
||||
*ogc_ptr = outs_gen_context; // TODO @#@# consider refactoring (a lot of copying) -- sowle
|
||||
*ogc_ptr = tx_gen_context; // TODO @#@# consider refactoring (a lot of copying) -- sowle
|
||||
|
||||
|
||||
if (tx.version > TRANSACTION_VERSION_PRE_HF4 && !pos)
|
||||
|
|
@ -510,19 +511,19 @@ namespace currency
|
|||
|
||||
// asset surjection proof
|
||||
currency::zc_asset_surjection_proof asp{};
|
||||
bool r = generate_asset_surjection_proof(tx_id, true, outs_gen_context, asp);
|
||||
bool r = generate_asset_surjection_proof(tx_id, true, tx_gen_context, asp);
|
||||
CHECK_AND_ASSERT_MES(r, false, "generete_asset_surjection_proof failed");
|
||||
tx.proofs.emplace_back(std::move(asp));
|
||||
|
||||
// range proofs
|
||||
currency::zc_outs_range_proof range_proofs{};
|
||||
r = generate_zc_outs_range_proof(tx_id, 0, outs_gen_context, tx.vout, range_proofs);
|
||||
r = generate_zc_outs_range_proof(tx_id, 0, tx_gen_context, tx.vout, range_proofs);
|
||||
CHECK_AND_ASSERT_MES(r, false, "Failed to generate zc_outs_range_proof()");
|
||||
tx.proofs.emplace_back(std::move(range_proofs));
|
||||
|
||||
// balance proof
|
||||
currency::zc_balance_proof balance_proof{};
|
||||
r = generate_tx_balance_proof(tx, tx_id, outs_gen_context, block_reward, balance_proof);
|
||||
r = generate_tx_balance_proof(tx, tx_id, tx_gen_context, block_reward, balance_proof);
|
||||
CHECK_AND_ASSERT_MES(r, false, "generate_tx_balance_proof failed");
|
||||
tx.proofs.emplace_back(std::move(balance_proof));
|
||||
}
|
||||
|
|
@ -1842,7 +1843,7 @@ namespace currency
|
|||
};
|
||||
//--------------------------------------------------------------------------------
|
||||
bool generate_ZC_sig(const crypto::hash& tx_hash_for_signature, size_t input_index, const tx_source_entry& se, const input_generation_context_data& in_context,
|
||||
const account_keys& sender_account_keys, const uint64_t tx_flags, outputs_generation_context& ogc, transaction& tx, bool last_output)
|
||||
const account_keys& sender_account_keys, const uint64_t tx_flags, tx_generation_context& ogc, transaction& tx, bool last_output)
|
||||
{
|
||||
bool watch_only_mode = sender_account_keys.spend_secret_key == null_skey;
|
||||
CHECK_AND_ASSERT_MES(se.is_zc(), false, "sources contains a non-zc input");
|
||||
|
|
@ -2209,7 +2210,8 @@ namespace currency
|
|||
//
|
||||
std::vector<tx_destination_entry> shuffled_dsts(destinations);
|
||||
size_t outputs_to_be_constructed = shuffled_dsts.size();
|
||||
outputs_generation_context outs_gen_context(zc_inputs_count, outputs_to_be_constructed); // auxiliary data for each output
|
||||
tx_generation_context& gen_context = result.ftp.gen_context;
|
||||
gen_context.resize(zc_inputs_count, outputs_to_be_constructed);
|
||||
|
||||
// ASSET oprations handling
|
||||
if (tx.version > TRANSACTION_VERSION_PRE_HF4)
|
||||
|
|
@ -2224,10 +2226,10 @@ namespace currency
|
|||
bool r = derive_key_pair_from_key_pair(sender_account_keys.account_address.spend_public_key, one_time_tx_secret_key, asset_control_key, pado->descriptor.owner, CRYPTO_HDS_ASSET_CONTROL_KEY);
|
||||
CHECK_AND_ASSERT_MES(r, false, "derive_key_pair_from_key_pair failed");
|
||||
|
||||
calculate_asset_id(pado->descriptor.owner, &outs_gen_context.ao_asset_id_pt, &outs_gen_context.ao_asset_id);
|
||||
calculate_asset_id(pado->descriptor.owner, &gen_context.ao_asset_id_pt, &gen_context.ao_asset_id);
|
||||
|
||||
// calculate amount blinding mask
|
||||
outs_gen_context.ao_amount_blinding_mask = crypto::hash_helper_t::hs(CRYPTO_HDS_ASSET_CONTROL_ABM, asset_control_key);
|
||||
gen_context.ao_amount_blinding_mask = crypto::hash_helper_t::hs(CRYPTO_HDS_ASSET_CONTROL_ABM, asset_control_key);
|
||||
|
||||
// set correct asset_id to the corresponding destination entries
|
||||
uint64_t amount_of_emitted_asset = 0;
|
||||
|
|
@ -2235,16 +2237,16 @@ namespace currency
|
|||
{
|
||||
if (item.asset_id == currency::ffff_pkey)
|
||||
{
|
||||
item.asset_id = outs_gen_context.ao_asset_id; // set calculated asset_id to the asset's outputs, if this asset is being emitted within this tx
|
||||
item.asset_id = gen_context.ao_asset_id; // set calculated asset_id to the asset's outputs, if this asset is being emitted within this tx
|
||||
amount_of_emitted_asset += item.amount;
|
||||
}
|
||||
}
|
||||
pado->descriptor.current_supply = amount_of_emitted_asset; // TODO: consider setting current_supply beforehand, not setting it hear in ad-hoc manner -- sowle
|
||||
|
||||
outs_gen_context.ao_amount_commitment = amount_of_emitted_asset * outs_gen_context.ao_asset_id_pt + outs_gen_context.ao_amount_blinding_mask * crypto::c_point_G;
|
||||
pado->opt_amount_commitment = (crypto::c_scalar_1div8 * outs_gen_context.ao_amount_commitment).to_public_key();
|
||||
//LOG_PRINT_CYAN("AO " << ": " << crypto::scalar_t(amount_of_emitted_asset) << " x " << outs_gen_context.ao_asset_id_pt << " + " << outs_gen_context.ao_amount_blinding_mask << " x G", LOG_LEVEL_0);
|
||||
//LOG_PRINT_CYAN(" == " << outs_gen_context.ao_amount_commitment << ", x 1/8 == " << pado->opt_amount_commitment.get(), LOG_LEVEL_0);
|
||||
gen_context.ao_amount_commitment = amount_of_emitted_asset * gen_context.ao_asset_id_pt + gen_context.ao_amount_blinding_mask * crypto::c_point_G;
|
||||
pado->opt_amount_commitment = (crypto::c_scalar_1div8 * gen_context.ao_amount_commitment).to_public_key();
|
||||
//LOG_PRINT_CYAN("AO " << ": " << crypto::scalar_t(amount_of_emitted_asset) << " x " << gen_context.ao_asset_id_pt << " + " << gen_context.ao_amount_blinding_mask << " x G", LOG_LEVEL_0);
|
||||
//LOG_PRINT_CYAN(" == " << gen_context.ao_amount_commitment << ", x 1/8 == " << pado->opt_amount_commitment.get(), LOG_LEVEL_0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2262,19 +2264,19 @@ namespace currency
|
|||
for(size_t j = 0; j < outputs_to_be_constructed; ++j, ++output_index)
|
||||
{
|
||||
tx_destination_entry& dst_entr = shuffled_dsts[j];
|
||||
if (all_inputs_are_obviously_native_coins && outs_gen_context.ao_asset_id == currency::null_pkey)
|
||||
if (all_inputs_are_obviously_native_coins && gen_context.ao_asset_id == currency::null_pkey)
|
||||
dst_entr.explicit_native_asset_id = true; // all inputs are obviously native coins -- all outputs must have explicit asset ids (unless there's an asset emission)
|
||||
|
||||
CHECK_AND_ASSERT_MES(dst_entr.amount > 0, false, "Destination with wrong amount: " << dst_entr.amount); // <<-- TODO @#@# consider removing this check
|
||||
r = construct_tx_out(dst_entr, txkey.sec, output_index, tx, deriv_cache, sender_account_keys,
|
||||
outs_gen_context.asset_id_blinding_masks[j], outs_gen_context.amount_blinding_masks[j],
|
||||
outs_gen_context.blinded_asset_ids[j], outs_gen_context.amount_commitments[j], result, tx_outs_attr);
|
||||
gen_context.asset_id_blinding_masks[j], gen_context.amount_blinding_masks[j],
|
||||
gen_context.blinded_asset_ids[j], gen_context.amount_commitments[j], result, tx_outs_attr);
|
||||
CHECK_AND_ASSERT_MES(r, false, "Failed to construct tx out");
|
||||
outs_gen_context.amounts[j] = dst_entr.amount;
|
||||
outs_gen_context.asset_ids[j] = crypto::point_t(dst_entr.asset_id);
|
||||
outs_gen_context.asset_id_blinding_mask_x_amount_sum += outs_gen_context.asset_id_blinding_masks[j] * dst_entr.amount;
|
||||
outs_gen_context.amount_blinding_masks_sum += outs_gen_context.amount_blinding_masks[j];
|
||||
outs_gen_context.amount_commitments_sum += outs_gen_context.amount_commitments[j];
|
||||
gen_context.amounts[j] = dst_entr.amount;
|
||||
gen_context.asset_ids[j] = crypto::point_t(dst_entr.asset_id);
|
||||
gen_context.asset_id_blinding_mask_x_amount_sum += gen_context.asset_id_blinding_masks[j] * dst_entr.amount;
|
||||
gen_context.amount_blinding_masks_sum += gen_context.amount_blinding_masks[j];
|
||||
gen_context.amount_commitments_sum += gen_context.amount_commitments[j];
|
||||
if (dst_entr.is_native_coin())
|
||||
native_coins_output_sum += dst_entr.amount;
|
||||
}
|
||||
|
|
@ -2359,7 +2361,7 @@ namespace currency
|
|||
{
|
||||
// ZC
|
||||
// blinding_masks_sum is supposed to be sum(mask of all tx output) - sum(masks of all pseudo out commitments)
|
||||
r = generate_ZC_sig(tx_hash_for_signature, i_ + input_starter_index, source_entry, in_contexts[i_mapped], sender_account_keys, flags, outs_gen_context, tx, i_ + 1 == sources.size());
|
||||
r = generate_ZC_sig(tx_hash_for_signature, i_ + input_starter_index, source_entry, in_contexts[i_mapped], sender_account_keys, flags, gen_context, tx, i_ + 1 == sources.size());
|
||||
CHECK_AND_ASSERT_MES(r, false, "generate_ZC_sigs failed");
|
||||
}
|
||||
else
|
||||
|
|
@ -2379,29 +2381,29 @@ namespace currency
|
|||
{
|
||||
// asset surjection proof
|
||||
currency::zc_asset_surjection_proof asp{};
|
||||
bool r = generate_asset_surjection_proof(tx_prefix_hash, has_non_zc_inputs, outs_gen_context, asp);
|
||||
bool r = generate_asset_surjection_proof(tx_prefix_hash, has_non_zc_inputs, gen_context, asp);
|
||||
CHECK_AND_ASSERT_MES(r, false, "generete_asset_surjection_proof failed");
|
||||
tx.proofs.emplace_back(std::move(asp));
|
||||
|
||||
// range proofs
|
||||
currency::zc_outs_range_proof range_proofs{};
|
||||
r = generate_zc_outs_range_proof(tx_prefix_hash, range_proof_start_index, outs_gen_context, tx.vout, range_proofs);
|
||||
r = generate_zc_outs_range_proof(tx_prefix_hash, range_proof_start_index, gen_context, tx.vout, range_proofs);
|
||||
CHECK_AND_ASSERT_MES(r, false, "Failed to generate zc_outs_range_proof()");
|
||||
tx.proofs.emplace_back(std::move(range_proofs));
|
||||
|
||||
// balance proof
|
||||
currency::zc_balance_proof balance_proof{};
|
||||
r = generate_tx_balance_proof(tx, tx_prefix_hash, outs_gen_context, 0, balance_proof);
|
||||
r = generate_tx_balance_proof(tx, tx_prefix_hash, gen_context, 0, balance_proof);
|
||||
CHECK_AND_ASSERT_MES(r, false, "generate_tx_balance_proof failed");
|
||||
tx.proofs.emplace_back(std::move(balance_proof));
|
||||
|
||||
// asset operation proof (if necessary)
|
||||
if (outs_gen_context.ao_asset_id != currency::null_pkey)
|
||||
if (gen_context.ao_asset_id != currency::null_pkey)
|
||||
{
|
||||
// construct the asset operation proof
|
||||
// TODO @#@# add support for hidden supply
|
||||
crypto::signature aop_g_sig{};
|
||||
crypto::generate_signature(tx_prefix_hash, crypto::point_t(outs_gen_context.ao_amount_blinding_mask * crypto::c_point_G).to_public_key(), outs_gen_context.ao_amount_blinding_mask, aop_g_sig);
|
||||
crypto::generate_signature(tx_prefix_hash, crypto::point_t(gen_context.ao_amount_blinding_mask * crypto::c_point_G).to_public_key(), gen_context.ao_amount_blinding_mask, aop_g_sig);
|
||||
asset_operation_proof aop{};
|
||||
aop.opt_amount_commitment_g_proof = aop_g_sig;
|
||||
tx.proofs.emplace_back(std::move(aop));
|
||||
|
|
|
|||
|
|
@ -154,6 +154,8 @@ namespace currency
|
|||
crypto::public_key spend_pub_key; // only for validations
|
||||
uint64_t tx_version;
|
||||
|
||||
tx_generation_context gen_context{}; // solely for consolidated txs
|
||||
|
||||
BEGIN_SERIALIZE_OBJECT()
|
||||
FIELD(unlock_time)
|
||||
FIELD(extra)
|
||||
|
|
@ -169,6 +171,8 @@ namespace currency
|
|||
FIELD(expiration_time)
|
||||
FIELD(spend_pub_key)
|
||||
FIELD(tx_version)
|
||||
if (flags & TX_FLAG_SIGNATURE_MODE_SEPARATE)
|
||||
FIELD(gen_context);
|
||||
END_SERIALIZE()
|
||||
};
|
||||
|
||||
|
|
@ -229,10 +233,10 @@ namespace currency
|
|||
};
|
||||
|
||||
bool verify_multiple_zc_outs_range_proofs(const std::vector<zc_outs_range_proofs_with_commitments>& range_proofs);
|
||||
bool generate_asset_surjection_proof(const crypto::hash& context_hash, bool has_non_zc_inputs, outputs_generation_context& ogc, zc_asset_surjection_proof& result);
|
||||
bool generate_asset_surjection_proof(const crypto::hash& context_hash, bool has_non_zc_inputs, tx_generation_context& ogc, zc_asset_surjection_proof& result);
|
||||
bool verify_asset_surjection_proof(const transaction& tx, const crypto::hash& tx_id);
|
||||
bool generate_tx_balance_proof(const transaction &tx, const crypto::hash& tx_id, const outputs_generation_context& ogc, uint64_t block_reward_for_miner_tx, zc_balance_proof& proof);
|
||||
bool generate_zc_outs_range_proof(const crypto::hash& context_hash, size_t out_index_start, const outputs_generation_context& outs_gen_context,
|
||||
bool generate_tx_balance_proof(const transaction &tx, const crypto::hash& tx_id, const tx_generation_context& ogc, uint64_t block_reward_for_miner_tx, zc_balance_proof& proof);
|
||||
bool generate_zc_outs_range_proof(const crypto::hash& context_hash, size_t out_index_start, const tx_generation_context& outs_gen_context,
|
||||
const std::vector<tx_out_v>& vouts, zc_outs_range_proof& result);
|
||||
bool check_tx_bare_balance(const transaction& tx, uint64_t additional_inputs_amount_and_fees_for_mining_tx = 0);
|
||||
bool check_tx_balance(const transaction& tx, const crypto::hash& tx_id, uint64_t additional_inputs_amount_and_fees_for_mining_tx = 0);
|
||||
|
|
@ -249,7 +253,7 @@ namespace currency
|
|||
size_t max_outs = CURRENCY_MINER_TX_MAX_OUTS,
|
||||
bool pos = false,
|
||||
const pos_entry& pe = pos_entry(),
|
||||
outputs_generation_context* ogc_ptr = nullptr,
|
||||
tx_generation_context* ogc_ptr = nullptr,
|
||||
const keypair* tx_one_time_key_to_use = nullptr);
|
||||
//---------------------------------------------------------------
|
||||
uint64_t get_string_uint64_hash(const std::string& str);
|
||||
|
|
|
|||
|
|
@ -206,19 +206,19 @@ namespace currency
|
|||
std::vector<tx_source_entry::output_entry> prepare_outputs_entries_for_key_offsets(const std::vector<tx_source_entry::output_entry>& outputs, size_t old_real_index, size_t& new_real_index) noexcept;
|
||||
|
||||
|
||||
struct outputs_generation_context
|
||||
struct tx_generation_context
|
||||
{
|
||||
outputs_generation_context() = default;
|
||||
tx_generation_context() = default;
|
||||
|
||||
outputs_generation_context(size_t zc_ins_count, size_t outs_count)
|
||||
: /*pseudo_outs_blinded_asset_ids(zc_ins_count)
|
||||
, */asset_ids(outs_count)
|
||||
, blinded_asset_ids(outs_count)
|
||||
, amount_commitments(outs_count)
|
||||
, asset_id_blinding_masks(outs_count)
|
||||
, amounts(outs_count)
|
||||
, amount_blinding_masks(outs_count)
|
||||
{}
|
||||
void resize(size_t zc_ins_count, size_t outs_count)
|
||||
{
|
||||
asset_ids.resize(outs_count);
|
||||
blinded_asset_ids.resize(outs_count);
|
||||
amount_commitments.resize(outs_count);
|
||||
asset_id_blinding_masks.resize(outs_count);
|
||||
amounts.resize(outs_count);
|
||||
amount_blinding_masks.resize(outs_count);
|
||||
}
|
||||
|
||||
// TODO @#@# reconsider this check -- sowle
|
||||
bool check_sizes(size_t zc_ins_count, size_t outs_count) const
|
||||
|
|
@ -242,9 +242,9 @@ namespace currency
|
|||
crypto::scalar_vec_t amount_blinding_masks; // generate_zc_outs_range_proof
|
||||
|
||||
// per zc input data
|
||||
std::vector<crypto::point_t> pseudo_outs_blinded_asset_ids;
|
||||
crypto::scalar_vec_t pseudo_outs_plus_real_out_blinding_masks; // r_pi + r'_j
|
||||
std::vector<crypto::point_t> real_zc_ins_asset_ids; // H_i
|
||||
std::vector<crypto::point_t> pseudo_outs_blinded_asset_ids; // generate_asset_surjection_proof
|
||||
crypto::scalar_vec_t pseudo_outs_plus_real_out_blinding_masks; // r_pi + r'_j // generate_asset_surjection_proof
|
||||
std::vector<crypto::point_t> real_zc_ins_asset_ids; // H_i // generate_asset_surjection_proof
|
||||
|
||||
// common data: inputs
|
||||
crypto::point_t pseudo_out_amount_commitments_sum = crypto::c_point_0; // generate_tx_balance_proof generate_ZC_sig
|
||||
|
|
@ -270,6 +270,9 @@ namespace currency
|
|||
KV_SERIALIZE_CONTAINER_POD_AS_BLOB(asset_id_blinding_masks);
|
||||
KV_SERIALIZE_CONTAINER_POD_AS_BLOB(amounts);
|
||||
KV_SERIALIZE_CONTAINER_POD_AS_BLOB(amount_blinding_masks);
|
||||
KV_SERIALIZE_CONTAINER_POD_AS_BLOB(pseudo_outs_blinded_asset_ids);
|
||||
KV_SERIALIZE_CONTAINER_POD_AS_BLOB(pseudo_outs_plus_real_out_blinding_masks);
|
||||
KV_SERIALIZE_CONTAINER_POD_AS_BLOB(real_zc_ins_asset_ids);
|
||||
KV_SERIALIZE_POD_AS_HEX_STRING(pseudo_out_amount_commitments_sum);
|
||||
KV_SERIALIZE_POD_AS_HEX_STRING(pseudo_out_amount_blinding_masks_sum);
|
||||
KV_SERIALIZE_POD_AS_HEX_STRING(real_in_asset_id_blinding_mask_x_amount_sum);
|
||||
|
|
@ -281,6 +284,31 @@ namespace currency
|
|||
KV_SERIALIZE_POD_AS_HEX_STRING(ao_amount_commitment);
|
||||
KV_SERIALIZE_POD_AS_HEX_STRING(ao_amount_blinding_mask);
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
// solely for consolidated txs, asset opration fields are not serialized
|
||||
BEGIN_SERIALIZE_OBJECT()
|
||||
FIELD(asset_ids);
|
||||
FIELD(blinded_asset_ids);
|
||||
FIELD(amount_commitments);
|
||||
FIELD((std::vector<crypto::scalar_t>&)(asset_id_blinding_masks));
|
||||
FIELD((std::vector<crypto::scalar_t>&)(amounts));
|
||||
FIELD((std::vector<crypto::scalar_t>&)(amount_blinding_masks));
|
||||
FIELD(pseudo_outs_blinded_asset_ids);
|
||||
FIELD((std::vector<crypto::scalar_t>&)(pseudo_outs_plus_real_out_blinding_masks));
|
||||
FIELD(real_zc_ins_asset_ids);
|
||||
FIELD(pseudo_out_amount_commitments_sum);
|
||||
FIELD(pseudo_out_amount_blinding_masks_sum);
|
||||
FIELD(real_in_asset_id_blinding_mask_x_amount_sum);
|
||||
FIELD(amount_commitments_sum);
|
||||
FIELD(amount_blinding_masks_sum);
|
||||
FIELD(asset_id_blinding_mask_x_amount_sum);
|
||||
|
||||
// no asset operation fields here
|
||||
//ao_asset_id
|
||||
//ao_asset_id_pt
|
||||
//ao_amount_commitment
|
||||
//ao_amount_blinding_mask
|
||||
END_SERIALIZE()
|
||||
}; // struct tx_generation_context
|
||||
|
||||
} // namespace currency
|
||||
|
|
|
|||
|
|
@ -877,7 +877,7 @@ namespace currency
|
|||
blobdata block_blob = t_serializable_object_to_blob(resp.b);
|
||||
res.blocktemplate_blob = string_tools::buff_to_hex_nodelimer(block_blob);
|
||||
res.prev_hash = string_tools::pod_to_hex(resp.b.prev_id);
|
||||
res.miner_tx_ogc = resp.miner_tx_ogc;
|
||||
res.miner_tx_tgc = resp.miner_tx_tgc;
|
||||
res.height = resp.height;
|
||||
//calculate epoch seed
|
||||
res.seed = currency::ethash_epoch_to_seed(currency::ethash_height_to_epoch(res.height));
|
||||
|
|
|
|||
|
|
@ -860,7 +860,7 @@ namespace currency
|
|||
crypto::hash seed;
|
||||
blobdata blocktemplate_blob;
|
||||
std::string prev_hash;
|
||||
outputs_generation_context miner_tx_ogc;
|
||||
tx_generation_context miner_tx_tgc;
|
||||
std::string status;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
|
|
@ -869,7 +869,7 @@ namespace currency
|
|||
KV_SERIALIZE_POD_AS_HEX_STRING(seed)
|
||||
KV_SERIALIZE(blocktemplate_blob)
|
||||
KV_SERIALIZE(prev_hash)
|
||||
KV_SERIALIZE(miner_tx_ogc)
|
||||
KV_SERIALIZE(miner_tx_tgc)
|
||||
KV_SERIALIZE(status)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3840,7 +3840,7 @@ bool wallet2::is_in_hardfork_zone(uint64_t hardfork_index) const
|
|||
return m_core_runtime_config.is_hardfork_active_for_height(hardfork_index, get_blockchain_current_size());
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
bool wallet2::prepare_and_sign_pos_block(const mining_context& cxt, currency::block& b, const pos_entry& pe, currency::outputs_generation_context& miner_tx_ogc) const
|
||||
bool wallet2::prepare_and_sign_pos_block(const mining_context& cxt, currency::block& b, const pos_entry& pe, currency::tx_generation_context& miner_tx_tgc) const
|
||||
{
|
||||
bool r = false;
|
||||
WLT_CHECK_AND_ASSERT_MES(pe.wallet_index < m_transfers.size(), false, "invalid pe.wallet_index: " << pe.wallet_index);
|
||||
|
|
@ -3987,12 +3987,12 @@ bool wallet2::prepare_and_sign_pos_block(const mining_context& cxt, currency::bl
|
|||
|
||||
crypto::hash hash_for_zarcanum_sig = get_block_hash(b);
|
||||
|
||||
WLT_CHECK_AND_ASSERT_MES(miner_tx_ogc.pseudo_out_amount_blinding_masks_sum.is_zero(), false, "pseudo_out_amount_blinding_masks_sum is nonzero"); // it should be zero because there's only one input (stake), and thus one pseudo out
|
||||
crypto::scalar_t pseudo_out_amount_blinding_mask = miner_tx_ogc.amount_blinding_masks_sum; // sum of outputs' amount blinding masks
|
||||
WLT_CHECK_AND_ASSERT_MES(miner_tx_tgc.pseudo_out_amount_blinding_masks_sum.is_zero(), false, "pseudo_out_amount_blinding_masks_sum is nonzero"); // it should be zero because there's only one input (stake), and thus one pseudo out
|
||||
crypto::scalar_t pseudo_out_amount_blinding_mask = miner_tx_tgc.amount_blinding_masks_sum; // sum of outputs' amount blinding masks
|
||||
|
||||
miner_tx_ogc.pseudo_outs_blinded_asset_ids.emplace_back(currency::native_coin_asset_id_pt);
|
||||
miner_tx_ogc.pseudo_outs_plus_real_out_blinding_masks.emplace_back(0);
|
||||
miner_tx_ogc.real_zc_ins_asset_ids.emplace_back(td.m_zc_info_ptr->asset_id);
|
||||
miner_tx_tgc.pseudo_outs_blinded_asset_ids.emplace_back(currency::native_coin_asset_id_pt);
|
||||
miner_tx_tgc.pseudo_outs_plus_real_out_blinding_masks.emplace_back(0);
|
||||
miner_tx_tgc.real_zc_ins_asset_ids.emplace_back(td.m_zc_info_ptr->asset_id);
|
||||
|
||||
uint8_t err = 0;
|
||||
r = crypto::zarcanum_generate_proof(hash_for_zarcanum_sig, cxt.kernel_hash, ring, cxt.last_pow_block_id_hashed, cxt.sk.kimage,
|
||||
|
|
@ -4001,7 +4001,7 @@ bool wallet2::prepare_and_sign_pos_block(const mining_context& cxt, currency::bl
|
|||
WLT_CHECK_AND_ASSERT_MES(r, false, "zarcanum_generate_proof failed, err: " << (int)err);
|
||||
|
||||
// TODO @#@# [architecture] the same value is calculated in zarcanum_generate_proof(), consider an impovement
|
||||
miner_tx_ogc.pseudo_out_amount_commitments_sum += cxt.stake_amount * currency::native_coin_asset_id_pt + pseudo_out_amount_blinding_mask * crypto::c_point_G;
|
||||
miner_tx_tgc.pseudo_out_amount_commitments_sum += cxt.stake_amount * currency::native_coin_asset_id_pt + pseudo_out_amount_blinding_mask * crypto::c_point_G;
|
||||
|
||||
//
|
||||
// The miner tx prefix should be sealed by now, and the tx hash should be defined.
|
||||
|
|
@ -4013,20 +4013,20 @@ bool wallet2::prepare_and_sign_pos_block(const mining_context& cxt, currency::bl
|
|||
|
||||
// asset surjection proof
|
||||
currency::zc_asset_surjection_proof asp{};
|
||||
r = generate_asset_surjection_proof(miner_tx_id, false, miner_tx_ogc, asp); // has_non_zc_inputs == false because after the HF4 PoS mining is only allowed for ZC stakes inputs
|
||||
r = generate_asset_surjection_proof(miner_tx_id, false, miner_tx_tgc, asp); // has_non_zc_inputs == false because after the HF4 PoS mining is only allowed for ZC stakes inputs
|
||||
WLT_CHECK_AND_ASSERT_MES(r, false, "generete_asset_surjection_proof failed");
|
||||
b.miner_tx.proofs.emplace_back(std::move(asp));
|
||||
|
||||
// range proofs
|
||||
currency::zc_outs_range_proof range_proofs{};
|
||||
r = generate_zc_outs_range_proof(miner_tx_id, 0, miner_tx_ogc, b.miner_tx.vout, range_proofs);
|
||||
r = generate_zc_outs_range_proof(miner_tx_id, 0, miner_tx_tgc, b.miner_tx.vout, range_proofs);
|
||||
WLT_CHECK_AND_ASSERT_MES(r, false, "Failed to generate zc_outs_range_proof()");
|
||||
b.miner_tx.proofs.emplace_back(std::move(range_proofs));
|
||||
|
||||
// balance proof
|
||||
uint64_t block_reward = COIN; // TODO @#@# move it somewhere -- sowle
|
||||
currency::zc_balance_proof balance_proof{};
|
||||
r = generate_tx_balance_proof(b.miner_tx, miner_tx_id, miner_tx_ogc, block_reward, balance_proof);
|
||||
r = generate_tx_balance_proof(b.miner_tx, miner_tx_id, miner_tx_tgc, block_reward, balance_proof);
|
||||
WLT_CHECK_AND_ASSERT_MES(r, false, "generate_tx_balance_proof failed");
|
||||
b.miner_tx.proofs.emplace_back(std::move(balance_proof));
|
||||
|
||||
|
|
@ -4178,7 +4178,7 @@ bool wallet2::build_minted_block(const mining_context& cxt, const currency::acco
|
|||
set_block_datetime(current_timestamp, b);
|
||||
WLT_LOG_MAGENTA("Applying actual timestamp: " << current_timestamp, LOG_LEVEL_0);
|
||||
|
||||
res = prepare_and_sign_pos_block(cxt, b, tmpl_req.pe, tmpl_rsp.miner_tx_ogc);
|
||||
res = prepare_and_sign_pos_block(cxt, b, tmpl_req.pe, tmpl_rsp.miner_tx_tgc);
|
||||
WLT_CHECK_AND_ASSERT_MES(res, false, "Failed to prepare_and_sign_pos_block");
|
||||
|
||||
crypto::hash block_hash = get_block_hash(b);
|
||||
|
|
|
|||
|
|
@ -856,7 +856,7 @@ namespace tools
|
|||
//next functions in public area only becausce of test_generator
|
||||
//TODO: Need refactoring - remove it back to private zone
|
||||
void set_genesis(const crypto::hash& genesis_hash);
|
||||
bool prepare_and_sign_pos_block(const mining_context& cxt, currency::block& b, const currency::pos_entry& pe, currency::outputs_generation_context& miner_tx_ogc) const;
|
||||
bool prepare_and_sign_pos_block(const mining_context& cxt, currency::block& b, const currency::pos_entry& pe, currency::tx_generation_context& miner_tx_tgc) const;
|
||||
void process_new_blockchain_entry(const currency::block& b,
|
||||
const currency::block_direct_data_entry& bche,
|
||||
const crypto::hash& bl_id,
|
||||
|
|
|
|||
|
|
@ -287,7 +287,7 @@ bool test_generator::construct_block(currency::block& blk,
|
|||
|
||||
blk.miner_tx = AUTO_VAL_INIT(blk.miner_tx);
|
||||
size_t target_block_size = txs_size + 0; // zero means no cost for ordinary coinbase
|
||||
outputs_generation_context miner_tx_ogc{};
|
||||
tx_generation_context miner_tx_tgc{};
|
||||
while (true)
|
||||
{
|
||||
r = construct_miner_tx(height, misc_utils::median(block_sizes),
|
||||
|
|
@ -302,7 +302,7 @@ bool test_generator::construct_block(currency::block& blk,
|
|||
test_generator::get_test_gentime_settings().miner_tx_max_outs,
|
||||
static_cast<bool>(coin_stake_sources.size()),
|
||||
pe,
|
||||
&miner_tx_ogc);
|
||||
&miner_tx_tgc);
|
||||
CHECK_AND_ASSERT_MES(r, false, "construct_miner_tx failed");
|
||||
|
||||
size_t coinbase_size = get_object_blobsize(blk.miner_tx);
|
||||
|
|
@ -343,7 +343,7 @@ bool test_generator::construct_block(currency::block& blk,
|
|||
else
|
||||
{
|
||||
//need to build pos block
|
||||
r = sign_block(wallets[won_walled_index].mining_context, pe, *wallets[won_walled_index].wallet, miner_tx_ogc, blk);
|
||||
r = sign_block(wallets[won_walled_index].mining_context, pe, *wallets[won_walled_index].wallet, miner_tx_tgc, blk);
|
||||
CHECK_AND_ASSERT_MES(r, false, "Failed to find_kernel_and_sign()");
|
||||
}
|
||||
|
||||
|
|
@ -363,10 +363,10 @@ bool test_generator::construct_block(currency::block& blk,
|
|||
bool test_generator::sign_block(const tools::wallet2::mining_context& mining_context,
|
||||
const pos_entry& pe,
|
||||
const tools::wallet2& w,
|
||||
outputs_generation_context& miner_tx_ogc,
|
||||
tx_generation_context& miner_tx_tgc,
|
||||
currency::block& b)
|
||||
{
|
||||
bool r = w.prepare_and_sign_pos_block(mining_context, b, pe, miner_tx_ogc);
|
||||
bool r = w.prepare_and_sign_pos_block(mining_context, b, pe, miner_tx_tgc);
|
||||
CHECK_AND_ASSERT_MES(r, false, "prepare_and_sign_pos_block failed");
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -467,7 +467,7 @@ public:
|
|||
bool sign_block(const tools::wallet2::mining_context& mining_context,
|
||||
const currency::pos_entry& pe,
|
||||
const tools::wallet2& w,
|
||||
currency::outputs_generation_context& miner_tx_ogc,
|
||||
currency::tx_generation_context& miner_tx_tgc,
|
||||
currency::block& b);
|
||||
|
||||
/*bool get_output_details_by_global_index(const test_generator::blockchain_vector& blck_chain,
|
||||
|
|
|
|||
|
|
@ -168,7 +168,7 @@ void pos_block_builder::step4_generate_coinbase_tx(size_t median_size,
|
|||
// generate miner tx using incorrect current_block_size only for size estimation
|
||||
size_t estimated_block_size = m_txs_total_size;
|
||||
bool r = construct_miner_tx(m_height, median_size, already_generated_coins, estimated_block_size, m_total_fee,
|
||||
reward_receiver_address, stakeholder_address, m_block.miner_tx, tx_version, extra_nonce, max_outs, true, pe, &m_miner_tx_ogc, tx_one_time_key_to_use);
|
||||
reward_receiver_address, stakeholder_address, m_block.miner_tx, tx_version, extra_nonce, max_outs, true, pe, &m_miner_tx_tgc, tx_one_time_key_to_use);
|
||||
CHECK_AND_ASSERT_THROW_MES(r, "construct_miner_tx failed");
|
||||
|
||||
estimated_block_size = m_txs_total_size + get_object_blobsize(m_block.miner_tx);
|
||||
|
|
@ -176,7 +176,7 @@ void pos_block_builder::step4_generate_coinbase_tx(size_t median_size,
|
|||
for (size_t try_count = 0; try_count != 10; ++try_count)
|
||||
{
|
||||
r = construct_miner_tx(m_height, median_size, already_generated_coins, estimated_block_size, m_total_fee,
|
||||
reward_receiver_address, stakeholder_address, m_block.miner_tx, tx_version, extra_nonce, max_outs, true, pe, &m_miner_tx_ogc, tx_one_time_key_to_use);
|
||||
reward_receiver_address, stakeholder_address, m_block.miner_tx, tx_version, extra_nonce, max_outs, true, pe, &m_miner_tx_tgc, tx_one_time_key_to_use);
|
||||
CHECK_AND_ASSERT_THROW_MES(r, "construct_homemade_pos_miner_tx failed");
|
||||
|
||||
cumulative_size = m_txs_total_size + get_object_blobsize(m_block.miner_tx);
|
||||
|
|
@ -232,7 +232,7 @@ void pos_block_builder::step5_sign(const currency::tx_source_entry& se, const cu
|
|||
|
||||
uint8_t err = 0;
|
||||
r = crypto::zarcanum_generate_proof(tx_hash_for_sig, m_context.kernel_hash, ring, m_context.last_pow_block_id_hashed, m_context.sk.kimage,
|
||||
secret_x, m_context.secret_q, prepared_real_out_index, se.real_out_asset_id_blinding_mask, -m_miner_tx_ogc.amount_blinding_masks_sum, m_context.stake_amount, m_context.stake_out_amount_blinding_mask,
|
||||
secret_x, m_context.secret_q, prepared_real_out_index, se.real_out_asset_id_blinding_mask, -m_miner_tx_tgc.amount_blinding_masks_sum, m_context.stake_amount, m_context.stake_out_amount_blinding_mask,
|
||||
static_cast<crypto::zarcanum_proof&>(sig), &err);
|
||||
CHECK_AND_ASSERT_THROW_MES(r, "zarcanum_generate_proof failed, err: " << (int)err);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ struct pos_block_builder
|
|||
size_t m_height = 0;
|
||||
size_t m_pos_stake_output_gindex = 0;
|
||||
//uint64_t m_pos_stake_amount = 0;
|
||||
currency::outputs_generation_context m_miner_tx_ogc {};
|
||||
currency::tx_generation_context m_miner_tx_tgc {};
|
||||
|
||||
currency::pos_mining_context m_context {};
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue