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
2
#include "
proof_of_possession.hpp
"
3
#include "
barretenberg/ecc/curves/grumpkin/grumpkin.hpp
"
4
#include <gtest/gtest.h>
5
6
using namespace
bb
;
7
using namespace
bb::crypto
;
8
9
template
<
typename
Hash>
struct
ProofOfPossessionTest
:
public
::testing::Test {
10
using
G
=
grumpkin::g1
;
11
using
Fr
=
grumpkin::fr
;
12
using
KeyPair
=
schnorr_key_pair<Fr, G>
;
13
14
static
KeyPair
generate_account
()
15
{
16
KeyPair
account;
17
account.
private_key
=
Fr::random_element
();
18
account.
public_key
=
G::one
* account.
private_key
;
19
return
account;
20
}
21
};
22
23
using
HashTypes
= ::testing::Types<KeccakHasher, Sha256Hasher, Blake2sHasher>;
24
TYPED_TEST_SUITE
(
ProofOfPossessionTest
,
HashTypes
);
25
26
TYPED_TEST
(
ProofOfPossessionTest
, valid_proof)
27
{
28
using
G
=
grumpkin::g1
;
29
using
Hash = TypeParam;
30
using
Proof =
SchnorrProofOfPossession<G, Hash>
;
31
32
const
auto
account = this->generate_account();
33
const
auto
proof = Proof(account);
34
EXPECT_TRUE(proof.verify(account.public_key));
35
}
36
37
TYPED_TEST
(
ProofOfPossessionTest
, invalid_empty_proof)
38
{
39
using
G
=
grumpkin::g1
;
40
using
Hash = TypeParam;
41
using
Proof =
SchnorrProofOfPossession<G, Hash>
;
42
43
const
auto
account = this->generate_account();
44
const
auto
proof = Proof();
45
EXPECT_FALSE(proof.verify(account.public_key));
46
}
47
48
TYPED_TEST
(
ProofOfPossessionTest
, fail_with_different_account)
49
{
50
using
G
=
grumpkin::g1
;
51
using
Hash = TypeParam;
52
using
Proof =
SchnorrProofOfPossession<G, Hash>
;
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
60
TYPED_TEST
(
ProofOfPossessionTest
, fail_zero_challenge)
61
{
62
using
G
=
grumpkin::g1
;
63
using
Hash = TypeParam;
64
using
Proof =
SchnorrProofOfPossession<G, Hash>
;
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
74
TYPED_TEST
(
ProofOfPossessionTest
, fail_zero_response)
75
{
76
using
G
=
grumpkin::g1
;
77
using
Hash = TypeParam;
78
using
Proof =
SchnorrProofOfPossession<G, Hash>
;
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
87
TYPED_TEST
(
ProofOfPossessionTest
,
serialize
)
88
{
89
using
G
=
grumpkin::g1
;
90
using
Hash = TypeParam;
91
using
Proof =
SchnorrProofOfPossession<G, Hash>
;
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
}
bb::group
group class. Represents an elliptic curve group element. Group is parametrised by Fq and Fr
Definition
group.hpp:36
bb::group::one
static constexpr element one
Definition
group.hpp:46
G
#define G(r, i, a, b, c, d)
Definition
blake2s.cpp:116
buf
uint8_t const * buf
Definition
data_store.hpp:9
grumpkin.hpp
bb::crypto
Definition
aes128.cpp:158
bb::grumpkin::g1
bb::group< bb::fr, bb::fq, G1Params > g1
Definition
grumpkin.hpp:45
bb::grumpkin::fr
bb::fq fr
Definition
grumpkin.hpp:18
bb
Entry point for Barretenberg command-line interface.
Definition
acir_format_getters.cpp:6
bb::TYPED_TEST_SUITE
TYPED_TEST_SUITE(ShpleminiTest, TestSettings)
bb::TYPED_TEST
TYPED_TEST(ShpleminiTest, CorrectnessOfMultivariateClaimBatching)
Definition
shplemini.test.cpp:47
serialize
Definition
serialize.hpp:57
proof_of_possession.hpp
HashTypes
::testing::Types< KeccakHasher, Sha256Hasher, Blake2sHasher > HashTypes
Definition
proof_of_possession.test.cpp:23
to_buffer
std::vector< uint8_t > to_buffer(T const &value)
Definition
serialize.hpp:425
ProofOfPossessionTest
Definition
proof_of_possession.test.cpp:9
ProofOfPossessionTest::generate_account
static KeyPair generate_account()
Definition
proof_of_possession.test.cpp:14
bb::crypto::SchnorrProofOfPossession
A proof of possession is a Schnorr proof of knowledge of a secret key corresponding to a given public...
Definition
proof_of_possession.hpp:24
bb::crypto::schnorr_key_pair
Definition
schnorr.hpp:22
bb::crypto::schnorr_key_pair::private_key
Fr private_key
Definition
schnorr.hpp:23
bb::crypto::schnorr_key_pair::public_key
G1::affine_element public_key
Definition
schnorr.hpp:24
bb::field< Bn254FqParams >
bb::field< Bn254FqParams >::random_element
static field random_element(numeric::RNG *engine=nullptr) noexcept
Definition
field_impl.hpp:665
src
barretenberg
crypto
schnorr
proof_of_possession.test.cpp
Generated by
1.9.8