diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2018-06-29 15:03:00 +0100 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2018-09-11 13:38:04 +0000 |
commit | c42917624849daeac0b4bc2fb1cd1f2539470b28 (patch) | |
tree | 301e71aef03eb5962360a95e2205432add3c78e9 /tests | |
parent | bulletproofs: speed up a few multiplies using existing Hi cache (diff) | |
download | monero-c42917624849daeac0b4bc2fb1cd1f2539470b28.tar.xz |
bulletproofs: reject points not in the main subgroup
Diffstat (limited to 'tests')
-rw-r--r-- | tests/performance_tests/crypto_ops.h | 2 | ||||
-rw-r--r-- | tests/performance_tests/main.cpp | 1 | ||||
-rw-r--r-- | tests/unit_tests/bulletproofs.cpp | 61 |
3 files changed, 64 insertions, 0 deletions
diff --git a/tests/performance_tests/crypto_ops.h b/tests/performance_tests/crypto_ops.h index 852a6670d..f52faa708 100644 --- a/tests/performance_tests/crypto_ops.h +++ b/tests/performance_tests/crypto_ops.h @@ -51,6 +51,7 @@ enum test_op op_addKeys2, op_addKeys3, op_addKeys3_2, + op_isInMainSubgroup, }; template<test_op op> @@ -102,6 +103,7 @@ public: case op_addKeys2: rct::addKeys2(key, scalar0, scalar1, point0); break; case op_addKeys3: rct::addKeys3(key, scalar0, point0, scalar1, precomp1); break; case op_addKeys3_2: rct::addKeys3(key, scalar0, precomp0, scalar1, precomp1); break; + case op_isInMainSubgroup: rct::isInMainSubgroup(point0); break; default: return false; } return true; diff --git a/tests/performance_tests/main.cpp b/tests/performance_tests/main.cpp index 142e544dd..19c2cb5e5 100644 --- a/tests/performance_tests/main.cpp +++ b/tests/performance_tests/main.cpp @@ -237,6 +237,7 @@ int main(int argc, char** argv) TEST_PERFORMANCE1(filter, p, test_crypto_ops, op_addKeys2); TEST_PERFORMANCE1(filter, p, test_crypto_ops, op_addKeys3); TEST_PERFORMANCE1(filter, p, test_crypto_ops, op_addKeys3_2); + TEST_PERFORMANCE1(filter, p, test_crypto_ops, op_isInMainSubgroup); TEST_PERFORMANCE2(filter, p, test_multiexp, multiexp_bos_coster, 2); TEST_PERFORMANCE2(filter, p, test_multiexp, multiexp_bos_coster, 4); diff --git a/tests/unit_tests/bulletproofs.cpp b/tests/unit_tests/bulletproofs.cpp index f163f7a20..2358aa27a 100644 --- a/tests/unit_tests/bulletproofs.cpp +++ b/tests/unit_tests/bulletproofs.cpp @@ -30,6 +30,7 @@ #include "gtest/gtest.h" +#include "string_tools.h" #include "ringct/rctOps.h" #include "ringct/rctSigs.h" #include "ringct/bulletproofs.h" @@ -193,3 +194,63 @@ TEST(bulletproofs, invalid_gamma_ff) rct::Bulletproof proof = bulletproof_PROVE(invalid_amount, gamma); ASSERT_FALSE(rct::bulletproof_VERIFY(proof)); } + +static const char * const torsion_elements[] = +{ + "c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac03fa", + "0000000000000000000000000000000000000000000000000000000000000000", + "26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc85", + "ecffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f", + "26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc05", + "0000000000000000000000000000000000000000000000000000000000000080", + "c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac037a", +}; + +TEST(bulletproofs, invalid_torsion) +{ + rct::Bulletproof proof = bulletproof_PROVE(7329838943733, rct::skGen()); + ASSERT_TRUE(rct::bulletproof_VERIFY(proof)); + for (const auto &xs: torsion_elements) + { + rct::key x; + ASSERT_TRUE(epee::string_tools::hex_to_pod(xs, x)); + ASSERT_FALSE(rct::isInMainSubgroup(x)); + for (auto &k: proof.V) + { + const rct::key org_k = k; + rct::addKeys(k, org_k, x); + ASSERT_FALSE(rct::bulletproof_VERIFY(proof)); + k = org_k; + } + for (auto &k: proof.L) + { + const rct::key org_k = k; + rct::addKeys(k, org_k, x); + ASSERT_FALSE(rct::bulletproof_VERIFY(proof)); + k = org_k; + } + for (auto &k: proof.R) + { + const rct::key org_k = k; + rct::addKeys(k, org_k, x); + ASSERT_FALSE(rct::bulletproof_VERIFY(proof)); + k = org_k; + } + const rct::key org_A = proof.A; + rct::addKeys(proof.A, org_A, x); + ASSERT_FALSE(rct::bulletproof_VERIFY(proof)); + proof.A = org_A; + const rct::key org_S = proof.S; + rct::addKeys(proof.S, org_S, x); + ASSERT_FALSE(rct::bulletproof_VERIFY(proof)); + proof.S = org_S; + const rct::key org_T1 = proof.T1; + rct::addKeys(proof.T1, org_T1, x); + ASSERT_FALSE(rct::bulletproof_VERIFY(proof)); + proof.T1 = org_T1; + const rct::key org_T2 = proof.T2; + rct::addKeys(proof.T2, org_T2, x); + ASSERT_FALSE(rct::bulletproof_VERIFY(proof)); + proof.T2 = org_T2; + } +} |