Full flow works, multiple deposits & withdraws

This commit is contained in:
arnaucube
2020-05-17 22:25:08 +02:00
parent ae07f70444
commit c2446cba36
10 changed files with 67 additions and 40 deletions

Binary file not shown.

View File

@@ -88,8 +88,10 @@
<br><br>
<h5 class="card-title">Stats</h5>
<hr>
<img src="miksi-logo00-square-pink.png" style="width:300px;" class="float-right">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum
<br>
</div>
<!-- config -->
<div class="tab-pane fade" id="config" role="tabpanel" aria-labelledby="config-tab">
@@ -174,10 +176,11 @@
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.3/Chart.bundle.min.js"></script> -->
<script src="lib/wasmsnark_bn128.js"></script>
<script src="lib/snarkjs.js"></script>
<script src="node_modules/web3/dist/web3.min.js"></script>
<script src="lib/miksi-browser.js"></script>
<script src="libs/wasmsnark_bn128.js"></script>
<script src="libs/snarkjs.js"></script>
<!-- <script src="node_modules/web3/dist/web3.min.js"></script> -->
<script src="libs/web3.min.js"></script>
<script src="libs/miksi-browser.js"></script>
<script src="index.js"></script>

View File

@@ -2,8 +2,7 @@ var circuit = {};
var provingKey = {};
var witnessCalc = {};
const abi = JSON.parse(`[{"inputs":[{"internalType":"address","name":"_depositVerifierContractAddr","type":"address"},{"internalType":"address","name":"_withdrawVerifierContractAddr","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"uint256","name":"_commitment","type":"uint256"},{"internalType":"uint256","name":"_root","type":"uint256"},{"internalType":"uint256[2]","name":"a","type":"uint256[2]"},{"internalType":"uint256[2][2]","name":"b","type":"uint256[2][2]"},{"internalType":"uint256[2]","name":"c","type":"uint256[2]"}],"name":"deposit","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"getCommitments","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address payable","name":"_address","type":"address"},{"internalType":"uint256","name":"nullifier","type":"uint256"},{"internalType":"uint256[2]","name":"a","type":"uint256[2]"},{"internalType":"uint256[2][2]","name":"b","type":"uint256[2][2]"},{"internalType":"uint256[2]","name":"c","type":"uint256[2]"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"}]`);
// const miksiAddress = "0x6E77f4bB1356426baD1Bd014d04388eFAc197Fe1";
const miksiAddress = "0xc9009d9Df413883B6064503FDA93A7A8ab9B7afb";
const miksiAddress = "0x29DB549Ea98d41e0F28A5aA50ED1D37d62BA8C4B";
function loadCircuit(circuitname) {
fetch("circuits-files/"+circuitname+"-proving_key.bin").then( (response) => {
@@ -33,7 +32,10 @@ async function deposit(circuitname) {
const nullifier = miksi.randBigInt().toString();
// const secret = "1234567890";
// const nullifier = "5678901234";
const commitments = [];
let res = await miksiContract.methods.getCommitments().call();
console.log("res", res);
const commitments = res[0];
console.log("commitments", commitments);
// getCommitments from the tree
// calculate witness

View File

@@ -58,30 +58,35 @@ module.exports = require('../package.json').version;
},{"../package.json":4}],4:[function(require,module,exports){
module.exports={
"_from": "@web3-js/websocket@^1.0.29",
"_args": [
[
"@web3-js/websocket@1.0.30",
"/home/user/git/miksi/miksi-core"
]
],
"_from": "@web3-js/websocket@1.0.30",
"_id": "@web3-js/websocket@1.0.30",
"_inBundle": false,
"_integrity": "sha512-fDwrD47MiDrzcJdSeTLF75aCcxVVt8B1N74rA+vh2XCAvFy4tEWJjtnUtj2QG7/zlQ6g9cQ88bZFBxwd9/FmtA==",
"_location": "/@web3-js/websocket",
"_phantomChildren": {},
"_requested": {
"type": "range",
"type": "version",
"registry": true,
"raw": "@web3-js/websocket@^1.0.29",
"raw": "@web3-js/websocket@1.0.30",
"name": "@web3-js/websocket",
"escapedName": "@web3-js%2fwebsocket",
"scope": "@web3-js",
"rawSpec": "^1.0.29",
"rawSpec": "1.0.30",
"saveSpec": null,
"fetchSpec": "^1.0.29"
"fetchSpec": "1.0.30"
},
"_requiredBy": [
"/web3-providers-ws"
],
"_resolved": "https://registry.npmjs.org/@web3-js/websocket/-/websocket-1.0.30.tgz",
"_shasum": "9ea15b7b582cf3bf3e8bc1f4d3d54c0731a87f87",
"_spec": "@web3-js/websocket@^1.0.29",
"_where": "/home/user/git/miksi/miksi-core/node_modules/web3-providers-ws",
"_spec": "1.0.30",
"_where": "/home/user/git/miksi/miksi-core",
"author": {
"name": "Brian McKelvey",
"email": "theturtle32@gmail.com",
@@ -91,7 +96,6 @@ module.exports={
"bugs": {
"url": "https://github.com/web3-js/WebSocket-Node/issues"
},
"bundleDependencies": false,
"config": {
"verbose": false
},
@@ -109,7 +113,6 @@ module.exports={
"typedarray-to-buffer": "^3.1.5",
"yaeti": "^0.0.6"
},
"deprecated": false,
"description": "Websocket Client & Server Library implementing the WebSocket protocol as specified in RFC 6455.",
"devDependencies": {
"buffer-equal": "^1.0.0",
@@ -27399,21 +27402,27 @@ utils.intFromLE = intFromLE;
},{"bn.js":38,"minimalistic-assert":261,"minimalistic-crypto-utils":262}],155:[function(require,module,exports){
module.exports={
"_from": "elliptic@^6.4.0",
"_args": [
[
"elliptic@6.5.2",
"/home/user/git/miksi/miksi-core"
]
],
"_from": "elliptic@6.5.2",
"_id": "elliptic@6.5.2",
"_inBundle": false,
"_integrity": "sha512-f4x70okzZbIQl/NSRLkI/+tteV/9WqL98zx+SQ69KbXxmVrmjwsNUPn/gYJJ0sHvEak24cZgHIPegRePAtA/xw==",
"_location": "/elliptic",
"_phantomChildren": {},
"_requested": {
"type": "range",
"type": "version",
"registry": true,
"raw": "elliptic@^6.4.0",
"raw": "elliptic@6.5.2",
"name": "elliptic",
"escapedName": "elliptic",
"rawSpec": "^6.4.0",
"rawSpec": "6.5.2",
"saveSpec": null,
"fetchSpec": "^6.4.0"
"fetchSpec": "6.5.2"
},
"_requiredBy": [
"/browserify-sign",
@@ -27424,9 +27433,8 @@ module.exports={
"/web3-utils/eth-lib"
],
"_resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.2.tgz",
"_shasum": "05c5678d7173c049d8ca433552224a495d0e3762",
"_spec": "elliptic@^6.4.0",
"_where": "/home/user/git/miksi/miksi-core/node_modules/eth-lib",
"_spec": "6.5.2",
"_where": "/home/user/git/miksi/miksi-core",
"author": {
"name": "Fedor Indutny",
"email": "fedor@indutny.com"
@@ -27434,7 +27442,6 @@ module.exports={
"bugs": {
"url": "https://github.com/indutny/elliptic/issues"
},
"bundleDependencies": false,
"dependencies": {
"bn.js": "^4.4.0",
"brorand": "^1.0.1",
@@ -27444,7 +27451,6 @@ module.exports={
"minimalistic-assert": "^1.0.0",
"minimalistic-crypto-utils": "^1.0.0"
},
"deprecated": false,
"description": "EC cryptography",
"devDependencies": {
"brfs": "^1.4.3",
@@ -75050,29 +75056,35 @@ module.exports = {
}).call(this,{"isBuffer":require("../../is-buffer/index.js")})
},{"../../is-buffer/index.js":247,"bn.js":38,"eth-lib/lib/hash":443,"ethereum-bloom-filters":162,"number-to-bn":265,"underscore":390,"utf8":394}],447:[function(require,module,exports){
module.exports={
"_from": "web3@^1.2.6",
"_args": [
[
"web3@1.2.7",
"/home/user/git/miksi/miksi-core"
]
],
"_from": "web3@1.2.7",
"_id": "web3@1.2.7",
"_inBundle": false,
"_integrity": "sha512-jAAJHMfUlTps+jH2li1ckDFEpPrEEriU/ubegSTGRl3KRdNhEqT93+3kd7FHJTn3NgjcyURo2+f7Da1YcZL8Mw==",
"_location": "/web3",
"_phantomChildren": {},
"_requested": {
"type": "range",
"type": "version",
"registry": true,
"raw": "web3@^1.2.6",
"raw": "web3@1.2.7",
"name": "web3",
"escapedName": "web3",
"rawSpec": "^1.2.6",
"rawSpec": "1.2.7",
"saveSpec": null,
"fetchSpec": "^1.2.6"
"fetchSpec": "1.2.7"
},
"_requiredBy": [
"#DEV:/",
"/circomlib"
],
"_resolved": "https://registry.npmjs.org/web3/-/web3-1.2.7.tgz",
"_shasum": "fcb83571036c1c6f475bc984785982a444e8d78e",
"_spec": "web3@^1.2.6",
"_where": "/home/user/git/miksi/miksi-core/node_modules/circomlib",
"_spec": "1.2.7",
"_where": "/home/user/git/miksi/miksi-core",
"author": {
"name": "ethereum.org"
},
@@ -75105,7 +75117,6 @@ module.exports={
"bugs": {
"url": "https://github.com/ethereum/web3.js/issues"
},
"bundleDependencies": false,
"dependencies": {
"web3-bzz": "1.2.7",
"web3-core": "1.2.7",
@@ -75115,7 +75126,6 @@ module.exports={
"web3-shh": "1.2.7",
"web3-utils": "1.2.7"
},
"deprecated": false,
"description": "Ethereum JavaScript API",
"devDependencies": {
"@types/node": "^12.12.34",
@@ -76282,6 +76292,7 @@ const WitnessCalculatorBuilder = require("circom_runtime").WitnessCalculatorBuil
const circomlib = require("circomlib");
const smt = require("circomlib").smt;
const Web3 = require("web3");
// const buildBn128 = require("wasmsnark").buildBn128;
const nLevels = 5;
@@ -76313,9 +76324,14 @@ exports.calcDepositWitness = async (wasm, secret, nullifier, commitments) => {
// old root
const rootOld = tree.root;
const resOld = await tree.find(commitment);
if (resOld.found) {
console.error("leaf expect to not exist but exists");
let oldKey = "0";
if (!resOld.found) {
oldKey = resOld.notFoundKey.toString();
}
console.log("oldKey", oldKey);
// if (resOld.found) {
// console.error("leaf expect to not exist but exists");
// }
let siblingsOld = resOld.siblings;
while (siblingsOld.length < nLevels) {
siblingsOld.push("0");
@@ -76340,6 +76356,7 @@ exports.calcDepositWitness = async (wasm, secret, nullifier, commitments) => {
"amount": amount,
"secret": secret,
"nullifier": nullifier,
"oldKey": oldKey,
"siblingsOld": siblingsOld,
"siblingsNew": siblingsNew,
"rootOld": rootOld,
@@ -76360,12 +76377,14 @@ exports.calcDepositWitness = async (wasm, secret, nullifier, commitments) => {
for (let j=0; j<8; j++) {
const bi = witness[i];
const v = bigInt(bi).shiftRight(j*32).and(0xFFFFFFFF).toJSNumber();
wBuff.writeUInt32LE(v, i*32 + j*4, 4)
// wBuff.writeUInt32LE(v, i*32 + j*4, 4)
wBuff.writeUInt32LE(v, i*32 + j*4)
}
}
// const witness = unstringifyBigInts(stringifyBigInts(w));
// return wBuff;
return {
witness: wBuff,
publicInputs: {
@@ -76438,6 +76457,8 @@ exports.calcWithdrawWitness = async (wasm, secret, nullifier, commitments, addr)
}
}).call(this,require("buffer").Buffer)
},{"big-integer":24,"buffer":70,"circom_runtime":76,"circomlib":95,"ffjavascript":209,"fs":69,"snarkjs":329,"web3":448}]},{},[461])(461)
});

1
libs/web3.min.js vendored Normal file

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB