diff --git a/src/crypto/crypto-ops.c b/src/crypto/crypto-ops.c index 8d2680c62..9dd9ff7dd 100644 --- a/src/crypto/crypto-ops.c +++ b/src/crypto/crypto-ops.c @@ -3920,7 +3920,7 @@ int ge_p3_is_point_at_infinity_vartime(const ge_p3 *p) { } // https://www.ietf.org/archive/id/draft-ietf-lwig-curve-representations-02.pdf E.2 -void fe_to_wei_x(unsigned char *wei_x, const fe inv_one_minus_y, const fe one_plus_y) +void fe_ed_y_derivatives_to_wei_x(unsigned char *wei_x, const fe inv_one_minus_y, const fe one_plus_y) { // (1/(1-y))*(1+y) fe inv_one_minus_y_mul_one_plus_y; diff --git a/src/crypto/crypto-ops.h b/src/crypto/crypto-ops.h index cd3821663..b5976c762 100644 --- a/src/crypto/crypto-ops.h +++ b/src/crypto/crypto-ops.h @@ -173,4 +173,4 @@ void fe_1(fe h); int ge_p3_is_point_at_infinity_vartime(const ge_p3 *p); -void fe_to_wei_x(unsigned char *wei_x, const fe inv_one_minus_y, const fe one_plus_y); +void fe_ed_y_derivatives_to_wei_x(unsigned char *wei_x, const fe inv_one_minus_y, const fe one_plus_y); diff --git a/src/fcmp_pp/curve_trees.cpp b/src/fcmp_pp/curve_trees.cpp index 12640c578..d8b08085d 100644 --- a/src/fcmp_pp/curve_trees.cpp +++ b/src/fcmp_pp/curve_trees.cpp @@ -736,12 +736,12 @@ static PreLeafTuple output_to_pre_leaf_tuple(const OutputPair &output_pair) crypto::derive_key_image_generator(output_pubkey, I); PreLeafTuple plt; - if (!fcmp_pp::point_to_pre_wei_x(O, plt.O_pre_x)) - throw std::runtime_error("failed to get pre wei x from O"); - if (!fcmp_pp::point_to_pre_wei_x(rct::pt2rct(I), plt.I_pre_x)) - throw std::runtime_error("failed to get pre wei x from I"); - if (!fcmp_pp::point_to_pre_wei_x(C, plt.C_pre_x)) - throw std::runtime_error("failed to get pre wei x from C"); + if (!fcmp_pp::point_to_ed_y_derivatives(O, plt.O_pre_x)) + throw std::runtime_error("failed to get ed y derivatives from O"); + if (!fcmp_pp::point_to_ed_y_derivatives(rct::pt2rct(I), plt.I_pre_x)) + throw std::runtime_error("failed to get ed y derivatives from I"); + if (!fcmp_pp::point_to_ed_y_derivatives(C, plt.C_pre_x)) + throw std::runtime_error("failed to get ed y derivatives from C"); return plt; } @@ -755,9 +755,9 @@ CurveTrees::LeafTuple CurveTrees::leaf_tuple(con const auto plt = output_to_pre_leaf_tuple(output_pair); rct::key O_x, I_x, C_x; - fcmp_pp::pre_wei_x_to_wei_x(plt.O_pre_x, O_x); - fcmp_pp::pre_wei_x_to_wei_x(plt.I_pre_x, I_x); - fcmp_pp::pre_wei_x_to_wei_x(plt.C_pre_x, C_x); + fcmp_pp::ed_y_derivatives_to_wei_x(plt.O_pre_x, O_x); + fcmp_pp::ed_y_derivatives_to_wei_x(plt.I_pre_x, I_x); + fcmp_pp::ed_y_derivatives_to_wei_x(plt.C_pre_x, C_x); return LeafTuple{ .O_x = tower_cycle::selene_scalar_from_bytes(O_x), @@ -1019,7 +1019,8 @@ void CurveTrees::set_valid_leaves( tools::threadpool& tpool = tools::threadpool::getInstanceForCompute(); tools::threadpool::waiter waiter(tpool); - // Step 1. Multithreaded convert valid outputs into pre-Wei x coords + // Step 1. Multithreaded convert valid outputs into Edwards y derivatives needed to get Wei x coordinates + // TODO: investigate batched threading (as opposed to small tasks) std::vector pre_leaves; pre_leaves.resize(new_outputs.size()); for (std::size_t i = 0; i < new_outputs.size(); ++i) @@ -1047,15 +1048,17 @@ void CurveTrees::set_valid_leaves( ); } - CHECK_AND_ASSERT_THROW_MES(waiter.wait(), "failed to convert outputs to pre wei x coords"); + CHECK_AND_ASSERT_THROW_MES(waiter.wait(), "failed to convert outputs to ed y derivatives"); - // Step 2. Collect valid pre-Wei x coords + // Step 2. Collect valid Edwards y derivatives const std::size_t n_valid_outputs = std::count(valid_outputs.begin(), valid_outputs.end(), True); const std::size_t n_valid_leaf_elems = n_valid_outputs * LEAF_TUPLE_SIZE; + // Collecting (1+y)'s fe *one_plus_y_vec = (fe *) malloc(n_valid_leaf_elems * sizeof(fe)); CHECK_AND_ASSERT_THROW_MES(one_plus_y_vec, "failed malloc one_plus_y_vec"); + // Collecting (1-y)'s fe *one_minus_y_vec = (fe *) malloc(n_valid_leaf_elems * sizeof(fe)); CHECK_AND_ASSERT_THROW_MES(one_minus_y_vec, "failed malloc one_minus_y_vec"); @@ -1090,14 +1093,15 @@ void CurveTrees::set_valid_leaves( CHECK_AND_ASSERT_THROW_MES(n_valid_leaf_elems == valid_i, "unexpected end valid_i"); - // Step 3. Get batch inverse of valid pre-Wei x (1-y)'s + // Step 3. Get batch inverse of all valid (1-y)'s // - Batch inversion is significantly faster than inverting 1 at a time fe *inv_one_minus_y_vec = (fe *) malloc(n_valid_leaf_elems * sizeof(fe)); CHECK_AND_ASSERT_THROW_MES(inv_one_minus_y_vec, "failed malloc inv_one_minus_y_vec"); CHECK_AND_ASSERT_THROW_MES(fe_batch_invert(inv_one_minus_y_vec, one_minus_y_vec, n_valid_leaf_elems) == 0, "failed to batch invert"); - // Step 4. Multithreaded get Wei x coords and convert to Selene scalars + // Step 4. Multithreaded get Wei x's and convert to Selene scalars + // TODO: investigate batched threading (as opposed to small tasks) flattened_leaves_out.resize(n_valid_leaf_elems); for (std::size_t i = 0; i < n_valid_leaf_elems; ++i) { @@ -1110,7 +1114,7 @@ void CurveTrees::set_valid_leaves( ]() { rct::key wei_x; - fe_to_wei_x(wei_x.bytes, inv_one_minus_y_vec[i], one_plus_y_vec[i]); + fe_ed_y_derivatives_to_wei_x(wei_x.bytes, inv_one_minus_y_vec[i], one_plus_y_vec[i]); flattened_leaves_out[i] = tower_cycle::selene_scalar_from_bytes(wei_x); }, true @@ -1119,7 +1123,7 @@ void CurveTrees::set_valid_leaves( CHECK_AND_ASSERT_THROW_MES(waiter.wait(), "failed to convert outputs to wei x coords"); - // Step 5. Set valid tuples + // Step 5. Set valid tuples to be stored in the db tuples_out.clear(); tuples_out.reserve(n_valid_outputs); for (std::size_t i = 0; i < valid_outputs.size(); ++i) diff --git a/src/fcmp_pp/curve_trees.h b/src/fcmp_pp/curve_trees.h index 7aa3f8275..1c9758c3a 100644 --- a/src/fcmp_pp/curve_trees.h +++ b/src/fcmp_pp/curve_trees.h @@ -159,9 +159,9 @@ using OutputsByUnlockBlock = std::unordered_map fe* @@ -384,8 +384,8 @@ TEST(Crypto, batch_inversion) }; // Init test elems and individual inversions - fe *init_elems = alloc(MAX_TEST_ELEMS); - fe *norm_inverted = alloc(MAX_TEST_ELEMS); + fe *init_elems = alloc(MAX_TEST_ELEMS); + fe *norm_inverted = alloc(MAX_TEST_ELEMS); for (std::size_t i = 0; i < MAX_TEST_ELEMS; ++i) { const cryptonote::keypair kp = cryptonote::keypair::generate(hw::get_device("default"));