Skip to content

Commit af248e5

Browse files
committed
initial import
0 parents  commit af248e5

27 files changed

+2943
-0
lines changed

CMakeLists.txt

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
project(qaptools)
2+
cmake_minimum_required(VERSION 3.1)
3+
set (CMAKE_CXX_STANDARD 11)
4+
5+
find_path(GMP_INCLUDE_DIR NAMES gmp.h)
6+
find_library(GMP_LIBRARIES NAMES gmp libgmp)
7+
find_library(GMPXX_LIBRARIES NAMES gmpxx libgmpxx)
8+
include_directories(${GMP_INCLUDE_DIR})
9+
10+
include_directories(depends/ate-pairing/include)
11+
include_directories(depends/xbyak)
12+
13+
add_definitions(-DBN_SUPPORT_SNARK=1)
14+
15+
add_library(
16+
zm
17+
STATIC
18+
19+
depends/ate-pairing/src/zm.cpp
20+
depends/ate-pairing/src/zm2.cpp
21+
)
22+
23+
add_library(
24+
qap
25+
STATIC
26+
27+
key.cpp
28+
proof.cpp
29+
modp.cpp
30+
base.cpp
31+
qap2key.cpp
32+
fft.cpp
33+
prove.cpp
34+
qap.cpp
35+
verify.cpp
36+
)
37+
38+
link_libraries(qap zm ${GMP_LIBRARIES} ${GMPXX_LIBRARIES})
39+
40+
add_executable(qapgen qapgen.cpp)
41+
add_executable(qapcoeffcache qapcoeffcache.cpp)
42+
add_executable(qapgenf qapgenf.cpp)
43+
add_executable(qapinput qapinput.cpp)
44+
add_executable(qapprove qapprove.cpp)
45+
add_executable(qapver qapver.cpp)

Makefile

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# cflags/ldflags for tools
2+
CFLAGS=-std=c++11 -DSUPPORT_SNARK -I ate-pairing/include
3+
LDFLAGS=-L ate-pairing/lib -L/usr/local/lib -lm -lzm -lgmpxx -lgmp
4+
5+
6+
EXECS=qapgen qapcoeffcache qapgenf qapinput qapprove qapver
7+
8+
all: $(EXECS)
9+
10+
%.o: %.cpp
11+
g++ $(CFLAGS) -c -o $@ $<
12+
13+
qapgen: qapgen.o key.o proof.o modp.o base.o qap2key.o fft.o
14+
g++ -o $@ $^ $(LDFLAGS)
15+
16+
qapcoeffcache: qapcoeffcache.o key.o proof.o modp.o base.o qap2key.o fft.o
17+
g++ -o $@ $^ $(LDFLAGS)
18+
19+
qapgenf: qapgenf.o key.o qap.o modp.o base.o qap2key.o fft.o
20+
g++ -o $@ $^ $(LDFLAGS)
21+
22+
qapinput: qapinput.o base.o key.o proof.o prove.o qap2key.o modp.o fft.o
23+
g++ -o $@ $^ $(LDFLAGS)
24+
25+
qapprove: qapprove.o base.o key.o modp.o proof.o prove.o qap.o modp.o fft.o
26+
g++ -o $@ $^ $(LDFLAGS)
27+
28+
qapver: qapver.o base.o key.o prove.o proof.o verify.o modp.o qap.o fft.o
29+
g++ -o $@ $^ $(LDFLAGS)
30+
31+
clean:
32+
rm -f *.o $(EXECS)

__init__.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright (c) 2016-2018 Koninklijke Philips N.V. All rights reserved. A
2+
# copyright license for redistribution and use in source and binary forms,
3+
# with or without modification, is hereby granted for non-commercial,
4+
# experimental and research purposes, provided that the following conditions
5+
# are met:
6+
# - Redistributions of source code must retain the above copyright notice,
7+
# this list of conditions and the following disclaimers.
8+
# - Redistributions in binary form must reproduce the above copyright notice,
9+
# this list of conditions and the following disclaimers in the
10+
# documentation and/or other materials provided with the distribution. If
11+
# you wish to use this software commercially, kindly contact
12+
# [email protected] to obtain a commercial license.
13+
#
14+
# This license extends only to copyright and does not include or grant any
15+
# patent license or other license whatsoever.
16+
#
17+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
18+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27+
# POSSIBILITY OF SUCH DAMAGE.

