my commit

to 0.7

update constructor calls in tests

remove 0.5 from config
This commit is contained in:
mirru2532 2021-10-26 21:19:02 +02:00
parent 77af0c5bdd
commit 09423d692b
16 changed files with 15104 additions and 60 deletions

BIN
.truffle-config.js.swp Normal file

Binary file not shown.

View File

@ -9,7 +9,7 @@
* ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
*/
pragma solidity 0.5.17;
pragma solidity ^0.7.6;
import "./Tornado.sol";
@ -18,20 +18,21 @@ contract ERC20Tornado is Tornado {
constructor(
IVerifier _verifier,
IHasher _hasher,
uint256 _denomination,
uint32 _merkleTreeHeight,
address _operator,
address _token
) Tornado(_verifier, _denomination, _merkleTreeHeight, _operator) public {
) Tornado(_verifier, _hasher, _denomination, _merkleTreeHeight, _operator) {
token = _token;
}
function _processDeposit() internal {
function _processDeposit() internal override {
require(msg.value == 0, "ETH value is supposed to be 0 for ERC20 instance");
_safeErc20TransferFrom(msg.sender, address(this), denomination);
}
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 override {
require(msg.value == _refund, "Incorrect refund amount received by the contract");
_safeErc20Transfer(_recipient, denomination - _fee);
@ -40,7 +41,7 @@ contract ERC20Tornado is Tornado {
}
if (_refund > 0) {
(bool success, ) = _recipient.call.value(_refund)("");
(bool success, ) = _recipient.call{value: _refund}("");
if (!success) {
// let's return _refund back to the relayer
_relayer.transfer(_refund);

View File

@ -9,32 +9,33 @@
* ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
*/
pragma solidity 0.5.17;
pragma solidity ^0.7.6;
import "./Tornado.sol";
contract ETHTornado is Tornado {
constructor(
IVerifier _verifier,
IHasher _hasher,
uint256 _denomination,
uint32 _merkleTreeHeight,
address _operator
) Tornado(_verifier, _denomination, _merkleTreeHeight, _operator) public {
) Tornado(_verifier, _hasher, _denomination, _merkleTreeHeight, _operator) {
}
function _processDeposit() internal {
function _processDeposit() internal override {
require(msg.value == denomination, "Please send `mixDenomination` ETH along with transaction");
}
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 override {
// sanity checks
require(msg.value == 0, "Message value is supposed to be zero for ETH instance");
require(_refund == 0, "Refund value is supposed to be zero for ETH instance");
(bool success, ) = _recipient.call.value(denomination - _fee)("");
(bool success, ) = _recipient.call{value: denomination - _fee}("");
require(success, "payment to _recipient did not go thru");
if (_fee > 0) {
(success, ) = _relayer.call.value(_fee)("");
(success, ) = _relayer.call{value: _fee}("");
require(success, "payment to _relayer did not go thru");
}
}

View File

@ -9,15 +9,16 @@
* ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
*/
pragma solidity 0.5.17;
pragma solidity ^0.7.6;
library Hasher {
function MiMCSponge(uint256 in_xL, uint256 in_xR) public pure returns (uint256 xL, uint256 xR);
interface IHasher {
function MiMCSponge(uint256 in_xL, uint256 in_xR) external pure returns (uint256 xL, uint256 xR);
}
contract MerkleTreeWithHistory {
uint256 public constant FIELD_SIZE = 21888242871839275222246405745257275088548364400416034343698204186575808495617;
uint256 public constant ZERO_VALUE = 21663839004416932945382355908790599225266501822907911457504978515578255421292; // = keccak256("tornado") % FIELD_SIZE
IHasher public immutable hasher;
uint32 public levels;
@ -30,28 +31,29 @@ contract MerkleTreeWithHistory {
uint32 public constant ROOT_HISTORY_SIZE = 100;
bytes32[ROOT_HISTORY_SIZE] public roots;
constructor(uint32 _treeLevels) public {
constructor(uint32 _treeLevels, IHasher _hasher) {
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);
for (uint32 i = 1; i < levels; i++) {
currentZero = hashLeftRight(currentZero, currentZero);
currentZero = hashLeftRight(_hasher, currentZero, currentZero);
zeros.push(currentZero);
filledSubtrees.push(currentZero);
}
roots[0] = hashLeftRight(currentZero, currentZero);
roots[0] = hashLeftRight(_hasher, currentZero, currentZero);
}
/**
@dev Hash 2 tree leaves, returns MiMC(_left, _right)
*/
function hashLeftRight(bytes32 _left, bytes32 _right) public pure returns (bytes32) {
function hashLeftRight(IHasher Hasher, bytes32 _left, bytes32 _right) public pure returns (bytes32) {
require(uint256(_left) < FIELD_SIZE, "_left should be inside the field");
require(uint256(_right) < FIELD_SIZE, "_right should be inside the field");
uint256 R = uint256(_left);
@ -81,7 +83,7 @@ contract MerkleTreeWithHistory {
right = currentLevelHash;
}
currentLevelHash = hashLeftRight(left, right);
currentLevelHash = hashLeftRight(hasher, left, right);
currentIndex /= 2;
}

View File

@ -1,10 +1,10 @@
pragma solidity >=0.4.21 <0.6.0;
pragma solidity >=0.4.21 <0.8.0;
contract Migrations {
address public owner;
uint public last_completed_migration;
constructor() public {
constructor() {
owner = msg.sender;
}

View File

@ -1,7 +1,7 @@
pragma solidity ^0.5.0;
pragma solidity >=0.5.0 <0.8.0;
contract BadRecipient {
function() external {
fallback() external {
require(false, "this contract does not accept ETH");
}
}

View File

@ -1,10 +1,12 @@
pragma solidity ^0.5.0;
pragma solidity ^0.7.6;
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") {
}
function mint(address receiver, uint256 amount) external {
_mint(receiver, amount);
}
}

View File

@ -1,10 +1,10 @@
pragma solidity 0.5.17;
pragma solidity ^0.7.6;
contract ERC20Basic {
abstract contract 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() public view virtual returns (uint);
function balanceOf(address who) public view virtual returns (uint);
function transfer(address to, uint value) public virtual;
event Transfer(address indexed from, address indexed to, uint value);
}
@ -12,9 +12,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;
abstract contract IUSDT is ERC20Basic {
function allowance(address owner, address spender) public view virtual returns (uint);
function transferFrom(address from, address to, uint value) public virtual;
function approve(address spender, uint value) public virtual;
event Approval(address indexed owner, address indexed spender, uint value);
}

View File

@ -1,10 +1,10 @@
pragma solidity 0.5.17;
pragma solidity ^0.7.6;
import '../MerkleTreeWithHistory.sol';
contract MerkleTreeWithHistoryMock is MerkleTreeWithHistory {
constructor (uint32 _treeLevels) MerkleTreeWithHistory(_treeLevels) public {}
constructor (IHasher _hasher, uint32 _treeLevels) MerkleTreeWithHistory(_treeLevels, _hasher) {}
function insert(bytes32 _leaf) public {
_insert(_leaf);

View File

@ -9,16 +9,16 @@
* ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
*/
pragma solidity 0.5.17;
pragma solidity ^0.7.6;
import "./MerkleTreeWithHistory.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
contract IVerifier {
function verifyProof(bytes memory _proof, uint256[6] memory _input) public returns(bool);
interface IVerifier {
function verifyProof(bytes memory _proof, uint256[6] memory _input) external returns(bool);
}
contract Tornado is MerkleTreeWithHistory, ReentrancyGuard {
abstract contract Tornado is MerkleTreeWithHistory, ReentrancyGuard {
uint256 public denomination;
mapping(bytes32 => bool) public nullifierHashes;
// we store all commitments just to prevent accidental deposits with the same commitment
@ -45,10 +45,11 @@ contract Tornado is MerkleTreeWithHistory, ReentrancyGuard {
*/
constructor(
IVerifier _verifier,
IHasher _hasher,
uint256 _denomination,
uint32 _merkleTreeHeight,
address _operator
) MerkleTreeWithHistory(_merkleTreeHeight) public {
) MerkleTreeWithHistory(_merkleTreeHeight, _hasher) {
require(_denomination > 0, "denomination should be greater than 0");
verifier = _verifier;
operator = _operator;
@ -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) {

View File

@ -11,7 +11,7 @@ module.exports = function(deployer, network, accounts) {
const verifier = await Verifier.deployed()
const hasherInstance = await hasherContract.deployed()
await ETHTornado.link(hasherContract, hasherInstance.address)
const tornado = await deployer.deploy(ETHTornado, verifier.address, ETH_AMOUNT, MERKLE_TREE_HEIGHT, accounts[0])
const tornado = await deployer.deploy(ETHTornado, verifier.address, hasherInstance.address, ETH_AMOUNT, MERKLE_TREE_HEIGHT, accounts[0])
console.log('ETHTornado\'s address ', tornado.address)
})
}

View File

@ -20,6 +20,7 @@ module.exports = function(deployer, network, accounts) {
const tornado = await deployer.deploy(
ERC20Tornado,
verifier.address,
hasherInstance.address,
TOKEN_AMOUNT,
MERKLE_TREE_HEIGHT,
accounts[0],

View File

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

View File

@ -52,8 +52,7 @@ contract('MerkleTreeWithHistory', accounts => {
prefix,
)
hasherInstance = await hasherContract.deployed()
await MerkleTreeWithHistory.link(hasherContract, hasherInstance.address)
merkleTreeWithHistory = await MerkleTreeWithHistory.new(levels)
merkleTreeWithHistory = await MerkleTreeWithHistory.new(hasherInstance.address, levels)
snapshotId = await takeSnapshot()
})
@ -182,7 +181,7 @@ contract('MerkleTreeWithHistory', accounts => {
it('should reject if tree is full', async () => {
const levels = 6
const merkleTreeWithHistory = await MerkleTreeWithHistory.new(levels)
const merkleTreeWithHistory = await MerkleTreeWithHistory.new(hasherInstance.address, levels)
for (let i = 0; i < 2**levels; i++) {
await merkleTreeWithHistory.insert(toFixedHex(i+42)).should.be.fulfilled

View File

@ -86,15 +86,13 @@ module.exports = {
// Configure your compilers
compilers: {
solc: {
version: '0.5.17', // 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
optimizer: {
enabled: true,
runs: 200
},
// evmVersion: "byzantium"
}
version: '0.7.6',
settings: {
optimizer: {
enabled: true,
runs: 200
},
},
},
external: {
command: 'node ./compileHasher.js',

15039
yarn.lock Normal file

File diff suppressed because it is too large Load Diff