Skip to content

Commit

Permalink
seraphis_main compiles with linking errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffro256 committed Jun 4, 2024
1 parent fa2947e commit 66e41c1
Show file tree
Hide file tree
Showing 6 changed files with 214 additions and 123 deletions.
12 changes: 10 additions & 2 deletions src/seraphis_impl/tx_input_selection_output_context_v1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,13 @@ static bool ephemeral_pubkeys_are_unique(const std::vector<jamtis::JamtisPayment
static bool need_additional_output(const std::size_t num_outputs,
const bool output_ephemeral_pubkeys_are_unique,
const std::vector<jamtis::JamtisSelfSendType> &self_send_output_types,
const std::vector<bool> &self_send_output_is_hidden,
const rct::xmr_amount change_amount)
{
// see if we need an additional output
return static_cast<bool>(try_get_additional_output_type_for_output_set_v1(num_outputs,
self_send_output_types,
self_send_output_is_hidden,
output_ephemeral_pubkeys_are_unique,
change_amount));
}
Expand All @@ -99,9 +101,13 @@ OutputSetContextForInputSelectionV1::OutputSetContextForInputSelectionV1(
{
// 1. collect self-send output types
m_self_send_output_types.reserve(selfsend_payment_proposals.size());
m_self_send_output_is_hidden.reserve(selfsend_payment_proposals.size());

for (const jamtis::JamtisPaymentProposalSelfSendV1 &selfsend_proposal : selfsend_payment_proposals)
{
m_self_send_output_types.emplace_back(selfsend_proposal.type);
m_self_send_output_is_hidden.emplace_back(selfsend_proposal.num_primary_view_tag_bits == 0);
}

// 2. collect total amount
m_total_output_amount = 0;
Expand All @@ -121,7 +127,8 @@ boost::multiprecision::uint128_t OutputSetContextForInputSelectionV1::total_amou
std::size_t OutputSetContextForInputSelectionV1::num_outputs_nochange() const
{
const bool need_additional_output_no_change{
need_additional_output(m_num_outputs, m_output_ephemeral_pubkeys_are_unique, m_self_send_output_types, 0)
need_additional_output(m_num_outputs, m_output_ephemeral_pubkeys_are_unique,
m_self_send_output_types, m_self_send_output_is_hidden, 0)
};

return m_num_outputs + (need_additional_output_no_change ? 1 : 0);
Expand All @@ -130,7 +137,8 @@ std::size_t OutputSetContextForInputSelectionV1::num_outputs_nochange() const
std::size_t OutputSetContextForInputSelectionV1::num_outputs_withchange() const
{
const bool need_additional_output_with_change{
need_additional_output(m_num_outputs, m_output_ephemeral_pubkeys_are_unique, m_self_send_output_types, 1)
need_additional_output(m_num_outputs, m_output_ephemeral_pubkeys_are_unique,
m_self_send_output_types, m_self_send_output_is_hidden, 1)
};

return m_num_outputs + (need_additional_output_with_change ? 1 : 0);
Expand Down
1 change: 1 addition & 0 deletions src/seraphis_impl/tx_input_selection_output_context_v1.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class OutputSetContextForInputSelectionV1 final : public OutputSetContextForInpu
std::size_t m_num_outputs;
bool m_output_ephemeral_pubkeys_are_unique;
std::vector<jamtis::JamtisSelfSendType> m_self_send_output_types;
std::vector<bool> m_self_send_output_is_hidden;
boost::multiprecision::uint128_t m_total_output_amount;
};

Expand Down
75 changes: 47 additions & 28 deletions src/seraphis_main/sp_knowledge_proof_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,22 +377,31 @@ void make_enote_ownership_proof_v1_sender_selfsend(const crypto::x25519_pubkey &
const rct::key &onetime_address,
EnoteOwnershipProofV1 &proof_out)
{
// 1. prepare the sender-receiver secret
// 1. helper privkeys
crypto::x25519_secret_key d_filter_assist;
jamtis::make_jamtis_filterassist_key(s_view_balance, d_filter_assist);

// 2. prepare X_fa
crypto::x25519_pubkey x_fa;
crypto::x25519_scmul_key(d_filter_assist, enote_ephemeral_pubkey, x_fa);

// 3. prepare the sender-receiver secret
rct::key sender_receiver_secret;
jamtis::make_jamtis_sender_receiver_secret_selfsend(s_view_balance,
jamtis::make_jamtis_sender_receiver_secret(x_fa.data,
reinterpret_cast<jamtis::secret256_ptr_t>(s_view_balance.data),
reinterpret_cast<jamtis::secret256_ptr_t>(s_view_balance.data),
enote_ephemeral_pubkey,
input_context,
jamtis::is_jamtis_auxiliary_selfsend_type(self_send_type),
sender_receiver_secret);

// 2. complete the proof
// 4. complete the proof
make_enote_ownership_proof_v1(jamtis_address_spend_key,
sender_receiver_secret,
amount_commitment,
onetime_address,
proof_out);

// 3. verify that the proof was created successfully
// 5. verify that the proof was created successfully
// - will fail if the enote is a jamtis plain type
CHECK_AND_ASSERT_THROW_MES(verify_enote_ownership_proof_v1(proof_out, amount_commitment, onetime_address),
"make enote ownership proof (v1 sender selfsend): failed to make proof.");
Expand All @@ -404,38 +413,48 @@ void make_enote_ownership_proof_v1_receiver(const SpEnoteRecordV1 &enote_record,
EnoteOwnershipProofV1 &proof_out)
{
// 1. helper privkeys
crypto::x25519_secret_key d_view_received;
crypto::x25519_secret_key d_unlock_received;
crypto::x25519_secret_key d_identify_received;
crypto::x25519_secret_key d_filter_assist;
crypto::secret_key s_generate_address;
jamtis::make_jamtis_viewreceived_key(s_view_balance, d_view_received);
jamtis::make_jamtis_generateaddress_secret(d_view_received, s_generate_address);
jamtis::make_jamtis_unlockreceived_key(s_view_balance, d_unlock_received);
jamtis::make_jamtis_identifyreceived_key(s_view_balance, d_identify_received);
jamtis::make_jamtis_filterassist_key(s_view_balance, d_filter_assist);
jamtis::make_jamtis_generateaddress_secret(s_view_balance, s_generate_address);

// 2. get the owning address's spendkey K^j_s
rct::key jamtis_address_spend_key;
jamtis::make_jamtis_address_spend_key(jamtis_spend_pubkey,
jamtis::make_jamtis_address_spend_key_sp(jamtis_spend_pubkey,
s_generate_address,
enote_record.address_index,
jamtis_address_spend_key);

// 3. get address privkey d^j_a
crypto::x25519_secret_key address_privkey;
jamtis::make_jamtis_address_privkey(jamtis_spend_pubkey,
s_generate_address,
enote_record.address_index,
address_privkey);

// 3. prepare the sender-receiver secret
rct::key sender_receiver_secret;
jamtis::JamtisSelfSendType self_send_type;
// 4. prepare plain X_fa, X_ir, X_ur
crypto::x25519_pubkey x_fa;
crypto::x25519_scmul_key(d_filter_assist, enote_record.enote_ephemeral_pubkey, x_fa);

if (jamtis::try_get_jamtis_self_send_type(enote_record.type, self_send_type))
{
jamtis::make_jamtis_sender_receiver_secret_selfsend(s_view_balance,
enote_record.enote_ephemeral_pubkey,
enote_record.input_context,
jamtis::is_jamtis_auxiliary_selfsend_type(self_send_type),
sender_receiver_secret);
}
else
{
jamtis::make_jamtis_sender_receiver_secret_plain(d_view_received,
enote_record.enote_ephemeral_pubkey,
enote_record.enote_ephemeral_pubkey,
enote_record.input_context,
sender_receiver_secret);
}
crypto::x25519_pubkey x_ir;
crypto::x25519_scmul_key(d_identify_received, enote_record.enote_ephemeral_pubkey, x_ir);

crypto::x25519_pubkey x_ur;
crypto::x25519_invmul_key({d_unlock_received, address_privkey}, enote_record.enote_ephemeral_pubkey, x_ur);

// 5. prepare the sender-receiver secret
const bool is_plain{enote_record.type == jamtis::JamtisEnoteType::PLAIN};
rct::key sender_receiver_secret;
jamtis::make_jamtis_sender_receiver_secret(x_fa.data,
is_plain ? x_ir.data : reinterpret_cast<jamtis::secret256_ptr_t>(s_view_balance.data),
is_plain ? x_ur.data : reinterpret_cast<jamtis::secret256_ptr_t>(s_view_balance.data),
enote_record.enote_ephemeral_pubkey,
enote_record.input_context,
sender_receiver_secret);

// 4. complete the proof
make_enote_ownership_proof_v1(jamtis_address_spend_key,
Expand Down
8 changes: 4 additions & 4 deletions src/seraphis_main/tx_builder_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ void get_enote_v1(const SpOutputProposalV1 &proposal, SpEnoteV1 &enote_out)
rct::commit(amount_ref(proposal), rct::sk2rct(proposal.core.amount_blinding_factor));

// enote misc. details
enote_out.encoded_amount = proposal.encoded_amount;
enote_out.addr_tag_enc = proposal.addr_tag_enc;
enote_out.view_tag = proposal.view_tag;
enote_out.encrypted_amount = proposal.encrypted_amount;
enote_out.addr_tag_enc = proposal.addr_tag_enc;
enote_out.view_tag = proposal.view_tag;
}
//-------------------------------------------------------------------------------------------------------------------
void get_coinbase_output_proposals_v1(const SpCoinbaseTxProposalV1 &tx_proposal,
Expand Down Expand Up @@ -295,7 +295,7 @@ SpOutputProposalV1 gen_sp_output_proposal_v1(const rct::xmr_amount amount,
temp.core = gen_sp_output_proposal_core(amount);

temp.enote_ephemeral_pubkey = crypto::x25519_pubkey_gen();
crypto::rand(sizeof(temp.encoded_amount), temp.encoded_amount.bytes);
crypto::rand(sizeof(temp.encrypted_amount), temp.encrypted_amount.bytes);
crypto::rand(sizeof(temp.addr_tag_enc), temp.addr_tag_enc.bytes);
temp.view_tag = jamtis::gen_view_tag();

Expand Down
Loading

0 comments on commit 66e41c1

Please sign in to comment.