Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6f42be6213 | ||
|
|
6a01ff9642 | ||
|
|
592d3e112d | ||
|
|
a4b98dd195 | ||
|
|
4d75035fab | ||
|
|
f8c25c30ab | ||
|
|
9506aa548e |
@@ -3,20 +3,17 @@
|
|||||||
pragma solidity ^0.6.0;
|
pragma solidity ^0.6.0;
|
||||||
pragma experimental ABIEncoderV2;
|
pragma experimental ABIEncoderV2;
|
||||||
|
|
||||||
import "torn-token/contracts/ENS.sol";
|
|
||||||
import "./interfaces/ITornadoTreesV1.sol";
|
import "./interfaces/ITornadoTreesV1.sol";
|
||||||
import "./interfaces/IVerifier.sol";
|
import "./interfaces/IBatchTreeUpdateVerifier.sol";
|
||||||
|
|
||||||
import "hardhat/console.sol";
|
contract TornadoTrees {
|
||||||
|
|
||||||
contract TornadoTrees is EnsResolve {
|
|
||||||
address public immutable governance;
|
address public immutable governance;
|
||||||
bytes32 public depositRoot;
|
bytes32 public depositRoot;
|
||||||
bytes32 public previousDepositRoot;
|
bytes32 public previousDepositRoot;
|
||||||
bytes32 public withdrawalRoot;
|
bytes32 public withdrawalRoot;
|
||||||
bytes32 public previousWithdrawalRoot;
|
bytes32 public previousWithdrawalRoot;
|
||||||
address public tornadoProxy;
|
address public tornadoProxy;
|
||||||
IVerifier public treeUpdateVerifier;
|
IBatchTreeUpdateVerifier public treeUpdateVerifier;
|
||||||
ITornadoTreesV1 public immutable tornadoTreesV1;
|
ITornadoTreesV1 public immutable tornadoTreesV1;
|
||||||
|
|
||||||
// make sure CHUNK_TREE_HEIGHT has the same value in BatchTreeUpdate.circom
|
// make sure CHUNK_TREE_HEIGHT has the same value in BatchTreeUpdate.circom
|
||||||
@@ -73,7 +70,7 @@ contract TornadoTrees is EnsResolve {
|
|||||||
address _governance,
|
address _governance,
|
||||||
address _tornadoProxy,
|
address _tornadoProxy,
|
||||||
ITornadoTreesV1 _tornadoTreesV1,
|
ITornadoTreesV1 _tornadoTreesV1,
|
||||||
IVerifier _treeUpdateVerifier,
|
IBatchTreeUpdateVerifier _treeUpdateVerifier,
|
||||||
SearchParams memory _searchParams
|
SearchParams memory _searchParams
|
||||||
) public {
|
) public {
|
||||||
governance = _governance;
|
governance = _governance;
|
||||||
@@ -113,6 +110,9 @@ contract TornadoTrees is EnsResolve {
|
|||||||
uint256 _from, // most likely array length after the proposal has passed
|
uint256 _from, // most likely array length after the proposal has passed
|
||||||
uint256 _step // optimal step size to find first match, approximately equals dispersion
|
uint256 _step // optimal step size to find first match, approximately equals dispersion
|
||||||
) public view returns (uint256) {
|
) public view returns (uint256) {
|
||||||
|
if (_from == 0 && _step == 0) {
|
||||||
|
return 0; // for tests
|
||||||
|
}
|
||||||
// Find the segment with correct array length
|
// Find the segment with correct array length
|
||||||
bool direction = elementExists(_tornadoTreesV1, _type, _from);
|
bool direction = elementExists(_tornadoTreesV1, _type, _from);
|
||||||
do {
|
do {
|
||||||
@@ -274,7 +274,7 @@ contract TornadoTrees is EnsResolve {
|
|||||||
tornadoProxy = _tornadoProxy;
|
tornadoProxy = _tornadoProxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
function setVerifierContract(IVerifier _treeUpdateVerifier) external onlyGovernance {
|
function setVerifierContract(IBatchTreeUpdateVerifier _treeUpdateVerifier) external onlyGovernance {
|
||||||
treeUpdateVerifier = _treeUpdateVerifier;
|
treeUpdateVerifier = _treeUpdateVerifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,6 @@
|
|||||||
|
|
||||||
pragma solidity ^0.6.0;
|
pragma solidity ^0.6.0;
|
||||||
|
|
||||||
interface IVerifier {
|
interface IBatchTreeUpdateVerifier {
|
||||||
function verifyProof(bytes calldata proof, uint256[1] calldata input) external view returns (bool);
|
function verifyProof(bytes calldata proof, uint256[1] calldata input) external view returns (bool);
|
||||||
}
|
}
|
||||||
@@ -5,7 +5,7 @@ pragma experimental ABIEncoderV2;
|
|||||||
|
|
||||||
import "../TornadoTrees.sol";
|
import "../TornadoTrees.sol";
|
||||||
import "../interfaces/ITornadoTreesV1.sol";
|
import "../interfaces/ITornadoTreesV1.sol";
|
||||||
import "../interfaces/IVerifier.sol";
|
import "../interfaces/IBatchTreeUpdateVerifier.sol";
|
||||||
|
|
||||||
contract TornadoTreesMock is TornadoTrees {
|
contract TornadoTreesMock is TornadoTrees {
|
||||||
uint256 public currentBlock;
|
uint256 public currentBlock;
|
||||||
@@ -14,14 +14,10 @@ contract TornadoTreesMock is TornadoTrees {
|
|||||||
address _governance,
|
address _governance,
|
||||||
address _tornadoProxy,
|
address _tornadoProxy,
|
||||||
ITornadoTreesV1 _tornadoTreesV1,
|
ITornadoTreesV1 _tornadoTreesV1,
|
||||||
IVerifier _treeUpdateVerifier,
|
IBatchTreeUpdateVerifier _treeUpdateVerifier,
|
||||||
SearchParams memory _searchParams
|
SearchParams memory _searchParams
|
||||||
) public TornadoTrees(_governance, _tornadoProxy, _tornadoTreesV1, _treeUpdateVerifier, _searchParams) {}
|
) public TornadoTrees(_governance, _tornadoProxy, _tornadoTreesV1, _treeUpdateVerifier, _searchParams) {}
|
||||||
|
|
||||||
function resolve(bytes32 _addr) public view override returns (address) {
|
|
||||||
return address(uint160(uint256(_addr) >> (12 * 8)));
|
|
||||||
}
|
|
||||||
|
|
||||||
function setBlockNumber(uint256 _blockNumber) public {
|
function setBlockNumber(uint256 _blockNumber) public {
|
||||||
currentBlock = _blockNumber;
|
currentBlock = _blockNumber;
|
||||||
}
|
}
|
||||||
@@ -44,6 +40,11 @@ contract TornadoTreesMock is TornadoTrees {
|
|||||||
registerWithdrawal(_instance, _nullifier);
|
registerWithdrawal(_instance, _nullifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateRoots(bytes32 _depositRoot, bytes32 _withdrawalRoot) public {
|
||||||
|
depositRoot = _depositRoot;
|
||||||
|
withdrawalRoot = _withdrawalRoot;
|
||||||
|
}
|
||||||
|
|
||||||
function updateDepositTreeMock(
|
function updateDepositTreeMock(
|
||||||
bytes32 _oldRoot,
|
bytes32 _oldRoot,
|
||||||
bytes32 _newRoot,
|
bytes32 _newRoot,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "tornado-trees",
|
"name": "tornado-trees",
|
||||||
"version": "0.0.1",
|
"version": "0.0.4",
|
||||||
"main": "src/index.js",
|
"main": "src/index.js",
|
||||||
"repository": "https://github.com/tornadocash/tornado-trees.git",
|
"repository": "https://github.com/tornadocash/tornado-trees.git",
|
||||||
"author": "Tornadocash team <hello@tornado.cash>",
|
"author": "Tornadocash team <hello@tornado.cash>",
|
||||||
|
|||||||
@@ -37,6 +37,13 @@ describe('findArrayLength', () => {
|
|||||||
expect(depositsLength).to.be.equal(depositsEven.length)
|
expect(depositsLength).to.be.equal(depositsEven.length)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should work for empty array', async () => {
|
||||||
|
publicArray = await PublicArray.deploy()
|
||||||
|
// will throw out of gas if you pass non zero params
|
||||||
|
const depositsLength = await tornadoTrees.findArrayLength(publicArray.address, 'deposits(uint256)', 0, 0)
|
||||||
|
expect(depositsLength).to.be.equal(0)
|
||||||
|
})
|
||||||
|
|
||||||
it('should work for odd array', async () => {
|
it('should work for odd array', async () => {
|
||||||
publicArray = await PublicArray.deploy()
|
publicArray = await PublicArray.deploy()
|
||||||
await publicArray.setDeposits(depositsOdd)
|
await publicArray.setDeposits(depositsOdd)
|
||||||
|
|||||||
Reference in New Issue
Block a user