mirror of
https://github.com/tornadocash/tornado-core.git
synced 2024-11-22 09:47:13 +01:00
inverted flags to reduce deploy cost, explicitly set state in toggleDeposits
This commit is contained in:
parent
54e2c5f890
commit
d019e48da3
@ -29,8 +29,8 @@ contract Mixer is MerkleTreeWithHistory {
|
|||||||
// - disable new deposits in case of emergency
|
// - disable new deposits in case of emergency
|
||||||
// - update snark verification key until this ability is permanently disabled
|
// - update snark verification key until this ability is permanently disabled
|
||||||
address public operator;
|
address public operator;
|
||||||
bool public isDepositsEnabled = true;
|
bool public isDepositsDisabled;
|
||||||
bool public isVerifierUpdateAllowed = true;
|
bool public isVerifierUpdateDisabled;
|
||||||
modifier onlyOperator {
|
modifier onlyOperator {
|
||||||
require(msg.sender == operator, "Only operator can call this function.");
|
require(msg.sender == operator, "Only operator can call this function.");
|
||||||
_;
|
_;
|
||||||
@ -63,7 +63,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 are disabled");
|
require(!isDepositsDisabled, "deposits are disabled");
|
||||||
require(!commitments[commitment], "The commitment has been submitted");
|
require(!commitments[commitment], "The commitment has been submitted");
|
||||||
uint256 insertedIndex = _insert(commitment);
|
uint256 insertedIndex = _insert(commitment);
|
||||||
commitments[commitment] = true;
|
commitments[commitment] = true;
|
||||||
@ -112,8 +112,8 @@ contract Mixer is MerkleTreeWithHistory {
|
|||||||
@dev Allow operator to temporarily disable new deposits. This is needed to protect users funds in case a vulnerability is discovered.
|
@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.
|
It does not affect existing deposits.
|
||||||
*/
|
*/
|
||||||
function toggleDeposits() external onlyOperator {
|
function toggleDeposits(bool _state) external onlyOperator {
|
||||||
isDepositsEnabled = !isDepositsEnabled;
|
isDepositsDisabled = _state;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -121,7 +121,7 @@ contract Mixer is MerkleTreeWithHistory {
|
|||||||
After that operator is supposed to permanently disable this ability.
|
After that operator is supposed to permanently disable this ability.
|
||||||
*/
|
*/
|
||||||
function updateVerifier(address newVerifier) external onlyOperator {
|
function updateVerifier(address newVerifier) external onlyOperator {
|
||||||
require(isVerifierUpdateAllowed, "Verifier updates have been disabled.");
|
require(!isVerifierUpdateDisabled, "Verifier updates have been disabled.");
|
||||||
verifier = IVerifier(newVerifier);
|
verifier = IVerifier(newVerifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,7 +130,7 @@ contract Mixer is MerkleTreeWithHistory {
|
|||||||
This is supposed to be called after the final trusted setup ceremony is held.
|
This is supposed to be called after the final trusted setup ceremony is held.
|
||||||
*/
|
*/
|
||||||
function disableVerifierUpdate() external onlyOperator {
|
function disableVerifierUpdate() external onlyOperator {
|
||||||
isVerifierUpdateAllowed = false;
|
isVerifierUpdateDisabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @dev operator can change his address */
|
/** @dev operator can change his address */
|
||||||
|
@ -115,11 +115,15 @@ contract('ETHMixer', accounts => {
|
|||||||
|
|
||||||
it('should not deposit if disabled', async () => {
|
it('should not deposit if disabled', async () => {
|
||||||
let commitment = 42;
|
let commitment = 42;
|
||||||
(await mixer.isDepositsEnabled()).should.be.equal(true)
|
(await mixer.isDepositsDisabled()).should.be.equal(false)
|
||||||
const err = await mixer.toggleDeposits({ from: accounts[1] }).should.be.rejected
|
const err = await mixer.toggleDeposits(true, { from: accounts[1] }).should.be.rejected
|
||||||
err.reason.should.be.equal('Only operator can call this function.')
|
err.reason.should.be.equal('Only operator can call this function.')
|
||||||
await mixer.toggleDeposits({ from: sender });
|
await mixer.toggleDeposits(false, { from: sender });
|
||||||
(await mixer.isDepositsEnabled()).should.be.equal(false)
|
(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
|
let error = await mixer.deposit(commitment, { value, from: sender }).should.be.rejected
|
||||||
error.reason.should.be.equal('deposits are disabled')
|
error.reason.should.be.equal('deposits are disabled')
|
||||||
})
|
})
|
||||||
@ -484,26 +488,26 @@ contract('ETHMixer', accounts => {
|
|||||||
let operator = await mixer.operator()
|
let operator = await mixer.operator()
|
||||||
operator.should.be.equal(sender)
|
operator.should.be.equal(sender)
|
||||||
|
|
||||||
let isVerifierUpdateAllowed = await mixer.isVerifierUpdateAllowed()
|
let isVerifierUpdateDisabled = await mixer.isVerifierUpdateDisabled()
|
||||||
isVerifierUpdateAllowed.should.be.equal(true)
|
isVerifierUpdateDisabled.should.be.equal(false)
|
||||||
|
|
||||||
await mixer.disableVerifierUpdate().should.be.fulfilled
|
await mixer.disableVerifierUpdate().should.be.fulfilled
|
||||||
|
|
||||||
const newValue = await mixer.isVerifierUpdateAllowed()
|
const newValue = await mixer.isVerifierUpdateDisabled()
|
||||||
newValue.should.be.equal(false)
|
newValue.should.be.equal(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('cannot update verifier after this function is called', async () => {
|
it('cannot update verifier after this function is called', async () => {
|
||||||
let operator = await mixer.operator()
|
let operator = await mixer.operator()
|
||||||
operator.should.be.equal(sender)
|
operator.should.be.equal(sender)
|
||||||
|
|
||||||
let isVerifierUpdateAllowed = await mixer.isVerifierUpdateAllowed()
|
let isVerifierUpdateDisabled = await mixer.isVerifierUpdateDisabled()
|
||||||
isVerifierUpdateAllowed.should.be.equal(true)
|
isVerifierUpdateDisabled.should.be.equal(false)
|
||||||
|
|
||||||
await mixer.disableVerifierUpdate().should.be.fulfilled
|
await mixer.disableVerifierUpdate().should.be.fulfilled
|
||||||
|
|
||||||
const newValue = await mixer.isVerifierUpdateAllowed()
|
const newValue = await mixer.isVerifierUpdateDisabled()
|
||||||
newValue.should.be.equal(false)
|
newValue.should.be.equal(true)
|
||||||
|
|
||||||
const newVerifier = accounts[7]
|
const newVerifier = accounts[7]
|
||||||
const error = await mixer.updateVerifier(newVerifier).should.be.rejected
|
const error = await mixer.updateVerifier(newVerifier).should.be.rejected
|
||||||
|
Loading…
Reference in New Issue
Block a user