Skip to content

Commit 3550e69

Browse files
Calo kruse/tax 3412 update zokrates version 0.8.0 (#31)
* feat: updated zokrates version to 0.8.0 * feat: compile-zok added to internal module --------- Co-authored-by: carlos-kruse <[email protected]>
1 parent 5c90114 commit 3550e69

File tree

3 files changed

+100
-2
lines changed

3 files changed

+100
-2
lines changed

Dockerfile

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
FROM ubuntu:20.04
12
ARG GPR_TOKEN
23

3-
FROM zokrates/zokrates:0.7.7 as builder
4+
FROM zokrates/zokrates:0.8.0 as builder
45

56
FROM node:16.0.0 as node-build
67
ARG GPR_TOKEN
@@ -23,6 +24,33 @@ COPY ./start-dev ./start-dev
2324

2425
RUN apt-get update -y
2526
RUN apt-get install -y netcat
27+
RUN apt-get install vim -y
28+
# RUN apt-get install libc6
29+
30+
RUN cd /etc
31+
RUN mkdir gcc-10-base
32+
RUN cd gcc-10-base/
33+
RUN wget http://ftp.de.debian.org/debian/pool/main/g/gcc-10/gcc-10-base_10.2.1-6_amd64.deb
34+
RUN dpkg -i gcc-10-base_10.2.1-6_amd64.deb || :
35+
36+
RUN cd /etc
37+
RUN mkdir libgcc-s1
38+
RUN cd libgcc-s1/
39+
RUN wget http://ftp.de.debian.org/debian/pool/main/g/gcc-10/libgcc-s1_10.2.1-6_amd64.deb
40+
RUN dpkg -i libgcc-s1_10.2.1-6_amd64.deb || :
41+
42+
RUN cd /etc
43+
RUN mkdir libcrypt1
44+
RUN cd libcrypt1/
45+
RUN wget http://ftp.de.debian.org/debian/pool/main/libx/libxcrypt/libcrypt1_4.4.18-4_amd64.deb
46+
RUN dpkg -i libcrypt1_4.4.18-4_amd64.deb || :
47+
48+
RUN cd /etc
49+
RUN mkdir libc6
50+
RUN cd libc6/
51+
RUN wget http://ftp.de.debian.org/debian/pool/main/g/glibc/libc6_2.31-13+deb11u5_amd64.deb
52+
RUN dpkg -i libc6_2.31-13+deb11u5_amd64.deb || :
53+
RUN cd ..
2654

2755
ENV ZOKRATES_HOME /app
2856
ENV ZOKRATES_STDLIB /app/stdlib

src/services/compile-zok.mjs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import fs from 'fs';
2+
import { spawn } from 'child_process';
3+
4+
/**
5+
* Compiles code found at `codePath` and outputs at the output path.
6+
*
7+
* @example
8+
* // Will compile contents, generating ./ft-mint.code` and ./ft-mint as outputs
9+
* compile('./code/ft-mint/ft-mint.code', './', 'ft-mint');
10+
*
11+
* @param {String} codePath - Path of code file to compile
12+
* @param {String} [outputPath=./] - Directory to output, defaults to current directory
13+
* @param {String} [outputName=out] - name of `.code` and `out` files. Defaults to out.
14+
*/
15+
async function compile(
16+
codePath,
17+
outputPath = './',
18+
outputName = 'out',
19+
curve = 'bn128',
20+
options = {},
21+
) {
22+
const { maxReturn = 10000000, verbose = false } = options;
23+
if (!fs.existsSync(codePath)) {
24+
throw new Error('Compile input file(s) not found');
25+
}
26+
const parsedOutputName = outputName; // TODO can have more checks here
27+
// TODO: Check if outputPath is directory, otherwise throw.
28+
const parsedOutputPath = outputPath.endsWith('/') ? outputPath : `${outputPath}/`;
29+
return new Promise((resolve, reject) => {
30+
const zokrates = spawn(
31+
'/app/zokrates',
32+
['compile', '-i', codePath, '-o', `${parsedOutputPath}${parsedOutputName}`, '--curve', curve],
33+
{
34+
stdio: ['ignore', 'pipe', 'pipe'],
35+
env: {
36+
ZOKRATES_STDLIB: process.env.ZOKRATES_STDLIB,
37+
},
38+
},
39+
);
40+
41+
let output = '';
42+
43+
zokrates.stdout.on('data', data => {
44+
if (verbose) {
45+
output += data.toString('utf8');
46+
// If the entire output gets too large, just send ...[truncated].
47+
if (output.length > maxReturn) output = '...[truncated]';
48+
}
49+
});
50+
51+
zokrates.stderr.on('data', err => {
52+
reject(new Error(`Compile failed: ${err}`));
53+
});
54+
55+
zokrates.on('close', () => {
56+
// ZoKrates sometimes outputs error through stdout instead of stderr,
57+
// so we need to catch those errors manually.
58+
if (output.includes('panicked')) {
59+
reject(new Error(output.slice(output.indexOf('panicked'))));
60+
}
61+
if (verbose) resolve(output);
62+
else resolve();
63+
});
64+
});
65+
}
66+
67+
export default compile;

src/services/generateKeys.mjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import fs from 'fs';
22
import path from 'path';
33
import zokrates from '@eyblockchain/zokrates-zexe.js';
44
import logger from '../utils/logger.mjs';
5+
import compile from './compile-zok.mjs';
56

7+
// TODO: REMOVE THE COMPILE MODULE WHEN IT IS CORRECTED ON @eyblockchain/zokrates-zexe.js
68
export default async function({
79
filepath,
810
curve = 'bn128',
@@ -19,7 +21,8 @@ export default async function({
1921
fs.mkdirSync(`${outputPath}/${circuitDir}`, { recursive: true });
2022

2123
logger.info('Compile...');
22-
await zokrates.compile(
24+
// TODO: Use again the zokrates node module.
25+
await compile(
2326
`${circuitsPath}/${filepath}`,
2427
`${outputPath}/${circuitDir}`,
2528
`${circuitName}_out`,

0 commit comments

Comments
 (0)