Skip to content

Commit 4f4b1af

Browse files
authored
Merge pull request monero-project#51 from jeffro256/fcmp++-stage-carrot-tx-proposal-overhaul
Carrot tx proposal overhaul, wallet2_basic lib, sweep fixes, and preliminary hot/cold types
2 parents 3860286 + c67784c commit 4f4b1af

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+4453
-2072
lines changed

src/carrot_core/core_types.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ janus_anchor_t gen_janus_anchor()
117117
return crypto::rand<janus_anchor_t>();
118118
}
119119
//-------------------------------------------------------------------------------------------------------------------
120+
encrypted_amount_t gen_encrypted_amount()
121+
{
122+
return crypto::rand<encrypted_amount_t>();
123+
}
124+
//-------------------------------------------------------------------------------------------------------------------
120125
payment_id_t gen_payment_id()
121126
{
122127
while (true)

src/carrot_core/core_types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ static inline bool operator!=(const view_tag_t &a, const view_tag_t &b) { return
129129

130130
/// generate a random janus anchor
131131
janus_anchor_t gen_janus_anchor();
132+
/// generate a random encrypted amount
133+
encrypted_amount_t gen_encrypted_amount();
132134
/// generate a random (non-null) payment ID
133135
payment_id_t gen_payment_id();
134136
/// generate a random encrypted payment ID

src/carrot_core/device.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,17 @@ struct generate_address_secret_device
180180
virtual ~generate_address_secret_device() = default;
181181
};
182182

183+
struct generate_image_key_device
184+
{
185+
/**
186+
* brief: generate_image_scalar_mult_hash_to_point -
187+
* [carrot] L_partial = k_gi Hp(K_o)
188+
* [legacy] L_partial = k_s Hp(K_o)
189+
* param: onetime_address - K_o
190+
* return: L_partial
191+
*/
192+
virtual crypto::ec_point generate_image_scalar_mult_hash_to_point(
193+
const crypto::public_key &onetime_address) const = 0;
194+
};
195+
183196
} //namespace carrot

src/carrot_core/device_ram_borrowed.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,15 @@ void generate_address_secret_ram_borrowed_device::make_index_extension_generator
9494
make_carrot_index_extension_generator(m_s_generate_address, major_index, minor_index, address_generator_out);
9595
}
9696
//-------------------------------------------------------------------------------------------------------------------
97+
crypto::ec_point generate_image_key_ram_borrowed_device::generate_image_scalar_mult_hash_to_point(
98+
const crypto::public_key &onetime_address) const
99+
{
100+
// I = Hp(K_o)
101+
crypto::ec_point key_image_generator;
102+
crypto::derive_key_image_generator(onetime_address, key_image_generator);
103+
104+
// L_partial = k_gi I
105+
return rct::rct2pt(rct::scalarmultKey(rct::pt2rct(key_image_generator), rct::sk2rct(m_k_generate_image)));
106+
}
107+
//-------------------------------------------------------------------------------------------------------------------
97108
} //namespace carrot

src/carrot_core/device_ram_borrowed.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,16 @@ class generate_address_secret_ram_borrowed_device: public generate_address_secre
9696
const crypto::secret_key &m_s_generate_address;
9797
};
9898

99+
class generate_image_key_ram_borrowed_device: public generate_image_key_device
100+
{
101+
public:
102+
generate_image_key_ram_borrowed_device(const crypto::secret_key &k_generate_image):
103+
m_k_generate_image(k_generate_image) {}
104+
105+
crypto::ec_point generate_image_scalar_mult_hash_to_point(const crypto::public_key &onetime_address) const override;
106+
107+
protected:
108+
const crypto::secret_key &m_k_generate_image;
109+
};
110+
99111
} //namespace carrot

src/carrot_core/exceptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ CARROT_DEFINE_SIMPLE_ERROR_TYPE(crypto_function_failed, carrot_runtime_error)
6060
CARROT_DEFINE_SIMPLE_ERROR_TYPE(not_enough_money, carrot_runtime_error)
6161
CARROT_DEFINE_SIMPLE_ERROR_TYPE(not_enough_usable_money, carrot_runtime_error)
6262
CARROT_DEFINE_SIMPLE_ERROR_TYPE(unexpected_scan_failure, carrot_runtime_error)
63+
CARROT_DEFINE_SIMPLE_ERROR_TYPE(burnt_enote, carrot_runtime_error)
6364

