deploy update

This commit is contained in:
Alexey 2021-02-06 22:27:44 +03:00
parent 285324595b
commit 7f508d450f
2 changed files with 54 additions and 18 deletions

@ -41,6 +41,22 @@ contract TornadoTreesV1Mock {
withdrawals.push(keccak256(abi.encode(_instance, _nullifier, blockNumber())));
}
function getRegisteredDeposits() external view returns (bytes32[] memory _deposits) {
uint256 count = deposits.length - lastProcessedDepositLeaf;
_deposits = new bytes32[](count);
for (uint256 i = 0; i < count; i++) {
_deposits[i] = deposits[lastProcessedDepositLeaf + i];
}
}
function getRegisteredWithdrawals() external view returns (bytes32[] memory _withdrawals) {
uint256 count = withdrawals.length - lastProcessedWithdrawalLeaf;
_withdrawals = new bytes32[](count);
for (uint256 i = 0; i < count; i++) {
_withdrawals[i] = withdrawals[lastProcessedWithdrawalLeaf + i];
}
}
function setLastProcessedDepositLeaf(uint256 _lastProcessedDepositLeaf) public {
lastProcessedDepositLeaf = _lastProcessedDepositLeaf;
}

@ -6,6 +6,7 @@
const hre = require('hardhat')
const { toFixedHex, poseidonHash2, randomBN } = require('../src/utils')
const MerkleTree = require('fixed-merkle-tree')
const abi = new hre.ethers.utils.AbiCoder()
const instances = [
'0x1111000000000000000000000000000000001111',
'0x2222000000000000000000000000000000002222',
@ -17,6 +18,9 @@ const blocks = ['0xaaaaaaaa', '0xbbbbbbbb', '0xcccccccc', '0xdddddddd']
const CHUNK_TREE_HEIGHT = 2
const levels = 20
const nonRandomBN = (nonce = 0) =>
hre.ethers.BigNumber.from('0x004d51bffaafdb3eed0661c1cfd76c8cd6ec1456b80b24bbb855f3a141ebf0be').sub(nonce)
async function main() {
const governance = '0x5efda50f22d34F262c29268506C5Fa42cB56A1Ce'
const [tornadoProxy] = await hre.ethers.getSigners()
@ -29,33 +33,46 @@ async function main() {
console.log('tornadoTreesV1Mock deployed to:', tornadoTreesV1Mock.address)
const notes = []
const depositEvents = []
const withdrawalEvents = []
const depositEvents = {}
const withdrawalEvents = {}
for (let i = 0; i < 2 ** CHUNK_TREE_HEIGHT; i++) {
notes[i] = {
const note = {
instance: instances[i % instances.length],
depositBlock: blocks[i % blocks.length],
withdrawalBlock: 2 + i + i * 4 * 60 * 24,
commitment: randomBN(),
nullifierHash: randomBN(),
commitment: nonRandomBN(i),
nullifierHash: nonRandomBN(i + instances.length),
}
await tornadoTreesV1Mock.register(
notes[i].instance,
toFixedHex(notes[i].commitment),
toFixedHex(notes[i].nullifierHash),
notes[i].depositBlock,
notes[i].withdrawalBlock,
note.instance,
toFixedHex(note.commitment),
toFixedHex(note.nullifierHash),
note.depositBlock,
note.withdrawalBlock,
{ gasLimit: 200000 },
)
depositEvents[i] = {
hash: toFixedHex(notes[i].commitment),
instance: toFixedHex(notes[i].instance, 20),
block: toFixedHex(notes[i].depositBlock, 4),
const encodedData = abi.encode(
['address', 'bytes32', 'uint256'],
[note.instance, toFixedHex(note.commitment), note.depositBlock],
)
const leaf = hre.ethers.utils.keccak256(encodedData)
depositEvents[leaf] = {
hash: toFixedHex(note.commitment),
instance: toFixedHex(note.instance, 20),
block: toFixedHex(note.depositBlock, 4),
}
withdrawalEvents[i] = {
hash: toFixedHex(notes[i].nullifierHash),
instance: toFixedHex(notes[i].instance, 20),
block: toFixedHex(notes[i].withdrawalBlock, 4),
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),
}
notes[i] = note
}
console.log(`Registered ${notes.length} new deposits and withdrawals in tornadoTreesV1Mock`)
console.log(JSON.stringify(depositEvents, null, 2))
@ -82,6 +99,9 @@ async function main() {
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')
console.log(`\nTORNADO_TREES_V1=${tornadoTreesV1Mock.address}`)
console.log(`TORNADO_TREES=${tornadoTrees.address}`)
}
// We recommend this pattern to be able to use async/await everywhere