Update to SMTProcessor for deposits

This commit is contained in:
arnaucube
2020-08-30 22:17:40 +02:00
parent 030e200500
commit 6d0a595525
6 changed files with 95 additions and 174 deletions

View File

@@ -22,7 +22,6 @@ describe("deposit test", function () {
const coinCode = "0";
const amount = '1000000000000000000';
// const nullifier = "567891234";
const poseidon = circomlib.poseidon.createHash(6, 8, 57);
const nullifier = poseidon([2, secret]);
@@ -31,42 +30,31 @@ describe("deposit test", function () {
// add commitment into SMT
let tree = await smt.newMemEmptyTrie();
await tree.insert(1, 0);
// await tree.insert(2, 0);
let rootOld = tree.root;
let res = await tree.find(2);
// console.log(res);
assert(!res.found);
let siblingsOld = res.siblings;
while (siblingsOld.length < nLevels) {
siblingsOld.push("0");
};
console.log("siblingsOld", siblingsOld);
await tree.insert(2, commitment);
let res = await tree.insert(2, commitment);
console.log("INSERT", res);
let rootNew = tree.root;
res = await tree.find(2);
// console.log(res);
assert(res.found);
let siblingsNew = res.siblings;
while (siblingsNew.length < nLevels) {
siblingsNew.push("0");
let siblings = res.siblings;
while (siblings.length < nLevels) {
siblings.push("0");
};
console.log("siblingsNew", siblingsNew);
console.log("rootOld", rootOld);
console.log("rootNew", rootNew);
console.log("siblings", siblings);
console.log(res);
const witness = await circuit.calculateWitness({
"coinCode": coinCode,
"amount": amount,
"secret": secret,
"oldKey": "1",
"oldValue": "0",
"siblingsOld": siblingsOld,
"siblingsNew": siblingsNew,
"rootOld": rootOld,
"rootNew": rootNew,
"oldKey": res.isOld0 ? 0 : res.oldKey,
"oldValue": res.isOld0 ? 0 : res.oldValue,
"isOld0": res.isOld0 ? 1 : 0,
"siblings": siblings,
"rootOld": res.oldRoot,
"rootNew": res.newRoot,
"commitment": commitment,
"key": 2
});

View File

@@ -77,11 +77,11 @@ contract("miksi", (accounts) => {
// expect(balance_wei).to.be.equal('98993526980000000000');
});
it("Make second deposit", async () => {
await computeTree(1);
// await computeTree(1);
await makeDeposit(1, addr3);
});
it("Make 3rd deposit", async () => {
await computeTree(2);
// await computeTree(2);
await makeDeposit(2, addr3);
});
@@ -183,12 +183,9 @@ async function computeTree(u) {
}
async function makeDeposit(u, addr) {
const resC = await tree.find(currKey);
assert(resC.found);
siblingsNew[u] = resC.siblings;
while (siblingsNew[u].length < nLevels) {
siblingsNew[u].push("0");
};
let resInsert = await tree.insert(currKey+1, commitment[u]);
rootNew[u] = tree.root;
currKey += 1;
// calculate witness
const wasm = await fs.promises.readFile("./test/build/deposit.wasm");
@@ -196,12 +193,12 @@ async function makeDeposit(u, addr) {
"coinCode": coinCode,
"amount": amount,
"secret": secret[u],
"oldKey": oldKey[u],
"oldValue": oldValue[u],
"siblingsOld": siblingsOld[u],
"siblingsNew": siblingsNew[u],
"rootOld": rootOld[u],
"rootNew": rootNew[u],
"oldKey": resInsert.isOld0 ? 0 : resInsert.oldKey,
"oldValue": resInsert.isOld0 ? 0 : resInsert.oldValue,
"isOld0": resInsert.isOld0 ? 1 : 0,
"siblings": resInsert.siblings,
"rootOld": resInsert.oldRoot,
"rootNew": resInsert.newRoot,
"commitment": commitment[u],
"key": currKey
});
@@ -220,7 +217,7 @@ async function makeDeposit(u, addr) {
publicSignals[u] = res.publicSignals;
const verificationKey = unstringifyBigInts(JSON.parse(fs.readFileSync("./test/build/deposit-verification_key.json", "utf8")));
let pubI = unstringifyBigInts([coinCode, amount, rootOld[u].toString(), rootNew[u].toString(), commitment[u], currKey]);
let pubI = unstringifyBigInts([coinCode, amount, res.oldRoot.toString(), res.newRoot.toString(), commitment[u], currKey]);
let validCheck = groth.isValid(verificationKey, proof[u], pubI);
assert(validCheck);
await insMiksi.deposit(