2021-02-06 19:45:47 +03:00
|
|
|
// We require the Hardhat Runtime Environment explicitly here. This is optional
|
|
|
|
// but useful for running the script in a standalone fashion through `node <script>`.
|
|
|
|
//
|
|
|
|
// When running the script with `hardhat run <script>` you'll find the Hardhat
|
|
|
|
// Runtime Environment's members available in the global scope.
|
|
|
|
const hre = require('hardhat')
|
2021-02-07 13:27:00 +03:00
|
|
|
const { toFixedHex, poseidonHash2 } = require('../src/utils')
|
2023-09-18 16:12:33 +03:00
|
|
|
const MerkleTree = require('@tornado/fixed-merkle-tree')
|
2021-02-06 22:27:44 +03:00
|
|
|
const abi = new hre.ethers.utils.AbiCoder()
|
2021-02-06 19:45:47 +03:00
|
|
|
const instances = [
|
|
|
|
'0x1111000000000000000000000000000000001111',
|
|
|
|
'0x2222000000000000000000000000000000002222',
|
|
|
|
'0x3333000000000000000000000000000000003333',
|
|
|
|
'0x4444000000000000000000000000000000004444',
|
|
|
|
]
|
|
|
|
|
|
|
|
const blocks = ['0xaaaaaaaa', '0xbbbbbbbb', '0xcccccccc', '0xdddddddd']
|
2021-02-26 11:17:13 +03:00
|
|
|
const CHUNK_TREE_HEIGHT = 8
|
2021-02-06 19:45:47 +03:00
|
|
|
const levels = 20
|
|
|
|
|
2021-02-06 22:27:44 +03:00
|
|
|
const nonRandomBN = (nonce = 0) =>
|
|
|
|
hre.ethers.BigNumber.from('0x004d51bffaafdb3eed0661c1cfd76c8cd6ec1456b80b24bbb855f3a141ebf0be').sub(nonce)
|
|
|
|
|
2021-02-06 19:45:47 +03:00
|
|
|
async function main() {
|
|
|
|
const governance = '0x5efda50f22d34F262c29268506C5Fa42cB56A1Ce'
|
|
|
|
const [tornadoProxy] = await hre.ethers.getSigners()
|
|
|
|
console.log('deployer/tornadoProxy acc: ', tornadoProxy.address)
|
|
|
|
|
|
|
|
const tree = new MerkleTree(levels, [], { hashFunction: poseidonHash2 })
|
|
|
|
const TornadoTreesV1Mock = await hre.ethers.getContractFactory('TornadoTreesV1Mock')
|
|
|
|
const tornadoTreesV1Mock = await TornadoTreesV1Mock.deploy(0, 0, tree.root(), tree.root())
|
|
|
|
await tornadoTreesV1Mock.deployed()
|
|
|
|
console.log('tornadoTreesV1Mock deployed to:', tornadoTreesV1Mock.address)
|
|
|
|
|
|
|
|
const notes = []
|
2021-02-06 22:27:44 +03:00
|
|
|
const depositEvents = {}
|
|
|
|
const withdrawalEvents = {}
|
2021-02-06 19:45:47 +03:00
|
|
|
for (let i = 0; i < 2 ** CHUNK_TREE_HEIGHT; i++) {
|
2021-02-06 22:27:44 +03:00
|
|
|
const note = {
|
2021-02-06 19:45:47 +03:00
|
|
|
instance: instances[i % instances.length],
|
|
|
|
depositBlock: blocks[i % blocks.length],
|
|
|
|
withdrawalBlock: 2 + i + i * 4 * 60 * 24,
|
2021-02-06 22:27:44 +03:00
|
|
|
commitment: nonRandomBN(i),
|
|
|
|
nullifierHash: nonRandomBN(i + instances.length),
|
2021-02-06 19:45:47 +03:00
|
|
|
}
|
2021-02-06 22:27:44 +03:00
|
|
|
|
2021-02-06 19:45:47 +03:00
|
|
|
await tornadoTreesV1Mock.register(
|
2021-02-06 22:27:44 +03:00
|
|
|
note.instance,
|
|
|
|
toFixedHex(note.commitment),
|
|
|
|
toFixedHex(note.nullifierHash),
|
|
|
|
note.depositBlock,
|
|
|
|
note.withdrawalBlock,
|
|
|
|
{ gasLimit: 200000 },
|
|
|
|
)
|
|
|
|
const encodedData = abi.encode(
|
|
|
|
['address', 'bytes32', 'uint256'],
|
|
|
|
[note.instance, toFixedHex(note.commitment), note.depositBlock],
|
2021-02-06 19:45:47 +03:00
|
|
|
)
|
2021-02-06 22:27:44 +03:00
|
|
|
const leaf = hre.ethers.utils.keccak256(encodedData)
|
|
|
|
depositEvents[leaf] = {
|
|
|
|
hash: toFixedHex(note.commitment),
|
|
|
|
instance: toFixedHex(note.instance, 20),
|
|
|
|
block: toFixedHex(note.depositBlock, 4),
|
2021-02-06 19:45:47 +03:00
|
|
|
}
|
2021-02-06 22:27:44 +03:00
|
|
|
const encodedDataW = abi.encode(
|
|
|
|
['address', 'bytes32', 'uint256'],
|
|
|
|
[note.instance, toFixedHex(note.nullifierHash), note.withdrawalBlock],
|
|
|
|
)
|
|
|
|
const leafW = hre.ethers.utils.keccak256(encodedDataW)
|
|
|
|
withdrawalEvents[leafW] = {
|
|
|
|
hash: toFixedHex(note.nullifierHash),
|
|
|
|
instance: toFixedHex(note.instance, 20),
|
|
|
|
block: toFixedHex(note.withdrawalBlock, 4),
|
2021-02-06 19:45:47 +03:00
|
|
|
}
|
2021-02-06 22:27:44 +03:00
|
|
|
notes[i] = note
|
2021-02-06 19:45:47 +03:00
|
|
|
}
|
|
|
|
console.log(`Registered ${notes.length} new deposits and withdrawals in tornadoTreesV1Mock`)
|
|
|
|
console.log(JSON.stringify(depositEvents, null, 2))
|
|
|
|
console.log(JSON.stringify(withdrawalEvents, null, 2))
|
|
|
|
|
|
|
|
const BatchTreeUpdateVerifier = await hre.ethers.getContractFactory('BatchTreeUpdateVerifier')
|
|
|
|
const verifier = await BatchTreeUpdateVerifier.deploy()
|
|
|
|
await verifier.deployed()
|
|
|
|
console.log('Verifier deployed to:', verifier.address)
|
|
|
|
|
|
|
|
const TornadoTrees = await hre.ethers.getContractFactory('TornadoTrees')
|
|
|
|
const tornadoTrees = await TornadoTrees.deploy(
|
|
|
|
governance,
|
|
|
|
tornadoProxy.address,
|
|
|
|
tornadoTreesV1Mock.address,
|
|
|
|
verifier.address,
|
|
|
|
{
|
|
|
|
unprocessedDeposits: 1, // this approximate value, actually there are 4, but the contract will figure out that
|
|
|
|
unprocessedWithdrawals: 1,
|
|
|
|
depositsPerDay: 2, // parameter for searching the count of unprocessedDeposits
|
|
|
|
withdrawalsPerDay: 2,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
await tornadoTrees.deployed()
|
|
|
|
console.log('tornadoTrees deployed to:', tornadoTrees.address)
|
|
|
|
console.log('You can use the same private key to register new deposits in the tornadoTrees')
|
2021-02-06 22:27:44 +03:00
|
|
|
|
|
|
|
console.log(`\nTORNADO_TREES_V1=${tornadoTreesV1Mock.address}`)
|
|
|
|
console.log(`TORNADO_TREES=${tornadoTrees.address}`)
|
2021-02-06 19:45:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// We recommend this pattern to be able to use async/await everywhere
|
|
|
|
// and properly handle errors.
|
|
|
|
main()
|
|
|
|
.then(() => process.exit(0))
|
|
|
|
.catch((error) => {
|
|
|
|
console.error(error)
|
|
|
|
process.exit(1)
|
|
|
|
})
|