aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tests/performance_tests/crypto_ops.h2
-rw-r--r--tests/performance_tests/main.cpp1
-rw-r--r--tests/unit_tests/bulletproofs.cpp61
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;
+ }
+}