Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent field aliasing on Withdraw which would allow double-spend #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion circuit/miximus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 12 additions & 4 deletions solidity/contracts/Miximus.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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);
}


Expand Down Expand Up @@ -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);
}


Expand Down Expand Up @@ -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" );
Expand Down