diff --git a/src/crypto/crypto-sugar.cpp b/src/crypto/crypto-sugar.cpp index b7298639..07fcc7c7 100644 --- a/src/crypto/crypto-sugar.cpp +++ b/src/crypto/crypto-sugar.cpp @@ -21,7 +21,7 @@ namespace crypto const scalar_t c_scalar_1div8 = { 0x6106e529e2dc2f79, 0x07d39db37d1cdad0, 0x0, 0x0600000000000000 }; 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"), cheched 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_0 = point_t(point_t::tag_zero()); static_assert(sizeof(scalar_t::m_sk) == sizeof(scalar_t::m_u64) && sizeof(scalar_t::m_u64) == sizeof(scalar_t::m_s), "size missmatch"); diff --git a/src/crypto/range_proofs.h b/src/crypto/range_proofs.h index c584c3ff..24e23463 100644 --- a/src/crypto/range_proofs.h +++ b/src/crypto/range_proofs.h @@ -125,12 +125,16 @@ namespace crypto return result; } + static const point_t& bpp_G; // NOTE! This notation follows original BP+ whitepaper, see mapping to Zano's generators below static const point_t& bpp_H; static const point_t& bpp_H2; }; // struct bpp_crypto_trait_zano template - const point_t& bpp_crypto_trait_zano::bpp_H = c_point_H; + const point_t& bpp_crypto_trait_zano::bpp_G = c_point_H; + + template + const point_t& bpp_crypto_trait_zano::bpp_H = c_point_G; template const point_t& bpp_crypto_trait_zano::bpp_H2 = c_point_H2; diff --git a/tests/functional_tests/crypto_tests_range_proofs.h b/tests/functional_tests/crypto_tests_range_proofs.h index 003371c6..5332ef54 100644 --- a/tests/functional_tests/crypto_tests_range_proofs.h +++ b/tests/functional_tests/crypto_tests_range_proofs.h @@ -68,22 +68,46 @@ TEST(bpp, basics) 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() << " }"); - scalar_vec_t values = { 5 }; - scalar_vec_t masks = { 0 }; - bpp_signature bpp_sig; - std::vector commitments_1div8; - uint8_t err = 0; - bool r = bpp_gen>(values, masks, bpp_sig, commitments_1div8, &err); - LOG_PRINT_L0("err = " << (uint16_t)err); - ASSERT_TRUE(r); + auto foo = [&](scalar_t v){ + scalar_vec_t values = { v }; + scalar_vec_t masks = { scalar_t::random() }; + bpp_signature bpp_sig; + std::vector commitments_1div8; + uint8_t err = 0; - std::vector sigs; - sigs.emplace_back(bpp_sig, commitments_1div8); + bool r = bpp_gen>(values, masks, bpp_sig, commitments_1div8, &err); + if (!r) + { + LOG_PRINT_L0("bpp_gen err = " << (uint16_t)err); + return false; + } - r = bpp_verify>(sigs, &err); - LOG_PRINT_L0("err = " << (uint16_t)err); - ASSERT_TRUE(r); + std::vector sigs; + sigs.emplace_back(bpp_sig, commitments_1div8); + + r = bpp_verify>(sigs, &err); + if (!r) + { + LOG_PRINT_L0("bpp_verify err = " << (uint16_t)err); + return false; + } + + return true; + }; + + ASSERT_TRUE(foo(scalar_t(0))); + ASSERT_TRUE(foo(scalar_t(1))); + ASSERT_TRUE(foo(scalar_t(5))); + ASSERT_TRUE(foo(scalar_t(UINT64_MAX))); + + ASSERT_FALSE(foo(scalar_t(UINT64_MAX, 1, 0, 0))); + ASSERT_FALSE(foo(scalar_t(0, 1, 0, 0))); + ASSERT_FALSE(foo(scalar_t(0, 0, 1, 0))); + ASSERT_FALSE(foo(scalar_t(0, 0, 0, 1))); + ASSERT_FALSE(foo(c_scalar_Lm1)); + ASSERT_FALSE(foo(c_scalar_L)); + ASSERT_FALSE(foo(c_scalar_256m1)); return true; }