Skip to content

Commit a68a28e

Browse files
committed
FCMP++: tower cycle Curve class + hash_grow implementation + tests
- The Curve class is an abstract interface for curves that form a cycle with another curve. This commit implements the Helios and Selene objects inherited from the Curve parent class. - This commit also tests the hash_grow flow under circumstances that occur when the curve trees merkle tree grows, and implements all the necessary functions on the Helios and Selene classes.
1 parent 86a0aa4 commit a68a28e

File tree

12 files changed

+800
-2
lines changed

12 files changed

+800
-2
lines changed

src/fcmp_pp/curve_trees.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,20 @@ OutputTuple output_to_tuple(const OutputPair &output_pair)
114114
return output_tuple_from_bytes(O, I, C);
115115
}
116116
//----------------------------------------------------------------------------------------------------------------------
117+
std::shared_ptr<CurveTreesV1> curve_trees_v1(const std::size_t selene_chunk_width, const std::size_t helios_chunk_width)
118+
{
119+
std::unique_ptr<Selene> selene(new Selene());
120+
std::unique_ptr<Helios> helios(new Helios());
121+
return std::shared_ptr<CurveTreesV1>(
122+
new CurveTreesV1(
123+
std::move(selene),
124+
std::move(helios),
125+
selene_chunk_width,
126+
helios_chunk_width
127+
)
128+
);
129+
};
130+
//----------------------------------------------------------------------------------------------------------------------
117131
//----------------------------------------------------------------------------------------------------------------------
118132
// Static functions
119133
//----------------------------------------------------------------------------------------------------------------------

src/fcmp_pp/curve_trees.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,19 @@ class CurveTrees
116116
const std::size_t m_c2_width;
117117
};
118118
//----------------------------------------------------------------------------------------------------------------------
119+
using Selene = tower_cycle::Selene;
120+
using Helios = tower_cycle::Helios;
121+
using CurveTreesV1 = CurveTrees<Selene, Helios>;
122+
123+
// https://github.com/kayabaNerve/fcmp-plus-plus/blob
124+
// /b2742e86f3d18155fd34dd1ed69cb8f79b900fce/crypto/fcmps/src/tests.rs#L81-L82
125+
const std::size_t SELENE_CHUNK_WIDTH = 38;
126+
const std::size_t HELIOS_CHUNK_WIDTH = 18;
127+
128+
std::shared_ptr<CurveTreesV1> curve_trees_v1(
129+
const std::size_t selene_chunk_width = SELENE_CHUNK_WIDTH,
130+
const std::size_t helios_chunk_width = HELIOS_CHUNK_WIDTH);
131+
//----------------------------------------------------------------------------------------------------------------------
119132
//----------------------------------------------------------------------------------------------------------------------
120133
} //namespace curve_trees
121134
} //namespace fcmp_pp

src/fcmp_pp/fcmp_pp_rust/Cargo.lock

Lines changed: 185 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/fcmp_pp/fcmp_pp_rust/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ ciphersuite = { version = "0.4.2", features = ["ed25519"] }
1212
dalek-ff-group = "0.4.4"
1313
helioselene = { git = "https://github.com/monero-oxide/monero-oxide", rev = "50dd3dbc0cc9048247eb734d27eb1d516aecacd2" }
1414

15+
full-chain-membership-proofs = { git = "https://github.com/monero-oxide/monero-oxide", rev = "50dd3dbc0cc9048247eb734d27eb1d516aecacd2" }
16+
17+
monero-generators = { git = "https://github.com/monero-oxide/monero-oxide", rev = "50dd3dbc0cc9048247eb734d27eb1d516aecacd2" }
18+
monero-fcmp-plus-plus = { git = "https://github.com/monero-oxide/monero-oxide", rev = "50dd3dbc0cc9048247eb734d27eb1d516aecacd2" }
19+
1520
[patch.crates-io]
1621
crypto-bigint = { git = "https://github.com/kayabaNerve/crypto-bigint", branch = "c-repr" }
1722

src/fcmp_pp/fcmp_pp_rust/fcmp++.h

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,23 @@ struct SeleneScalar {
3838
uintptr_t _0[32 / sizeof(uintptr_t)];
3939
};
4040

41+
/// The field novel to Helios/Selene.
42+
struct HeliosScalar {
43+
uintptr_t _0[32 / sizeof(uintptr_t)];
44+
};
45+
46+
struct HeliosPoint {
47+
struct SeleneScalar x;
48+
struct SeleneScalar y;
49+
struct SeleneScalar z;
50+
};
51+
52+
struct SelenePoint {
53+
struct HeliosScalar x;
54+
struct HeliosScalar y;
55+
struct HeliosScalar z;
56+
};
57+
4158
// ----- End deps C bindings -----
4259

4360
struct OutputTuple
@@ -47,12 +64,64 @@ struct OutputTuple
4764
uint8_t C[32];
4865
};
4966

67+
struct HeliosScalarSlice
68+
{
69+
const struct HeliosScalar *buf;
70+
uintptr_t len;
71+
};
72+
73+
struct SeleneScalarSlice
74+
{
75+
const struct SeleneScalar *buf;
76+
uintptr_t len;
77+
};
78+
79+
struct HeliosScalarChunks
80+
{
81+
const struct HeliosScalarSlice *buf;
82+
uintptr_t len;
83+
};
84+
85+
struct SeleneScalarChunks
86+
{
87+
const struct SeleneScalarSlice *buf;
88+
uintptr_t len;
89+
};
90+
5091
#ifdef __cplusplus
5192
extern "C" {
5293
#endif
5394

5495
int selene_scalar_from_bytes(const uint8_t *selene_scalar_bytes, struct SeleneScalar *selene_scalar_out);
5596

97+
struct HeliosPoint helios_hash_init_point(void);
98+
99+
struct SelenePoint selene_hash_init_point(void);
100+
101+
struct HeliosScalar helios_zero_scalar(void);
102+
103+
struct SeleneScalar selene_zero_scalar(void);
104+
105+
void helios_scalar_to_bytes(const struct HeliosScalar *helios_scalar, uint8_t bytes_out[32]);
106+
107+
void selene_scalar_to_bytes(const struct SeleneScalar *selene_scalar, uint8_t bytes_out[32]);
108+
109+
void helios_point_to_bytes(const struct HeliosPoint *helios_point, uint8_t bytes_out[32]);
110+
111+
void selene_point_to_bytes(const struct SelenePoint *selene_point, uint8_t bytes_out[32]);
112+
113+
int hash_grow_helios(struct HeliosPoint existing_hash,
114+
uintptr_t offset,
115+
struct HeliosScalar existing_child_at_offset,
116+
struct HeliosScalarSlice new_children,
117+
struct HeliosPoint *hash_out);
118+
119+
int hash_grow_selene(struct SelenePoint existing_hash,
120+
uintptr_t offset,
121+
struct SeleneScalar existing_child_at_offset,
122+
struct SeleneScalarSlice new_children,
123+
struct SelenePoint *hash_out);
124+
56125
#ifdef __cplusplus
57126
} //extern "C"
58127
#endif

0 commit comments

Comments
 (0)