mirror of
https://github.com/tornadocash/tornado-root-updater.git
synced 2024-12-04 15:14:38 +01:00
fix bignumber
This commit is contained in:
parent
65c6527f6c
commit
c90ed424b5
@ -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) {
|
||||
|
@ -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' })
|
||||
|
Loading…
Reference in New Issue
Block a user