Skip to content

Commit 2d978ea

Browse files
committed
enote equality operators
1 parent ee3a869 commit 2d978ea

File tree

5 files changed

+94
-17
lines changed

5 files changed

+94
-17
lines changed

src/carrot_core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ set(carrot_core_sources
3030
account_secrets.cpp
3131
address_utils.cpp
3232
carrot_enote_scan.cpp
33+
carrot_enote_types.cpp
3334
core_types.cpp
3435
destination.cpp
3536
device_ram_borrowed.cpp

src/carrot_core/address_utils.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,31 +55,31 @@ void make_carrot_index_extension_generator(const crypto::secret_key &s_generate_
5555
derive_bytes_32(transcript.data(), transcript.size(), &s_generate_address, &address_generator_out);
5656
}
5757
//-------------------------------------------------------------------------------------------------------------------
58-
void make_carrot_subaddress_scalar(const crypto::public_key &spend_pubkey,
58+
void make_carrot_subaddress_scalar(const crypto::public_key &account_spend_pubkey,
5959
const crypto::secret_key &s_address_generator,
6060
const std::uint32_t j_major,
6161
const std::uint32_t j_minor,
6262
crypto::secret_key &subaddress_scalar_out)
6363
{
6464
// k^j_subscal = H_n(K_s, j_major, j_minor, s^j_gen)
6565
const auto transcript = sp::make_fixed_transcript<CARROT_DOMAIN_SEP_SUBADDRESS_SCALAR>(
66-
spend_pubkey, j_major, j_minor);
66+
account_spend_pubkey, j_major, j_minor);
6767
derive_scalar(transcript.data(), transcript.size(), &s_address_generator, subaddress_scalar_out.data);
6868
}
6969
//-------------------------------------------------------------------------------------------------------------------
70-
void make_carrot_address_spend_pubkey(const crypto::public_key &spend_pubkey,
70+
void make_carrot_address_spend_pubkey(const crypto::public_key &account_spend_pubkey,
7171
const crypto::secret_key &s_generate_address,
7272
const std::uint32_t j_major,
7373
const std::uint32_t j_minor,
7474
crypto::public_key &address_spend_pubkey_out)
7575
{
7676
// k^j_subscal = H_n(K_s, j_major, j_minor, s^j_gen)
7777
crypto::secret_key subaddress_scalar;
78-
make_carrot_subaddress_scalar(spend_pubkey, s_generate_address, j_major, j_minor, subaddress_scalar);
78+
make_carrot_subaddress_scalar(account_spend_pubkey, s_generate_address, j_major, j_minor, subaddress_scalar);
7979

8080
// K^j_s = k^j_subscal * K_s
8181
address_spend_pubkey_out = rct::rct2pk(rct::scalarmultKey(
82-
rct::pk2rct(spend_pubkey), rct::sk2rct(subaddress_scalar)));
82+
rct::pk2rct(account_spend_pubkey), rct::sk2rct(subaddress_scalar)));
8383
}
8484
//-------------------------------------------------------------------------------------------------------------------
8585
} //namespace carrot

