From 5568e0eeaf6cdec7dcb9edfdc6cb2ead1bc3e783 Mon Sep 17 00:00:00 2001 From: sowle Date: Wed, 8 Feb 2023 18:16:04 +0100 Subject: [PATCH] crypto: generator U + assertion tests for generators --- src/crypto/crypto-sugar.cpp | 2 +- src/crypto/crypto-sugar.h | 8 ++++++++ tests/functional_tests/crypto_tests.cpp | 17 +++++++++++++++++ .../crypto_tests_range_proofs.h | 11 ----------- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/crypto/crypto-sugar.cpp b/src/crypto/crypto-sugar.cpp index 1823833a..0f0be387 100644 --- a/src/crypto/crypto-sugar.cpp +++ b/src/crypto/crypto-sugar.cpp @@ -23,7 +23,7 @@ namespace crypto const point_t c_point_H = { 0x05087c1f5b9b32d6, 0x00547595f445c3b5, 0x764df64578552f2a, 0x8a49a651e0e0da45 }; // == Hp(G), this is being checked in bpp_basics const point_t c_point_H2 = { 0x70c8d1ab9dbf1cc0, 0xc561bb12639a8516, 0x3cfff1def9e5b268, 0xe0936386f3bcce1a }; // == Hp("h2_generator"), checked in bpp_basics - + const point_t c_point_U = { 0xc9d2f543dbbc253a, 0x87099e9ac33d06dd, 0x76bcf12dcf6ffcba, 0x20384a4a88752d32 }; // == Hp("U_generator"), checked in const point_t c_point_X = { 0xc9d2f543dbbc253a, 0x87099e9ac33d06dd, 0x76bcf12dcf6ffcba, 0x20384a4a88752d32 }; // == Hp("X_generator"), checked in clsag_ggxg_basics const point_t c_point_0 = point_t(point_t::tag_zero()); diff --git a/src/crypto/crypto-sugar.h b/src/crypto/crypto-sugar.h index 7ebe078e..7f1b56b4 100644 --- a/src/crypto/crypto-sugar.h +++ b/src/crypto/crypto-sugar.h @@ -917,6 +917,7 @@ namespace crypto extern const point_t c_point_H; extern const point_t c_point_H2; + extern const point_t c_point_U; extern const point_t c_point_X; extern const point_t c_point_0; extern const point_t c_point_H_plus_G; @@ -1199,6 +1200,13 @@ namespace crypto return result; } + static point_t hp(const std::string& str) + { + point_t result; + ge_bytes_hash_to_ec(&result.m_p3, str.data(), str.size()); + return result; + } + }; // hash_helper_t struct diff --git a/tests/functional_tests/crypto_tests.cpp b/tests/functional_tests/crypto_tests.cpp index a893b27b..fe1f0358 100644 --- a/tests/functional_tests/crypto_tests.cpp +++ b/tests/functional_tests/crypto_tests.cpp @@ -12,6 +12,7 @@ #include "common/crypto_stream_operators.h" #include "common/varint.h" #include "currency_core/difficulty.h" +#include "currency_core/currency_basic.h" #include "crypto/crypto-sugar.h" #include "crypto/range_proofs.h" @@ -500,6 +501,22 @@ struct test_keeper_t // Tests // +TEST(crypto, basics) +{ + ASSERT_EQ(c_point_H, hash_helper_t::hp(c_point_G)); + ASSERT_EQ(c_point_H2, hash_helper_t::hp("h2_generator")); + ASSERT_EQ(c_point_U, hash_helper_t::hp("U_generator")); + ASSERT_EQ(c_point_X, hash_helper_t::hp("X_generator")); + + ASSERT_EQ(currency::native_coin_asset_id, c_point_H.to_public_key()); + + LOG_PRINT_L0("c_point_0 = " << c_point_0 << " = { " << c_point_0.to_hex_comma_separated_uint64_str() << " }"); + LOG_PRINT_L0("Zano G = " << c_point_G << " = { " << c_point_G.to_hex_comma_separated_bytes_str() << " }"); + LOG_PRINT_L0("Zano H = " << c_point_H << " = { " << c_point_H.to_hex_comma_separated_uint64_str() << " }"); + LOG_PRINT_L0("Zano H2 = " << c_point_H2 << " = { " << c_point_H2.to_hex_comma_separated_uint64_str() << " }"); +} + + #include "crypto_tests_performance.h" TEST(crypto, ge_scalarmult_vartime_p3) diff --git a/tests/functional_tests/crypto_tests_range_proofs.h b/tests/functional_tests/crypto_tests_range_proofs.h index 6be87120..16a6bda0 100644 --- a/tests/functional_tests/crypto_tests_range_proofs.h +++ b/tests/functional_tests/crypto_tests_range_proofs.h @@ -58,17 +58,6 @@ TEST(bpp, basics) std::cout << scalar_t::random().to_string_as_secret_key() << ENDL; */ - point_t H = hash_helper_t::hp(c_point_G); - ASSERT_EQ(H, c_point_H); - std::string h2_hash_str("h2_generator"); - point_t H2 = hash_helper_t::hp(h2_hash_str.c_str(), h2_hash_str.size()); - ASSERT_EQ(H2, c_point_H2); - LOG_PRINT_L0("c_point_0 = " << c_point_0 << " = { " << c_point_0.to_hex_comma_separated_uint64_str() << " }"); - LOG_PRINT_L0("Zano G = " << c_point_G << " = { " << c_point_G.to_hex_comma_separated_bytes_str() << " }"); - LOG_PRINT_L0("Zano H = " << H << " = { " << H.to_hex_comma_separated_uint64_str() << " }"); - LOG_PRINT_L0("Zano H2 = " << H2 << " = { " << H2.to_hex_comma_separated_uint64_str() << " }"); - - auto foo = [&](scalar_t v){ scalar_vec_t values = { v }; scalar_vec_t masks = { scalar_t::random() };