fix: optimism poseidon hash for events

This commit is contained in:
nikdementev 2021-04-02 16:45:29 +03:00 committed by Alexey Pertsev
parent 18518856ff
commit 6d219e19ee
2 changed files with 15 additions and 3 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "tornado-anonymity-mining", "name": "tornado-anonymity-mining",
"version": "2.1.3", "version": "2.1.4",
"main": "index.js", "main": "index.js",
"repository": "https://github.com/tornadocash/tornado-anonymity-mining.git", "repository": "https://github.com/tornadocash/tornado-anonymity-mining.git",
"author": "Tornadocash team <hello@tornado.cash>", "author": "Tornadocash team <hello@tornado.cash>",

View File

@ -131,7 +131,13 @@ class Controller {
const newAccount = new Account({ amount: newAmount }) const newAccount = new Account({ amount: newAmount })
depositDataEvents = depositDataEvents || (await this._fetchDepositDataEvents()) depositDataEvents = depositDataEvents || (await this._fetchDepositDataEvents())
const depositLeaves = depositDataEvents.map((x) => poseidonHash([x.instance, x.hash, x.block])) const depositLeaves = depositDataEvents.map((x) => {
if (x.poseidon) {
return x.poseidon
}
return poseidonHash([x.instance, x.hash, x.block])
})
const depositTree = new MerkleTree(this.merkleTreeHeight, depositLeaves, { hashFunction: poseidonHash2 }) const depositTree = new MerkleTree(this.merkleTreeHeight, depositLeaves, { hashFunction: poseidonHash2 })
const depositItem = depositDataEvents.filter((x) => x.hash === toFixedHex(note.commitment)) const depositItem = depositDataEvents.filter((x) => x.hash === toFixedHex(note.commitment))
if (depositItem.length === 0) { if (depositItem.length === 0) {
@ -140,7 +146,13 @@ class Controller {
const depositPath = depositTree.path(depositItem[0].index) const depositPath = depositTree.path(depositItem[0].index)
withdrawalDataEvents = withdrawalDataEvents || (await this._fetchWithdrawalDataEvents()) withdrawalDataEvents = withdrawalDataEvents || (await this._fetchWithdrawalDataEvents())
const withdrawalLeaves = withdrawalDataEvents.map((x) => poseidonHash([x.instance, x.hash, x.block])) const withdrawalLeaves = withdrawalDataEvents.map((x) => {
if (x.poseidon) {
return x.poseidon
}
return poseidonHash([x.instance, x.hash, x.block])
})
const withdrawalTree = new MerkleTree(this.merkleTreeHeight, withdrawalLeaves, { const withdrawalTree = new MerkleTree(this.merkleTreeHeight, withdrawalLeaves, {
hashFunction: poseidonHash2, hashFunction: poseidonHash2,
}) })