From b68c9fa5d2ef59257ff2091cba1a7b2cff9bc70b Mon Sep 17 00:00:00 2001 From: Jordi Baylina Date: Mon, 7 Dec 2020 12:20:50 +0100 Subject: [PATCH] NPublic in code --- package-lock.json | 6 +++--- package.json | 2 +- ports/c/builder.js | 6 ++++-- ports/wasm/build_runtime.js | 11 +++++++++++ ports/wasm/builder.js | 18 ++++++++++-------- src/build.js | 1 + 6 files changed, 30 insertions(+), 14 deletions(-) diff --git a/package-lock.json b/package-lock.json index e956b80..4b74828 100644 --- a/package-lock.json +++ b/package-lock.json @@ -208,9 +208,9 @@ "integrity": "sha1-V00xLt2Iu13YkS6Sht1sCu1KrII=" }, "circom_runtime": { - "version": "0.1.8", - "resolved": "https://registry.npmjs.org/circom_runtime/-/circom_runtime-0.1.8.tgz", - "integrity": "sha512-5ZmzCyidkNPb1zZsJGRXTuWcJ6kW6+gRBtHgf2tFqTh5dUyWVVPH0Zg7AsU2ijPr1AmYZUlme0yORUZK5HrjOA==", + "version": "0.1.9", + "resolved": "https://registry.npmjs.org/circom_runtime/-/circom_runtime-0.1.9.tgz", + "integrity": "sha512-eh34quaGpeEWXthnhmC9zpoBL/5zJ0mGDbPT/plb/xVmFaKxJDcLuCr2sma5s3il8AYlEIb/nbqytojyI3TWDQ==", "requires": { "ffjavascript": "0.2.10", "fnv-plus": "^1.3.1" diff --git a/package.json b/package.json index 1219703..7994850 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ }, "dependencies": { "chai": "^4.2.0", - "circom_runtime": "0.1.8", + "circom_runtime": "0.1.9", "fastfile": "0.0.18", "ffiasm": "0.1.1", "ffjavascript": "0.2.22", diff --git a/ports/c/builder.js b/ports/c/builder.js index b1a86f7..1b5b896 100644 --- a/ports/c/builder.js +++ b/ports/c/builder.js @@ -433,6 +433,7 @@ class BuilderC { `#define NOutputs ${this.header.NOutputs}`, `#define NInputs ${this.header.NInputs}`, `#define NVars ${this.header.NVars}`, + `#define NPublic ${this.header.NPublic}`, `#define __P__ "${this.header.P.toString()}"`, "" ); @@ -662,7 +663,7 @@ class BuilderC { async _buildCircuitVar(fdData) { - const buff = new Uint8Array(72); + const buff = new Uint8Array(76); const buffV = new DataView(buff.buffer); utils.setUint64(buffV, 0, this.pWit2Sig, true); @@ -678,6 +679,7 @@ class BuilderC { buffV.setUint32(60, this.header.NInputs, true); buffV.setUint32(64, this.header.NVars, true); buffV.setUint32(68, this.nCets, true); + buffV.setUint32(72, this.header.NPublic, true); fdData.pos = 0; @@ -697,7 +699,7 @@ class BuilderC { async build(fdCode, fdData) { const encoder = new TextEncoder("utf-8"); - fdData.pos = 72; + fdData.pos = 76; while (fdData.pos % 8) fdData.pos++; const code=new BigArray(); diff --git a/ports/wasm/build_runtime.js b/ports/wasm/build_runtime.js index 863bd9a..69fe5de 100644 --- a/ports/wasm/build_runtime.js +++ b/ports/wasm/build_runtime.js @@ -693,6 +693,15 @@ module.exports = function buildRuntime(module, builder) { f.addCode(c.i32_const(builder.header.NVars)); } + function buildGetNPublic() { + const f = module.addFunction("getNPublic"); + f.setReturnType("i32"); + + const c = f.getCodeBuilder(); + + f.addCode(c.i32_const(builder.header.NPublic)); + } + function buildGetFrLen() { const f = module.addFunction("getFrLen"); f.setReturnType("i32"); @@ -892,6 +901,7 @@ module.exports = function buildRuntime(module, builder) { buildCheckAssert(); buildGetNVars(); + buildGetNPublic(); buildGetFrLen(); buildGetPWitness(); buildGetPRawPrime(); @@ -901,6 +911,7 @@ module.exports = function buildRuntime(module, builder) { module.exportFunction("init"); module.exportFunction("getNVars"); + module.exportFunction("getNPublic"); module.exportFunction("getFrLen"); module.exportFunction("getSignalOffset32"); module.exportFunction("setSignal"); diff --git a/ports/wasm/builder.js b/ports/wasm/builder.js index 2a4c08d..2d9decd 100644 --- a/ports/wasm/builder.js +++ b/ports/wasm/builder.js @@ -781,20 +781,21 @@ class BuilderWasm { _buildHeader(module) { - this.pCircuit = module.alloc(48); + this.pCircuit = module.alloc(52); this.pNSignals = this.pCircuit; this.pNComponents = this.pCircuit + 4; this.pNInputs = this.pCircuit + 8; this.pNOutputs = this.pCircuit + 12; this.pNVars = this.pCircuit + 16; - this.ppWit2sig = this.pCircuit + 20; - this.ppComponents = this.pCircuit + 24; - this.ppMapIsInput = this.pCircuit + 28; - this.ppConstants = this.pCircuit + 32; - this.ppSignals = this.pCircuit + 36; - this.ppInputSignalsToTrigger = this.pCircuit + 40; - this.ppSignalsAssigned = this.pCircuit + 44; + this.pNPublic = this.pCircuit + 20; + this.ppWit2sig = this.pCircuit + 24; + this.ppComponents = this.pCircuit + 28; + this.ppMapIsInput = this.pCircuit + 32; + this.ppConstants = this.pCircuit + 36; + this.ppSignals = this.pCircuit + 40; + this.ppInputSignalsToTrigger = this.pCircuit + 44; + this.ppSignalsAssigned = this.pCircuit + 48; } _buildSizes(module) { @@ -985,6 +986,7 @@ class BuilderWasm { module.addData(this.pNInputs, intToBytes32(this.header.NInputs)); module.addData(this.pNOutputs, intToBytes32(this.header.NOutputs)); module.addData(this.pNVars, intToBytes32(this.header.NVars)); + module.addData(this.pNPublic, intToBytes32(this.header.NPublic)); module.addData(this.ppWit2sig, intToBytes32(this.pWit2sig)); module.addData(this.ppComponents, intToBytes32(this.pComponents)); module.addData(this.ppMapIsInput, intToBytes32(this.pMapIsInput)); diff --git a/src/build.js b/src/build.js index 93cf682..190fc56 100644 --- a/src/build.js +++ b/src/build.js @@ -196,6 +196,7 @@ function buildHeader(ctx) { NInputs: ctx.components[ ctx.getComponentIdx("main") ].nInSignals, NOutputs: ctx.totals[ ctx.stOUTPUT ], NVars: ctx.totals[ctx.stONE] + ctx.totals[ctx.stOUTPUT] + ctx.totals[ctx.stPUBINPUT] + ctx.totals[ctx.stPRVINPUT] + ctx.totals[ctx.stINTERNAL], + NPublic: ctx.totals[ctx.stOUTPUT] + ctx.totals[ctx.stPUBINPUT], P: ctx.F.p }); }