6465
/// one needs to include misc_log_ex.h to use the following macros
6566
#define CARROT_THROW(errtype, message) { \

src/carrot_impl/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ set(carrot_impl_sources
3131
address_utils_compat.cpp
3232
format_utils.cpp
3333
input_selection.cpp
34+
key_image_device_composed.cpp
35+
key_image_device_precomputed.cpp
36+
output_opening_types.cpp
3437
tx_builder_inputs.cpp
3538
tx_builder_outputs.cpp
3639
tx_proposal_utils.cpp

src/carrot_impl/address_device.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ struct hybrid_hierarchy_address_device
8888
{
8989
virtual bool supports_address_derivation_type(AddressDeriveType derive_type) const = 0;
9090

91-
virtual cryptonote_hierarchy_address_device &access_cryptonote_hierarchy_device() const = 0;
91+
virtual const cryptonote_hierarchy_address_device &access_cryptonote_hierarchy_device() const = 0;
9292

93-
virtual carrot_hierarchy_address_device &access_carrot_hierarchy_device() const = 0;
93+
virtual const carrot_hierarchy_address_device &access_carrot_hierarchy_device() const = 0;
9494

9595
virtual ~hybrid_hierarchy_address_device() = default;
9696
};

src/carrot_impl/address_device_ram_borrowed.cpp

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
//local headers
3333
#include "address_utils_compat.h"
34+
#include "carrot_core/address_utils.h"
3435

3536
//third party headers
3637

@@ -53,4 +54,88 @@ void cryptonote_hierarchy_address_device_ram_borrowed::make_legacy_subaddress_ex
5354
legacy_subaddress_extension_out);
5455
}
5556
//-------------------------------------------------------------------------------------------------------------------
57+
carrot_hierarchy_address_device_ram_borrowed::carrot_hierarchy_address_device_ram_borrowed(
58+
const crypto::public_key &account_spend_pubkey,
59+
const crypto::public_key &account_view_pubkey,
60+
const crypto::public_key &main_address_view_pubkey,
61+
const crypto::secret_key &s_generate_address)
62+
:
63+
m_account_spend_pubkey(account_spend_pubkey),
64+
m_account_view_pubkey(account_view_pubkey),
65+
m_main_address_view_pubkey(main_address_view_pubkey),
66+
m_s_generate_address(s_generate_address)
67+
{}
68+
//-------------------------------------------------------------------------------------------------------------------
69+
void carrot_hierarchy_address_device_ram_borrowed::make_index_extension_generator(const std::uint32_t major_index,
70+
const std::uint32_t minor_index,
71+
crypto::secret_key &address_generator_out) const
72+
{
73+
make_carrot_index_extension_generator(m_s_generate_address, major_index, minor_index, address_generator_out);
74+
}
75+
//-------------------------------------------------------------------------------------------------------------------
76+
crypto::public_key carrot_hierarchy_address_device_ram_borrowed::get_carrot_account_spend_pubkey() const
77+
{
78+
return m_account_spend_pubkey;
79+
}
80+
//-------------------------------------------------------------------------------------------------------------------
81+
crypto::public_key carrot_hierarchy_address_device_ram_borrowed::get_carrot_account_view_pubkey() const
82+
{
83+
return m_account_view_pubkey;
84+
}
85+
//-------------------------------------------------------------------------------------------------------------------
86+
crypto::public_key carrot_hierarchy_address_device_ram_borrowed::get_carrot_main_address_view_pubkey() const
87+
{
88+
return m_main_address_view_pubkey;
89+
}
90+
//-------------------------------------------------------------------------------------------------------------------
91+
hybrid_hierarchy_address_device_composed::hybrid_hierarchy_address_device_composed(
92+
const cryptonote_hierarchy_address_device *cn_addr_dev,
93+
const carrot_hierarchy_address_device *carrot_addr_dev)
94+
:
95+
m_cn_addr_dev(cn_addr_dev),
96+
m_carrot_addr_dev(carrot_addr_dev)
97+
{}
98+
//-------------------------------------------------------------------------------------------------------------------
99+
bool hybrid_hierarchy_address_device_composed::supports_address_derivation_type(AddressDeriveType derive_type) const
100+
{
101+
switch (derive_type)
102+
{
103+
case AddressDeriveType::PreCarrot:
104+
return m_cn_addr_dev;
105+
case AddressDeriveType::Carrot:
106+
return m_carrot_addr_dev;
107+
case AddressDeriveType::Auto:
108+
return m_cn_addr_dev || m_carrot_addr_dev;
109+
default:
110+
throw device_error("Default",
111+
"hybrid_hierarchy_address_device_composed",
112+
"supports_address_derivation_type",
113+
"unrecognized derive type", -1);
114+
}
115+
}
116+
//-------------------------------------------------------------------------------------------------------------------
117+
const cryptonote_hierarchy_address_device &hybrid_hierarchy_address_device_composed::access_cryptonote_hierarchy_device() const
118+
{
119+
if (!m_cn_addr_dev)
120+
{
121+
throw device_error("Default",
122+
"hybrid_hierarchy_address_device_composed",
123+
"access_cryptonote_hierarchy_device",
124+
"cryptonote sub-device unavailable", -1);
125+
}
126+
return *m_cn_addr_dev;
127+
}
128+
//-------------------------------------------------------------------------------------------------------------------
129+
const carrot_hierarchy_address_device &hybrid_hierarchy_address_device_composed::access_carrot_hierarchy_device() const
130+
{
131+
if (!m_carrot_addr_dev)
132+
{
133+
throw device_error("Default",
134+
"hybrid_hierarchy_address_device_composed",
135+
"access_carrot_hierarchy_device",
136+
"carrot sub-device unavailable", -1);
137+
}
138+
return *m_carrot_addr_dev;
139+
}
140+
//-------------------------------------------------------------------------------------------------------------------
56141
} //namespace carrot

