mirror of
https://github.com/tornadocash/tornado-core.git
synced 2025-12-15 16:39:24 -05:00
move unused tree args to the right and provide defaults
This commit is contained in:
parent
8f687ca146
commit
981325b1ff
5 changed files with 32 additions and 55 deletions
|
|
@ -9,9 +9,8 @@ const { takeSnapshot, revertSnapshot, increaseTime } = require('../scripts/ganac
|
|||
const MerkleTreeWithHistory = artifacts.require('./MerkleTreeWithHistoryMock.sol')
|
||||
const MiMC = artifacts.require('./MiMC.sol')
|
||||
|
||||
const JsStorage = require('../lib/Storage')
|
||||
const MerkleTree = require('../lib/MerkleTree')
|
||||
const MimcHacher = require('../lib/MiMC')
|
||||
const MimcHasher = require('../lib/MiMC')
|
||||
|
||||
function BNArrayToStringArray(array) {
|
||||
const arrayToPrint = []
|
||||
|
|
@ -34,14 +33,11 @@ contract('MerkleTreeWithHistory', async accounts => {
|
|||
let hasher
|
||||
|
||||
before(async () => {
|
||||
const storage = new JsStorage()
|
||||
hasher = new MimcHacher()
|
||||
tree = new MerkleTree(
|
||||
prefix,
|
||||
storage,
|
||||
hasher,
|
||||
levels,
|
||||
zeroValue,
|
||||
null,
|
||||
prefix,
|
||||
)
|
||||
miMC = await MiMC.deployed()
|
||||
await MerkleTreeWithHistory.link(MiMC, miMC.address)
|
||||
|
|
@ -73,14 +69,12 @@ contract('MerkleTreeWithHistory', async accounts => {
|
|||
})
|
||||
|
||||
it('tests insert', async () => {
|
||||
const storage = new JsStorage()
|
||||
hasher = new MimcHacher()
|
||||
hasher = new MimcHasher()
|
||||
tree = new MerkleTree(
|
||||
prefix,
|
||||
storage,
|
||||
hasher,
|
||||
2,
|
||||
zeroValue,
|
||||
null,
|
||||
prefix,
|
||||
)
|
||||
await tree.insert('5')
|
||||
let {root, path_elements, path_index} = await tree.path(0)
|
||||
|
|
@ -97,15 +91,11 @@ contract('MerkleTreeWithHistory', async accounts => {
|
|||
await tree.insert(el)
|
||||
}
|
||||
|
||||
const storage = new JsStorage()
|
||||
hasher = new MimcHacher()
|
||||
const batchTree = new MerkleTree(
|
||||
prefix,
|
||||
storage,
|
||||
hasher,
|
||||
levels,
|
||||
zeroValue,
|
||||
elements
|
||||
elements,
|
||||
prefix,
|
||||
);
|
||||
for(const [i, el] of Object.entries(elements)) {
|
||||
const pathViaConstructor = await batchTree.path(i)
|
||||
|
|
@ -120,15 +110,11 @@ contract('MerkleTreeWithHistory', async accounts => {
|
|||
await tree.insert(el)
|
||||
}
|
||||
|
||||
const storage = new JsStorage()
|
||||
hasher = new MimcHacher()
|
||||
const batchTree = new MerkleTree(
|
||||
prefix,
|
||||
storage,
|
||||
hasher,
|
||||
levels,
|
||||
zeroValue,
|
||||
elements
|
||||
elements,
|
||||
prefix,
|
||||
);
|
||||
for(const [i, el] of Object.entries(elements)) {
|
||||
const pathViaConstructor = await batchTree.path(i)
|
||||
|
|
@ -142,16 +128,12 @@ contract('MerkleTreeWithHistory', async accounts => {
|
|||
for(let i = 1000; i < 31001; i++) {
|
||||
elements.push(i)
|
||||
}
|
||||
const storage = new JsStorage()
|
||||
hasher = new MimcHacher()
|
||||
console.time('MerkleTree');
|
||||
tree = new MerkleTree(
|
||||
prefix,
|
||||
storage,
|
||||
hasher,
|
||||
levels,
|
||||
zeroValue,
|
||||
elements
|
||||
elements,
|
||||
prefix,
|
||||
);
|
||||
console.timeEnd('MerkleTree');
|
||||
// 2,7 GHz Intel Core i7
|
||||
|
|
@ -184,21 +166,21 @@ contract('MerkleTreeWithHistory', async accounts => {
|
|||
describe('#MIMC', async () => {
|
||||
it.skip('gas price', async () => {
|
||||
const gas = await merkleTreeWithHistory.hashLeftRight.estimateGas(1,2)
|
||||
console.log('gas', gas)
|
||||
// console.log('gas', gas)
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
await revertSnapshot(snapshotId.result)
|
||||
snapshotId = await takeSnapshot()
|
||||
const storage = new JsStorage()
|
||||
hasher = new MimcHacher()
|
||||
hasher = new MimcHasher()
|
||||
tree = new MerkleTree(
|
||||
prefix,
|
||||
storage,
|
||||
hasher,
|
||||
levels,
|
||||
zeroValue,
|
||||
null,
|
||||
prefix,
|
||||
null,
|
||||
hasher,
|
||||
)
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -13,9 +13,7 @@ const utils = require("../scripts/utils")
|
|||
const stringifyBigInts = require("websnark/tools/stringifybigint").stringifyBigInts
|
||||
const snarkjs = require("snarkjs");
|
||||
const bigInt = snarkjs.bigInt;
|
||||
const JsStorage = require('../lib/Storage')
|
||||
const MerkleTree = require('../lib/MerkleTree')
|
||||
const MimcHacher = require('../lib/MiMC')
|
||||
|
||||
function generateDeposit() {
|
||||
let deposit = {
|
||||
|
|
@ -29,7 +27,6 @@ function generateDeposit() {
|
|||
|
||||
contract('Mixer', async accounts => {
|
||||
let mixer
|
||||
let miMC
|
||||
const sender = accounts[0]
|
||||
const emptyAddress = '0x0000000000000000000000000000000000000000'
|
||||
const levels = 16
|
||||
|
|
@ -37,17 +34,13 @@ contract('Mixer', async accounts => {
|
|||
let snapshotId
|
||||
let prefix = 'test'
|
||||
let tree
|
||||
let hasher
|
||||
|
||||
before(async () => {
|
||||
const storage = new JsStorage()
|
||||
hasher = new MimcHacher()
|
||||
tree = new MerkleTree(
|
||||
prefix,
|
||||
storage,
|
||||
hasher,
|
||||
levels,
|
||||
zeroValue,
|
||||
null,
|
||||
prefix,
|
||||
)
|
||||
mixer = await Mixer.deployed()
|
||||
snapshotId = await takeSnapshot()
|
||||
|
|
@ -78,8 +71,8 @@ contract('Mixer', async accounts => {
|
|||
it('should work', async () => {
|
||||
const deposit = generateDeposit()
|
||||
await tree.insert(deposit.commitment)
|
||||
let gas = await mixer.deposit.estimateGas(toBN(deposit.commitment.toString()), { value: AMOUNT, from: sender })
|
||||
console.log('deposit gas', gas)
|
||||
// let gas = await mixer.deposit.estimateGas(toBN(deposit.commitment.toString()), { value: AMOUNT, from: sender })
|
||||
// console.log('deposit gas', gas)
|
||||
await mixer.deposit(toBN(deposit.commitment.toString()), { value: AMOUNT, from: sender })
|
||||
|
||||
const {root, path_elements, path_index} = await tree.path(0);
|
||||
|
|
@ -101,8 +94,8 @@ contract('Mixer', async accounts => {
|
|||
const { pi_a, pi_b, pi_c, publicSignals } = await utils.snarkProof(input)
|
||||
// console.log('proof', pi_a, pi_b, pi_c, publicSignals)
|
||||
|
||||
gas = await mixer.withdraw.estimateGas(pi_a, pi_b, pi_c, publicSignals, { from: sender })
|
||||
console.log('withdraw gas', gas)
|
||||
// gas = await mixer.withdraw.estimateGas(pi_a, pi_b, pi_c, publicSignals, { from: sender })
|
||||
// console.log('withdraw gas', gas)
|
||||
const { logs } = await mixer.withdraw(pi_a, pi_b, pi_c, publicSignals, { from: sender })
|
||||
logs[0].event.should.be.equal('Withdraw')
|
||||
// logs[0].args.nullifier.should.be.eq.BN(toBN(commitment))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue