diff --git a/circuit/miximus.cpp b/circuit/miximus.cpp index 79bc282..b88f8c1 100644 --- a/circuit/miximus.cpp +++ b/circuit/miximus.cpp @@ -87,7 +87,7 @@ namespace ethsnarks { class mod_miximus : public GadgetT { public: - typedef MiMC_hash_gadget HashT; + typedef MiMC_e7_hash_gadget HashT; const size_t tree_depth = MIXIMUS_TREE_DEPTH; // public inputs diff --git a/ethsnarks b/ethsnarks index 450bb9b..2cade96 160000 --- a/ethsnarks +++ b/ethsnarks @@ -1 +1 @@ -Subproject commit 450bb9be7123491f8ca2dddb46b7059466fafbb5 +Subproject commit 2cade96d77437b4cb9999d82b8267364806cba60 diff --git a/solidity/contracts/Miximus.sol b/solidity/contracts/Miximus.sol index ffc0725..4755b5a 100644 --- a/solidity/contracts/Miximus.sol +++ b/solidity/contracts/Miximus.sol @@ -21,7 +21,7 @@ pragma solidity ^0.5.0; import "../../ethsnarks/contracts/Verifier.sol"; import "../../ethsnarks/contracts/MerkleTree.sol"; -import "../../ethsnarks/contracts/MiMC.sol"; +import "../../ethsnarks/contracts/MiMC_hash.sol"; contract Miximus @@ -63,7 +63,9 @@ contract Miximus /** - * Returns leaf offset + * Inserts a new leaf into the tree upon a deposit of the correct amount + * + * Returns the index of the new leaf, and the new merkle root for the tree */ function Deposit(uint256 leaf) public payable returns (uint256 new_root, uint256 new_offset) @@ -83,7 +85,7 @@ contract Miximus { uint256[] memory vals = new uint256[](1); vals[0] = secret; - return MiMC.Hash(vals); + return MiMC_hash.MiMCpe7_mp(vals, 0); } @@ -132,7 +134,7 @@ contract Miximus inputs_to_hash[1] = in_nullifier; inputs_to_hash[2] = in_exthash; - return MiMC.Hash(inputs_to_hash); + return MiMC_hash.MiMCpe7_mp(inputs_to_hash, 0); } @@ -168,6 +170,12 @@ contract Miximus ) public { + // Clamp inputs to the scalar field + // This avoids aliasing, which would allow double spend! + uint256 Q = Verifier.ScalarField(); + in_root = in_root % Q; + in_nullifier = in_nullifier % Q; + require( false == nullifiers[in_nullifier], "Cannot double-spend" ); require( true == roots[in_root], "Must specify known merkle tree root" );