src/carrot_impl/address_device_ram_borrowed.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,47 @@ struct cryptonote_hierarchy_address_device_ram_borrowed:
6363
protected:
6464
const crypto::public_key &m_cryptonote_account_spend_pubkey;
6565
};
66+
67+
class carrot_hierarchy_address_device_ram_borrowed: public carrot_hierarchy_address_device
68+
{
69+
public:
70+
carrot_hierarchy_address_device_ram_borrowed(
71+
const crypto::public_key &account_spend_pubkey,
72+
const crypto::public_key &account_view_pubkey,
73+
const crypto::public_key &main_address_view_pubkey,
74+
const crypto::secret_key &s_generate_address);
75+
76+
void make_index_extension_generator(const std::uint32_t major_index,
77+
const std::uint32_t minor_index,
78+
crypto::secret_key &address_generator_out) const override;
79+
80+
crypto::public_key get_carrot_account_spend_pubkey() const override;
81+
82+
crypto::public_key get_carrot_account_view_pubkey() const override;
83+
84+
crypto::public_key get_carrot_main_address_view_pubkey() const override;
85+
86+
protected:
87+
const crypto::public_key &m_account_spend_pubkey;
88+
const crypto::public_key &m_account_view_pubkey;
89+
const crypto::public_key &m_main_address_view_pubkey;
90+
const crypto::secret_key &m_s_generate_address;
91+
};
92+
93+
class hybrid_hierarchy_address_device_composed: public hybrid_hierarchy_address_device
94+
{
95+
public:
96+
hybrid_hierarchy_address_device_composed(const cryptonote_hierarchy_address_device *cn_addr_dev,
97+
const carrot_hierarchy_address_device *carrot_addr_dev);
98+
99+
bool supports_address_derivation_type(AddressDeriveType derive_type) const override;
100+
101+
const cryptonote_hierarchy_address_device &access_cryptonote_hierarchy_device() const override;
102+
103+
const carrot_hierarchy_address_device &access_carrot_hierarchy_device() const override;
104+
105+
protected:
106+
const cryptonote_hierarchy_address_device *m_cn_addr_dev;
107+
const carrot_hierarchy_address_device *m_carrot_addr_dev;
108+
};
66109
} //namespace carrot

0 commit comments

Comments
 (0)