Skip to content

Commit

Permalink
Remove ringct dep in fcmp_pp, impl in fcmp_pp_crypto
Browse files Browse the repository at this point in the history
  • Loading branch information
j-berman committed Aug 9, 2024
1 parent 9ad4918 commit b6bcca9
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/fcmp_pp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

set(fcmp_pp_sources
curve_trees.cpp
fcmp_pp_crypto.cpp
tower_cycle.cpp)

monero_find_all_headers(fcmp_pp_headers "${CMAKE_CURRENT_SOURCE_DIR}")
Expand All @@ -52,7 +53,6 @@ target_link_libraries(fcmp_pp
cncrypto
cryptonote_basic
epee
ringct_basic
PRIVATE
${CMAKE_CURRENT_BINARY_DIR}/fcmp_pp_rust/libfcmp_pp_rust.a
${EXTRA_LIBRARIES}
Expand Down
14 changes: 8 additions & 6 deletions src/fcmp_pp/curve_trees.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "cryptonote_basic/cryptonote_format_utils.h"
#include "curve_trees.h"

#include "cryptonote_basic/cryptonote_format_utils.h"
#include "fcmp_pp_crypto.h"
#include "ringct/rctOps.h"


Expand Down Expand Up @@ -705,9 +707,9 @@ CurveTrees<Helios, Selene>::LeafTuple CurveTrees<Helios, Selene>::leaf_tuple(
const rct::key &commitment = output_pair.commitment;

rct::key O, C;
if (!rct::clear_torsion(rct::pk2rct(output_pubkey), O))
if (!fcmp_pp::clear_torsion(rct::pk2rct(output_pubkey), O))
throw std::runtime_error("output pubkey is invalid");
if (!rct::clear_torsion(commitment, C))
if (!fcmp_pp::clear_torsion(commitment, C))
throw std::runtime_error("commitment is invalid");

if (O == rct::I)
Expand All @@ -722,11 +724,11 @@ CurveTrees<Helios, Selene>::LeafTuple CurveTrees<Helios, Selene>::leaf_tuple(
crypto::derive_key_image_generator(output_pubkey, I);

rct::key O_x, I_x, C_x;
if (!rct::point_to_wei_x(O, O_x))
if (!fcmp_pp::point_to_wei_x(O, O_x))
throw std::runtime_error("failed to get wei x scalar from O");
if (!rct::point_to_wei_x(rct::pt2rct(I), I_x))
if (!fcmp_pp::point_to_wei_x(rct::pt2rct(I), I_x))
throw std::runtime_error("failed to get wei x scalar from I");
if (!rct::point_to_wei_x(C, C_x))
if (!fcmp_pp::point_to_wei_x(C, C_x))
throw std::runtime_error("failed to get wei x scalar from C");

return LeafTuple{
Expand Down
25 changes: 0 additions & 25 deletions src/ringct/rctOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -725,29 +725,4 @@ namespace rct {
sc_sub(masked.amount.bytes, masked.amount.bytes, sharedSec2.bytes);
}
}

bool clear_torsion(const key &k, key &k_out) {
ge_p3 point;
if (ge_frombytes_vartime(&point, k.bytes) != 0)
return false;
// mul by inv 8, then mul by 8
ge_p2 point_inv_8;
ge_scalarmult(&point_inv_8, INV_EIGHT.bytes, &point);
ge_p1p1 point_inv_8_mul_8;
ge_mul8(&point_inv_8_mul_8, &point_inv_8);
ge_p3 torsion_cleared_point;
ge_p1p1_to_p3(&torsion_cleared_point, &point_inv_8_mul_8);
ge_p3_tobytes(k_out.bytes, &torsion_cleared_point);
return true;
}

bool point_to_wei_x(const key &pub, key &wei_x) {
if (pub == I)
return false;
fe y;
if (fe_frombytes_vartime(y, pub.bytes) != 0)
return false;
fe_ed_y_to_wei_x(wei_x.bytes, y);
return true;
}
}
4 changes: 0 additions & 4 deletions src/ringct/rctOps.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,5 @@ namespace rct {
key genCommitmentMask(const key &sk);
void ecdhEncode(ecdhTuple & unmasked, const key & sharedSec, bool v2);
void ecdhDecode(ecdhTuple & masked, const key & sharedSec, bool v2);

// TODO: tests for these functions specifically
bool clear_torsion(const key &k, key &k_out);
bool point_to_wei_x(const key &pub, key &wei_x);
}
#endif /* RCTOPS_H */
3 changes: 2 additions & 1 deletion tests/unit_tests/curve_trees.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include "cryptonote_basic/cryptonote_format_utils.h"
#include "curve_trees.h"
#include "fcmp_pp/fcmp_pp_crypto.h"
#include "misc_log_ex.h"
#include "ringct/rctOps.h"
#include "unit_tests_utils.h"
Expand Down Expand Up @@ -777,7 +778,7 @@ static const Selene::Scalar generate_random_selene_scalar()
crypto::generate_keys(S, s, s, false);

rct::key S_x;
CHECK_AND_ASSERT_THROW_MES(rct::point_to_wei_x(rct::pk2rct(S), S_x), "failed to convert to wei x");
CHECK_AND_ASSERT_THROW_MES(fcmp_pp::point_to_wei_x(rct::pk2rct(S), S_x), "failed to convert to wei x");
return fcmp_pp::tower_cycle::selene_scalar_from_bytes(S_x);
}
//----------------------------------------------------------------------------------------------------------------------
Expand Down

0 comments on commit b6bcca9

Please sign in to comment.