base.cpp

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/**
2+
* Copyright (c) 2016-2018 Koninklijke Philips N.V. All rights reserved. A
3+
* copyright license for redistribution and use in source and binary forms,
4+
* with or without modification, is hereby granted for non-commercial,
5+
* experimental and research purposes, provided that the following conditions
6+
* are met:
7+
* - Redistributions of source code must retain the above copyright notice,
8+
* this list of conditions and the following disclaimers.
9+
* - Redistributions in binary form must reproduce the above copyright notice,
10+
* this list of conditions and the following disclaimers in the
11+
* documentation and/or other materials provided with the distribution. If
12+
* you wish to use this software commercially, kindly contact
13+
* [email protected] to obtain a commercial license.
14+
*
15+
* This license extends only to copyright and does not include or grant any
16+
* patent license or other license whatsoever.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
19+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
* POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
31+
#include <gmpxx.h>
32+
#define MIE_ATE_USE_GMP
33+
#include <bn.h>
34+
35+
using namespace bn;
36+
using namespace std;
37+
38+
gmp_randstate_t randst;
39+
mpz_class qap_modulus;
40+
Ec1 g1, g10;
41+
Ec2 g2, g20;
42+
43+
void libqap_init() {
44+
CurveParam cp = CurveSNARK1;
45+
cp.b = 3;
46+
Param::init(cp);
47+
qap_modulus = mpz_class(Param::r.toString());
48+
49+
g1=Ec1(1, 2);
50+
g10=g1*0;
51+
g2=Ec2(Fp2(Fp("10857046999023057135944570762232829481370756359578518086990519993285655852781"),
52+
Fp("11559732032986387107991004021392285783925812861821192530917403151452391805634")),
53+
Fp2(Fp("8495653923123431417604973247489272438418190587263600148770280649306958101930"),
54+
Fp("4082367875863433681332203403145435568316851327593401208105741076214120093531")));
55+
g20=g2*0;
56+
57+
gmp_randinit_default (randst);
58+
}
59+

base.h

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* Copyright (c) 2016-2018 Koninklijke Philips N.V. All rights reserved. A
3+
* copyright license for redistribution and use in source and binary forms,
4+
* with or without modification, is hereby granted for non-commercial,
5+
* experimental and research purposes, provided that the following conditions
6+
* are met:
7+
* - Redistributions of source code must retain the above copyright notice,
8+
* this list of conditions and the following disclaimers.
9+
* - Redistributions in binary form must reproduce the above copyright notice,
10+
* this list of conditions and the following disclaimers in the
11+
* documentation and/or other materials provided with the distribution. If
12+
* you wish to use this software commercially, kindly contact
13+
* [email protected] to obtain a commercial license.
14+
*
15+
* This license extends only to copyright and does not include or grant any
16+
* patent license or other license whatsoever.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
19+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
* POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
31+
#pragma once
32+
33+
#include <gmpxx.h>
34+
#define MIE_ATE_USE_GMP
35+
#include <bn.h>
36+
using namespace bn;
37+
38+
extern gmp_randstate_t randst;
39+
extern mpz_class qap_modulus;
40+
extern Ec1 g1, g10;
41+
extern Ec2 g2, g20;
42+
43+
void libqap_init();

fft.cpp

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/**
2+
* Copyright (c) 2016-2018 Koninklijke Philips N.V. All rights reserved. A
3+
* copyright license for redistribution and use in source and binary forms,
4+
* with or without modification, is hereby granted for non-commercial,
5+
* experimental and research purposes, provided that the following conditions
6+
* are met:
7+
* - Redistributions of source code must retain the above copyright notice,
8+
* this list of conditions and the following disclaimers.
9+
* - Redistributions in binary form must reproduce the above copyright notice,
10+
* this list of conditions and the following disclaimers in the
11+
* documentation and/or other materials provided with the distribution. If
12+
* you wish to use this software commercially, kindly contact
13+
* [email protected] to obtain a commercial license.
14+
*
15+
* This license extends only to copyright and does not include or grant any
16+
* patent license or other license whatsoever.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
19+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
* POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
31+
#include <gmpxx.h>
32+
#define MIE_ATE_USE_GMP
33+
#include <bn.h>
34+
35+
using namespace bn;
36+
using namespace std;
37+
38+
#include "fft.h"
39+
#include "modp.h"
40+
41+
template<typename T> void fft(
42+
const vector<T>& roots,
43+
vector<T>& X, int X0,
44+
const vector<T>& x, int N, int x0, int s, int rs) {
45+
46+
int Ndiv2 = N/2;
47+
int NR = roots.size();
48+
49+
if (N==1) { X[X0] = x[x0]; return; }
50+
51+
fft(roots, X, X0, x, Ndiv2, x0, 2*s, 2*rs);
52+
fft(roots, X, X0+Ndiv2, x, Ndiv2, x0+s, 2*s, 2*rs);
53+
54+
for (int k = 0; k < Ndiv2; k++) {
55+
int rix = (((k*rs) % NR) + NR) % NR;
56+
T t = X[X0+k], delta = roots[rix]*X[X0+Ndiv2+k];
57+
X[X0+k] = t + delta;
58+
X[X0+Ndiv2+k] = t - delta;
59+
}
60+
}
61+
62+
template<typename T> void fft(const vector<T>& roots, vector<T>& ret, const vector<T>& coeff) {
63+
fft(roots, ret, 0, coeff, coeff.size(), 0, 1, 1);
64+
}
65+
66+
template<typename T> void fftinv(const vector<T>& roots, vector<T>& ret, const vector<T>& coeff) {
67+
fft(roots, ret, 0, coeff, coeff.size(), 0, 1, -1);
68+
69+
T n(ret.size()), ninv = n.inv();
70+
for (unsigned int i = 0; i < ret.size(); i++)
71+
ret[i] = ninv*ret[i];
72+
}
73+
74+
template void fft<modp>(const vector<modp>& roots, std::vector<modp>& ret, const std::vector<modp>& coeff);
75+
template void fftinv<modp>(const vector<modp>& roots, std::vector<modp>& ret, const std::vector<modp>& coeff);

fft.h

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* Copyright (c) 2016-2018 Koninklijke Philips N.V. All rights reserved. A
3+
* copyright license for redistribution and use in source and binary forms,
4+
* with or without modification, is hereby granted for non-commercial,
5+
* experimental and research purposes, provided that the following conditions
6+
* are met:
7+
* - Redistributions of source code must retain the above copyright notice,
8+
* this list of conditions and the following disclaimers.
9+
* - Redistributions in binary form must reproduce the above copyright notice,
10+
* this list of conditions and the following disclaimers in the
11+
* documentation and/or other materials provided with the distribution. If
12+
* you wish to use this software commercially, kindly contact
13+
* [email protected] to obtain a commercial license.
14+
*
15+
* This license extends only to copyright and does not include or grant any
16+
* patent license or other license whatsoever.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
19+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
* POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
31+
#pragma once
32+
33+
#include <vector>
34+
using namespace std;
35+
36+
//template<typename T> void fft(const vector<T>& roots, vector<T>& X, int X0, const vector<T>& x, int N, int x0, int s, int rs);
37+
template<typename T> void fft(const vector<T>& roots, vector<T>& ret, const vector<T>& coeff);
38+
template<typename T> void fftinv(const vector<T>& roots, vector<T>& ret, const vector<T>& coeff);

0 commit comments

Comments
 (0)