Skip to content

Commit d86ae71

Browse files
committed
carrot+fcmp: hot/cold wallet support
1 parent 56a3e8d commit d86ae71

30 files changed

Lines changed: 3068 additions & 1172 deletions

src/carrot_core/config.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,10 @@ static constexpr const unsigned int CARROT_MIN_TX_OUTPUTS = 2;
7171
static constexpr const unsigned int CARROT_MAX_TX_OUTPUTS = 8;
7272
static constexpr const unsigned int CARROT_MIN_TX_INPUTS = 1;
7373
static constexpr const unsigned int CARROT_MAX_TX_INPUTS = 8;
74+
75+
// Downstream hot/cold protocol domain separators
76+
static constexpr const unsigned char HOT_COLD_DOMAIN_SEP_NORMAL_JANUS_ANCHOR[] = "Carrot Hot-cold normal janus anchor";
77+
static constexpr const unsigned char HOT_COLD_DOMAIN_SEP_SPECIAL_EPHEM[] = "Carrot Hot-cold special ephemeral privkey";
78+
static constexpr const unsigned char HOT_COLD_DOMAIN_SEP_DUMMY_PID[] = "Carrot Hot-cold dummy encrypted payment id";
79+
static constexpr const unsigned char HOT_COLD_DOMAIN_SEP_RERANDOMIZATION[] = "Carrot Hot-cold rerandomization scalar";
7480
} //namespace carrot

src/carrot_impl/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
set(carrot_impl_sources
3030
address_device_ram_borrowed.cpp
31-
address_utils_compat.cpp
31+
address_utils.cpp
3232
format_utils.cpp
3333
input_selection.cpp
3434
key_image_device_composed.cpp

src/carrot_impl/address_device_ram_borrowed.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include "address_device_ram_borrowed.h"
3131

3232
//local headers
33-
#include "address_utils_compat.h"
33+
#include "address_utils.h"
3434
#include "carrot_core/address_utils.h"
3535

3636
//third party headers
Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@
2727
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828

2929
//paired header
30-
#include "address_utils_compat.h"
30+
#include "address_utils.h"
3131

3232
//local headers
33+
#include "address_device.h"
34+
#include "crypto/generators.h"
3335
#include "cryptonote_config.h"
3436
#include "int-util.h"
3537
#include "ringct/rctOps.h"
@@ -87,4 +89,39 @@ void make_legacy_subaddress_spend_pubkey(const crypto::secret_key &legacy_subadd
8789
legacy_subaddress_spend_pubkey_out = rct::rct2pk(res_k);
8890
}
8991
//-------------------------------------------------------------------------------------------------------------------
92+
void make_legacy_subaddress_spend_pubkey(const cryptonote_hierarchy_address_device &addr_dev,
93+
const std::uint32_t major_index,
94+
const std::uint32_t minor_index,
95+
crypto::public_key &legacy_subaddress_spend_pubkey_out)
96+
{
97+
// k^j_subext = ScalarDeriveLegacy("SubAddr" || IntToBytes8(0) || k_v || IntToBytes32(j_major) || IntToBytes32(j_minor))
98+
crypto::secret_key legacy_subaddress_extension;
99+
addr_dev.make_legacy_subaddress_extension(major_index, minor_index, legacy_subaddress_extension);
100+
101+
// K^j_s = K_s + k^j_subext G
102+
make_legacy_subaddress_spend_pubkey(legacy_subaddress_extension,
103+
addr_dev.get_cryptonote_account_spend_pubkey(),
104+
legacy_subaddress_spend_pubkey_out);
105+
}
106+
//-------------------------------------------------------------------------------------------------------------------
107+
void make_legacy_subaddress_pubkeys(const cryptonote_hierarchy_address_device &addr_dev,
108+
const std::uint32_t major_index,
109+
const std::uint32_t minor_index,
110+
crypto::public_key &legacy_subaddress_spend_pubkey_out,
111+
crypto::public_key &legacy_subaddress_view_pubkey_out)
112+
{
113+
// K^j_s = K_s + k^j_subext G
114+
make_legacy_subaddress_spend_pubkey(addr_dev,
115+
major_index,
116+
minor_index,
117+
legacy_subaddress_spend_pubkey_out);
118+
119+
// K^j_base = G if j=0, else K^j_s
120+
const bool is_subaddress = major_index || minor_index;
121+
const crypto::public_key base_pubkey = is_subaddress ? legacy_subaddress_spend_pubkey_out : crypto::get_G();
122+
123+
// K^j_v = k_v K^j_base
124+
addr_dev.view_key_scalar_mult_ed25519(base_pubkey, legacy_subaddress_view_pubkey_out);
125+
}
126+
//-------------------------------------------------------------------------------------------------------------------
90127
} //namespace carrot
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
#include <cstdint>
3838

