mirror of
https://github.com/tornadocash/tornado-core.git
synced 2024-11-22 01:37:07 +01:00
add pauseDeposits
This commit is contained in:
parent
9b14a22b0d
commit
d91435dd00
@ -3,4 +3,5 @@ MERKLE_TREE_HEIGHT=16
|
|||||||
AMOUNT=1000000000000000000
|
AMOUNT=1000000000000000000
|
||||||
EMPTY_ELEMENT=1337
|
EMPTY_ELEMENT=1337
|
||||||
PRIVATE_KEY=
|
PRIVATE_KEY=
|
||||||
|
PAUSEACCOUNT=0x17017Ba4FA022299067B5F235e2F230973bc7Fed
|
||||||
|
|
||||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,6 +1,7 @@
|
|||||||
build
|
build
|
||||||
.vscode
|
.vscode
|
||||||
/index.js
|
/index.js
|
||||||
|
Mixer_flat.sol
|
||||||
|
|
||||||
# Created by .ignore support plugin (hsz.mobi)
|
# Created by .ignore support plugin (hsz.mobi)
|
||||||
### Node template
|
### Node template
|
||||||
|
6
.solhint.json
Normal file
6
.solhint.json
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"extends": "solhint:recommended",
|
||||||
|
"rules": {
|
||||||
|
"indent": ["error", 2]
|
||||||
|
}
|
||||||
|
}
|
@ -8,6 +8,8 @@ contract IVerifier {
|
|||||||
|
|
||||||
contract Mixer is MerkleTreeWithHistory {
|
contract Mixer is MerkleTreeWithHistory {
|
||||||
uint256 public transferValue;
|
uint256 public transferValue;
|
||||||
|
bool public isDepositsEnabled = true;
|
||||||
|
address public pauseAccount;
|
||||||
mapping(uint256 => bool) public nullifierHashes;
|
mapping(uint256 => bool) public nullifierHashes;
|
||||||
// we store all commitments just to prevent accidental deposits with the same commitment
|
// we store all commitments just to prevent accidental deposits with the same commitment
|
||||||
mapping(uint256 => bool) public commitments;
|
mapping(uint256 => bool) public commitments;
|
||||||
@ -25,10 +27,12 @@ contract Mixer is MerkleTreeWithHistory {
|
|||||||
address _verifier,
|
address _verifier,
|
||||||
uint256 _transferValue,
|
uint256 _transferValue,
|
||||||
uint8 _merkleTreeHeight,
|
uint8 _merkleTreeHeight,
|
||||||
uint256 _emptyElement
|
uint256 _emptyElement,
|
||||||
|
address _pauseAccount
|
||||||
) MerkleTreeWithHistory(_merkleTreeHeight, _emptyElement) public {
|
) MerkleTreeWithHistory(_merkleTreeHeight, _emptyElement) public {
|
||||||
verifier = IVerifier(_verifier);
|
verifier = IVerifier(_verifier);
|
||||||
transferValue = _transferValue;
|
transferValue = _transferValue;
|
||||||
|
pauseAccount = _pauseAccount;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -36,6 +40,7 @@ contract Mixer is MerkleTreeWithHistory {
|
|||||||
@param commitment the note commitment, which is PedersenHash(nullifier + secret)
|
@param commitment the note commitment, which is PedersenHash(nullifier + secret)
|
||||||
*/
|
*/
|
||||||
function deposit(uint256 commitment) public payable {
|
function deposit(uint256 commitment) public payable {
|
||||||
|
require(isDepositsEnabled, "deposits disabled");
|
||||||
require(msg.value == transferValue, "Please send `transferValue` ETH along with transaction");
|
require(msg.value == transferValue, "Please send `transferValue` ETH along with transaction");
|
||||||
require(!commitments[commitment], "The commitment has been submitted");
|
require(!commitments[commitment], "The commitment has been submitted");
|
||||||
_insert(commitment);
|
_insert(commitment);
|
||||||
@ -70,6 +75,11 @@ contract Mixer is MerkleTreeWithHistory {
|
|||||||
emit Withdraw(receiver, nullifierHash, fee);
|
emit Withdraw(receiver, nullifierHash, fee);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function toggleDeposits() external {
|
||||||
|
require(msg.sender == pauseAccount, "unauthorized");
|
||||||
|
isDepositsEnabled = !isDepositsEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
function isSpent(uint256 nullifier) public view returns(bool) {
|
function isSpent(uint256 nullifier) public view returns(bool) {
|
||||||
return nullifierHashes[nullifier];
|
return nullifierHashes[nullifier];
|
||||||
}
|
}
|
||||||
|
@ -5,13 +5,13 @@ const Verifier = artifacts.require('Verifier')
|
|||||||
const MiMC = artifacts.require('MiMC')
|
const MiMC = artifacts.require('MiMC')
|
||||||
|
|
||||||
|
|
||||||
module.exports = function(deployer) {
|
module.exports = function(deployer, network, accounts) {
|
||||||
return deployer.then(async () => {
|
return deployer.then(async () => {
|
||||||
const { MERKLE_TREE_HEIGHT, AMOUNT, EMPTY_ELEMENT } = process.env
|
const { MERKLE_TREE_HEIGHT, AMOUNT, EMPTY_ELEMENT } = process.env
|
||||||
const verifier = await Verifier.deployed()
|
const verifier = await Verifier.deployed()
|
||||||
const miMC = await MiMC.deployed()
|
const miMC = await MiMC.deployed()
|
||||||
await Mixer.link(MiMC, miMC.address)
|
await Mixer.link(MiMC, miMC.address)
|
||||||
const mixer = await deployer.deploy(Mixer, verifier.address, AMOUNT, MERKLE_TREE_HEIGHT, EMPTY_ELEMENT)
|
const mixer = await deployer.deploy(Mixer, verifier.address, AMOUNT, MERKLE_TREE_HEIGHT, EMPTY_ELEMENT, accounts[0])
|
||||||
console.log('Mixer\'s address ', mixer.address)
|
console.log('Mixer\'s address ', mixer.address)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
1604
package-lock.json
generated
1604
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -14,7 +14,8 @@
|
|||||||
"migrate": "npx truffle migrate --network kovan --reset",
|
"migrate": "npx truffle migrate --network kovan --reset",
|
||||||
"migrate:dev": "npx truffle migrate --network development --reset",
|
"migrate:dev": "npx truffle migrate --network development --reset",
|
||||||
"browserify": "npx browserify cli.js -o index.js --exclude worker_threads",
|
"browserify": "npx browserify cli.js -o index.js --exclude worker_threads",
|
||||||
"eslint": "npx eslint --ignore-path .gitignore ."
|
"eslint": "npx eslint --ignore-path .gitignore .",
|
||||||
|
"flat": "truffle-flattener contracts/Mixer.sol > Mixer_flat.sol"
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "",
|
"author": "",
|
||||||
@ -38,5 +39,8 @@
|
|||||||
"web3": "^1.0.0-beta.55",
|
"web3": "^1.0.0-beta.55",
|
||||||
"web3-utils": "^1.0.0-beta.55",
|
"web3-utils": "^1.0.0-beta.55",
|
||||||
"websnark": "git+https://github.com/poma/websnark.git#271c74a76f4d9277c049283c45929fb3a5bb46fc"
|
"websnark": "git+https://github.com/poma/websnark.git#271c74a76f4d9277c049283c45929fb3a5bb46fc"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"truffle-flattener": "^1.4.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -111,6 +111,17 @@ contract('Mixer', accounts => {
|
|||||||
logs[0].args.leafIndex.should.be.eq.BN(toBN(1))
|
logs[0].args.leafIndex.should.be.eq.BN(toBN(1))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should not deposit if disabled', async () => {
|
||||||
|
let commitment = 42;
|
||||||
|
(await mixer.isDepositsEnabled()).should.be.equal(true)
|
||||||
|
const err = await mixer.toggleDeposits({ from: accounts[1] }).should.be.rejected
|
||||||
|
err.reason.should.be.equal('unauthorized')
|
||||||
|
await mixer.toggleDeposits({ from: sender });
|
||||||
|
(await mixer.isDepositsEnabled()).should.be.equal(false)
|
||||||
|
let error = await mixer.deposit(commitment, { value, from: sender }).should.be.rejected
|
||||||
|
error.reason.should.be.equal('deposits disabled')
|
||||||
|
})
|
||||||
|
|
||||||
it('should throw if there is a such commitment', async () => {
|
it('should throw if there is a such commitment', async () => {
|
||||||
const commitment = 42
|
const commitment = 42
|
||||||
await mixer.deposit(commitment, { value, from: sender }).should.be.fulfilled
|
await mixer.deposit(commitment, { value, from: sender }).should.be.fulfilled
|
||||||
|
@ -72,7 +72,7 @@ module.exports = {
|
|||||||
// docker: true, // Use "0.5.1" you've installed locally with docker (default: false)
|
// docker: true, // Use "0.5.1" you've installed locally with docker (default: false)
|
||||||
settings: { // See the solidity docs for advice about optimization and evmVersion
|
settings: { // See the solidity docs for advice about optimization and evmVersion
|
||||||
optimizer: {
|
optimizer: {
|
||||||
enabled: false,
|
enabled: true,
|
||||||
runs: 200
|
runs: 200
|
||||||
},
|
},
|
||||||
// evmVersion: "byzantium"
|
// evmVersion: "byzantium"
|
||||||
|
Loading…
Reference in New Issue
Block a user