Browse Source

NPublic in code

master
Jordi Baylina 3 years ago
parent
commit
b68c9fa5d2
No known key found for this signature in database GPG Key ID: 7480C80C1BE43112
6 changed files with 30 additions and 14 deletions
  1. +3
    -3
      package-lock.json
  2. +1
    -1
      package.json
  3. +4
    -2
      ports/c/builder.js
  4. +11
    -0
      ports/wasm/build_runtime.js
  5. +10
    -8
      ports/wasm/builder.js
  6. +1
    -0
      src/build.js

+ 3
- 3
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"

+ 1
- 1
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",

+ 4
- 2
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();

+ 11
- 0
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");

+ 10
- 8
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));

+ 1
- 0
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
});
}

Loading…
Cancel
Save