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.

59 lines
1.4 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. mapping(uint256 => Deposit) deposits;
  9. struct Deposit {
  10. uint256 coinCode;
  11. uint256 amount;
  12. bool used;
  13. }
  14. function deposit(
  15. uint256 coinCode,
  16. // uint256 amount,
  17. uint256 commitment
  18. ) public payable {
  19. deposits[commitment] = Deposit(coinCode, msg.value, false);
  20. }
  21. function getDeposit(
  22. uint256 commitment
  23. ) public view returns (uint256, uint256) {
  24. return (
  25. deposits[commitment].coinCode,
  26. deposits[commitment].amount
  27. );
  28. }
  29. function withdraw(
  30. uint256 commitment,
  31. address payable _address,
  32. uint[2] memory a,
  33. uint[2][2] memory b,
  34. uint[2] memory c
  35. ) public {
  36. uint256[4] memory input = [
  37. deposits[commitment].coinCode,
  38. deposits[commitment].amount,
  39. commitment,
  40. uint256(_address)
  41. ];
  42. require(verifier.verifyProof(a, b, c, input), "zkProof withdraw could not be verified");
  43. // zk verification passed, proceed with the withdraw
  44. require(!deposits[commitment].used, "deposit already withdrawed");
  45. deposits[commitment].used = true;
  46. _address.send(deposits[commitment].amount);
  47. // _address.call.value(deposits[commitment].amount).gas(20317)();
  48. }
  49. }