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

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) {