miksi-core/contracts/Miksi.sol
contracts/Miksi.solRaw
1pragma solidity ^0.6.0;
2
3import './verifier.sol';
4
5contract Miksi {
6 Verifier verifier;
7
8 constructor( address _verifierContractAddr) public {
9 verifier = Verifier(_verifierContractAddr);
10 }
11 uint256 amount = uint256(1000000000000000000);
12 uint256 root;
13 uint256[] commitments;
14 mapping(uint256 => bool) nullifiers;
15
16 function deposit(
17 uint256 _commitment,
18 uint256 _root
19 ) public payable {
20 // TODO check root state transition update with zkp
21
22 require(msg.value==amount, "value should be 1 ETH"); // this can be flexible with a wrapper with preset fixed amounts
23 commitments.push(_commitment);
24 root = _root;
25 }
26
27 function getCommitments() public view returns (uint256[] memory, uint256) {
28 return (commitments, root);
29 }
30
31 function withdraw(
32 address payable _address,
33 uint256 nullifier,
34 uint[2] memory a,
35 uint[2][2] memory b,
36 uint[2] memory c
37 ) public {
38
39 uint256[5] memory input = [
40 0,
41 amount,
42 nullifier,
43 root,
44 uint256(_address)
45 ];
46 require(verifier.verifyProof(a, b, c, input), "zkProof withdraw could not be verified");
47 // zk verification passed
48 require(useNullifier(nullifier), "nullifier already used");
49 // nullifier check passed
50 // proceed with the withdraw
51
52 _address.send(amount);
53 // _address.call.value(amount).gas(20317)();
54 }
55
56 function useNullifier(
57 uint256 nullifier
58 ) internal returns (bool) {
59 if (nullifiers[nullifier]) {
60 return false;
61 }
62 nullifiers[nullifier] = true;
63 return true;
64 }
65}