final test

This commit is contained in:
Alexey 2019-07-13 00:50:26 +03:00
parent 1194e76b9a
commit 0db7be23b5
4 changed files with 27 additions and 7 deletions

View File

@ -3,7 +3,7 @@ pragma solidity ^0.5.8;
import "./MerkleTreeWithHistory.sol";
contract IVerifier {
function verify(uint256[2] memory a, uint256[2][2] memory b, uint256[2] memory c, uint256[4] memory input) public returns(bool);
function verifyProof(uint256[2] memory a, uint256[2][2] memory b, uint256[2] memory c, uint256[4] memory input) public returns(bool);
}
contract Mixer is MerkleTreeWithHistory {
@ -56,7 +56,7 @@ contract Mixer is MerkleTreeWithHistory {
require(fee < transferValue, "Fee exceeds transfer value");
require(!nullifiers[nullifier], "The note has been already spent");
require(isKnownRoot(root), "Cannot find your merkle root"); // Make sure to use a recent one
require(verifier.verify(a, b, c, input), "Invalid withdraw proof");
require(verifier.verifyProof(a, b, c, input), "Invalid withdraw proof");
nullifiers[nullifier] = true;
receiver.transfer(transferValue - fee);

View File

@ -87,7 +87,12 @@ function convertWitness(witness) {
async function snarkProof(input) {
input = unstringifyBigInts2(input);
const circuit = new snarkjs.Circuit(unstringifyBigInts2(require("../build/circuits/withdraw.json")));
const proving_key = fs.readFileSync("../build/circuits/withdraw_proving_key.bin");
const pwd = process.cwd()
let pathToProvingKey = 'build/circuits/withdraw_proving_key.bin'
if (pwd.split('/').pop() === 'scripts') {
pathToProvingKey = '../build/circuits/withdraw_proving_key.bin'
}
const proving_key = fs.readFileSync(pathToProvingKey);
const witness = circuit.calculateWitness(input);
const witnessBin = convertWitness(stringifyBigInts2(witness));

View File

@ -43,7 +43,7 @@ contract('MerkleTreeWithHistory', async accounts => {
levels,
zeroValue,
)
miMC = MiMC.deployed()
miMC = await MiMC.deployed()
await MerkleTreeWithHistory.link(MiMC, miMC.address)
merkleTreeWithHistory = await MerkleTreeWithHistory.new(levels, zeroValue)
snapshotId = await takeSnapshot()
@ -181,6 +181,13 @@ contract('MerkleTreeWithHistory', async accounts => {
})
})
describe('#MIMC', async () => {
it.skip('gas price', async () => {
const gas = await merkleTreeWithHistory.hashLeftRight.estimateGas(1,2)
console.log('gas', gas)
})
})
afterEach(async () => {
await revertSnapshot(snapshotId.result)
snapshotId = await takeSnapshot()

View File

@ -75,9 +75,11 @@ contract('Mixer', async accounts => {
})
describe('#withdraw', async () => {
it.skip('should work', async () => {
it('should work', async () => {
const deposit = generateDeposit()
await tree.insert(deposit.commitment)
let gas = await mixer.deposit.estimateGas(toBN(deposit.commitment.toString()), { value: AMOUNT, from: sender })
console.log('deposit gas', gas)
await mixer.deposit(toBN(deposit.commitment.toString()), { value: AMOUNT, from: sender })
const {root, path_elements, path_index} = await tree.path(0);
@ -97,9 +99,15 @@ contract('Mixer', async accounts => {
})
const { pi_a, pi_b, pi_c, publicSignals } = await utils.snarkProof(input)
console.log('proof', pi_a, pi_b, pi_c, publicSignals)
// console.log('proof', pi_a, pi_b, pi_c, publicSignals)
gas = await mixer.withdraw.estimateGas(pi_a, pi_b, pi_c, publicSignals, { from: sender })
console.log('withdraw gas', gas)
const { logs } = await mixer.withdraw(pi_a, pi_b, pi_c, publicSignals, { from: sender })
console.log('logs', logs)
logs[0].event.should.be.equal('Withdraw')
// logs[0].args.nullifier.should.be.eq.BN(toBN(commitment))
// logs[0].args.fee.should.be.eq.BN(toBN(0))
// console.log('logs', logs)
})
})