make sure pathIndex is always a number (fixes bug with string concat instead of integer addition)

This commit is contained in:
poma 2019-11-09 16:49:31 +03:00
parent bc8d0b20fc
commit 1a17e7eea3

View File

@ -1,6 +1,5 @@
const jsStorage = require('./Storage')
const hasherImpl = require('./MiMC')
const { bigInt } = require('snarkjs')
class MerkleTree {
@ -12,7 +11,7 @@ class MerkleTree {
this.zero_values = []
this.totalElements = 0
let current_zero_value = bigInt('5702960885942360421128284892092891246826997279710054143430547229469817701242')
let current_zero_value = '5702960885942360421128284892092891246826997279710054143430547229469817701242'
this.zero_values.push(current_zero_value)
for (let i = 0; i < n_levels; i++) {
current_zero_value = this.hasher.hash(i, current_zero_value, current_zero_value)
@ -77,6 +76,7 @@ class MerkleTree {
this.path_index.push(element_index % 2)
}
}
index = Number(index)
let traverser = new PathTraverser(this.prefix, this.storage, this.zero_values)
const root = await this.storage.get_or_element(
MerkleTree.index_to_key(this.prefix, this.n_levels, 0),