This commit is contained in:
Roman Storm 2021-02-10 21:37:18 -08:00
parent 77af0c5bdd
commit 3c4def1e64
No known key found for this signature in database
GPG Key ID: 522F2A785F34E71F
12 changed files with 6724 additions and 78 deletions

View File

@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT
// https://tornado.cash
/*
* d888888P dP a88888b. dP
@ -9,7 +11,7 @@
* ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
*/
pragma solidity 0.5.17;
pragma solidity 0.6.12;
import "./Tornado.sol";
@ -18,11 +20,11 @@ contract ERC20Tornado is Tornado {
constructor(
IVerifier _verifier,
Hasher _hasher,
uint256 _denomination,
uint32 _merkleTreeHeight,
address _operator,
address _token
) Tornado(_verifier, _denomination, _merkleTreeHeight, _operator) public {
) Tornado(_verifier, _hasher, _denomination, _merkleTreeHeight) public {
token = _token;
}

View File

@ -1,3 +1,6 @@
// SPDX-License-Identifier: MIT
// SPDX-License-Identifier: MIT
// https://tornado.cash
/*
* d888888P dP a88888b. dP
@ -9,17 +12,17 @@
* ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
*/
pragma solidity 0.5.17;
pragma solidity 0.6.12;
import "./Tornado.sol";
contract ETHTornado is Tornado {
constructor(
IVerifier _verifier,
Hasher _hasher,
uint256 _denomination,
uint32 _merkleTreeHeight,
address _operator
) Tornado(_verifier, _denomination, _merkleTreeHeight, _operator) public {
uint32 _merkleTreeHeight
) Tornado(_verifier, _hasher, _denomination, _merkleTreeHeight) public {
}
function _processDeposit() internal {

View File

@ -1,3 +1,6 @@
// SPDX-License-Identifier: MIT
// SPDX-License-Identifier: MIT
// https://tornado.cash
/*
* d888888P dP a88888b. dP
@ -9,9 +12,9 @@
* ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
*/
pragma solidity 0.5.17;
pragma solidity 0.6.12;
library Hasher {
interface Hasher {
function MiMCSponge(uint256 in_xL, uint256 in_xR) public pure returns (uint256 xL, uint256 xR);
}
@ -29,12 +32,15 @@ contract MerkleTreeWithHistory {
uint32 public nextIndex = 0;
uint32 public constant ROOT_HISTORY_SIZE = 100;
bytes32[ROOT_HISTORY_SIZE] public roots;
Hasher public immutable hasher;
constructor(uint32 _treeLevels) public {
constructor(uint32 _treeLevels, Hasher _hasher) public {
require(_treeLevels > 0, "_treeLevels should be greater than zero");
require(_treeLevels < 32, "_treeLevels should be less than 32");
levels = _treeLevels;
hasher = _hasher;
bytes32 currentZero = bytes32(ZERO_VALUE);
zeros.push(currentZero);
filledSubtrees.push(currentZero);
@ -56,9 +62,9 @@ contract MerkleTreeWithHistory {
require(uint256(_right) < FIELD_SIZE, "_right should be inside the field");
uint256 R = uint256(_left);
uint256 C = 0;
(R, C) = Hasher.MiMCSponge(R, C);
(R, C) = hasher.MiMCSponge(R, C);
R = addmod(R, uint256(_right), FIELD_SIZE);
(R, C) = Hasher.MiMCSponge(R, C);
(R, C) = hasher.MiMCSponge(R, C);
return bytes32(R);
}

View File

@ -1,4 +1,6 @@
pragma solidity >=0.4.21 <0.6.0;
// SPDX-License-Identifier: MIT
pragma solidity 0.6.12;
contract Migrations {
address public owner;

View File

@ -1,7 +1,9 @@
pragma solidity ^0.5.0;
// SPDX-License-Identifier: MIT
pragma solidity 0.6.12;
contract BadRecipient {
function() external {
fallback() external {
require(false, "this contract does not accept ETH");
}
}

View File

@ -1,10 +1,10 @@
pragma solidity ^0.5.0;
// SPDX-License-Identifier: MIT
pragma solidity 0.6.12;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20Mintable.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20Detailed.sol";
contract ERC20Mock is ERC20Detailed, ERC20Mintable {
constructor() ERC20Detailed("DAIMock", "DAIM", 18) public {
contract ERC20Mock is ERC20 {
constructor() ERC20("DAIMock", "DAIM") public {
}
}

View File

@ -1,10 +1,12 @@
pragma solidity 0.5.17;
// SPDX-License-Identifier: MIT
contract ERC20Basic {
pragma solidity 0.6.12;
interface ERC20Basic {
uint public _totalSupply;
function totalSupply() public view returns (uint);
function balanceOf(address who) public view returns (uint);
function transfer(address to, uint value) public;
function totalSupply() external view returns (uint);
function balanceOf(address who) external view returns (uint);
function transfer(address to, uint value) external;
event Transfer(address indexed from, address indexed to, uint value);
}
@ -12,9 +14,9 @@ contract ERC20Basic {
* @title ERC20 interface
* @dev see https://github.com/ethereum/EIPs/issues/20
*/
contract IUSDT is ERC20Basic {
function allowance(address owner, address spender) public view returns (uint);
function transferFrom(address from, address to, uint value) public;
function approve(address spender, uint value) public;
interface IUSDT is ERC20Basic {
function allowance(address owner, address spender) external view returns (uint);
function transferFrom(address from, address to, uint value) external;
function approve(address spender, uint value) external;
event Approval(address indexed owner, address indexed spender, uint value);
}

View File

@ -1,10 +1,12 @@
pragma solidity 0.5.17;
// SPDX-License-Identifier: MIT
pragma solidity 0.6.12;
import '../MerkleTreeWithHistory.sol';
contract MerkleTreeWithHistoryMock is MerkleTreeWithHistory {
constructor (uint32 _treeLevels) MerkleTreeWithHistory(_treeLevels) public {}
constructor (uint32 _treeLevels, Hasher _hasher) MerkleTreeWithHistory(_treeLevels, _hasher) public {}
function insert(bytes32 _leaf) public {
_insert(_leaf);

View File

@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT
// https://tornado.cash
/*
* d888888P dP a88888b. dP
@ -9,7 +11,7 @@
* ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
*/
pragma solidity 0.5.17;
pragma solidity 0.6.12;
import "./MerkleTreeWithHistory.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
@ -23,7 +25,7 @@ contract Tornado is MerkleTreeWithHistory, ReentrancyGuard {
mapping(bytes32 => bool) public nullifierHashes;
// we store all commitments just to prevent accidental deposits with the same commitment
mapping(bytes32 => bool) public commitments;
IVerifier public verifier;
IVerifier public immutable verifier;
// operator can update snark verification key
// after the final trusted setup ceremony operator rights are supposed to be transferred to zero address
@ -45,13 +47,12 @@ contract Tornado is MerkleTreeWithHistory, ReentrancyGuard {
*/
constructor(
IVerifier _verifier,
Hasher _hasher,
uint256 _denomination,
uint32 _merkleTreeHeight,
address _operator
) MerkleTreeWithHistory(_merkleTreeHeight) public {
uint32 _merkleTreeHeight
) MerkleTreeWithHistory(_merkleTreeHeight, _hasher) public {
require(_denomination > 0, "denomination should be greater than 0");
verifier = _verifier;
operator = _operator;
denomination = _denomination;
}
@ -70,7 +71,7 @@ contract Tornado is MerkleTreeWithHistory, ReentrancyGuard {
}
/** @dev this function is defined in a child contract */
function _processDeposit() internal;
function _processDeposit() internal virtual;
/**
@dev Withdraw a deposit from the contract. `proof` is a zkSNARK proof data, and input is an array of circuit public inputs
@ -92,7 +93,7 @@ contract Tornado is MerkleTreeWithHistory, ReentrancyGuard {
}
/** @dev this function is defined in a child contract */
function _processWithdraw(address payable _recipient, address payable _relayer, uint256 _fee, uint256 _refund) internal;
function _processWithdraw(address payable _recipient, address payable _relayer, uint256 _fee, uint256 _refund) internal virtual;
/** @dev whether a note is already spent */
function isSpent(bytes32 _nullifierHash) public view returns(bool) {
@ -109,16 +110,4 @@ contract Tornado is MerkleTreeWithHistory, ReentrancyGuard {
}
}
/**
@dev allow operator to update SNARK verification keys. This is needed to update keys after the final trusted setup ceremony is held.
After that operator rights are supposed to be transferred to zero address
*/
function updateVerifier(address _newVerifier) external onlyOperator {
verifier = IVerifier(_newVerifier);
}
/** @dev operator can change his address */
function changeOperator(address _newOperator) external onlyOperator {
operator = _newOperator;
}
}

View File

@ -27,7 +27,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"@openzeppelin/contracts": "^2.4.0",
"@openzeppelin/contracts": "^3.4.0",
"@truffle/contract": "^4.0.39",
"@truffle/hdwallet-provider": "^1.0.24",
"axios": "^0.19.0",

View File

@ -1,6 +1,6 @@
require('dotenv').config()
const HDWalletProvider = require('@truffle/hdwallet-provider')
const utils = require('web3-utils')
require("dotenv").config();
const HDWalletProvider = require("@truffle/hdwallet-provider");
const utils = require("web3-utils");
// const infuraKey = "fj4jll3k.....";
//
// const fs = require('fs');
@ -25,9 +25,9 @@ module.exports = {
// options below to some value.
development: {
host: '127.0.0.1', // Localhost (default: none)
host: "127.0.0.1", // Localhost (default: none)
port: 8545, // Standard Ethereum port (default: none)
network_id: '*', // Any network (default: none)
network_id: "*", // Any network (default: none)
},
// Another network with more advanced options...
@ -43,31 +43,56 @@ module.exports = {
// Useful for deploying to a public network.
// NB: It's important to wrap the provider as a function.
kovan: {
provider: () => new HDWalletProvider(process.env.PRIVATE_KEY, 'https://kovan.infura.io/v3/97c8bf358b9942a9853fab1ba93dc5b3'),
provider: () =>
new HDWalletProvider(
process.env.PRIVATE_KEY,
"https://kovan.infura.io/v3/97c8bf358b9942a9853fab1ba93dc5b3"
),
network_id: 42,
gas: 6000000,
gasPrice: utils.toWei('1', 'gwei'),
gasPrice: utils.toWei("1", "gwei"),
// confirmations: 0,
// timeoutBlocks: 200,
skipDryRun: true
skipDryRun: true,
},
goerli: {
provider: () =>
new HDWalletProvider(
process.env.PRIVATE_KEY,
"https://goerli.infura.io/v3/d34c08f2cb7c4111b645d06ac7e35ba8"
),
network_id: 5,
gas: 6000000,
gasPrice: utils.toWei("1", "gwei"),
// confirmations: 0,
// timeoutBlocks: 200,
skipDryRun: true,
},
rinkeby: {
provider: () => new HDWalletProvider(process.env.PRIVATE_KEY, 'https://rinkeby.infura.io/v3/97c8bf358b9942a9853fab1ba93dc5b3'),
provider: () =>
new HDWalletProvider(
process.env.PRIVATE_KEY,
"https://rinkeby.infura.io/v3/97c8bf358b9942a9853fab1ba93dc5b3"
),
network_id: 4,
gas: 6000000,
gasPrice: utils.toWei('1', 'gwei'),
gasPrice: utils.toWei("1", "gwei"),
// confirmations: 0,
// timeoutBlocks: 200,
skipDryRun: true
skipDryRun: true,
},
mainnet: {
provider: () => new HDWalletProvider(process.env.PRIVATE_KEY, 'http://ethereum-rpc.trustwalletapp.com'),
provider: () =>
new HDWalletProvider(
process.env.PRIVATE_KEY,
"http://ethereum-rpc.trustwalletapp.com"
),
network_id: 1,
gas: 6000000,
gasPrice: utils.toWei('2', 'gwei'),
gasPrice: utils.toWei("2", "gwei"),
// confirmations: 0,
// timeoutBlocks: 200,
skipDryRun: true
skipDryRun: true,
},
// Useful for private networks
@ -86,21 +111,24 @@ module.exports = {
// Configure your compilers
compilers: {
solc: {
version: '0.5.17', // Fetch exact version from solc-bin (default: truffle's version)
version: "0.6.12", // Fetch exact version from solc-bin (default: truffle's version)
// docker: true, // Use "0.5.1" you've installed locally with docker (default: false)
settings: { // See the solidity docs for advice about optimization and evmVersion
settings: {
// See the solidity docs for advice about optimization and evmVersion
optimizer: {
enabled: true,
runs: 200
runs: 200,
},
// evmVersion: "byzantium"
}
},
},
external: {
command: 'node ./compileHasher.js',
targets: [{
path: './build/Hasher.json'
}]
}
}
}
command: "node ./compileHasher.js",
targets: [
{
path: "./build/Hasher.json",
},
],
},
},
};

6610
yarn.lock Normal file

File diff suppressed because it is too large Load Diff