fix bignumber

This commit is contained in:
poma 2021-02-25 21:11:36 +03:00
parent 65c6527f6c
commit c90ed424b5
No known key found for this signature in database
GPG Key ID: BA20CB01FE165657
2 changed files with 5 additions and 3 deletions

View File

@ -1,7 +1,9 @@
require('dotenv').config()
const { getTornadoTrees, txManager, getProvider } = require('./singletons')
const { action, getExplorer, poseidonHash, poseidonHash2, toFixedHex } = require('./utils')
const { parseUnits } = require('ethers').utils
const ethers = require('ethers')
const BigNumber = ethers.BigNumber
const { parseUnits } = ethers.utils
const tornadoTrees = require('tornado-trees')
const MerkleTree = require('fixed-merkle-tree')
@ -13,7 +15,7 @@ async function updateTree(committedEvents, pendingEvents, type) {
const tree = new MerkleTree(20, leaves, { hashFunction: poseidonHash2 })
const rootMethod = type === action.DEPOSIT ? 'depositRoot' : 'withdrawalRoot'
const root = toFixedHex(await getTornadoTrees()[rootMethod]())
if (root !== tree.root()) {
if (!BigNumber.from(root).eq(tree.root())) {
throw new Error(`Invalid ${type} root! Contract: ${root}, local: ${tree.root()}`)
}
while (pendingEvents.length >= INSERT_BATCH_SIZE) {

View File

@ -9,7 +9,7 @@ const toFixedHex = (number, length = 32) =>
: BigNumber.from(number).toHexString().slice(2)
).padStart(length * 2, '0')
const poseidonHash = (items) => toFixedHex(poseidon(items))
const poseidonHash = (items) => BigNumber.from(poseidon(items))
const poseidonHash2 = (a, b) => poseidonHash([a, b])
const action = Object.freeze({ DEPOSIT: 'deposit', WITHDRAWAL: 'withdrawal' })