mirror of
https://github.com/tornadocash/tornado-nova
synced 2024-02-02 14:53:56 +01:00
fix utxo index
This commit is contained in:
parent
45a2c01e33
commit
5b90a793f5
16
src/index.js
16
src/index.js
@ -25,24 +25,18 @@ async function getProof({ inputs, outputs, tree, extAmount, fee, recipient, rela
|
|||||||
|
|
||||||
for (const input of inputs) {
|
for (const input of inputs) {
|
||||||
if (input.amount > 0) {
|
if (input.amount > 0) {
|
||||||
const index = tree.indexOf(toFixedHex(input.getCommitment()))
|
input.index = tree.indexOf(toFixedHex(input.getCommitment()))
|
||||||
if (index < 0) {
|
if (input.index < 0) {
|
||||||
throw new Error(`Input commitment ${toFixedHex(input.getCommitment())} was not found`)
|
throw new Error(`Input commitment ${toFixedHex(input.getCommitment())} was not found`)
|
||||||
}
|
}
|
||||||
inputMerklePathIndices.push(index)
|
inputMerklePathIndices.push(input.index)
|
||||||
inputMerklePathElements.push(tree.path(index).pathElements)
|
inputMerklePathElements.push(tree.path(input.index).pathElements)
|
||||||
} else {
|
} else {
|
||||||
inputMerklePathIndices.push(0)
|
inputMerklePathIndices.push(0)
|
||||||
inputMerklePathElements.push(new Array(tree.levels).fill(0))
|
inputMerklePathElements.push(new Array(tree.levels).fill(0))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const oldRoot = tree.root()
|
|
||||||
for (const output of outputs) {
|
|
||||||
output.index = tree.elements().length
|
|
||||||
tree.insert(output.getCommitment())
|
|
||||||
}
|
|
||||||
|
|
||||||
const extData = {
|
const extData = {
|
||||||
recipient: toFixedHex(recipient, 20),
|
recipient: toFixedHex(recipient, 20),
|
||||||
extAmount: toFixedHex(extAmount),
|
extAmount: toFixedHex(extAmount),
|
||||||
@ -55,7 +49,7 @@ async function getProof({ inputs, outputs, tree, extAmount, fee, recipient, rela
|
|||||||
|
|
||||||
const extDataHash = getExtDataHash(extData)
|
const extDataHash = getExtDataHash(extData)
|
||||||
let input = {
|
let input = {
|
||||||
root: oldRoot,
|
root: tree.root(),
|
||||||
inputNullifier: inputs.map((x) => x.getNullifier()),
|
inputNullifier: inputs.map((x) => x.getNullifier()),
|
||||||
outputCommitment: outputs.map((x) => x.getCommitment()),
|
outputCommitment: outputs.map((x) => x.getCommitment()),
|
||||||
publicAmount: BigNumber.from(extAmount).sub(fee).add(FIELD_SIZE).mod(FIELD_SIZE).toString(),
|
publicAmount: BigNumber.from(extAmount).sub(fee).add(FIELD_SIZE).mod(FIELD_SIZE).toString(),
|
||||||
|
Loading…
Reference in New Issue
Block a user