mirror of
https://github.com/tornadocash/tornado-core.git
synced 2024-11-25 11:18:29 +01:00
isSpent fix
This commit is contained in:
parent
caaedbc959
commit
63f984b2d5
18
cli.js
18
cli.js
@ -48,24 +48,32 @@ async function withdraw(note, receiver) {
|
||||
|
||||
console.log('Getting current state from mixer contract')
|
||||
const events = await mixer.getPastEvents('Deposit', { fromBlock: mixer.deployedBlock, toBlock: 'latest' })
|
||||
let leafIndex
|
||||
|
||||
const commitment = deposit.commitment.toString(16).padStart('66', '0x000000')
|
||||
const leaves = events
|
||||
.sort((a, b) => a.returnValues.leafIndex.sub(b.returnValues.leafIndex))
|
||||
.map(e => e.returnValues.commitment)
|
||||
.map(e => {
|
||||
if (e.returnValues.commitment.eq(commitment)) {
|
||||
leafIndex = e.returnValues.leafIndex.toNumber()
|
||||
}
|
||||
return e.returnValues.commitment
|
||||
})
|
||||
const tree = new merkleTree(MERKLE_TREE_HEIGHT, EMPTY_ELEMENT, leaves)
|
||||
const validRoot = await mixer.methods.isKnownRoot(await tree.root()).call()
|
||||
// todo make sure that function input is 32 bytes long
|
||||
const isSpent = await mixer.methods.isSpent('0x' + deposit.nullifier.toString(16)).call()
|
||||
const nullifierHash = pedersenHash(deposit.nullifier.leInt2Buff(32))
|
||||
const nullifierHashToCheck = nullifierHash.toString(16).padStart('66', '0x000000')
|
||||
const isSpent = await mixer.methods.isSpent(nullifierHashToCheck).call()
|
||||
assert(validRoot === true)
|
||||
assert(isSpent === false)
|
||||
|
||||
const leafIndex = leaves.map(el => el.toString()).indexOf(deposit.commitment.toString())
|
||||
assert(leafIndex >= 0)
|
||||
const { root, path_elements, path_index } = await tree.path(leafIndex)
|
||||
// Circuit input
|
||||
const input = {
|
||||
// public
|
||||
root: root,
|
||||
nullifierHash: pedersenHash(deposit.nullifier.leInt2Buff(32)),
|
||||
nullifierHash,
|
||||
receiver: bigInt(receiver),
|
||||
fee: bigInt(0),
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user