mirror of
https://github.com/tornadocash/tornado-core.git
synced 2024-10-01 01:06:17 -04:00
rename mimc mentions to a generic hasher
This commit is contained in:
parent
6b067f067f
commit
71b767ade1
@ -11,7 +11,7 @@
|
||||
|
||||
pragma solidity ^0.5.8;
|
||||
|
||||
library MiMC {
|
||||
library Hasher {
|
||||
function MiMCSponge(uint256 in_xL, uint256 in_xR, uint256 in_k) public pure returns (uint256 xL, uint256 xR);
|
||||
}
|
||||
|
||||
@ -42,18 +42,18 @@ contract MerkleTreeWithHistory {
|
||||
_roots[0] = hashLeftRight(_zeros[levels - 1], _zeros[levels - 1]);
|
||||
}
|
||||
|
||||
function hashLeftRight(uint256 left, uint256 right) public pure returns (uint256 mimc_hash) {
|
||||
function hashLeftRight(uint256 left, uint256 right) public pure returns (uint256 hash) {
|
||||
uint256 k = 21888242871839275222246405745257275088548364400416034343698204186575808495617;
|
||||
uint256 R = 0;
|
||||
uint256 C = 0;
|
||||
|
||||
R = addmod(R, left, k);
|
||||
(R, C) = MiMC.MiMCSponge(R, C, 0);
|
||||
(R, C) = Hasher.MiMCSponge(R, C, 0);
|
||||
|
||||
R = addmod(R, right, k);
|
||||
(R, C) = MiMC.MiMCSponge(R, C, 0);
|
||||
(R, C) = Hasher.MiMCSponge(R, C, 0);
|
||||
|
||||
mimc_hash = R;
|
||||
hash = R;
|
||||
}
|
||||
|
||||
function _insert(uint256 leaf) internal {
|
||||
|
@ -1,12 +1,12 @@
|
||||
const jsStorage = require('./Storage')
|
||||
const mimcHasher = require('./MiMC')
|
||||
const hasherImpl = require('./MiMC')
|
||||
|
||||
class MerkleTree {
|
||||
|
||||
constructor(n_levels, zero_value, defaultElements, prefix, storage, hasher) {
|
||||
this.prefix = prefix
|
||||
this.storage = storage || new jsStorage()
|
||||
this.hasher = hasher || new mimcHasher()
|
||||
this.hasher = hasher || new hasherImpl()
|
||||
this.n_levels = n_levels
|
||||
this.zero_values = []
|
||||
this.totalElements = 0
|
||||
|
@ -1,7 +1,7 @@
|
||||
/* global artifacts */
|
||||
const path = require('path')
|
||||
|
||||
const mimcGenContract = require('circomlib/src/mimcsponge_gencontract.js')
|
||||
const genContract = require('circomlib/src/mimcsponge_gencontract.js')
|
||||
const Artifactor = require('truffle-artifactor')
|
||||
|
||||
const SEED = 'mimcsponge'
|
||||
@ -11,14 +11,14 @@ module.exports = function(deployer) {
|
||||
return deployer.then( async () => {
|
||||
const contractsDir = path.join(__dirname, '..', 'build/contracts')
|
||||
let artifactor = new Artifactor(contractsDir)
|
||||
let mimcContractName = 'MiMC'
|
||||
let contractName = 'Hasher'
|
||||
await artifactor.save({
|
||||
contractName: mimcContractName,
|
||||
abi: mimcGenContract.abi,
|
||||
unlinked_binary: mimcGenContract.createCode(SEED, 220),
|
||||
contractName,
|
||||
abi: genContract.abi,
|
||||
unlinked_binary: genContract.createCode(SEED, 220),
|
||||
}).then(async () => {
|
||||
const MiMC = artifacts.require(mimcContractName)
|
||||
await deployer.deploy(MiMC)
|
||||
const hasherContract = artifacts.require(contractName)
|
||||
await deployer.deploy(hasherContract)
|
||||
})
|
||||
})
|
||||
}
|
@ -2,15 +2,15 @@
|
||||
require('dotenv').config({ path: '../.env' })
|
||||
const ETHMixer = artifacts.require('ETHMixer')
|
||||
const Verifier = artifacts.require('Verifier')
|
||||
const MiMC = artifacts.require('MiMC')
|
||||
const hasherContract = artifacts.require('hasher')
|
||||
|
||||
|
||||
module.exports = function(deployer, network, accounts) {
|
||||
return deployer.then(async () => {
|
||||
const { MERKLE_TREE_HEIGHT, ETH_AMOUNT, EMPTY_ELEMENT } = process.env
|
||||
const verifier = await Verifier.deployed()
|
||||
const miMC = await MiMC.deployed()
|
||||
await ETHMixer.link(MiMC, miMC.address)
|
||||
const hasherInstance = await hasherContract.deployed()
|
||||
await ETHMixer.link(hasherContract, hasherInstance.address)
|
||||
const mixer = await deployer.deploy(ETHMixer, verifier.address, ETH_AMOUNT, MERKLE_TREE_HEIGHT, EMPTY_ELEMENT, accounts[0])
|
||||
console.log('ETHMixer\'s address ', mixer.address)
|
||||
})
|
||||
|
@ -2,7 +2,7 @@
|
||||
require('dotenv').config({ path: '../.env' })
|
||||
const ERC20Mixer = artifacts.require('ERC20Mixer')
|
||||
const Verifier = artifacts.require('Verifier')
|
||||
const MiMC = artifacts.require('MiMC')
|
||||
const hasherContract = artifacts.require('hasher')
|
||||
const ERC20Mock = artifacts.require('ERC20Mock')
|
||||
|
||||
|
||||
@ -10,8 +10,8 @@ module.exports = function(deployer, network, accounts) {
|
||||
return deployer.then(async () => {
|
||||
const { MERKLE_TREE_HEIGHT, ETH_AMOUNT, EMPTY_ELEMENT, ERC20_TOKEN, TOKEN_AMOUNT } = process.env
|
||||
const verifier = await Verifier.deployed()
|
||||
const miMC = await MiMC.deployed()
|
||||
await ERC20Mixer.link(MiMC, miMC.address)
|
||||
const hasherInstance = await hasherContract.deployed()
|
||||
await ERC20Mixer.link(hasherContract, hasherInstance.address)
|
||||
let token = ERC20_TOKEN
|
||||
if(token === '') {
|
||||
const tokenInstance = await deployer.deploy(ERC20Mock)
|
||||
|
@ -7,10 +7,10 @@ require('chai')
|
||||
const { takeSnapshot, revertSnapshot } = require('../lib/ganacheHelper')
|
||||
|
||||
const MerkleTreeWithHistory = artifacts.require('./MerkleTreeWithHistoryMock.sol')
|
||||
const MiMC = artifacts.require('./MiMC.sol')
|
||||
const hasherContract = artifacts.require('./Hasher.sol')
|
||||
|
||||
const MerkleTree = require('../lib/MerkleTree')
|
||||
const MimcHasher = require('../lib/MiMC')
|
||||
const hasherImpl = require('../lib/MiMC')
|
||||
|
||||
const { ETH_AMOUNT, MERKLE_TREE_HEIGHT, EMPTY_ELEMENT } = process.env
|
||||
|
||||
@ -25,7 +25,7 @@ function BNArrayToStringArray(array) {
|
||||
|
||||
contract('MerkleTreeWithHistory', accounts => {
|
||||
let merkleTreeWithHistory
|
||||
let miMC
|
||||
let hasherInstance
|
||||
let levels = MERKLE_TREE_HEIGHT || 16
|
||||
let zeroValue = EMPTY_ELEMENT || 1337
|
||||
const sender = accounts[0]
|
||||
@ -43,8 +43,8 @@ contract('MerkleTreeWithHistory', accounts => {
|
||||
null,
|
||||
prefix,
|
||||
)
|
||||
miMC = await MiMC.deployed()
|
||||
await MerkleTreeWithHistory.link(MiMC, miMC.address)
|
||||
hasherInstance = await hasherContract.deployed()
|
||||
await MerkleTreeWithHistory.link(hasherContract, hasherInstance.address)
|
||||
merkleTreeWithHistory = await MerkleTreeWithHistory.new(levels, zeroValue)
|
||||
snapshotId = await takeSnapshot()
|
||||
})
|
||||
@ -67,7 +67,7 @@ contract('MerkleTreeWithHistory', accounts => {
|
||||
})
|
||||
|
||||
it('tests insert', async () => {
|
||||
hasher = new MimcHasher()
|
||||
hasher = new hasherImpl()
|
||||
tree = new MerkleTree(
|
||||
2,
|
||||
zeroValue,
|
||||
@ -191,7 +191,7 @@ contract('MerkleTreeWithHistory', accounts => {
|
||||
error.reason.should.be.equal('Merkle tree is full. No more leafs can be added')
|
||||
})
|
||||
|
||||
it.skip('mimc gas', async () => {
|
||||
it.skip('hasher gas', async () => {
|
||||
levels = 6
|
||||
zeroValue = 1337
|
||||
merkleTreeWithHistory = await MerkleTreeWithHistory.new(levels, zeroValue)
|
||||
@ -205,7 +205,7 @@ contract('MerkleTreeWithHistory', accounts => {
|
||||
await revertSnapshot(snapshotId.result)
|
||||
// eslint-disable-next-line require-atomic-updates
|
||||
snapshotId = await takeSnapshot()
|
||||
hasher = new MimcHasher()
|
||||
hasher = new hasherImpl()
|
||||
tree = new MerkleTree(
|
||||
levels,
|
||||
zeroValue,
|
||||
|
Loading…
Reference in New Issue
Block a user