Merge pull request #32 from tornadocash/migrationScript

Migration script
This commit is contained in:
Roman Storm 2019-12-13 13:15:06 -08:00 committed by GitHub
commit 51c3d6b28c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 180 additions and 5 deletions

View File

@ -1,4 +1,4 @@
MERKLE_TREE_HEIGHT=16 MERKLE_TREE_HEIGHT=20
# in wei # in wei
ETH_AMOUNT=100000000000000000 ETH_AMOUNT=100000000000000000
TOKEN_AMOUNT=100000000000000000 TOKEN_AMOUNT=100000000000000000

View File

@ -52,4 +52,4 @@ template Withdraw(levels) {
} }
} }
component main = Withdraw(16); component main = Withdraw(20);

6
cli.js
View File

@ -56,7 +56,7 @@ async function deposit() {
const deposit = createDeposit(rbigint(31), rbigint(31)) const deposit = createDeposit(rbigint(31), rbigint(31))
console.log('Submitting deposit transaction') console.log('Submitting deposit transaction')
await tornado.methods.deposit(toHex(deposit.commitment)).send({ value: ETH_AMOUNT, from: senderAccount, gas:1e6 }) await tornado.methods.deposit(toHex(deposit.commitment)).send({ value: ETH_AMOUNT, from: senderAccount, gas:2e6 })
const note = toHex(deposit.preimage, 62) const note = toHex(deposit.preimage, 62)
console.log('Your note:', note) console.log('Your note:', note)
@ -71,14 +71,14 @@ async function depositErc20() {
if(ERC20_TOKEN === '') { if(ERC20_TOKEN === '') {
console.log('Minting some test tokens to deposit') console.log('Minting some test tokens to deposit')
await erc20.methods.mint(senderAccount, TOKEN_AMOUNT).send({ from: senderAccount, gas: 1e6 }) await erc20.methods.mint(senderAccount, TOKEN_AMOUNT).send({ from: senderAccount, gas: 2e6 })
} }
console.log('Approving tokens for deposit') console.log('Approving tokens for deposit')
await erc20.methods.approve(erc20tornado._address, TOKEN_AMOUNT).send({ from: senderAccount, gas:1e6 }) await erc20.methods.approve(erc20tornado._address, TOKEN_AMOUNT).send({ from: senderAccount, gas:1e6 })
console.log('Submitting deposit transaction') console.log('Submitting deposit transaction')
await erc20tornado.methods.deposit(toHex(deposit.commitment)).send({ from: senderAccount, gas:1e6 }) await erc20tornado.methods.deposit(toHex(deposit.commitment)).send({ from: senderAccount, gas:2e6 })
const note = toHex(deposit.preimage, 62) const note = toHex(deposit.preimage, 62)
console.log('Your note:', note) console.log('Your note:', note)

View File

@ -38,4 +38,34 @@ contract ETHTornado is Tornado {
require(success, "payment to _relayer did not go thru"); require(success, "payment to _relayer did not go thru");
} }
} }
/**
@dev Migrate state from old mixer to this one.
@param _commitments deposited commitments from previous contract
@param _nullifierHashes spent nullifiers from previous contract
*/
bool public isMigrated = false;
function migrateState(bytes32[] calldata _commitments, bytes32[] calldata _nullifierHashes) external onlyOperator {
require(!isMigrated, "Migration is disabled");
for (uint32 i = 0; i < _commitments.length; i++) {
commitments[_commitments[i]] = true;
emit Deposit(_commitments[i], nextIndex + i, block.timestamp);
}
nextIndex += uint32(_commitments.length);
for (uint256 i = 0; i < _nullifierHashes.length; i++) {
nullifierHashes[_nullifierHashes[i]] = true;
emit Withdrawal(address(0), _nullifierHashes[i], address(0), 0);
}
}
function initializeTreeForMigration(bytes32[] calldata _filledSubtrees, bytes32 _root) external onlyOperator {
require(!isMigrated, "already migrated");
filledSubtrees = _filledSubtrees;
roots[0] = _root;
}
function finishMigration() external payable onlyOperator {
isMigrated = true;
}
} }

145
migrationDeposits.js Normal file

File diff suppressed because one or more lines are too long