Skip to content

Commit

Permalink
make JamtisDestinationV1 serializable (monero-project#11)
Browse files Browse the repository at this point in the history
make JamtisDestinationV1 serializable 

---------

Co-authored-by: DangerousFreedom <monero-inflation-checker@protonmail.com>
  • Loading branch information
2 people authored and UkoeHB committed Mar 6, 2024
1 parent fc3fa5f commit e86d813
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 3 deletions.
31 changes: 30 additions & 1 deletion src/seraphis_impl/serialization_demo_types.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022, The Monero Project
// Copyright (c) 2023, The Monero Project
//
// All rights reserved.
//
Expand Down Expand Up @@ -36,6 +36,7 @@
#include "ringct/rctTypes.h"
#include "seraphis_core/binned_reference_set.h"
#include "seraphis_core/discretized_fee.h"
#include "seraphis_core/jamtis_destination.h"
#include "seraphis_core/jamtis_support_types.h"
#include "serialization/containers.h"
#include "serialization/crypto.h"
Expand All @@ -56,6 +57,12 @@ namespace sp
namespace serialization
{

/// serializable jamtis::address_tag_t
struct ser_address_tag_t final
{
unsigned char bytes[sizeof(jamtis::address_tag_t)];
};

/// serializable jamtis::encrypted_address_tag_t
struct ser_encrypted_address_tag_t final
{
Expand Down Expand Up @@ -406,8 +413,30 @@ struct ser_SpTxSquashedV1 final
END_SERIALIZE()
};

/// serializable JamtisDestinationV1
struct ser_JamtisDestinationV1 final
{
/// K_1 (address spend key)
rct::key addr_K1;
/// xK_2 (address view key)
crypto::x25519_pubkey addr_K2;
/// xK_3 (DH base key)
crypto::x25519_pubkey addr_K3;
/// addr_tag
ser_address_tag_t addr_tag;

BEGIN_SERIALIZE()
FIELD(addr_K1)
FIELD(addr_K2)
FIELD(addr_K3)
FIELD(addr_tag) static_assert(sizeof(addr_tag) == sizeof(jamtis::address_tag_t), "");
END_SERIALIZE()
};


} //namespace serialization
} //namespace sp

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);
23 changes: 22 additions & 1 deletion src/seraphis_impl/serialization_demo_utils.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022, The Monero Project
// Copyright (c) 2023, The Monero Project
//
// All rights reserved.
//
Expand Down Expand Up @@ -36,6 +36,7 @@
#include "ringct/rctTypes.h"
#include "seraphis_core/binned_reference_set.h"
#include "seraphis_core/discretized_fee.h"
#include "seraphis_core/jamtis_destination.h"
#include "seraphis_crypto/bulletproofs_plus2.h"
#include "seraphis_crypto/grootle.h"
#include "seraphis_crypto/sp_composition_proof.h"
Expand Down Expand Up @@ -389,6 +390,16 @@ void make_serializable_sp_tx_squashed_v1(const SpTxSquashedV1 &tx, ser_SpTxSquas
make_serializable_discretized_fee(tx.tx_fee, serializable_tx_out.tx_fee);
}
//-------------------------------------------------------------------------------------------------------------------
void make_serializable_sp_destination_v1(const jamtis::JamtisDestinationV1 &dest, ser_JamtisDestinationV1 &serializable_dest_out)
{
serializable_dest_out.addr_K1 = dest.addr_K1;
serializable_dest_out.addr_K2 = dest.addr_K2;
serializable_dest_out.addr_K3 = dest.addr_K3;
memcpy(serializable_dest_out.addr_tag.bytes,
dest.addr_tag.bytes,
sizeof(dest.addr_tag));
}
//-------------------------------------------------------------------------------------------------------------------

//-------------------------------------------------------------------------------------------------------------------
void recover_bpp2(ser_BulletproofPlus2_PARTIAL &serializable_bpp2_in,
Expand Down Expand Up @@ -680,5 +691,15 @@ bool try_recover_sp_tx_squashed_v1(ser_SpTxSquashedV1 &serializable_tx_in, SpTxS
return true;
}
//-------------------------------------------------------------------------------------------------------------------
void recover_sp_destination_v1(const ser_JamtisDestinationV1 &serializable_destination, jamtis::JamtisDestinationV1 &dest_out)
{
dest_out.addr_K1 = serializable_destination.addr_K1;
dest_out.addr_K2 = serializable_destination.addr_K2;
dest_out.addr_K3 = serializable_destination.addr_K3;
memcpy(dest_out.addr_tag.bytes,
serializable_destination.addr_tag.bytes,
sizeof(serializable_destination.addr_tag));
}
//-------------------------------------------------------------------------------------------------------------------
} //namespace serialization
} //namespace sp
5 changes: 4 additions & 1 deletion src/seraphis_impl/serialization_demo_utils.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022, The Monero Project
// Copyright (c) 2023, The Monero Project
//
// All rights reserved.
//
Expand Down Expand Up @@ -38,6 +38,7 @@
#include "ringct/rctTypes.h"
#include "seraphis_core/binned_reference_set.h"
#include "seraphis_core/discretized_fee.h"
#include "seraphis_core/jamtis_destination.h"
#include "seraphis_core/sp_core_types.h"
#include "seraphis_impl/serialization_demo_types.h"
#include "seraphis_main/tx_component_types.h"
Expand Down Expand Up @@ -135,6 +136,7 @@ void make_serializable_discretized_fee(const DiscretizedFee discretized_fee,
unsigned char &serializable_discretized_fee_out);
void make_serializable_sp_tx_coinbase_v1(const SpTxCoinbaseV1 &tx, ser_SpTxCoinbaseV1 &serializable_tx_out);
void make_serializable_sp_tx_squashed_v1(const SpTxSquashedV1 &tx, ser_SpTxSquashedV1 &serializable_tx_out);
void make_serializable_sp_destination_v1(const jamtis::JamtisDestinationV1 &dest, ser_JamtisDestinationV1 &serializable_dest_out);
/**
* brief: recover_* - convert a serializable object back into its normal object parent
* param: serializable_object_in - serializable object to be consumed (destructive: may be left in an unusable state)
Expand Down Expand Up @@ -186,6 +188,7 @@ bool try_recover_sp_tx_squashed_v1(ser_SpTxSquashedV1 &serializable_tx_in,
const std::size_t sp_ref_set_decomp_m,
SpTxSquashedV1 &tx_out);
bool try_recover_sp_tx_squashed_v1(ser_SpTxSquashedV1 &serializable_tx_in, SpTxSquashedV1 &tx_out);
void recover_sp_destination_v1(const ser_JamtisDestinationV1 &serializable_destination, jamtis::JamtisDestinationV1 &dest_out);

} //namespace serialization
} //namespace sp

0 comments on commit e86d813

Please sign in to comment.