1
0
Fork 0
forked from lthn/blockchain

zarcanum WIP (use standard derivation to scalar conversion to simplify things) + minor

This commit is contained in:
sowle 2022-09-23 22:18:22 +02:00
parent 0bfe224b66
commit 078440a815
No known key found for this signature in database
GPG key ID: C07A24B2D89D49FC
4 changed files with 28 additions and 28 deletions

View file

@ -912,7 +912,8 @@ namespace currency
{
// normal output
crypto::public_key derivation = (crypto::scalar_t(tx_sec_key) * crypto::point_t(apa.view_public_key)).modify_mul8().to_public_key(); // d = 8 * r * V
crypto::scalar_t h = crypto::hash_helper_t::hs(derivation, output_index);
crypto::scalar_t h; // = crypto::hash_helper_t::hs(derivation, output_index);
crypto::derivation_to_scalar((const crypto::key_derivation&)derivation, output_index, h.as_secret_key()); // h = Hs(8 * r * V, i)
out.stealth_address = (h * crypto::c_point_G + crypto::point_t(apa.spend_public_key)).to_public_key();
out.concealing_point = (crypto::c_scalar_1div8 * crypto::hash_helper_t::hs(CRYPTO_HDS_OUT_CONCEALING_POINT, h) * crypto::point_t(apa.view_public_key)).to_public_key(); // Q = 1/8 * Hs(domain_sep, h) * V
@ -2452,7 +2453,8 @@ namespace currency
bool is_out_to_acc(const account_keys& acc, const tx_out_zarcanum& zo, const crypto::key_derivation& derivation, size_t output_index, uint64_t& decoded_amount, crypto::scalar_t& 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)
crypto::scalar_t h; // = crypto::hash_helper_t::hs(reinterpret_cast<const crypto::public_key&>(derivation), output_index); // h = Hs(8 * r * V, i)
crypto::derivation_to_scalar(derivation, output_index, h.as_secret_key()); // h = Hs(8 * r * V, i)
crypto::point_t P_prime = h * crypto::c_point_G + crypto::point_t(acc.account_address.spend_public_key); // P =? Hs(8rV, i) * G + S
if (P_prime.to_public_key() != zo.stealth_address)

View file

@ -68,7 +68,7 @@ namespace currency
if (!check_tx_balance(tx))
{
LOG_PRINT_RED_L0("tx balance check failed, tx id= " << get_transaction_hash(tx));
LOG_PRINT_RED_L0("balance check failed for tx " << get_transaction_hash(tx));
return false;
}

View file

@ -714,7 +714,7 @@ void wallet2::process_new_transaction(const currency::transaction& tx, uint64_t
if (out_type_to_key || out_type_zc)
{
WLT_LOG_L0("Received money, transfer #" << transfer_index << ", amount: " << print_money(td.amount()) << ", with tx: " << get_transaction_hash(tx) << ", at height " << height);
WLT_LOG_L0("Received money, transfer #" << transfer_index << ", amount: " << print_money_brief(td.amount()) << (out_type_zc ? " (hidden)" : "") << ", with tx: " << get_transaction_hash(tx) << ", at height " << height);
}
else if (out_is_to_htlc(out_v))
{

View file

@ -217,13 +217,9 @@ bool test_generator::construct_block(currency::block& blk,
const std::list<currency::account_base>& coin_stake_sources)//in case of PoS block
{
bool r = false;
// if (height > m_hardfork_01_after_heigh)
// blk.major_version = CURRENT_BLOCK_MAJOR_VERSION;
// else
// blk.major_version = BLOCK_MAJOR_VERSION_INITIAL;
bool pos = coin_stake_sources.size() > 0;
blk.major_version = m_hardforks.get_block_major_version_by_height(height);
blk.minor_version = CURRENT_BLOCK_MINOR_VERSION;
blk.timestamp = timestamp;
blk.prev_id = prev_id;
@ -259,21 +255,21 @@ bool test_generator::construct_block(currency::block& blk,
size_t won_walled_index = 0;
pos_entry pe = AUTO_VAL_INIT(pe);
if (coin_stake_sources.size())
if (pos)
{
//build outputs index
build_outputs_indext_for_chain(blocks, oi, txs_outs);
//build wallets
build_wallets(blocks, coin_stake_sources, txs_outs, wallets);
bool r = find_kernel(coin_stake_sources,
blocks,
oi,
wallets,
pe,
won_walled_index,
blk.timestamp,
kernerl_hash);
r = find_kernel(coin_stake_sources,
blocks,
oi,
wallets,
pe,
won_walled_index,
blk.timestamp,
kernerl_hash);
CHECK_AND_ASSERT_THROW_MES(r, "failed to find_kernel ");
blk.flags = CURRENCY_BLOCK_FLAG_POS_BLOCK;
}
@ -325,7 +321,7 @@ bool test_generator::construct_block(currency::block& blk,
CHECK_AND_ASSERT_MES(a_diffic, false, "get_difficulty_for_next_block for test blocks returned 0!");
// Nonce search...
blk.nonce = 0;
if (!coin_stake_sources.size())
if (!pos)
{
//pow block
while (!find_nounce(blk, blocks, a_diffic, height))
@ -334,7 +330,7 @@ bool test_generator::construct_block(currency::block& blk,
else
{
//need to build pos block
bool r = sign_block(blk, pe, *wallets[won_walled_index], blocks, oi);
r = sign_block(blk, pe, *wallets[won_walled_index], blocks, oi);
CHECK_AND_ASSERT_MES(r, false, "Failed to find_kernel_and_sign()");
}
@ -392,10 +388,12 @@ bool test_generator::build_wallets(const blockchain_vector& blockchain,
{
const tx_global_indexes& m_txs_outs;
const blockchain_vector& m_blockchain;
const core_runtime_config& m_core_runtime_config;
stub_core_proxy(const blockchain_vector& blockchain, const tx_global_indexes& txs_outs)
stub_core_proxy(const blockchain_vector& blockchain, const tx_global_indexes& txs_outs, const core_runtime_config& crc)
: m_blockchain(blockchain)
, m_txs_outs(txs_outs)
, m_core_runtime_config(crc)
{}
bool call_COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES(const currency::COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES::request& rqt, currency::COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES::response& rsp) override
@ -415,10 +413,10 @@ bool test_generator::build_wallets(const blockchain_vector& blockchain,
bool call_COMMAND_RPC_GET_POS_MINING_DETAILS(const currency::COMMAND_RPC_GET_POS_MINING_DETAILS::request& req, currency::COMMAND_RPC_GET_POS_MINING_DETAILS::response& rsp) override
{
rsp.pos_mining_allowed = true;
rsp.pos_mining_allowed = m_blockchain.size() >= m_core_runtime_config.pos_minimum_heigh;
if (!rsp.pos_mining_allowed)
{
rsp.status = API_RETURN_CODE_NOT_FOUND;
rsp.status = API_RETURN_CODE_FAIL;
return true;
}
@ -452,7 +450,7 @@ bool test_generator::build_wallets(const blockchain_vector& blockchain,
};
std::shared_ptr<tools::i_core_proxy> tmp_proxy(new stub_core_proxy(blockchain, txs_outs));
std::shared_ptr<tools::i_core_proxy> tmp_proxy(new stub_core_proxy(blockchain, txs_outs, cc));
//build wallets
wallets.clear();
@ -597,8 +595,8 @@ bool test_generator::find_kernel(const std::list<currency::account_base>& accs,
{
//found kernel
found_wallet_index = wallet_index;
found_kh = crypto::cn_fast_hash(&context.sk, sizeof(context.sk)); // TODO: consider passing kernel_hash from scan_pos and do_pos_mining_iteration
found_timestamp = context.sk.block_timestamp;
found_kh = crypto::cn_fast_hash(&context.sk, sizeof(context.sk)); // TODO: consider passing kernel_hash from scan_pos and do_pos_mining_iteration
tools::wallet2::transfer_details td = AUTO_VAL_INIT(td);
r = w->get_transfer_info_by_index(context.index, td);
@ -614,9 +612,9 @@ bool test_generator::find_kernel(const std::list<currency::account_base>& accs,
pe.wallet_index = context.index;
LOG_PRINT_GREEN("Found kernel: amount=" << print_money_brief(pe.amount)
<< ", index=" << pe.g_index
<< ", key_image" << pe.keyimage
/*<< ", diff: " << this_coin_diff*/, LOG_LEVEL_0);
<< ", gindex=" << pe.g_index
<< ", key_image=" << pe.keyimage
/*<< ", diff: " << this_coin_diff*/, LOG_LEVEL_1);
return true;
}