Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
proof_of_possession.test.cpp
Go to the documentation of this file.
1
4#include <gtest/gtest.h>
5
6using namespace bb;
7using namespace bb::crypto;
8
9template <typename Hash> struct ProofOfPossessionTest : public ::testing::Test {
10 using G = grumpkin::g1;
13
15 {
16 KeyPair account;
18 account.public_key = G::one * account.private_key;
19 return account;
20 }
21};
22
23using HashTypes = ::testing::Types<KeccakHasher, Sha256Hasher, Blake2sHasher>;
25
27{
28 using G = grumpkin::g1;
29 using Hash = TypeParam;
31
32 const auto account = this->generate_account();
33 const auto proof = Proof(account);
34 EXPECT_TRUE(proof.verify(account.public_key));
35}
36
37TYPED_TEST(ProofOfPossessionTest, invalid_empty_proof)
38{
39 using G = grumpkin::g1;
40 using Hash = TypeParam;
42
43 const auto account = this->generate_account();
44 const auto proof = Proof();
45 EXPECT_FALSE(proof.verify(account.public_key));
46}
47
48TYPED_TEST(ProofOfPossessionTest, fail_with_different_account)
49{
50 using G = grumpkin::g1;
51 using Hash = TypeParam;
53
54 const auto account1 = this->generate_account();
55 const auto account2 = this->generate_account();
56 auto proof = Proof(account1);
57 EXPECT_FALSE(proof.verify(account2.public_key));
58}
59
60TYPED_TEST(ProofOfPossessionTest, fail_zero_challenge)
61{
62 using G = grumpkin::g1;
63 using Hash = TypeParam;
65
66 const auto account = this->generate_account();
67 auto proof = Proof(account);
68 proof.challenge = {
69 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
70 };
71 EXPECT_FALSE(proof.verify(account.public_key));
72}
73
75{
76 using G = grumpkin::g1;
77 using Hash = TypeParam;
79
80 const auto account = this->generate_account();
81 auto proof = Proof(account);
82 // Setting the response part of the proof of posession should cause verification to fail.
83 proof.response = 0;
84 EXPECT_FALSE(proof.verify(account.public_key));
85}
86
88{
89 using G = grumpkin::g1;
90 using Hash = TypeParam;
92 const auto account = this->generate_account();
93 const auto proof = Proof(account);
94 EXPECT_TRUE(proof.verify(account.public_key));
95
96 auto buf = to_buffer(proof);
97 EXPECT_EQ(buf.size(), 64);
98 Proof proof2{ from_buffer<Proof, std::vector<uint8_t>>(buf) };
99 EXPECT_EQ(proof.response, proof2.response);
100 EXPECT_EQ(proof.challenge, proof2.challenge);
101
102 EXPECT_TRUE(proof2.verify(account.public_key));
103}
group class. Represents an elliptic curve group element. Group is parametrised by Fq and Fr
Definition group.hpp:36
static constexpr element one
Definition group.hpp:46
#define G(r, i, a, b, c, d)
Definition blake2s.cpp:116
uint8_t const * buf
Definition data_store.hpp:9
bb::group< bb::fr, bb::fq, G1Params > g1
Definition grumpkin.hpp:45
Entry point for Barretenberg command-line interface.
TYPED_TEST_SUITE(ShpleminiTest, TestSettings)
TYPED_TEST(ShpleminiTest, CorrectnessOfMultivariateClaimBatching)
::testing::Types< KeccakHasher, Sha256Hasher, Blake2sHasher > HashTypes
std::vector< uint8_t > to_buffer(T const &value)
A proof of possession is a Schnorr proof of knowledge of a secret key corresponding to a given public...
G1::affine_element public_key
Definition schnorr.hpp:24
static field random_element(numeric::RNG *engine=nullptr) noexcept