mirror of
https://github.com/tornadocash/tornado-core.git
synced 2024-12-24 13:59:23 -05:00
remove toggleDeposits
This commit is contained in:
parent
bc8d0b20fc
commit
183847ad67
@ -24,12 +24,9 @@ contract Mixer is MerkleTreeWithHistory {
|
||||
mapping(bytes32 => bool) public commitments;
|
||||
IVerifier public verifier;
|
||||
|
||||
// operator can
|
||||
// - disable new deposits in case of emergency
|
||||
// - update snark verification key until this ability is permanently disabled
|
||||
// operator can update snark verification key
|
||||
// after the final trusted setup ceremony operator rights are supposed to be transferred to zero address
|
||||
address public operator;
|
||||
bool public isDepositsDisabled;
|
||||
bool public isVerifierUpdateDisabled;
|
||||
modifier onlyOperator {
|
||||
require(msg.sender == operator, "Only operator can call this function.");
|
||||
_;
|
||||
@ -62,7 +59,6 @@ contract Mixer is MerkleTreeWithHistory {
|
||||
@param _commitment the note commitment, which is PedersenHash(nullifier + secret)
|
||||
*/
|
||||
function deposit(bytes32 _commitment) external payable {
|
||||
require(!isDepositsDisabled, "deposits are disabled");
|
||||
require(!commitments[_commitment], "The commitment has been submitted");
|
||||
|
||||
uint32 insertedIndex = _insert(_commitment);
|
||||
@ -102,31 +98,14 @@ contract Mixer is MerkleTreeWithHistory {
|
||||
return nullifierHashes[_nullifierHash];
|
||||
}
|
||||
|
||||
/**
|
||||
@dev Allow operator to temporarily disable new deposits. This is needed to protect users funds in case a vulnerability is discovered.
|
||||
It does not affect existing deposits.
|
||||
*/
|
||||
function toggleDeposits(bool _state) external onlyOperator {
|
||||
isDepositsDisabled = _state;
|
||||
}
|
||||
|
||||
/**
|
||||
@dev allow operator to update SNARK verification keys. This is needed to update keys after the final trusted setup ceremony is held.
|
||||
After that operator is supposed to permanently disable this ability.
|
||||
After that operator rights are supposed to be transferred to zero address
|
||||
*/
|
||||
function updateVerifier(address _newVerifier) external onlyOperator {
|
||||
require(!isVerifierUpdateDisabled, "Verifier updates have been disabled.");
|
||||
verifier = IVerifier(_newVerifier);
|
||||
}
|
||||
|
||||
/**
|
||||
@dev an option for operator to permanently disable verification keys update ability.
|
||||
This is supposed to be called after the final trusted setup ceremony is held.
|
||||
*/
|
||||
function disableVerifierUpdate() external onlyOperator {
|
||||
isVerifierUpdateDisabled = true;
|
||||
}
|
||||
|
||||
/** @dev operator can change his address */
|
||||
function changeOperator(address _newOperator) external onlyOperator {
|
||||
operator = _newOperator;
|
||||
|
@ -118,21 +118,6 @@ contract('ETHMixer', accounts => {
|
||||
logs[0].args.leafIndex.should.be.eq.BN(1)
|
||||
})
|
||||
|
||||
it('should not deposit if disabled', async () => {
|
||||
let commitment = toFixedHex(42);
|
||||
(await mixer.isDepositsDisabled()).should.be.equal(false)
|
||||
const err = await mixer.toggleDeposits(true, { from: accounts[1] }).should.be.rejected
|
||||
err.reason.should.be.equal('Only operator can call this function.')
|
||||
await mixer.toggleDeposits(false, { from: sender });
|
||||
(await mixer.isDepositsDisabled()).should.be.equal(false)
|
||||
await mixer.toggleDeposits(true, { from: sender });
|
||||
(await mixer.isDepositsDisabled()).should.be.equal(true)
|
||||
await mixer.toggleDeposits(true, { from: sender });
|
||||
(await mixer.isDepositsDisabled()).should.be.equal(true)
|
||||
let error = await mixer.deposit(commitment, { value, from: sender }).should.be.rejected
|
||||
error.reason.should.be.equal('deposits are disabled')
|
||||
})
|
||||
|
||||
it('should throw if there is a such commitment', async () => {
|
||||
const commitment = toFixedHex(42)
|
||||
await mixer.deposit(commitment, { value, from: sender }).should.be.fulfilled
|
||||
@ -557,38 +542,6 @@ contract('ETHMixer', accounts => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('#disableVerifierUpdate', () => {
|
||||
it('should work', async () => {
|
||||
let operator = await mixer.operator()
|
||||
operator.should.be.equal(sender)
|
||||
|
||||
let isVerifierUpdateDisabled = await mixer.isVerifierUpdateDisabled()
|
||||
isVerifierUpdateDisabled.should.be.equal(false)
|
||||
|
||||
await mixer.disableVerifierUpdate().should.be.fulfilled
|
||||
|
||||
const newValue = await mixer.isVerifierUpdateDisabled()
|
||||
newValue.should.be.equal(true)
|
||||
})
|
||||
|
||||
it('cannot update verifier after this function is called', async () => {
|
||||
let operator = await mixer.operator()
|
||||
operator.should.be.equal(sender)
|
||||
|
||||
let isVerifierUpdateDisabled = await mixer.isVerifierUpdateDisabled()
|
||||
isVerifierUpdateDisabled.should.be.equal(false)
|
||||
|
||||
await mixer.disableVerifierUpdate().should.be.fulfilled
|
||||
|
||||
const newValue = await mixer.isVerifierUpdateDisabled()
|
||||
newValue.should.be.equal(true)
|
||||
|
||||
const newVerifier = accounts[7]
|
||||
const error = await mixer.updateVerifier(newVerifier).should.be.rejected
|
||||
error.reason.should.be.equal('Verifier updates have been disabled.')
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
await revertSnapshot(snapshotId.result)
|
||||
// eslint-disable-next-line require-atomic-updates
|
||||
|
Loading…
Reference in New Issue
Block a user