Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions src/cryptonote_core/tx_verification_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,28 @@

using namespace cryptonote;

static void collect_transparent_amount_commitments_static(
const std::vector<std::reference_wrapper<const transaction>> &tx_refs,
std::unordered_map<uint64_t, rct::key> &transparent_amount_commitments_inout)
{
// Note: we do not clear transparent_amount_commitments_inout because it may be a rolling cache

for (const std::reference_wrapper<const transaction> &tx_ref : tx_refs)
{
const transaction &tx = tx_ref.get();

// We only need commitments for transparent amounts, which are tx version 1 || coinbase txs
if (tx.version > 1 && !cryptonote::is_coinbase(tx))
continue;
for (const auto &tx_out : tx.vout)
{
const uint64_t amount = tx_out.amount;
if (transparent_amount_commitments_inout.find(amount) == transparent_amount_commitments_inout.end())
transparent_amount_commitments_inout[amount] = rct::zeroCommitVartime(amount);
}
}
}

// Do RCT expansion, then do post-expansion sanity checks, then do full non-semantics verification.
static bool expand_tx_and_ver_rct_non_sem(transaction& tx, const rct::ctkeyM& mix_ring)
{
Expand Down Expand Up @@ -315,6 +337,46 @@ static bool ver_non_input_consensus_templated(TxForwardIt tx_begin, TxForwardIt
namespace cryptonote
{

std::vector<std::reference_wrapper<const transaction>> collect_transparent_amount_commitments(
const transaction &miner_tx,
const std::vector<std::pair<transaction, blobdata>> &tx_pairs,
std::unordered_map<uint64_t, rct::key> &transparent_amount_commitments_inout)
Comment on lines +340 to +343

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{
std::vector<std::reference_wrapper<const transaction>> tx_refs;
tx_refs.reserve(1 + tx_pairs.size());
tx_refs.push_back(std::cref(miner_tx));
for (const auto &tx : tx_pairs)
tx_refs.push_back(std::cref(tx.first));
collect_transparent_amount_commitments_static(tx_refs, transparent_amount_commitments_inout);
return tx_refs;
}

std::vector<std::reference_wrapper<const transaction>> collect_transparent_amount_commitments(
const transaction &miner_tx,
const std::vector<transaction> &txs,
std::unordered_map<uint64_t, rct::key> &transparent_amount_commitments_inout)
Comment on lines +354 to +357

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{
std::vector<std::reference_wrapper<const transaction>> tx_refs;
tx_refs.reserve(1 + txs.size());
tx_refs.push_back(std::cref(miner_tx));
for (const auto &tx : txs)
tx_refs.push_back(std::cref(tx));
collect_transparent_amount_commitments_static(tx_refs, transparent_amount_commitments_inout);
return tx_refs;
}

std::vector<std::reference_wrapper<const transaction>> collect_transparent_amount_commitments(
const std::unordered_map<crypto::hash, std::pair<transaction, blobdata>> &txs_by_txid,
std::unordered_map<uint64_t, rct::key> &transparent_amount_commitments_inout)
Comment on lines +368 to +370

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{
std::vector<std::reference_wrapper<const transaction>> tx_refs;
tx_refs.reserve(txs_by_txid.size());
for (const auto &tx_pair : txs_by_txid)
tx_refs.push_back(std::cref(tx_pair.second.first));
collect_transparent_amount_commitments_static(tx_refs, transparent_amount_commitments_inout);
return tx_refs;
}

uint64_t get_transaction_weight_limit(const uint8_t hf_version)
{
// from v8, limit a tx to 50% of the minimum block weight
Expand Down
29 changes: 29 additions & 0 deletions src/cryptonote_core/tx_verification_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,42 @@

#pragma once

#include <functional>
#include <unordered_map>

#include "cryptonote_basic/blobdatatype.h"
#include "cryptonote_basic/cryptonote_basic.h"
#include "cryptonote_basic/verification_context.h"

namespace cryptonote
{

/**
* @brief Calculate all commitments for any transparent amounts passed in
*
* The container passed in may have some commitments already calculated.
* This function won't erase from it, it'll just add to the collection
* if the commitment hasn't been calculated yet.
*
* @param miner_tx the miner tx included in a block
* @param tx_pairs the txs included in a block
* @param transparent_amount_commitments_inout the collection passed in and returned by ref
* @return all passed in txs reference wrappers
*/
std::vector<std::reference_wrapper<const transaction>> collect_transparent_amount_commitments(
const transaction &miner_tx,
const std::vector<std::pair<transaction, blobdata>> &tx_pairs,
std::unordered_map<uint64_t, rct::key> &transparent_amount_commitments_inout);

std::vector<std::reference_wrapper<const transaction>> collect_transparent_amount_commitments(
const transaction &miner_tx,
const std::vector<transaction> &txs,
std::unordered_map<uint64_t, rct::key> &transparent_amount_commitments_inout);

std::vector<std::reference_wrapper<const transaction>> collect_transparent_amount_commitments(
const std::unordered_map<crypto::hash, std::pair<transaction, blobdata>> &txs_by_txid,
std::unordered_map<uint64_t, rct::key> &transparent_amount_commitments_inout);

/**
* @brief Get the maximum transaction weight for a given hardfork
*
Expand Down
Loading