forked from iden3/rapidsnark-old
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathzkey_utils.cpp
55 lines (38 loc) · 1.16 KB
/
zkey_utils.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
48
49
50
51
52
53
54
#include <stdexcept>
#include "zkey_utils.hpp"
namespace ZKeyUtils {
Header::Header() {
}
Header::~Header() {
mpz_clear(qPrime);
mpz_clear(rPrime);
}
std::unique_ptr<Header> loadHeader(BinFileUtils::BinFile *f) {
auto h = new Header();
f->startReadSection(1);
uint32_t protocol = f->readU32LE();
if (protocol != 1) {
throw std::invalid_argument( "zkey file is not groth16" );
}
f->endReadSection();
f->startReadSection(2);
h->n8q = f->readU32LE();
mpz_init(h->qPrime);
mpz_import(h->qPrime, h->n8q, -1, 1, -1, 0, f->read(h->n8q));
h->n8r = f->readU32LE();
mpz_init(h->rPrime);
mpz_import(h->rPrime, h->n8r , -1, 1, -1, 0, f->read(h->n8r));
h->nVars = f->readU32LE();
h->nPublic = f->readU32LE();
h->domainSize = f->readU32LE();
h->vk_alpha1 = f->read(h->n8q*2);
h->vk_beta1 = f->read(h->n8q*2);
h->vk_beta2 = f->read(h->n8q*4);
h->vk_gamma2 = f->read(h->n8q*4);
h->vk_delta1 = f->read(h->n8q*2);
h->vk_delta2 = f->read(h->n8q*4);
f->endReadSection();
h->nCoefs = f->getSectionSize(4) / (12 + h->n8r);
return std::unique_ptr<Header>(h);
}
} // namespace