You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.6 KiB

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