From e68ea2e054ea9048b60f2f79591863712b7aa2e0 Mon Sep 17 00:00:00 2001 From: j-berman Date: Thu, 23 May 2024 12:34:48 -0700 Subject: [PATCH] small cleanup --- src/fcmp/curve_trees.cpp | 9 ++++----- src/fcmp/tower_cycle.cpp | 40 ++++++++++++++++++++-------------------- src/fcmp/tower_cycle.h | 14 +++++++------- 3 files changed, 31 insertions(+), 32 deletions(-) diff --git a/src/fcmp/curve_trees.cpp b/src/fcmp/curve_trees.cpp index 3399d8146..0fd0fb913 100644 --- a/src/fcmp/curve_trees.cpp +++ b/src/fcmp/curve_trees.cpp @@ -73,7 +73,6 @@ static typename C::Point get_first_parent(const C &curve, return get_new_parent(curve, new_children); std::vector prior_children; - if (child_layer_last_hash_updated) { // If the last chunk has updated children in it, then we need to get the delta to the old children @@ -299,18 +298,18 @@ typename CurveTrees::TreeExtension CurveTrees::get_tree_extensio // TODO: calculate max number of layers it should take to add all leaves (existing leaves + new leaves) while (true) { - const LastChunkData *c1_last_chunk_ptr = (c1_last_chunks.size() <= c1_last_idx) + const LastChunkData *c1_last_chunk_ptr = (c1_last_idx >= c1_last_chunks.size()) ? nullptr : &c1_last_chunks[c1_last_idx]; - const LastChunkData *c2_last_chunk_ptr = (c2_last_chunks.size() <= c2_last_idx) + const LastChunkData *c2_last_chunk_ptr = (c2_last_idx >= c2_last_chunks.size()) ? nullptr : &c2_last_chunks[c2_last_idx]; // TODO: templated function if (parent_is_c1) { - CHECK_AND_ASSERT_THROW_MES(c2_layer_extensions_out.size() > c2_last_idx, "missing c2 layer"); + CHECK_AND_ASSERT_THROW_MES(c2_last_idx < c2_layer_extensions_out.size(), "missing c2 layer"); const auto &c2_child_extension = c2_layer_extensions_out[c2_last_idx]; @@ -337,7 +336,7 @@ typename CurveTrees::TreeExtension CurveTrees::get_tree_extensio } else { - CHECK_AND_ASSERT_THROW_MES(c1_layer_extensions_out.size() > c1_last_idx, "missing c1 layer"); + CHECK_AND_ASSERT_THROW_MES(c1_last_idx < c1_layer_extensions_out.size(), "missing c1 layer"); const auto &c1_child_extension = c1_layer_extensions_out[c1_last_idx]; diff --git a/src/fcmp/tower_cycle.cpp b/src/fcmp/tower_cycle.cpp index cca657fe4..96fa5fe09 100644 --- a/src/fcmp/tower_cycle.cpp +++ b/src/fcmp/tower_cycle.cpp @@ -146,26 +146,6 @@ std::string Selene::to_string(const typename Selene::Point &point) const //---------------------------------------------------------------------------------------------------------------------- // Exposed helper functions //---------------------------------------------------------------------------------------------------------------------- -Helios::Generators random_helios_generators(std::size_t n) -{ - return fcmp_rust::random_helios_generators(n); -} -//---------------------------------------------------------------------------------------------------------------------- -Selene::Generators random_selene_generators(std::size_t n) -{ - return fcmp_rust::random_selene_generators(n); -} -//---------------------------------------------------------------------------------------------------------------------- -Helios::Point random_helios_hash_init_point() -{ - return fcmp_rust::random_helios_hash_init_point(); -} -//---------------------------------------------------------------------------------------------------------------------- -Selene::Point random_selene_hash_init_point() -{ - return fcmp_rust::random_selene_hash_init_point(); -} -//---------------------------------------------------------------------------------------------------------------------- SeleneScalar ed_25519_point_to_scalar(const crypto::ec_point &point) { static_assert(sizeof(RustEd25519Point) == sizeof(crypto::ec_point), @@ -221,6 +201,26 @@ template void extend_scalars_from_cycle_points(const Selene &cur const std::vector &points, std::vector &scalars_out); //---------------------------------------------------------------------------------------------------------------------- +Helios::Generators random_helios_generators(std::size_t n) +{ + return fcmp_rust::random_helios_generators(n); +} +//---------------------------------------------------------------------------------------------------------------------- +Selene::Generators random_selene_generators(std::size_t n) +{ + return fcmp_rust::random_selene_generators(n); +} +//---------------------------------------------------------------------------------------------------------------------- +Helios::Point random_helios_hash_init_point() +{ + return fcmp_rust::random_helios_hash_init_point(); +} +//---------------------------------------------------------------------------------------------------------------------- +Selene::Point random_selene_hash_init_point() +{ + return fcmp_rust::random_selene_hash_init_point(); +} +//---------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------- } //namespace tower_cycle } //namespace fcmp diff --git a/src/fcmp/tower_cycle.h b/src/fcmp/tower_cycle.h index bf08bd04f..f63cac5ff 100644 --- a/src/fcmp/tower_cycle.h +++ b/src/fcmp/tower_cycle.h @@ -184,13 +184,6 @@ public: }; //---------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------- -// TODO: use static constants and get rid of the below functions (WARNING: number of generators must be >= curve's -// width, and also need to account for selene leaf layer 3x) -Helios::Generators random_helios_generators(std::size_t n); -Selene::Generators random_selene_generators(std::size_t n); -Helios::Point random_helios_hash_init_point(); -Selene::Point random_selene_hash_init_point(); -//---------------------------------------------------------------------------------------------------------------------- // Ed25519 point x-coordinates are Selene scalars SeleneScalar ed_25519_point_to_scalar(const crypto::ec_point &point); //---------------------------------------------------------------------------------------------------------------------- @@ -204,6 +197,13 @@ void extend_scalars_from_cycle_points(const C_POINTS &curve, const std::vector &points, std::vector &scalars_out); //---------------------------------------------------------------------------------------------------------------------- +// TODO: use static constants and get rid of the below functions (WARNING: number of generators must be >= curve's +// width, and also need to account for selene leaf layer 3x) +Helios::Generators random_helios_generators(std::size_t n); +Selene::Generators random_selene_generators(std::size_t n); +Helios::Point random_helios_hash_init_point(); +Selene::Point random_selene_hash_init_point(); +//---------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------- }//namespace tower_cycle }//namespace fcmp