@peeramid-labs/sdk 3.7.3 → 3.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli/abis/MAODistribution.js +10 -0
- package/cli/abis/MAODistribution.js.map +1 -1
- package/cli/abis/RankToken.js +84 -0
- package/cli/abis/RankToken.js.map +1 -1
- package/cli/abis/superinterface.js +9 -3
- package/cli/abis/superinterface.js.map +1 -1
- package/cli/cli/commands/distributions/add.js +2 -0
- package/cli/cli/commands/distributions/add.js.map +1 -1
- package/cli/cli/commands/distributions/index.js +3 -1
- package/cli/cli/commands/distributions/index.js.map +1 -1
- package/cli/cli/commands/distributions/remove.js +67 -0
- package/cli/cli/commands/distributions/remove.js.map +1 -0
- package/cli/cli/commands/fellowship/create.js +8 -1
- package/cli/cli/commands/fellowship/create.js.map +1 -1
- package/cli/cli/commands/fellowship/endTurn.js +42 -0
- package/cli/cli/commands/fellowship/endTurn.js.map +1 -0
- package/cli/cli/commands/fellowship/games.js +1 -1
- package/cli/cli/commands/fellowship/games.js.map +1 -1
- package/cli/cli/commands/fellowship/index.js +5 -1
- package/cli/cli/commands/fellowship/index.js.map +1 -1
- package/cli/cli/commands/fellowship/params.js +49 -0
- package/cli/cli/commands/fellowship/params.js.map +1 -0
- package/cli/rankify/GameMaster.js +1076 -0
- package/cli/rankify/GameMaster.js.map +1 -0
- package/cli/rankify/InstanceBase.js +1 -0
- package/cli/rankify/InstanceBase.js.map +1 -1
- package/cli/rankify/MAODistributor.js +28 -0
- package/cli/rankify/MAODistributor.js.map +1 -1
- package/cli/utils/ApiError.js +11 -6
- package/cli/utils/ApiError.js.map +1 -1
- package/docs/classes/GameMaster.md +2 -2
- package/docs/classes/InstanceBase.md +2 -2
- package/docs/classes/InstancePlayer.md +2 -2
- package/docs/classes/MAODistributorClient.md +18 -1
- package/docs/docs/classes/GameMaster.md +2 -2
- package/docs/docs/classes/InstanceBase.md +2 -2
- package/docs/docs/classes/InstancePlayer.md +2 -2
- package/docs/docs/classes/MAODistributorClient.md +18 -1
- package/docs/docs/index.md +4 -4
- package/docs/index.md +4 -4
- package/lib.commonjs/abis/MAODistribution.d.ts +8 -0
- package/lib.commonjs/abis/MAODistribution.d.ts.map +1 -1
- package/lib.commonjs/abis/MAODistribution.js +10 -0
- package/lib.commonjs/abis/MAODistribution.js.map +1 -1
- package/lib.commonjs/abis/RankToken.d.ts +65 -0
- package/lib.commonjs/abis/RankToken.d.ts.map +1 -1
- package/lib.commonjs/abis/RankToken.js +84 -0
- package/lib.commonjs/abis/RankToken.js.map +1 -1
- package/lib.commonjs/abis/index.d.ts +74 -1
- package/lib.commonjs/abis/index.d.ts.map +1 -1
- package/lib.commonjs/abis/superinterface.d.ts +1 -1
- package/lib.commonjs/abis/superinterface.d.ts.map +1 -1
- package/lib.commonjs/abis/superinterface.js +9 -3
- package/lib.commonjs/abis/superinterface.js.map +1 -1
- package/lib.commonjs/multipass/MultipassBase.d.ts.map +1 -1
- package/lib.commonjs/multipass/Registrar.d.ts.map +1 -1
- package/lib.commonjs/rankify/GameMaster.d.ts +1 -1
- package/lib.commonjs/rankify/GameMaster.d.ts.map +1 -1
- package/lib.commonjs/rankify/GameMaster.js +37 -26
- package/lib.commonjs/rankify/GameMaster.js.map +1 -1
- package/lib.commonjs/rankify/InstanceBase.d.ts +1 -1
- package/lib.commonjs/rankify/InstanceBase.d.ts.map +1 -1
- package/lib.commonjs/rankify/InstanceBase.js +1 -0
- package/lib.commonjs/rankify/InstanceBase.js.map +1 -1
- package/lib.commonjs/rankify/MAODistributor.d.ts +1036 -0
- package/lib.commonjs/rankify/MAODistributor.d.ts.map +1 -1
- package/lib.commonjs/rankify/MAODistributor.js +28 -0
- package/lib.commonjs/rankify/MAODistributor.js.map +1 -1
- package/lib.commonjs/rankify/Player.d.ts.map +1 -1
- package/lib.commonjs/rankify/RankToken.d.ts.map +1 -1
- package/lib.commonjs/utils/ApiError.d.ts.map +1 -1
- package/lib.commonjs/utils/ApiError.js +11 -6
- package/lib.commonjs/utils/ApiError.js.map +1 -1
- package/lib.commonjs/utils/artifacts.d.ts.map +1 -1
- package/lib.commonjs/utils/index.d.ts.map +1 -1
- package/lib.commonjs/utils/permutations.d.ts.map +1 -1
- package/lib.esm/abis/MAODistribution.d.ts +8 -0
- package/lib.esm/abis/MAODistribution.d.ts.map +1 -1
- package/lib.esm/abis/MAODistribution.js +10 -0
- package/lib.esm/abis/MAODistribution.js.map +1 -1
- package/lib.esm/abis/RankToken.d.ts +65 -0
- package/lib.esm/abis/RankToken.d.ts.map +1 -1
- package/lib.esm/abis/RankToken.js +84 -0
- package/lib.esm/abis/RankToken.js.map +1 -1
- package/lib.esm/abis/index.d.ts +74 -1
- package/lib.esm/abis/index.d.ts.map +1 -1
- package/lib.esm/abis/superinterface.d.ts +1 -1
- package/lib.esm/abis/superinterface.d.ts.map +1 -1
- package/lib.esm/abis/superinterface.js +9 -3
- package/lib.esm/abis/superinterface.js.map +1 -1
- package/lib.esm/multipass/MultipassBase.d.ts.map +1 -1
- package/lib.esm/multipass/Registrar.d.ts.map +1 -1
- package/lib.esm/rankify/GameMaster.d.ts +1 -1
- package/lib.esm/rankify/GameMaster.d.ts.map +1 -1
- package/lib.esm/rankify/GameMaster.js +38 -27
- package/lib.esm/rankify/GameMaster.js.map +1 -1
- package/lib.esm/rankify/InstanceBase.d.ts +1 -1
- package/lib.esm/rankify/InstanceBase.d.ts.map +1 -1
- package/lib.esm/rankify/InstanceBase.js +1 -0
- package/lib.esm/rankify/InstanceBase.js.map +1 -1
- package/lib.esm/rankify/MAODistributor.d.ts +1036 -0
- package/lib.esm/rankify/MAODistributor.d.ts.map +1 -1
- package/lib.esm/rankify/MAODistributor.js +28 -0
- package/lib.esm/rankify/MAODistributor.js.map +1 -1
- package/lib.esm/rankify/Player.d.ts.map +1 -1
- package/lib.esm/rankify/RankToken.d.ts.map +1 -1
- package/lib.esm/utils/ApiError.d.ts.map +1 -1
- package/lib.esm/utils/ApiError.js +11 -6
- package/lib.esm/utils/ApiError.js.map +1 -1
- package/lib.esm/utils/artifacts.d.ts.map +1 -1
- package/lib.esm/utils/index.d.ts.map +1 -1
- package/lib.esm/utils/permutations.d.ts.map +1 -1
- package/package.json +8 -8
- package/zk_artifacts/circuits/proposals_integrity_15.circom/ProposalsIntegrity15.groth16.vkey.json +1 -0
- package/zk_artifacts/circuits/proposals_integrity_15.circom/ProposalsIntegrity15.groth16.zkey +0 -0
- package/zk_artifacts/circuits/proposals_integrity_15.circom/ProposalsIntegrity15.r1cs +0 -0
- package/zk_artifacts/circuits/proposals_integrity_15.circom/ProposalsIntegrity15.sym +19202 -0
- package/zk_artifacts/circuits/proposals_integrity_15.circom/ProposalsIntegrity15_artifacts.json +84 -0
- package/zk_artifacts/circuits/proposals_integrity_15.circom/ProposalsIntegrity15_js/ProposalsIntegrity15.wasm +0 -0
- package/zk_artifacts/circuits/proposals_integrity_15.circom/ProposalsIntegrity15_js/generate_witness.js +21 -0
- package/zk_artifacts/circuits/proposals_integrity_15.circom/ProposalsIntegrity15_js/witness_calculator.js +384 -0
- package/zk_artifacts/types/core/ProposalsIntegrity15.ts +163 -0
- package/zk_artifacts/types/core/index.ts +6 -0
- package/zk_artifacts/types/hardhat.d.ts +14 -0
- package/zk_artifacts/types/helpers.ts +44 -0
- package/zk_artifacts/types/index.ts +8 -0
- package/zk_artifacts/zk_artifacts/circuits/proposals_integrity_15.circom/ProposalsIntegrity15.groth16.vkey.json +1 -0
- package/zk_artifacts/zk_artifacts/circuits/proposals_integrity_15.circom/ProposalsIntegrity15.groth16.zkey +0 -0
- package/zk_artifacts/zk_artifacts/circuits/proposals_integrity_15.circom/ProposalsIntegrity15.r1cs +0 -0
- package/zk_artifacts/zk_artifacts/circuits/proposals_integrity_15.circom/ProposalsIntegrity15.sym +19202 -0
- package/zk_artifacts/zk_artifacts/circuits/proposals_integrity_15.circom/ProposalsIntegrity15_artifacts.json +84 -0
- package/zk_artifacts/zk_artifacts/circuits/proposals_integrity_15.circom/ProposalsIntegrity15_js/ProposalsIntegrity15.wasm +0 -0
- package/zk_artifacts/zk_artifacts/circuits/proposals_integrity_15.circom/ProposalsIntegrity15_js/generate_witness.js +21 -0
- package/zk_artifacts/zk_artifacts/circuits/proposals_integrity_15.circom/ProposalsIntegrity15_js/witness_calculator.js +384 -0
- package/zk_artifacts/zk_artifacts/types/core/ProposalsIntegrity15.ts +163 -0
- package/zk_artifacts/zk_artifacts/types/core/index.ts +6 -0
- package/zk_artifacts/zk_artifacts/types/hardhat.d.ts +14 -0
- package/zk_artifacts/zk_artifacts/types/helpers.ts +44 -0
- package/zk_artifacts/zk_artifacts/types/index.ts +8 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
{
|
|
2
|
+
"_format": "hh-zkit-artifacts-1",
|
|
3
|
+
"circuitTemplateName": "ProposalsIntegrity15",
|
|
4
|
+
"circuitFileName": "proposals_integrity_15",
|
|
5
|
+
"circuitSourceName": "circuits/proposals_integrity_15.circom",
|
|
6
|
+
"baseCircuitInfo": {
|
|
7
|
+
"constraintsNumber": 12605,
|
|
8
|
+
"signals": [
|
|
9
|
+
{
|
|
10
|
+
"name": "commitments",
|
|
11
|
+
"dimension": [
|
|
12
|
+
15
|
|
13
|
+
],
|
|
14
|
+
"type": "Input",
|
|
15
|
+
"visibility": "Public"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"name": "permutedProposals",
|
|
19
|
+
"dimension": [
|
|
20
|
+
15
|
|
21
|
+
],
|
|
22
|
+
"type": "Input",
|
|
23
|
+
"visibility": "Public"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"name": "permutationCommitment",
|
|
27
|
+
"dimension": [],
|
|
28
|
+
"type": "Input",
|
|
29
|
+
"visibility": "Public"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"name": "numActive",
|
|
33
|
+
"dimension": [],
|
|
34
|
+
"type": "Input",
|
|
35
|
+
"visibility": "Public"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"name": "permutation",
|
|
39
|
+
"dimension": [
|
|
40
|
+
15
|
|
41
|
+
],
|
|
42
|
+
"type": "Input",
|
|
43
|
+
"visibility": "Private"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"name": "randomnesses",
|
|
47
|
+
"dimension": [
|
|
48
|
+
15
|
|
49
|
+
],
|
|
50
|
+
"type": "Input",
|
|
51
|
+
"visibility": "Private"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"name": "permutationRandomness",
|
|
55
|
+
"dimension": [],
|
|
56
|
+
"type": "Input",
|
|
57
|
+
"visibility": "Private"
|
|
58
|
+
}
|
|
59
|
+
],
|
|
60
|
+
"parameters": {}
|
|
61
|
+
},
|
|
62
|
+
"compilerOutputFiles": {
|
|
63
|
+
"r1cs": {
|
|
64
|
+
"fileSourcePath": "/Users/t/GitHub/peeramid/contracts/zk_artifacts/circuits/proposals_integrity_15.circom/ProposalsIntegrity15.r1cs",
|
|
65
|
+
"fileHash": "f54b5736695b4d389900c180b0dfa1b092d2ad92"
|
|
66
|
+
},
|
|
67
|
+
"wasm": {
|
|
68
|
+
"fileSourcePath": "/Users/t/GitHub/peeramid/contracts/zk_artifacts/circuits/proposals_integrity_15.circom/ProposalsIntegrity15_js/ProposalsIntegrity15.wasm",
|
|
69
|
+
"fileHash": "668aecd270f295133e97fa9038d8904e9b162468"
|
|
70
|
+
},
|
|
71
|
+
"sym": {
|
|
72
|
+
"fileSourcePath": "/Users/t/GitHub/peeramid/contracts/zk_artifacts/circuits/proposals_integrity_15.circom/ProposalsIntegrity15.sym",
|
|
73
|
+
"fileHash": "68fbc3dce139fdc8bf364367ec4c401a179b636a"
|
|
74
|
+
},
|
|
75
|
+
"groth16.zkey": {
|
|
76
|
+
"fileSourcePath": "/Users/t/GitHub/peeramid/contracts/zk_artifacts/circuits/proposals_integrity_15.circom/ProposalsIntegrity15.groth16.zkey",
|
|
77
|
+
"fileHash": "19bf11eec4bf6e83589576f9585da4db6e4c37af"
|
|
78
|
+
},
|
|
79
|
+
"groth16.vkey": {
|
|
80
|
+
"fileSourcePath": "/Users/t/GitHub/peeramid/contracts/zk_artifacts/circuits/proposals_integrity_15.circom/ProposalsIntegrity15.groth16.vkey.json",
|
|
81
|
+
"fileHash": "cf0ca014500478e1e6c42091d84a36b2bb32a340"
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const wc = require("./witness_calculator.js");
|
|
2
|
+
const { readFileSync, writeFile } = require("fs");
|
|
3
|
+
|
|
4
|
+
if (process.argv.length != 5) {
|
|
5
|
+
console.log("Usage: node generate_witness.js <file.wasm> <input.json> <output.wtns>");
|
|
6
|
+
} else {
|
|
7
|
+
const input = JSON.parse(readFileSync(process.argv[3], "utf8"));
|
|
8
|
+
|
|
9
|
+
const buffer = readFileSync(process.argv[2]);
|
|
10
|
+
wc(buffer).then(async witnessCalculator => {
|
|
11
|
+
const w= await witnessCalculator.calculateWitness(input,0);
|
|
12
|
+
/*
|
|
13
|
+
for (let i=0; i< w.length; i++){
|
|
14
|
+
console.log(w[i]);
|
|
15
|
+
}*/
|
|
16
|
+
const buff= await witnessCalculator.calculateWTNSBin(input,0);
|
|
17
|
+
writeFile(process.argv[4], buff, function(err) {
|
|
18
|
+
if (err) throw err;
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
}
|
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
module.exports = async function builder(code, options) {
|
|
2
|
+
|
|
3
|
+
options = options || {};
|
|
4
|
+
|
|
5
|
+
let wasmModule;
|
|
6
|
+
try {
|
|
7
|
+
wasmModule = await WebAssembly.compile(code);
|
|
8
|
+
} catch (err) {
|
|
9
|
+
console.log(err);
|
|
10
|
+
console.log("\nTry to run circom --c in order to generate c++ code instead\n");
|
|
11
|
+
throw new Error(err);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
let wc;
|
|
15
|
+
|
|
16
|
+
let errStr = "";
|
|
17
|
+
let msgStr = "";
|
|
18
|
+
|
|
19
|
+
const instance = await WebAssembly.instantiate(wasmModule, {
|
|
20
|
+
runtime: {
|
|
21
|
+
printDebug : function(value) {
|
|
22
|
+
console.log("printDebug:",value);
|
|
23
|
+
},
|
|
24
|
+
exceptionHandler : function(code) {
|
|
25
|
+
let err;
|
|
26
|
+
if (code == 1) {
|
|
27
|
+
err = "Signal not found.\n";
|
|
28
|
+
} else if (code == 2) {
|
|
29
|
+
err = "Too many signals set.\n";
|
|
30
|
+
} else if (code == 3) {
|
|
31
|
+
err = "Signal already set.\n";
|
|
32
|
+
} else if (code == 4) {
|
|
33
|
+
err = "Assert Failed.\n";
|
|
34
|
+
} else if (code == 5) {
|
|
35
|
+
err = "Not enough memory.\n";
|
|
36
|
+
} else if (code == 6) {
|
|
37
|
+
err = "Input signal array access exceeds the size.\n";
|
|
38
|
+
} else {
|
|
39
|
+
err = "Unknown error.\n";
|
|
40
|
+
}
|
|
41
|
+
throw new Error(err + errStr);
|
|
42
|
+
},
|
|
43
|
+
printErrorMessage : function() {
|
|
44
|
+
errStr += getMessage() + "\n";
|
|
45
|
+
// console.error(getMessage());
|
|
46
|
+
},
|
|
47
|
+
writeBufferMessage : function() {
|
|
48
|
+
const msg = getMessage();
|
|
49
|
+
// Any calls to `log()` will always end with a `\n`, so that's when we print and reset
|
|
50
|
+
if (msg === "\n") {
|
|
51
|
+
console.log(msgStr);
|
|
52
|
+
msgStr = "";
|
|
53
|
+
} else {
|
|
54
|
+
// If we've buffered other content, put a space in between the items
|
|
55
|
+
if (msgStr !== "") {
|
|
56
|
+
msgStr += " "
|
|
57
|
+
}
|
|
58
|
+
// Then append the message to the message we are creating
|
|
59
|
+
msgStr += msg;
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
showSharedRWMemory : function() {
|
|
63
|
+
printSharedRWMemory ();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const sanityCheck =
|
|
70
|
+
options
|
|
71
|
+
// options &&
|
|
72
|
+
// (
|
|
73
|
+
// options.sanityCheck ||
|
|
74
|
+
// options.logGetSignal ||
|
|
75
|
+
// options.logSetSignal ||
|
|
76
|
+
// options.logStartComponent ||
|
|
77
|
+
// options.logFinishComponent
|
|
78
|
+
// );
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
wc = new WitnessCalculator(instance, sanityCheck);
|
|
82
|
+
return wc;
|
|
83
|
+
|
|
84
|
+
function getMessage() {
|
|
85
|
+
var message = "";
|
|
86
|
+
var c = instance.exports.getMessageChar();
|
|
87
|
+
while ( c != 0 ) {
|
|
88
|
+
message += String.fromCharCode(c);
|
|
89
|
+
c = instance.exports.getMessageChar();
|
|
90
|
+
}
|
|
91
|
+
return message;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function printSharedRWMemory () {
|
|
95
|
+
const shared_rw_memory_size = instance.exports.getFieldNumLen32();
|
|
96
|
+
const arr = new Uint32Array(shared_rw_memory_size);
|
|
97
|
+
for (let j=0; j<shared_rw_memory_size; j++) {
|
|
98
|
+
arr[shared_rw_memory_size-1-j] = instance.exports.readSharedRWMemory(j);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// If we've buffered other content, put a space in between the items
|
|
102
|
+
if (msgStr !== "") {
|
|
103
|
+
msgStr += " "
|
|
104
|
+
}
|
|
105
|
+
// Then append the value to the message we are creating
|
|
106
|
+
msgStr += (fromArray32(arr).toString());
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
class WitnessCalculator {
|
|
112
|
+
constructor(instance, sanityCheck) {
|
|
113
|
+
this.instance = instance;
|
|
114
|
+
|
|
115
|
+
this.version = this.instance.exports.getVersion();
|
|
116
|
+
this.n32 = this.instance.exports.getFieldNumLen32();
|
|
117
|
+
|
|
118
|
+
this.instance.exports.getRawPrime();
|
|
119
|
+
const arr = new Uint32Array(this.n32);
|
|
120
|
+
for (let i=0; i<this.n32; i++) {
|
|
121
|
+
arr[this.n32-1-i] = this.instance.exports.readSharedRWMemory(i);
|
|
122
|
+
}
|
|
123
|
+
this.prime = fromArray32(arr);
|
|
124
|
+
|
|
125
|
+
this.witnessSize = this.instance.exports.getWitnessSize();
|
|
126
|
+
|
|
127
|
+
this.sanityCheck = sanityCheck;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
circom_version() {
|
|
131
|
+
return this.instance.exports.getVersion();
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
async _doCalculateWitness(input_orig, sanityCheck) {
|
|
135
|
+
//input is assumed to be a map from signals to arrays of bigints
|
|
136
|
+
this.instance.exports.init((this.sanityCheck || sanityCheck) ? 1 : 0);
|
|
137
|
+
let prefix = "";
|
|
138
|
+
var input = new Object();
|
|
139
|
+
//console.log("Input: ", input_orig);
|
|
140
|
+
qualify_input(prefix,input_orig,input);
|
|
141
|
+
//console.log("Input after: ",input);
|
|
142
|
+
const keys = Object.keys(input);
|
|
143
|
+
var input_counter = 0;
|
|
144
|
+
keys.forEach( (k) => {
|
|
145
|
+
const h = fnvHash(k);
|
|
146
|
+
const hMSB = parseInt(h.slice(0,8), 16);
|
|
147
|
+
const hLSB = parseInt(h.slice(8,16), 16);
|
|
148
|
+
const fArr = flatArray(input[k]);
|
|
149
|
+
let signalSize = this.instance.exports.getInputSignalSize(hMSB, hLSB);
|
|
150
|
+
if (signalSize < 0){
|
|
151
|
+
throw new Error(`Signal ${k} not found\n`);
|
|
152
|
+
}
|
|
153
|
+
if (fArr.length < signalSize) {
|
|
154
|
+
throw new Error(`Not enough values for input signal ${k}\n`);
|
|
155
|
+
}
|
|
156
|
+
if (fArr.length > signalSize) {
|
|
157
|
+
throw new Error(`Too many values for input signal ${k}\n`);
|
|
158
|
+
}
|
|
159
|
+
for (let i=0; i<fArr.length; i++) {
|
|
160
|
+
const arrFr = toArray32(normalize(fArr[i],this.prime),this.n32)
|
|
161
|
+
for (let j=0; j<this.n32; j++) {
|
|
162
|
+
this.instance.exports.writeSharedRWMemory(j,arrFr[this.n32-1-j]);
|
|
163
|
+
}
|
|
164
|
+
try {
|
|
165
|
+
this.instance.exports.setInputSignal(hMSB, hLSB,i);
|
|
166
|
+
input_counter++;
|
|
167
|
+
} catch (err) {
|
|
168
|
+
// console.log(`After adding signal ${i} of ${k}`)
|
|
169
|
+
throw new Error(err);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
});
|
|
174
|
+
if (input_counter < this.instance.exports.getInputSize()) {
|
|
175
|
+
throw new Error(`Not all inputs have been set. Only ${input_counter} out of ${this.instance.exports.getInputSize()}`);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
async calculateWitness(input, sanityCheck) {
|
|
180
|
+
|
|
181
|
+
const w = [];
|
|
182
|
+
await this._doCalculateWitness(input, sanityCheck);
|
|
183
|
+
|
|
184
|
+
for (let i=0; i<this.witnessSize; i++) {
|
|
185
|
+
this.instance.exports.getWitness(i);
|
|
186
|
+
const arr = new Uint32Array(this.n32);
|
|
187
|
+
for (let j=0; j<this.n32; j++) {
|
|
188
|
+
arr[this.n32-1-j] = this.instance.exports.readSharedRWMemory(j);
|
|
189
|
+
}
|
|
190
|
+
w.push(fromArray32(arr));
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return w;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
async calculateBinWitness(input, sanityCheck) {
|
|
198
|
+
|
|
199
|
+
const buff32 = new Uint32Array(this.witnessSize*this.n32);
|
|
200
|
+
const buff = new Uint8Array( buff32.buffer);
|
|
201
|
+
await this._doCalculateWitness(input, sanityCheck);
|
|
202
|
+
|
|
203
|
+
for (let i=0; i<this.witnessSize; i++) {
|
|
204
|
+
this.instance.exports.getWitness(i);
|
|
205
|
+
const pos = i*this.n32;
|
|
206
|
+
for (let j=0; j<this.n32; j++) {
|
|
207
|
+
buff32[pos+j] = this.instance.exports.readSharedRWMemory(j);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return buff;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
async calculateWTNSBin(input, sanityCheck) {
|
|
216
|
+
|
|
217
|
+
const buff32 = new Uint32Array(this.witnessSize*this.n32+this.n32+11);
|
|
218
|
+
const buff = new Uint8Array( buff32.buffer);
|
|
219
|
+
await this._doCalculateWitness(input, sanityCheck);
|
|
220
|
+
|
|
221
|
+
//"wtns"
|
|
222
|
+
buff[0] = "w".charCodeAt(0)
|
|
223
|
+
buff[1] = "t".charCodeAt(0)
|
|
224
|
+
buff[2] = "n".charCodeAt(0)
|
|
225
|
+
buff[3] = "s".charCodeAt(0)
|
|
226
|
+
|
|
227
|
+
//version 2
|
|
228
|
+
buff32[1] = 2;
|
|
229
|
+
|
|
230
|
+
//number of sections: 2
|
|
231
|
+
buff32[2] = 2;
|
|
232
|
+
|
|
233
|
+
//id section 1
|
|
234
|
+
buff32[3] = 1;
|
|
235
|
+
|
|
236
|
+
const n8 = this.n32*4;
|
|
237
|
+
//id section 1 length in 64bytes
|
|
238
|
+
const idSection1length = 8 + n8;
|
|
239
|
+
const idSection1lengthHex = idSection1length.toString(16);
|
|
240
|
+
buff32[4] = parseInt(idSection1lengthHex.slice(0,8), 16);
|
|
241
|
+
buff32[5] = parseInt(idSection1lengthHex.slice(8,16), 16);
|
|
242
|
+
|
|
243
|
+
//this.n32
|
|
244
|
+
buff32[6] = n8;
|
|
245
|
+
|
|
246
|
+
//prime number
|
|
247
|
+
this.instance.exports.getRawPrime();
|
|
248
|
+
|
|
249
|
+
var pos = 7;
|
|
250
|
+
for (let j=0; j<this.n32; j++) {
|
|
251
|
+
buff32[pos+j] = this.instance.exports.readSharedRWMemory(j);
|
|
252
|
+
}
|
|
253
|
+
pos += this.n32;
|
|
254
|
+
|
|
255
|
+
// witness size
|
|
256
|
+
buff32[pos] = this.witnessSize;
|
|
257
|
+
pos++;
|
|
258
|
+
|
|
259
|
+
//id section 2
|
|
260
|
+
buff32[pos] = 2;
|
|
261
|
+
pos++;
|
|
262
|
+
|
|
263
|
+
// section 2 length
|
|
264
|
+
const idSection2length = n8*this.witnessSize;
|
|
265
|
+
const idSection2lengthHex = idSection2length.toString(16);
|
|
266
|
+
buff32[pos] = parseInt(idSection2lengthHex.slice(0,8), 16);
|
|
267
|
+
buff32[pos+1] = parseInt(idSection2lengthHex.slice(8,16), 16);
|
|
268
|
+
|
|
269
|
+
pos += 2;
|
|
270
|
+
for (let i=0; i<this.witnessSize; i++) {
|
|
271
|
+
this.instance.exports.getWitness(i);
|
|
272
|
+
for (let j=0; j<this.n32; j++) {
|
|
273
|
+
buff32[pos+j] = this.instance.exports.readSharedRWMemory(j);
|
|
274
|
+
}
|
|
275
|
+
pos += this.n32;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
return buff;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
function qualify_input_list(prefix,input,input1){
|
|
285
|
+
if (Array.isArray(input)) {
|
|
286
|
+
for (let i = 0; i<input.length; i++) {
|
|
287
|
+
let new_prefix = prefix + "[" + i + "]";
|
|
288
|
+
qualify_input_list(new_prefix,input[i],input1);
|
|
289
|
+
}
|
|
290
|
+
} else {
|
|
291
|
+
qualify_input(prefix,input,input1);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function qualify_input(prefix,input,input1) {
|
|
296
|
+
if (Array.isArray(input)) {
|
|
297
|
+
a = flatArray(input);
|
|
298
|
+
if (a.length > 0) {
|
|
299
|
+
let t = typeof a[0];
|
|
300
|
+
for (let i = 1; i<a.length; i++) {
|
|
301
|
+
if (typeof a[i] != t){
|
|
302
|
+
throw new Error(`Types are not the same in the the key ${prefix}`);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
if (t == "object") {
|
|
306
|
+
qualify_input_list(prefix,input,input1);
|
|
307
|
+
} else {
|
|
308
|
+
input1[prefix] = input;
|
|
309
|
+
}
|
|
310
|
+
} else {
|
|
311
|
+
input1[prefix] = input;
|
|
312
|
+
}
|
|
313
|
+
} else if (typeof input == "object") {
|
|
314
|
+
const keys = Object.keys(input);
|
|
315
|
+
keys.forEach( (k) => {
|
|
316
|
+
let new_prefix = prefix == ""? k : prefix + "." + k;
|
|
317
|
+
qualify_input(new_prefix,input[k],input1);
|
|
318
|
+
});
|
|
319
|
+
} else {
|
|
320
|
+
input1[prefix] = input;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
function toArray32(rem,size) {
|
|
325
|
+
const res = []; //new Uint32Array(size); //has no unshift
|
|
326
|
+
const radix = BigInt(0x100000000);
|
|
327
|
+
while (rem) {
|
|
328
|
+
res.unshift( Number(rem % radix));
|
|
329
|
+
rem = rem / radix;
|
|
330
|
+
}
|
|
331
|
+
if (size) {
|
|
332
|
+
var i = size - res.length;
|
|
333
|
+
while (i>0) {
|
|
334
|
+
res.unshift(0);
|
|
335
|
+
i--;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
return res;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
function fromArray32(arr) { //returns a BigInt
|
|
342
|
+
var res = BigInt(0);
|
|
343
|
+
const radix = BigInt(0x100000000);
|
|
344
|
+
for (let i = 0; i<arr.length; i++) {
|
|
345
|
+
res = res*radix + BigInt(arr[i]);
|
|
346
|
+
}
|
|
347
|
+
return res;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
function flatArray(a) {
|
|
351
|
+
var res = [];
|
|
352
|
+
fillArray(res, a);
|
|
353
|
+
return res;
|
|
354
|
+
|
|
355
|
+
function fillArray(res, a) {
|
|
356
|
+
if (Array.isArray(a)) {
|
|
357
|
+
for (let i=0; i<a.length; i++) {
|
|
358
|
+
fillArray(res, a[i]);
|
|
359
|
+
}
|
|
360
|
+
} else {
|
|
361
|
+
res.push(a);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
function normalize(n, prime) {
|
|
367
|
+
let res = BigInt(n) % prime
|
|
368
|
+
if (res < 0) res += prime
|
|
369
|
+
return res
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
function fnvHash(str) {
|
|
373
|
+
const uint64_max = BigInt(2) ** BigInt(64);
|
|
374
|
+
let hash = BigInt("0xCBF29CE484222325");
|
|
375
|
+
for (var i = 0; i < str.length; i++) {
|
|
376
|
+
hash ^= BigInt(str[i].charCodeAt());
|
|
377
|
+
hash *= BigInt(0x100000001B3);
|
|
378
|
+
hash %= uint64_max;
|
|
379
|
+
}
|
|
380
|
+
let shash = hash.toString(16);
|
|
381
|
+
let n = 16 - shash.length;
|
|
382
|
+
shash = '0'.repeat(n).concat(shash);
|
|
383
|
+
return shash;
|
|
384
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/* Autogenerated file. Do not edit manually. */
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
/* tslint:disable */
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
CircuitZKit,
|
|
8
|
+
CircuitZKitConfig,
|
|
9
|
+
Groth16Proof,
|
|
10
|
+
PlonkProof,
|
|
11
|
+
NumberLike,
|
|
12
|
+
NumericString,
|
|
13
|
+
PublicSignals,
|
|
14
|
+
Groth16Implementer,
|
|
15
|
+
PlonkImplementer,
|
|
16
|
+
} from "@solarity/zkit";
|
|
17
|
+
|
|
18
|
+
import { normalizePublicSignals, denormalizePublicSignals } from "../helpers";
|
|
19
|
+
|
|
20
|
+
export type PrivateProposalsIntegrity15Groth16 = {
|
|
21
|
+
commitments: NumberLike[];
|
|
22
|
+
permutedProposals: NumberLike[];
|
|
23
|
+
permutationCommitment: NumberLike;
|
|
24
|
+
numActive: NumberLike;
|
|
25
|
+
permutation: NumberLike[];
|
|
26
|
+
randomnesses: NumberLike[];
|
|
27
|
+
permutationRandomness: NumberLike;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export type PublicProposalsIntegrity15Groth16 = {
|
|
31
|
+
commitments: NumberLike[];
|
|
32
|
+
permutedProposals: NumberLike[];
|
|
33
|
+
permutationCommitment: NumberLike;
|
|
34
|
+
numActive: NumberLike;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type ProofProposalsIntegrity15Groth16 = {
|
|
38
|
+
proof: Groth16Proof;
|
|
39
|
+
publicSignals: PublicProposalsIntegrity15Groth16;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export type CalldataProposalsIntegrity15Groth16 = [
|
|
43
|
+
[NumericString, NumericString],
|
|
44
|
+
[[NumericString, NumericString], [NumericString, NumericString]],
|
|
45
|
+
[NumericString, NumericString],
|
|
46
|
+
[
|
|
47
|
+
NumericString,
|
|
48
|
+
NumericString,
|
|
49
|
+
NumericString,
|
|
50
|
+
NumericString,
|
|
51
|
+
NumericString,
|
|
52
|
+
NumericString,
|
|
53
|
+
NumericString,
|
|
54
|
+
NumericString,
|
|
55
|
+
NumericString,
|
|
56
|
+
NumericString,
|
|
57
|
+
NumericString,
|
|
58
|
+
NumericString,
|
|
59
|
+
NumericString,
|
|
60
|
+
NumericString,
|
|
61
|
+
NumericString,
|
|
62
|
+
NumericString,
|
|
63
|
+
NumericString,
|
|
64
|
+
NumericString,
|
|
65
|
+
NumericString,
|
|
66
|
+
NumericString,
|
|
67
|
+
NumericString,
|
|
68
|
+
NumericString,
|
|
69
|
+
NumericString,
|
|
70
|
+
NumericString,
|
|
71
|
+
NumericString,
|
|
72
|
+
NumericString,
|
|
73
|
+
NumericString,
|
|
74
|
+
NumericString,
|
|
75
|
+
NumericString,
|
|
76
|
+
NumericString,
|
|
77
|
+
NumericString,
|
|
78
|
+
NumericString,
|
|
79
|
+
],
|
|
80
|
+
];
|
|
81
|
+
|
|
82
|
+
export class ProposalsIntegrity15 extends CircuitZKit<"groth16"> {
|
|
83
|
+
constructor(config: CircuitZKitConfig) {
|
|
84
|
+
super(config, new Groth16Implementer());
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
public async generateProof(
|
|
88
|
+
inputs: PrivateProposalsIntegrity15Groth16,
|
|
89
|
+
): Promise<ProofProposalsIntegrity15Groth16> {
|
|
90
|
+
const proof = await super.generateProof(inputs as any);
|
|
91
|
+
|
|
92
|
+
return {
|
|
93
|
+
proof: proof.proof,
|
|
94
|
+
publicSignals: this._normalizePublicSignals(proof.publicSignals),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
public async calculateWitness(
|
|
99
|
+
inputs: PrivateProposalsIntegrity15Groth16,
|
|
100
|
+
): Promise<bigint[]> {
|
|
101
|
+
return super.calculateWitness(inputs as any);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
public async verifyProof(
|
|
105
|
+
proof: ProofProposalsIntegrity15Groth16,
|
|
106
|
+
): Promise<boolean> {
|
|
107
|
+
return super.verifyProof({
|
|
108
|
+
proof: proof.proof,
|
|
109
|
+
publicSignals: this._denormalizePublicSignals(proof.publicSignals),
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
public async generateCalldata(
|
|
114
|
+
proof: ProofProposalsIntegrity15Groth16,
|
|
115
|
+
): Promise<CalldataProposalsIntegrity15Groth16> {
|
|
116
|
+
return super.generateCalldata({
|
|
117
|
+
proof: proof.proof,
|
|
118
|
+
publicSignals: this._denormalizePublicSignals(proof.publicSignals),
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
public getSignalNames(): string[] {
|
|
123
|
+
return [
|
|
124
|
+
"commitments",
|
|
125
|
+
"permutedProposals",
|
|
126
|
+
"permutationCommitment",
|
|
127
|
+
"numActive",
|
|
128
|
+
];
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
public getSignalDimensions(name: string): number[] {
|
|
132
|
+
switch (name) {
|
|
133
|
+
case "commitments":
|
|
134
|
+
return [15];
|
|
135
|
+
case "permutedProposals":
|
|
136
|
+
return [15];
|
|
137
|
+
case "permutationCommitment":
|
|
138
|
+
return [];
|
|
139
|
+
case "numActive":
|
|
140
|
+
return [];
|
|
141
|
+
default:
|
|
142
|
+
throw new Error(`Unknown signal name: ${name}`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
private _normalizePublicSignals(
|
|
147
|
+
publicSignals: PublicSignals,
|
|
148
|
+
): PublicProposalsIntegrity15Groth16 {
|
|
149
|
+
return normalizePublicSignals(
|
|
150
|
+
publicSignals,
|
|
151
|
+
this.getSignalNames(),
|
|
152
|
+
this.getSignalDimensions,
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
private _denormalizePublicSignals(
|
|
157
|
+
publicSignals: PublicProposalsIntegrity15Groth16,
|
|
158
|
+
): PublicSignals {
|
|
159
|
+
return denormalizePublicSignals(publicSignals, this.getSignalNames());
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export default ProposalsIntegrity15;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/* Autogenerated file. Do not edit manually. */
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
/* tslint:disable */
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
|
|
6
|
+
import * as Circuits from ".";
|
|
7
|
+
|
|
8
|
+
declare module "hardhat/types/runtime" {
|
|
9
|
+
interface HardhatZKit {
|
|
10
|
+
getCircuit(
|
|
11
|
+
name: "ProposalsIntegrity15",
|
|
12
|
+
): Promise<Circuits.ProposalsIntegrity15>;
|
|
13
|
+
}
|
|
14
|
+
}
|