mirror of
https://github.com/tornadocash/tornado-core.git
synced 2024-11-22 01:37:07 +01:00
mixer deploy WIP
This commit is contained in:
parent
19f916e6fd
commit
fb3f2425d2
6
.env.example
Normal file
6
.env.example
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
MERKLE_TREE_HEIGHT=16
|
||||||
|
# in wei
|
||||||
|
AMOUNT=1000000000000000000
|
||||||
|
EMPTY_ELEMENT=1337
|
||||||
|
PRIVATE_KEY=
|
||||||
|
|
@ -1,11 +1,11 @@
|
|||||||
## Testing
|
## Testing
|
||||||
1. `npm i`
|
1. `npm i`
|
||||||
|
2. `npm run build:circuit`
|
||||||
2. `npx truffle compile`
|
2. `npx truffle compile`
|
||||||
3. `npx truffle test` - it may fail for the first time, just run one more time.
|
3. `npx truffle test` - it may fail for the first time, just run one more time.
|
||||||
|
|
||||||
Short version:
|
## Deploy
|
||||||
|
1. `npx truffle migrate --network kovan --reset`
|
||||||
We have a merkle tree of deposit commitments `Pedersen(secret + nullifier)`, merkle tree uses MiMC
|
|
||||||
On withdrawal a SNARK proof verifies merkle proof and leaf preimage, .....
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,7 +19,12 @@ contract Mixer is MerkleTreeWithHistory {
|
|||||||
@param _verifier the address of SNARK verifier for this contract
|
@param _verifier the address of SNARK verifier for this contract
|
||||||
@param _transferValue the value for all deposits in this contract in wei
|
@param _transferValue the value for all deposits in this contract in wei
|
||||||
*/
|
*/
|
||||||
constructor(address _verifier, uint256 _transferValue) MerkleTreeWithHistory(16, 0) public {
|
constructor(
|
||||||
|
address _verifier,
|
||||||
|
uint256 _transferValue,
|
||||||
|
uint8 _merkleTreeHeight,
|
||||||
|
uint256 _emptyElement
|
||||||
|
) MerkleTreeWithHistory(_merkleTreeHeight, _emptyElement) public {
|
||||||
verifier = IVerifier(_verifier);
|
verifier = IVerifier(_verifier);
|
||||||
transferValue = _transferValue;
|
transferValue = _transferValue;
|
||||||
}
|
}
|
||||||
|
1
contracts/Verifier.sol
Symbolic link
1
contracts/Verifier.sol
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../build/circuits/Verifier.sol
|
6
migrations/3_deploy_verifier.js
Normal file
6
migrations/3_deploy_verifier.js
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
require('dotenv').config()
|
||||||
|
const Verifier = artifacts.require("Verifier");
|
||||||
|
|
||||||
|
module.exports = function(deployer) {
|
||||||
|
deployer.deploy(Verifier);
|
||||||
|
};
|
15
migrations/4_deploy_mixer.js
Normal file
15
migrations/4_deploy_mixer.js
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
require('dotenv').config({ path: '../.env' })
|
||||||
|
const Mixer = artifacts.require("Mixer");
|
||||||
|
const Verifier = artifacts.require("Verifier");
|
||||||
|
const MiMC = artifacts.require("MiMC");
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = function(deployer) {
|
||||||
|
return deployer.then(async () => {
|
||||||
|
const { MERKLE_TREE_HEIGHT, AMOUNT, EMPTY_ELEMENT } = process.env
|
||||||
|
const verifier = await Verifier.deployed()
|
||||||
|
const miMC = MiMC.deployed()
|
||||||
|
await Mixer.link(MiMC, miMC.address)
|
||||||
|
await deployer.deploy(Mixer, verifier.address, AMOUNT, MERKLE_TREE_HEIGHT, EMPTY_ELEMENT)
|
||||||
|
})
|
||||||
|
};
|
2046
package-lock.json
generated
2046
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
12
package.json
12
package.json
@ -6,7 +6,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"build:circuit:compile": "circom circuits/withdraw.circom -o build/circuits/withdraw.json && snarkjs info -c build/circuits/withdraw.json",
|
"build:circuit:compile": "circom circuits/withdraw.circom -o build/circuits/withdraw.json && snarkjs info -c build/circuits/withdraw.json",
|
||||||
"build:circuit:setup": "snarkjs setup --protocol groth -c build/circuits/withdraw.json --pk build/circuits/withdraw_proving_key.json --vk build/circuits/withdraw_verification_key.json",
|
"build:circuit:setup": "snarkjs setup --protocol groth -c build/circuits/withdraw.json --pk build/circuits/withdraw_proving_key.json --vk build/circuits/withdraw_verification_key.json",
|
||||||
"build:circuit:contract": "snarkjs generateverifier -v build/circuits/withdraw_verifier.sol --vk build/circuits/withdraw_verification_key.json",
|
"build:circuit:contract": "snarkjs generateverifier -v build/circuits/Verifier.sol --vk build/circuits/withdraw_verification_key.json",
|
||||||
"build:circuit": "mkdir -p build/circuits && npm run build:circuit:compile && npm run build:circuit:setup && npm run build:circuit:contract",
|
"build:circuit": "mkdir -p build/circuits && npm run build:circuit:compile && npm run build:circuit:setup && npm run build:circuit:contract",
|
||||||
"build:contract": "truffle compile",
|
"build:contract": "truffle compile",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
@ -15,16 +15,18 @@
|
|||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"circom": "0.0.30",
|
|
||||||
"snarkjs": "^0.1.14",
|
|
||||||
"websnark": "0.0.4",
|
|
||||||
"bn-chai": "^1.0.1",
|
"bn-chai": "^1.0.1",
|
||||||
"chai": "^4.2.0",
|
"chai": "^4.2.0",
|
||||||
"chai-as-promised": "^7.1.1",
|
"chai-as-promised": "^7.1.1",
|
||||||
|
"circom": "0.0.30",
|
||||||
"circomlib": "git+https://github.com/kobigurk/circomlib.git#323966c0584bafebf9652681c44d9ea348fe9bb5",
|
"circomlib": "git+https://github.com/kobigurk/circomlib.git#323966c0584bafebf9652681c44d9ea348fe9bb5",
|
||||||
|
"dotenv": "^8.0.0",
|
||||||
"ganache-cli": "^6.4.5",
|
"ganache-cli": "^6.4.5",
|
||||||
|
"snarkjs": "^0.1.14",
|
||||||
"truffle": "^5.0.20",
|
"truffle": "^5.0.20",
|
||||||
"truffle-artifactor": "^4.0.22",
|
"truffle-artifactor": "^4.0.22",
|
||||||
"web3-utils": "^1.0.0-beta.55"
|
"truffle-hdwallet-provider": "^1.0.14",
|
||||||
|
"web3-utils": "^1.0.0-beta.55",
|
||||||
|
"websnark": "0.0.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
41
test/Mixer.test.js
Normal file
41
test/Mixer.test.js
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
const should = require('chai')
|
||||||
|
.use(require('bn-chai')(web3.utils.BN))
|
||||||
|
.use(require('chai-as-promised'))
|
||||||
|
.should()
|
||||||
|
|
||||||
|
const { toWei, toBN, fromWei } = require('web3-utils')
|
||||||
|
const { takeSnapshot, revertSnapshot, increaseTime } = require('../scripts/ganacheHelper');
|
||||||
|
|
||||||
|
const Mixer = artifacts.require('./Mixer.sol')
|
||||||
|
|
||||||
|
|
||||||
|
contract('Mixer', async accounts => {
|
||||||
|
let mixer
|
||||||
|
let miMC
|
||||||
|
const sender = accounts[0]
|
||||||
|
const emptyAddress = '0x0000000000000000000000000000000000000000'
|
||||||
|
const levels = 16
|
||||||
|
const zeroValue = 1337
|
||||||
|
let snapshotId
|
||||||
|
let prefix = 'test'
|
||||||
|
let tree
|
||||||
|
let hasher
|
||||||
|
|
||||||
|
before(async () => {
|
||||||
|
mixer = await Mixer.deployed()
|
||||||
|
snapshotId = await takeSnapshot()
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('#constuctor', async () => {
|
||||||
|
it('should initialize', async () => {
|
||||||
|
const { AMOUNT } = process.env
|
||||||
|
const transferValue = await mixer.transferValue()
|
||||||
|
transferValue.should.be.eq.BN(toBN(AMOUNT))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
afterEach(async () => {
|
||||||
|
await revertSnapshot(snapshotId.result)
|
||||||
|
snapshotId = await takeSnapshot()
|
||||||
|
})
|
||||||
|
})
|
@ -1,24 +1,6 @@
|
|||||||
/**
|
require('dotenv').config()
|
||||||
* Use this file to configure your truffle project. It's seeded with some
|
const HDWalletProvider = require('truffle-hdwallet-provider');
|
||||||
* common settings for different networks and features like migrations,
|
const utils = require('web3-utils')
|
||||||
* compilation and testing. Uncomment the ones you need or modify
|
|
||||||
* them to suit your project as necessary.
|
|
||||||
*
|
|
||||||
* More information about configuration can be found at:
|
|
||||||
*
|
|
||||||
* truffleframework.com/docs/advanced/configuration
|
|
||||||
*
|
|
||||||
* To deploy via Infura you'll need a wallet provider (like truffle-hdwallet-provider)
|
|
||||||
* to sign your transactions before they're sent to a remote public node. Infura accounts
|
|
||||||
* are available for free at: infura.io/register.
|
|
||||||
*
|
|
||||||
* You'll also need a mnemonic - the twelve word phrase the wallet uses to generate
|
|
||||||
* public/private key pairs. If you're publishing your code to GitHub make sure you load this
|
|
||||||
* phrase from a file you've .gitignored so it doesn't accidentally become public.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
// const HDWalletProvider = require('truffle-hdwallet-provider');
|
|
||||||
// const infuraKey = "fj4jll3k.....";
|
// const infuraKey = "fj4jll3k.....";
|
||||||
//
|
//
|
||||||
// const fs = require('fs');
|
// const fs = require('fs');
|
||||||
@ -60,14 +42,15 @@ module.exports = {
|
|||||||
|
|
||||||
// Useful for deploying to a public network.
|
// Useful for deploying to a public network.
|
||||||
// NB: It's important to wrap the provider as a function.
|
// NB: It's important to wrap the provider as a function.
|
||||||
// ropsten: {
|
kovan: {
|
||||||
// provider: () => new HDWalletProvider(mnemonic, `https://ropsten.infura.io/v3/YOUR-PROJECT-ID`),
|
provider: () => new HDWalletProvider(process.env.PRIVATE_KEY, 'https://kovan.infura.io/v3/c7463beadf2144e68646ff049917b716'),
|
||||||
// network_id: 3, // Ropsten's id
|
network_id: 42,
|
||||||
// gas: 5500000, // Ropsten has a lower block limit than mainnet
|
gas: 7000000,
|
||||||
// confirmations: 2, // # of confs to wait between deployments. (default: 0)
|
gasPrice: utils.toWei('1', 'gwei'),
|
||||||
// timeoutBlocks: 200, // # of blocks before a deployment times out (minimum/default: 50)
|
// confirmations: 0,
|
||||||
// skipDryRun: true // Skip dry run before migrations? (default: false for public nets )
|
// timeoutBlocks: 200,
|
||||||
// },
|
skipDryRun: true
|
||||||
|
},
|
||||||
|
|
||||||
// Useful for private networks
|
// Useful for private networks
|
||||||
// private: {
|
// private: {
|
||||||
|
Loading…
Reference in New Issue
Block a user