1818*/
1919
2020pragma solidity 0.4.24 ;
21- pragma experimental ABIEncoderV2;
2221
2322import "./Verifier.sol " ;
2423import "./SnarkUtils.sol " ;
2524import "./MerkleTree.sol " ;
25+ import "./LongsightL.sol " ;
2626
2727
2828contract Miximus
@@ -35,39 +35,89 @@ contract Miximus
3535
3636 MerkleTree.Data internal tree;
3737
38+
39+ function GetRoot ()
40+ public view returns (uint256 )
41+ {
42+ return tree.GetRoot ();
43+ }
44+
45+
46+ /**
47+ * Returns leaf offset
48+ */
3849 function Deposit (uint256 leaf )
39- public payable returns (uint256 )
50+ public payable returns (uint256 new_root , uint256 new_offset )
4051 {
4152 require ( msg .value == AMOUNT );
4253
4354 return tree.Insert (leaf);
4455 }
4556
4657
47- function Withdraw (
48- uint256 in_root ,
49- uint256 in_nullifier ,
50- Verifier.Proof in_proof
51- )
52- public
58+ function MakeLeafHash (uint256 spend_preimage , uint256 nullifier )
59+ public pure returns (uint256 )
5360 {
54- require ( false == nullifiers[in_nullifier] );
61+ uint256 [10 ] memory round_constants;
62+ LongsightL.ConstantsL12p5 (round_constants);
63+
64+ uint256 spend_hash = LongsightL.LongsightL12p5_MP ([spend_preimage, nullifier], 0 , round_constants);
65+
66+ return LongsightL.LongsightL12p5_MP ([nullifier, spend_hash], 0 , round_constants);
67+ }
5568
56- uint256 [] memory snark_input = new uint256 [](3 );
5769
58- snark_input[0 ] = SnarkUtils.ReverseBits (in_root);
70+ function GetPath (uint256 leaf )
71+ public view returns (uint256 [29 ] out_path , bool [29 ] out_addr )
72+ {
73+ return tree.GetProof (leaf);
74+ }
5975
60- snark_input[1 ] = SnarkUtils.ReverseBits (in_nullifier);
6176
62- snark_input[2 ] = SnarkUtils.ReverseBits (uint256 (sha256 (
77+ function GetExtHash ()
78+ public view returns (uint256 )
79+ {
80+ return uint256 (sha256 (
6381 abi.encodePacked (
6482 address (this ),
6583 msg .sender
66- )))) % Verifier.ScalarField ();
84+ ))) % Verifier.ScalarField ();
85+ }
86+
87+
88+ function IsSpent (uint256 nullifier )
89+ public view returns (bool )
90+ {
91+ return nullifiers[nullifier];
92+ }
93+
94+
95+ function VerifyProof ( uint256 in_root , uint256 in_nullifier , uint256 in_exthash , uint256 [8 ] proof )
96+ public view returns (bool )
97+ {
98+ uint256 [] memory snark_input = new uint256 [](3 );
99+ snark_input[0 ] = in_root;
100+ snark_input[1 ] = in_nullifier;
101+ snark_input[2 ] = in_exthash;
102+
103+ uint256 [14 ] memory vk;
104+ uint256 [] memory vk_gammaABC;
105+ (vk, vk_gammaABC) = GetVerifyingKey ();
106+
107+ return Verifier.Verify ( vk, vk_gammaABC, proof, snark_input );
108+ }
67109
68- Verifier.VerifyingKey memory vk = GetVerifyingKey ();
69110
70- bool is_valid = Verifier.Verify ( vk, in_proof, snark_input );
111+ function Withdraw (
112+ uint256 in_root ,
113+ uint256 in_nullifier ,
114+ uint256 [8 ] proof
115+ )
116+ public
117+ {
118+ require ( false == nullifiers[in_nullifier] );
119+
120+ bool is_valid = VerifyProof (in_root, in_nullifier, GetExtHash (), proof);
71121
72122 require ( is_valid );
73123
@@ -76,7 +126,7 @@ contract Miximus
76126 msg .sender .transfer (AMOUNT);
77127 }
78128
79- function GetVerifyingKey ()
80- internal pure returns (Verifier.VerifyingKey memory );
81129
130+ function GetVerifyingKey ()
131+ public view returns (uint256 [14 ] out_vk , uint256 [] out_gammaABC );
82132}
0 commit comments