From 6d219e19ee89c0d7e7ef193955dfba8773d39a14 Mon Sep 17 00:00:00 2001 From: nikdementev Date: Fri, 2 Apr 2021 16:45:29 +0300 Subject: [PATCH] fix: optimism poseidon hash for events --- package.json | 2 +- src/controller.js | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 606da47..785d16e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tornado-anonymity-mining", - "version": "2.1.3", + "version": "2.1.4", "main": "index.js", "repository": "https://github.com/tornadocash/tornado-anonymity-mining.git", "author": "Tornadocash team ", diff --git a/src/controller.js b/src/controller.js index 5a74a57..38ed9f6 100644 --- a/src/controller.js +++ b/src/controller.js @@ -131,7 +131,13 @@ class Controller { const newAccount = new Account({ amount: newAmount }) 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 depositItem = depositDataEvents.filter((x) => x.hash === toFixedHex(note.commitment)) if (depositItem.length === 0) { @@ -140,7 +146,13 @@ class Controller { const depositPath = depositTree.path(depositItem[0].index) 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, { hashFunction: poseidonHash2, })