Skip to content

Commit

Permalink
Merge pull request #12 from seraphis-migration/seraphis_lib
Browse files Browse the repository at this point in the history
Seraphis wallet: Update to latest Seraphis library
  • Loading branch information
rbrunner7 authored Oct 25, 2023
2 parents 9f0a03c + f5915c6 commit 702e5b1
Show file tree
Hide file tree
Showing 8 changed files with 340 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/common/container_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,12 @@ inline auto compare_func(ComparisonOpT comparison_op_func)
}
/// test if a container is sorted and unique according to a comparison criteria (defaults to operator<)
/// NOTE: ComparisonOpT must establish 'strict weak ordering' https://en.cppreference.com/w/cpp/named_req/Compare
/// NOTE: T::const_iterator must satisfy LegacyForwardIterator https://en.cppreference.com/w/cpp/named_req/ForwardIterator
template <typename T, typename ComparisonOpT = std::less<typename T::value_type>>
bool is_sorted_and_unique(const T &container, ComparisonOpT comparison_op = ComparisonOpT{})
{
using ValueT = typename T::value_type;
using ConstIt = typename T::const_iterator;
static_assert(
std::is_same<
bool,
Expand All @@ -90,17 +92,20 @@ bool is_sorted_and_unique(const T &container, ComparisonOpT comparison_op = Comp
"invalid callable - expected callable in form bool(ValueT, ValueT)"
);

if (!std::is_sorted(container.begin(), container.end(), comparison_op))
return false;

if (std::adjacent_find(container.begin(),
container.end(),
[comparison_op = std::move(comparison_op)](const ValueT &a, const ValueT &b) -> bool
{
return !comparison_op(a, b) && !comparison_op(b, a);
})
!= container.end())
return false;
const ConstIt end = container.cend();

ConstIt it_a = container.cbegin();
if (it_a == end)
return true;

ConstIt it_b = it_a;
it_b++;

for (; it_b != end; it_a = it_b++)
{
if (!comparison_op(*it_a, *it_b))
return false;
}

return true;
}
Expand Down
13 changes: 13 additions & 0 deletions src/seraphis_core/jamtis_payment_proposal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,19 @@ static void get_output_proposal_address_parts_v1(const rct::key &q,
}
//-------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------
/// equality operators
bool operator==(const JamtisPaymentProposalV1 a, const JamtisPaymentProposalV1 b)
{
return a.destination == b.destination && a.amount == b.amount &&
a.enote_ephemeral_privkey == b.enote_ephemeral_privkey && a.partial_memo == b.partial_memo;
}
//-------------------------------------------------------------------------------------------------------------------
bool operator==(const JamtisPaymentProposalSelfSendV1 a, const JamtisPaymentProposalSelfSendV1 b)
{
return a.destination == b.destination && a.amount == b.amount && a.type == b.type &&
a.enote_ephemeral_privkey == b.enote_ephemeral_privkey && a.partial_memo == b.partial_memo;
}
//-------------------------------------------------------------------------------------------------------------------
void get_enote_ephemeral_pubkey(const JamtisPaymentProposalV1 &proposal,
crypto::x25519_pubkey &enote_ephemeral_pubkey_out)
{
Expand Down
4 changes: 4 additions & 0 deletions src/seraphis_core/jamtis_payment_proposal.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ struct JamtisPaymentProposalSelfSendV1 final
TxExtra partial_memo;
};

/// equality operators
bool operator==(const JamtisPaymentProposalV1 a, const JamtisPaymentProposalV1 b);
bool operator==(const JamtisPaymentProposalSelfSendV1 a, const JamtisPaymentProposalSelfSendV1 b);

/**
* brief: get_enote_ephemeral_pubkey - get the proposal's enote ephemeral pubkey xK_e
* param: proposal -
Expand Down
48 changes: 48 additions & 0 deletions src/seraphis_impl/serialization_demo_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ namespace sp
{
namespace serialization
{
/// serializable jamtis::address_index_t
struct ser_address_index_t final
{
unsigned char bytes[sizeof(jamtis::address_index_t)];
};

/// serializable jamtis::address_tag_t
struct ser_address_tag_t final
Expand Down Expand Up @@ -433,10 +438,53 @@ struct ser_JamtisDestinationV1 final
END_SERIALIZE()
};

/// serializable JamtisPaymentProposalV1
struct ser_JamtisPaymentProposalV1 final
{
/// destination address
ser_JamtisDestinationV1 destination;
/// amount
rct::xmr_amount amount;
/// enote ephemeral private key
crypto::x25519_scalar enote_ephemeral_privkey;
/// memo elements
std::vector<unsigned char> partial_memo;

BEGIN_SERIALIZE()
FIELD(destination)
FIELD(amount)
FIELD(enote_ephemeral_privkey)
FIELD(partial_memo)
END_SERIALIZE()
};

/// serializable JamtisPaymentProposalV1
struct ser_JamtisPaymentProposalSelfSendV1 final
{
/// destination address
ser_JamtisDestinationV1 destination;
/// amount
rct::xmr_amount amount;
/// selfspend type
unsigned char type;
/// enote ephemeral private key
crypto::x25519_scalar enote_ephemeral_privkey;
/// memo elements
std::vector<unsigned char> partial_memo;

BEGIN_SERIALIZE()
FIELD(destination)
FIELD(amount)
FIELD(type)
FIELD(enote_ephemeral_privkey)
FIELD(partial_memo)
END_SERIALIZE()
};

} //namespace serialization
} //namespace sp

BLOB_SERIALIZER(sp::serialization::ser_address_index_t);
BLOB_SERIALIZER(sp::serialization::ser_address_tag_t);
BLOB_SERIALIZER(sp::serialization::ser_encrypted_address_tag_t);
BLOB_SERIALIZER(sp::serialization::ser_encoded_amount_t);
37 changes: 37 additions & 0 deletions src/seraphis_impl/serialization_demo_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#include "seraphis_core/binned_reference_set.h"
#include "seraphis_core/discretized_fee.h"
#include "seraphis_core/jamtis_destination.h"
#include "seraphis_core/jamtis_payment_proposal.h"
#include "seraphis_core/jamtis_support_types.h"
#include "seraphis_crypto/bulletproofs_plus2.h"
#include "seraphis_crypto/grootle.h"
#include "seraphis_crypto/sp_composition_proof.h"
Expand Down Expand Up @@ -223,6 +225,23 @@ void make_serializable_grootle_proof(const GrootleProof &grootle, ser_GrootlePro
serializable_grootle_out.z = grootle.z;
}
//-------------------------------------------------------------------------------------------------------------------
void make_serializable_jamtis_payment_proposal_v1(const jamtis::JamtisPaymentProposalV1 &payment, ser_JamtisPaymentProposalV1 &serializable_payment_out)
{
make_serializable_sp_destination_v1(payment.destination, serializable_payment_out.destination);
serializable_payment_out.amount = payment.amount;
serializable_payment_out.enote_ephemeral_privkey = payment.enote_ephemeral_privkey;
serializable_payment_out.partial_memo = payment.partial_memo;
}
//-------------------------------------------------------------------------------------------------------------------
void make_serializable_jamtis_payment_proposal_selfsend_v1(const jamtis::JamtisPaymentProposalSelfSendV1 &payment, ser_JamtisPaymentProposalSelfSendV1 &serializable_payment_out)
{
make_serializable_sp_destination_v1(payment.destination, serializable_payment_out.destination);
serializable_payment_out.amount = payment.amount;
serializable_payment_out.type = static_cast<unsigned char>(payment.type);
serializable_payment_out.enote_ephemeral_privkey = payment.enote_ephemeral_privkey;
serializable_payment_out.partial_memo = payment.partial_memo;
}
//-------------------------------------------------------------------------------------------------------------------
void make_serializable_sp_composition_proof(const SpCompositionProof &proof,
ser_SpCompositionProof &serializable_proof_out)
{
Expand Down Expand Up @@ -435,6 +454,23 @@ void recover_grootle_proof(ser_GrootleProof &serializable_grootle_in, GrootlePro
grootle_out.z = serializable_grootle_in.z;
}
//-------------------------------------------------------------------------------------------------------------------
void recover_jamtis_payment_proposal_v1(const ser_JamtisPaymentProposalV1 &serializable_payment, jamtis::JamtisPaymentProposalV1 &payment_out)
{
recover_sp_destination_v1(serializable_payment.destination, payment_out.destination);
payment_out.amount = serializable_payment.amount;
payment_out.enote_ephemeral_privkey = serializable_payment.enote_ephemeral_privkey;
payment_out.partial_memo = serializable_payment.partial_memo;
}
//-------------------------------------------------------------------------------------------------------------------
void recover_jamtis_payment_proposal_selfsend_v1(const ser_JamtisPaymentProposalSelfSendV1 &serializable_payment, jamtis::JamtisPaymentProposalSelfSendV1 &payment_out)
{
recover_sp_destination_v1(serializable_payment.destination, payment_out.destination);
payment_out.amount = serializable_payment.amount;
payment_out.type = static_cast<jamtis::JamtisSelfSendType>(serializable_payment.type);
payment_out.enote_ephemeral_privkey = serializable_payment.enote_ephemeral_privkey;
payment_out.partial_memo = serializable_payment.partial_memo;
}
//-------------------------------------------------------------------------------------------------------------------
void recover_sp_composition_proof(const ser_SpCompositionProof &serializable_proof, SpCompositionProof &proof_out)
{
proof_out.c = serializable_proof.c;
Expand Down Expand Up @@ -701,5 +737,6 @@ void recover_sp_destination_v1(const ser_JamtisDestinationV1 &serializable_desti
sizeof(serializable_destination.addr_tag));
}
//-------------------------------------------------------------------------------------------------------------------

} //namespace serialization
} //namespace sp
4 changes: 4 additions & 0 deletions src/seraphis_impl/serialization_demo_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ bool try_get_serializable(epee::span<const std::uint8_t> serialized, Serializabl
void make_serializable_bpp2(const BulletproofPlus2 &bpp2, ser_BulletproofPlus2_PARTIAL &serializable_bpp2_out);
void make_serializable_clsag(const rct::clsag &clsag, ser_clsag_PARTIAL &serializable_clsag_out);
void make_serializable_grootle_proof(const GrootleProof &grootle, ser_GrootleProof &serializable_grootle_out);
void make_serializable_jamtis_payment_proposal_v1(const jamtis::JamtisPaymentProposalV1 &payment, ser_JamtisPaymentProposalV1 &serializable_payment_out);
void make_serializable_jamtis_payment_proposal_selfsend_v1(const jamtis::JamtisPaymentProposalSelfSendV1 &payment, ser_JamtisPaymentProposalSelfSendV1 &serializable_payment_out);
void make_serializable_sp_composition_proof(const SpCompositionProof &proof,
ser_SpCompositionProof &serializable_proof_out);
void make_serializable_sp_coinbase_enote_core(const SpCoinbaseEnoteCore &enote,
Expand Down Expand Up @@ -148,6 +150,8 @@ void recover_bpp2(ser_BulletproofPlus2_PARTIAL &serializable_bpp2_in,
BulletproofPlus2 &bpp2_out);
void recover_clsag(ser_clsag_PARTIAL &serializable_clsag_in, const crypto::key_image &key_image, rct::clsag &clsag_out);
void recover_grootle_proof(ser_GrootleProof &serializable_grootle_in, GrootleProof &grootle_out);
void recover_jamtis_payment_proposal_v1(const ser_JamtisPaymentProposalV1 &serializable_payment, jamtis::JamtisPaymentProposalV1 &payment_out);
void recover_jamtis_payment_proposal_selfsend_v1(const ser_JamtisPaymentProposalSelfSendV1 &serializable_payment, jamtis::JamtisPaymentProposalSelfSendV1 &payment_out);
void recover_sp_composition_proof(const ser_SpCompositionProof &serializable_proof, SpCompositionProof &proof_out);
void recover_sp_coinbase_enote_core(const ser_SpCoinbaseEnoteCore &serializable_enote, SpCoinbaseEnoteCore &enote_out);
void recover_sp_enote_core(const ser_SpEnoteCore &serializable_enote, SpEnoteCore &enote_out);
Expand Down
Loading

0 comments on commit 702e5b1

Please sign in to comment.