src/carrot_core/address_utils.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,27 +66,27 @@ void make_carrot_index_extension_generator(const crypto::secret_key &s_generate_
6666
/**
6767
* brief: make_carrot_address_privkey - d^j_a
6868
* k^j_subscal = H_n(K_s, j_major, j_minor, s^j_gen)
69-
* param: spend_pubkey - K_s = k_vb X + k_m U
69+
* param: account_spend_pubkey - K_s = k_vb X + k_m U
7070
* param: s_address_generator - s^j_gen
7171
* param: j_major -
7272
* param: j_minor -
7373
* outparam: subaddress_scalar_out - k^j_subscal
7474
*/
75-
void make_carrot_subaddress_scalar(const crypto::public_key &spend_pubkey,
75+
void make_carrot_subaddress_scalar(const crypto::public_key &account_spend_pubkey,
7676
const crypto::secret_key &s_address_generator,
7777
const std::uint32_t j_major,
7878
const std::uint32_t j_minor,
7979
crypto::secret_key &subaddress_scalar_out);
8080
/**
8181
* brief: make_carrot_address_spend_pubkey - K^j_s
8282
* K^j_s = k^j_subscal * K_s
83-
* param: spend_pubkey - K_s = k_gi G + k_ps U
83+
* param: account_spend_pubkey - K_s = k_gi G + k_ps U
8484
* param: s_generate_address - s_ga
8585
* param: j_major -
8686
* param: j_minor -
8787
* outparam: address_spend_pubkey_out - K^j_s
8888
*/
89-
void make_carrot_address_spend_pubkey(const crypto::public_key &spend_pubkey,
89+
void make_carrot_address_spend_pubkey(const crypto::public_key &account_spend_pubkey,
9090
const crypto::secret_key &s_generate_address,
9191
const std::uint32_t j_major,
9292
const std::uint32_t j_minor,
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Copyright (c) 2024, The Monero Project
2+
//
3+
// All rights reserved.
4+
//
5+
// Redistribution and use in source and binary forms, with or without modification, are
6+
// permitted provided that the following conditions are met:
7+
//
8+
// 1. Redistributions of source code must retain the above copyright notice, this list of
9+
// conditions and the following disclaimer.
10+
//
11+
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
12+
// of conditions and the following disclaimer in the documentation and/or other
13+
// materials provided with the distribution.
14+
//
15+
// 3. Neither the name of the copyright holder nor the names of its contributors may be
16+
// used to endorse or promote products derived from this software without specific
17+
// prior written permission.
18+
//
19+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20+
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21+
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22+
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24+
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26+
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
27+
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
29+
// Utilities for scanning carrot enotes
30+
31+
//paired header
32+
#include "carrot_enote_types.h"
33+
34+
//local headers
35+
36+
//third party headers
37+
38+
//standard headers
39+
40+
/*
41+
onetime address
42+
// - amount commitment
43+
// - encrypted amount
44+
// - encrypted janus anchor
45+
// - view tag
46+
// - ephemeral pubkey
47+
// - tx first key image*/
48+
49+
namespace carrot
50+
{
51+
//-------------------------------------------------------------------------------------------------------------------
52+
bool operator==(const CarrotEnoteV1 &a, const CarrotEnoteV1 &b)
53+
{
54+
return a.onetime_address == b.onetime_address &&
55+
a.amount_commitment == b.amount_commitment &&
56+
a.amount_enc == b.amount_enc &&
57+
a.anchor_enc == b.anchor_enc &&
58+
a.view_tag == b.view_tag &&
59+
a.tx_first_key_image == b.tx_first_key_image &&
60+
memcmp(a.enote_ephemeral_pubkey.data, b.enote_ephemeral_pubkey.data, sizeof(mx25519_pubkey)) == 0;
61+
}
62+
//-------------------------------------------------------------------------------------------------------------------
63+
bool operator==(const CarrotCoinbaseEnoteV1 &a, const CarrotCoinbaseEnoteV1 &b)
64+
{
65+
return a.onetime_address == b.onetime_address &&
66+
a.amount == b.amount &&
67+
a.anchor_enc == b.anchor_enc &&
68+
a.view_tag == b.view_tag &&
69+
a.block_index == b.block_index &&
70+
memcmp(a.enote_ephemeral_pubkey.data, b.enote_ephemeral_pubkey.data, sizeof(mx25519_pubkey)) == 0;
71+
}
72+
//-------------------------------------------------------------------------------------------------------------------
73+
} //namespace carrot

src/carrot_core/carrot_enote_types.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ namespace carrot
5252
// - encrypted amount
5353
// - encrypted janus anchor
5454
// - view tag
55+
// - ephemeral pubkey
56+
// - tx first key image
5557
///
5658
struct CarrotEnoteV1 final
5759
{
@@ -71,12 +73,18 @@ struct CarrotEnoteV1 final
7173
crypto::key_image tx_first_key_image;
7274
};
7375

76+
/// equality operators
77+
bool operator==(const CarrotEnoteV1 &a, const CarrotEnoteV1 &b);
78+
static inline bool operator!=(const CarrotEnoteV1 &a, const CarrotEnoteV1 &b) { return !(a == b); }
79+
7480
////
7581
// CarrotCoinbaseEnoteV1
7682
// - onetime address
7783
// - cleartext amount
7884
// - encrypted janus anchor
7985
// - view tag
86+
// - ephemeral pubkey
87+
// - block index
8088
///
8189
struct CarrotCoinbaseEnoteV1 final
8290
{
@@ -94,13 +102,8 @@ struct CarrotCoinbaseEnoteV1 final
94102
std::uint64_t block_index;
95103
};
96104

97-
/**
98-
* brief: gen_carrot_enote_v1() - generate a carrot v1 enote (all random)
99-
*/
100-
CarrotEnoteV1 gen_carrot_enote_v1();
101-
/**
102-
* brief: gen_carrot_coinbase_enote_v1() - generate a carrot coinbase v1 enote (all random)
103-
*/
104-
CarrotCoinbaseEnoteV1 gen_carrot_coinbase_enote_v1();
105+
/// equality operators
106+
bool operator==(const CarrotCoinbaseEnoteV1 &a, const CarrotCoinbaseEnoteV1 &b);
107+
static inline bool operator!=(const CarrotCoinbaseEnoteV1 &a, const CarrotCoinbaseEnoteV1 &b) { return !(a == b); }
105108

106109
} //namespace carrot

0 commit comments

Comments
 (0)