carrot_impl: make_signable_tx_hash_from_carrot_transaction_proposal_v1 and bug fixes
This commit is contained in:
@@ -37,6 +37,7 @@ extern "C"
|
||||
#include "crypto/crypto-ops.h"
|
||||
}
|
||||
#include "cryptonote_basic/cryptonote_format_utils.h"
|
||||
#include "ringct/rctSigs.h"
|
||||
#include "ringct/rctOps.h"
|
||||
|
||||
//third party headers
|
||||
@@ -205,7 +206,7 @@ void make_carrot_transaction_proposal_v1(const std::vector<CarrotPaymentProposal
|
||||
tx_proposal_out.key_images_sorted.push_back(selected_input.key_image);
|
||||
std::sort(tx_proposal_out.key_images_sorted.begin(),
|
||||
tx_proposal_out.key_images_sorted.end(),
|
||||
&compare_input_key_images);
|
||||
std::greater{}); // consensus rules dictate inputs sorted in *reverse* lexicographical order since v7
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
void make_carrot_transaction_proposal_v1_transfer_subtractable(
|
||||
@@ -474,10 +475,32 @@ void make_carrot_transaction_proposal_v1_sweep(
|
||||
tx_proposal_out);
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
void make_signable_tx_hash_from_carrot_transaction_proposal_v1(const CarrotTransactionProposalV1 &tx_proposal,
|
||||
const view_balance_secret_device *s_view_balance_dev,
|
||||
const view_incoming_key_device *k_view_dev,
|
||||
crypto::hash &signable_tx_hash_out)
|
||||
{
|
||||
//! @TODO: there's a more efficient way to do this than constructing&serializing a whole cryptonote::transaction
|
||||
// HW devices will need to implement this function to sign tx proposals, and most of these devices don't have a lot of memory
|
||||
|
||||
cryptonote::transaction pruned_tx;
|
||||
make_pruned_transaction_from_carrot_proposal_v1(tx_proposal,
|
||||
s_view_balance_dev,
|
||||
k_view_dev,
|
||||
pruned_tx);
|
||||
|
||||
//! @TODO: better input number calculation in get_pre_mlsag_hash. possible?
|
||||
pruned_tx.rct_signatures.p.pseudoOuts.resize(pruned_tx.vin.size());
|
||||
|
||||
hw::device &hwdev = hw::get_device("default");
|
||||
const rct::key signable_tx_hash_k = rct::get_pre_mlsag_hash(pruned_tx.rct_signatures, hwdev);
|
||||
|
||||
signable_tx_hash_out = rct::rct2hash(signable_tx_hash_k);
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
void make_pruned_transaction_from_carrot_proposal_v1(const CarrotTransactionProposalV1 &tx_proposal,
|
||||
const view_balance_secret_device *s_view_balance_dev,
|
||||
const view_incoming_key_device *k_view_dev,
|
||||
const crypto::public_key &account_spend_pubkey,
|
||||
cryptonote::transaction &pruned_tx_out)
|
||||
{
|
||||
// collect self-sends proposal cores
|
||||
|
||||
@@ -61,11 +61,6 @@ static inline std::size_t get_fcmppp_tx_weight(const std::size_t num_inputs,
|
||||
std::size_t get_fcmppp_coinbase_tx_weight(const std::size_t num_outputs,
|
||||
const std::size_t tx_extra_size);
|
||||
|
||||
static inline bool compare_input_key_images(const crypto::key_image &lhs, const crypto::key_image &rhs)
|
||||
{
|
||||
return memcmp(lhs.data, rhs.data, sizeof(crypto::key_image)) > 0;
|
||||
}
|
||||
|
||||
void make_carrot_transaction_proposal_v1(const std::vector<CarrotPaymentProposalV1> &normal_payment_proposals,
|
||||
const std::vector<CarrotPaymentProposalVerifiableSelfSendV1> &selfsend_payment_proposals,
|
||||
const rct::xmr_amount fee_per_weight,
|
||||
@@ -112,10 +107,14 @@ void make_carrot_transaction_proposal_v1_sweep(
|
||||
const crypto::public_key &account_spend_pubkey,
|
||||
CarrotTransactionProposalV1 &tx_proposal_out);
|
||||
|
||||
void make_signable_tx_hash_from_carrot_transaction_proposal_v1(const CarrotTransactionProposalV1 &tx_proposal,
|
||||
const view_balance_secret_device *s_view_balance_dev,
|
||||
const view_incoming_key_device *k_view_dev,
|
||||
crypto::hash &signable_tx_hash_out);
|
||||
|
||||
void make_pruned_transaction_from_carrot_proposal_v1(const CarrotTransactionProposalV1 &tx_proposal,
|
||||
const view_balance_secret_device *s_view_balance_dev,
|
||||
const view_incoming_key_device *k_view_dev,
|
||||
const crypto::public_key &account_spend_pubkey,
|
||||
cryptonote::transaction &pruned_tx_out);
|
||||
|
||||
} //namespace carrot
|
||||
|
||||
@@ -281,12 +281,14 @@ bool try_load_carrot_from_transaction_v1(const cryptonote::transaction &tx,
|
||||
std::vector<mx25519_pubkey> enote_ephemeral_pubkeys;
|
||||
if (!try_load_carrot_extra_v1(tx.extra, enote_ephemeral_pubkeys, encrypted_payment_id_out))
|
||||
return false;
|
||||
else if (enote_ephemeral_pubkeys.size() > nouts)
|
||||
|
||||
const size_t n_ephemeral = enote_ephemeral_pubkeys.size();
|
||||
if (n_ephemeral < 0 || n_ephemeral > nouts)
|
||||
return false;
|
||||
|
||||
// collect D_e
|
||||
for (size_t i = 0; i < enotes_out.size(); ++i)
|
||||
enotes_out[i].enote_ephemeral_pubkey = enote_ephemeral_pubkeys.at(std::min(i, nouts - 1));
|
||||
enotes_out[i].enote_ephemeral_pubkey = enote_ephemeral_pubkeys.at(std::min(i, n_ephemeral - 1));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user