-
Notifications
You must be signed in to change notification settings - Fork 0
/
src.cpp
47 lines (39 loc) · 1.44 KB
/
src.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <secp256k1.h>
#include <secp256k1_bulletproofs.h>
using namespace std;
int main(int argc, char** argv) {
// Generate a random 32-byte secret key
unsigned char sk[32];
secp256k1_rand256(sk);
// Generate a random 32-byte value
unsigned char v[32];
secp256k1_rand256(v);
// Generate a Pedersen commitment to the value
secp256k1_pedersen_commitment comm;
if (!secp256k1_pedersen_commit(ctx, &comm, sk, v, NULL, NULL)) {
cerr << "Error: failed to create Pedersen commitment" << endl;
return 1;
}
// Generate a Bulletproof for the commitment
secp256k1_bulletproof_generators gens;
secp256k1_bulletproof_generators_init(&gens, 64, 1);
secp256k1_bulletproof_proof proof;
unsigned char message[32];
unsigned char blinding_factor[32];
memset(message, 0, sizeof(message));
memset(blinding_factor, 0, sizeof(blinding_factor));
if (!secp256k1_bulletproof_prove(ctx, &proof, &gens, &comm, NULL, NULL, blinding_factor, v, message, sizeof(message))) {
cerr << "Error: failed to create Bulletproof" << endl;
return 1;
}
// Verify the Bulletproof
if (!secp256k1_bulletproof_verify(ctx, &proof, &gens, &comm, NULL, NULL, v, message, sizeof(message))) {
cerr << "Error: failed to verify Bulletproof" << endl;
return 1;
}
cout << "Bulletproof verified!" << endl;
return 0;
}