3939
//forward declarations
40+
namespace carrot
41+
{
42+
struct cryptonote_hierarchy_address_device;
43+
}
4044

4145
namespace carrot
4246
{
@@ -57,9 +61,32 @@ void make_legacy_subaddress_extension(const crypto::secret_key &k_view,
5761
* K^j_s = K_s + k^j_subext G
5862
* param: legacy_subaddress_extension_out - k^j_subext
5963
* param: account_spend_pubkey - K_s
64+
* param: addr_dev -
65+
* param: major_index - j_major
66+
* param: minor_index - j_minor
6067
* outparam: legacy_subaddress_spend_pubkey_out - K^j_s
6168
*/
6269
void make_legacy_subaddress_spend_pubkey(const crypto::secret_key &legacy_subaddress_extension,
6370
const crypto::public_key &account_spend_pubkey,
6471
crypto::public_key &legacy_subaddress_spend_pubkey_out);
72+
void make_legacy_subaddress_spend_pubkey(const cryptonote_hierarchy_address_device &addr_dev,
73+
const std::uint32_t major_index,
74+
const std::uint32_t minor_index,
75+
crypto::public_key &legacy_subaddress_spend_pubkey_out);
76+
/**
77+
* brief: make_legacy_subaddress_spend_pubkey - K^j_s
78+
* K^j_s = K_s + k^j_subext G
79+
* K^j_v = k_v (G if j=0, else K^j_s)
80+
* param: addr_dev
81+
* param: major_index - j_major
82+
* param: minor_index - j_minor
83+
* param: account_spend_pubkey - K_s
84+
* outparam: legacy_subaddress_spend_pubkey_out - K^j_s
85+
* outparam: legacy_subaddress_view_pubkey_out - K^j_v
86+
*/
87+
void make_legacy_subaddress_pubkeys(const cryptonote_hierarchy_address_device &addr_dev,
88+
const std::uint32_t major_index,
89+
const std::uint32_t minor_index,
90+
crypto::public_key &legacy_subaddress_spend_pubkey_out,
91+
crypto::public_key &legacy_subaddress_view_pubkey_out);
6592
} //namespace carrot

src/carrot_impl/carrot_offchain_serialization.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,24 @@ BLOB_SERIALIZER(carrot::encrypted_amount_t);
4848
BLOB_SERIALIZER(carrot::payment_id_t);
4949

5050
BEGIN_SERIALIZE_OBJECT_FN(carrot::CarrotDestinationV1)
51+
static constexpr uint8_t flag_is_subaddr = 1 << 0;
52+
static constexpr uint8_t flag_has_pid = 1 << 1;
53+
uint8_t flags = 0;
54+
if (v.is_subaddress) flags |= flag_is_subaddr;
55+
if (v.payment_id != carrot::null_payment_id) flags |= flag_has_pid;
56+
FIELD(flags)
57+
v.is_subaddress = flags & flag_is_subaddr;
58+
5159
FIELD_F(address_spend_pubkey)
5260
FIELD_F(address_view_pubkey)
53-
FIELD_F(is_subaddress)
54-
FIELD_F(payment_id)
61+
if (flags & flag_has_pid)
62+
{
63+
FIELD_F(payment_id)
64+
}
65+
else // no pid
66+
{
67+
v.payment_id = carrot::null_payment_id;
68+
}
5569
END_SERIALIZE()
5670

5771
BEGIN_SERIALIZE_OBJECT_FN(carrot::CarrotPaymentProposalV1)

src/carrot_impl/key_image_device_composed.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ crypto::key_image key_image_device_composed::derive_key_image(const OutputOpenin
127127
// get k^g_o, k^t_o
128128
crypto::secret_key sender_extension_g;
129129
crypto::secret_key sender_extension_t;
130-
if (!try_scan_opening_hint(opening_hint,
130+
if (!try_scan_opening_hint_sender_extensions(opening_hint,
131131
{&main_address_spend_pubkey, 1},
132132
m_k_view_incoming_dev,
133133
m_s_view_balance_dev,

0 commit comments

Comments
 (0)