diff --git a/contracts/staking/README.md b/contracts/staking/README.md index 423138efc1..3749f77e78 100644 --- a/contracts/staking/README.md +++ b/contracts/staking/README.md @@ -41,7 +41,7 @@ If a vulnerability is discovered in the staking contract, operations may be halt In this worst-case scenario, state has been irreperably corrupted and the staking contracts must be re-deployed. Users withdraw their funds from the vaults and re-stake under the new system, at will. -4. Vaults enter "Catostrophic Failure Mode" allowing users to withdraw their ZRX and Rewards. +4. Vaults enter "Catastrophic Failure Mode" allowing users to withdraw their ZRX and Rewards. 5. A Balance Oracle is deployed for determining the Reward balance of each user. (\*) ![](images/architecture_failure_mode.png) diff --git a/contracts/staking/contracts/src/interfaces/IStakingPoolRewardVault.sol b/contracts/staking/contracts/src/interfaces/IStakingPoolRewardVault.sol index 434ba1e59d..4ae3f46998 100644 --- a/contracts/staking/contracts/src/interfaces/IStakingPoolRewardVault.sol +++ b/contracts/staking/contracts/src/interfaces/IStakingPoolRewardVault.sol @@ -22,7 +22,7 @@ pragma solidity ^0.5.9; /// @dev This vault manages staking pool rewards. /// Rewards can be deposited and withdraw by the staking contract. /// There is a "Catastrophic Failure Mode" that, when invoked, only -/// allows withdrawals to be made. Once this vault is in catostrophic +/// allows withdrawals to be made. Once this vault is in catastrophic /// failure mode, it cannot be returned to normal mode; this prevents /// corruption of related state in the staking contract. interface IStakingPoolRewardVault { diff --git a/contracts/staking/contracts/src/interfaces/IVaultCore.sol b/contracts/staking/contracts/src/interfaces/IVaultCore.sol index d9c818d958..b9ba9369ef 100644 --- a/contracts/staking/contracts/src/interfaces/IVaultCore.sol +++ b/contracts/staking/contracts/src/interfaces/IVaultCore.sol @@ -27,7 +27,7 @@ pragma solidity ^0.5.9; /// Vaults should only be set to Catastrophic Failure Mode iff there is /// non-recoverable corruption of the staking contracts. If there is a /// recoverable flaw/bug/vulnerability, simply detach the staking contract -/// by setting its address to `address(0)`. Once in Catostrophic Failure Mode, +/// by setting its address to `address(0)`. Once in Catastrophic Failure Mode, /// a vault cannot be reset to normal mode; this prevents corruption of related /// state in the staking contract. interface IVaultCore { @@ -38,9 +38,9 @@ interface IVaultCore { address stakingContractAddress ); - /// @dev Emitted when the Staking contract is put into Catostrophic Failure Mode + /// @dev Emitted when the Staking contract is put into Catastrophic Failure Mode /// @param sender Address of sender (`msg.sender`) - event InCatostrophicFailureMode( + event InCatastrophicFailureMode( address sender ); @@ -50,9 +50,9 @@ interface IVaultCore { function setStakingContract(address payable _stakingContractAddress) external; - /// @dev Vault enters into Catostrophic Failure Mode. + /// @dev Vault enters into Catastrophic Failure Mode. /// *** WARNING - ONCE IN CATOSTROPHIC FAILURE MODE, YOU CAN NEVER GO BACK! *** /// Note that only the contract owner can call this function. - function enterCatostrophicFailure() + function enterCatastrophicFailure() external; } diff --git a/contracts/staking/contracts/src/interfaces/IZrxVault.sol b/contracts/staking/contracts/src/interfaces/IZrxVault.sol index d991ab1099..7554ead6f6 100644 --- a/contracts/staking/contracts/src/interfaces/IZrxVault.sol +++ b/contracts/staking/contracts/src/interfaces/IZrxVault.sol @@ -23,7 +23,7 @@ pragma solidity ^0.5.9; /// When a user mints stake, their Zrx Tokens are deposited into this vault. /// Similarly, when they burn stake, their Zrx Tokens are withdrawn from this vault. /// There is a "Catastrophic Failure Mode" that, when invoked, only -/// allows withdrawals to be made. Once this vault is in catostrophic +/// allows withdrawals to be made. Once this vault is in catastrophic /// failure mode, it cannot be returned to normal mode; this prevents /// corruption of related state in the staking contract. interface IZrxVault { @@ -62,21 +62,21 @@ interface IZrxVault { /// @dev Sets the ERC20 proxy. /// Note that only the contract owner can call this. - /// Note that this can only be called when *not* in Catostrophic Failure mode. + /// Note that this can only be called when *not* in Catastrophic Failure mode. /// @param erc20ProxyAddress Address of the 0x ERC20 Proxy. function setErc20Proxy(address erc20ProxyAddress) external; /// @dev Sets the Zrx Asset Data. /// Note that only the contract owner can call this. - /// Note that this can only be called when *not* in Catostrophic Failure mode. + /// Note that this can only be called when *not* in Catastrophic Failure mode. /// @param _zrxAssetData Zrx asset data for the ERC20 Proxy. function setZrxAssetData(bytes calldata _zrxAssetData) external; /// @dev Deposit an `amount` of Zrx Tokens from `owner` into the vault. /// Note that only the Staking contract can call this. - /// Note that this can only be called when *not* in Catostrophic Failure mode. + /// Note that this can only be called when *not* in Catastrophic Failure mode. /// @param owner of Zrx Tokens. /// @param amount of Zrx Tokens to deposit. function depositFrom(address owner, uint256 amount) @@ -84,14 +84,14 @@ interface IZrxVault { /// @dev Withdraw an `amount` of Zrx Tokens to `owner` from the vault. /// Note that only the Staking contract can call this. - /// Note that this can only be called when *not* in Catostrophic Failure mode. + /// Note that this can only be called when *not* in Catastrophic Failure mode. /// @param owner of Zrx Tokens. /// @param amount of Zrx Tokens to withdraw. function withdrawFrom(address owner, uint256 amount) external; /// @dev Withdraw ALL Zrx Tokens to `owner` from the vault. - /// Note that this can only be called when *in* Catostrophic Failure mode. + /// Note that this can only be called when *in* Catastrophic Failure mode. /// @param owner of Zrx Tokens. function withdrawAllFrom(address owner) external diff --git a/contracts/staking/contracts/src/libs/LibSignatureValidator.sol b/contracts/staking/contracts/src/libs/LibSignatureValidator.sol index 74015dff2f..7e2e4bb469 100644 --- a/contracts/staking/contracts/src/libs/LibSignatureValidator.sol +++ b/contracts/staking/contracts/src/libs/LibSignatureValidator.sol @@ -42,7 +42,7 @@ library LibSignatureValidator { returns (bool isValid) { if (signature.length == 0) { - LibRichErrors.rrevert(LibStakingRichErrors.LengthGreaterThan0RequiredError()); + LibRichErrors.rrevert(LibStakingRichErrors.SignatureLengthGreaterThan0RequiredError()); } // Pop last byte off of signature byte array. @@ -78,7 +78,7 @@ library LibSignatureValidator { // offered explicitly. It can be implicitly created by providing // a correctly formatted but incorrect signature. } else if (signatureType == IStructs.SignatureType.Invalid) { - if (signature.legnth > 0) { + if (signature.length > 0) { LibRichErrors.rrevert(LibStakingRichErrors.SignatureLength0RequiredError( signature )); @@ -88,7 +88,7 @@ library LibSignatureValidator { // Signature using EIP712 } else if (signatureType == IStructs.SignatureType.EIP712) { - if (signature.legnth != 65) { + if (signature.length != 65) { LibRichErrors.rrevert(LibStakingRichErrors.SignatureLength65RequiredError( signature )); @@ -107,7 +107,7 @@ library LibSignatureValidator { // Signed using web3.eth_sign } else if (signatureType == IStructs.SignatureType.EthSign) { - if (signature.legnth != 65) { + if (signature.length != 65) { LibRichErrors.rrevert(LibStakingRichErrors.SignatureLength65RequiredError( signature )); diff --git a/contracts/staking/contracts/src/stake/MixinStake.sol b/contracts/staking/contracts/src/stake/MixinStake.sol index e94400d3b9..a23a09c73a 100644 --- a/contracts/staking/contracts/src/stake/MixinStake.sol +++ b/contracts/staking/contracts/src/stake/MixinStake.sol @@ -123,7 +123,7 @@ contract MixinStake is LibRichErrors.rrevert(LibStakingRichErrors.InsufficientBalanceError( amount, getDeactivatedStake(owner) - ); + )); } _burnStake(owner, amount); @@ -140,7 +140,7 @@ contract MixinStake is LibRichErrors.rrevert(LibStakingRichErrors.InsufficientBalanceError( amount, getActivatableStake(owner) - ); + )); } activatedStakeByOwner[owner] = activatedStakeByOwner[owner]._add(amount); @@ -158,7 +158,7 @@ contract MixinStake is LibRichErrors.rrevert(LibStakingRichErrors.InsufficientBalanceError( amount, getActivatedStake(owner) - ); + )); } activatedStakeByOwner[owner] = activatedStakeByOwner[owner]._sub(amount); diff --git a/contracts/staking/contracts/src/vaults/MixinVaultCore.sol b/contracts/staking/contracts/src/vaults/MixinVaultCore.sol index 4a6789c2b3..b80a140939 100644 --- a/contracts/staking/contracts/src/vaults/MixinVaultCore.sol +++ b/contracts/staking/contracts/src/vaults/MixinVaultCore.sol @@ -32,7 +32,7 @@ import "../interfaces/IVaultCore.sol"; /// Vaults should only be set to Catastrophic Failure Mode iff there is /// non-recoverable corruption of the staking contracts. If there is a /// recoverable flaw/bug/vulnerability, simply detach the staking contract -/// by setting its address to `address(0)`. Once in Catostrophic Failure Mode, +/// by setting its address to `address(0)`. Once in Catastrophic Failure Mode, /// a vault cannot be reset to normal mode; this prevents corruption of related /// state in the staking contract. contract MixinVaultCore is @@ -43,13 +43,13 @@ contract MixinVaultCore is // Address of staking contract address payable internal stakingContractAddress; - // True iff vault has been set to Catostrophic Failure Mode - bool internal isInCatostrophicFailure; + // True iff vault has been set to Catastrophic Failure Mode + bool internal isInCatastrophicFailure; /// @dev Constructor. constructor() public { stakingContractAddress = 0x0000000000000000000000000000000000000000; - isInCatostrophicFailure = false; + isInCatastrophicFailure = false; } /// @dev Asserts that the sender (`msg.sender`) is the staking contract. @@ -62,9 +62,9 @@ contract MixinVaultCore is _; } - /// @dev Asserts that this contract *is in* Catostrophic Failure Mode. - modifier onlyInCatostrophicFailure { - if (!isInCatostrophicFailure) { + /// @dev Asserts that this contract *is in* Catastrophic Failure Mode. + modifier onlyInCatastrophicFailure { + if (!isInCatastrophicFailure) { LibRichErrors.rrevert( LibStakingRichErrors.OnlyCallableInCatastrophicFailureError() ); @@ -72,9 +72,9 @@ contract MixinVaultCore is _; } - /// @dev Asserts that this contract *is not in* Catostrophic Failure Mode. - modifier onlyNotInCatostrophicFailure { - if (isInCatostrophicFailure) { + /// @dev Asserts that this contract *is not in* Catastrophic Failure Mode. + modifier onlyNotInCatastrophicFailure { + if (isInCatastrophicFailure) { LibRichErrors.rrevert( LibStakingRichErrors.OnlyCallableNotInCatastrophicFailureError() ); @@ -93,14 +93,14 @@ contract MixinVaultCore is emit StakingContractChanged(stakingContractAddress); } - /// @dev Vault enters into Catostrophic Failure Mode. + /// @dev Vault enters into Catastrophic Failure Mode. /// *** WARNING - ONCE IN CATOSTROPHIC FAILURE MODE, YOU CAN NEVER GO BACK! *** /// Note that only the contract owner can call this function. - function enterCatostrophicFailure() + function enterCatastrophicFailure() external onlyOwner { - isInCatostrophicFailure = true; - emit InCatostrophicFailureMode(msg.sender); + isInCatastrophicFailure = true; + emit InCatastrophicFailureMode(msg.sender); } } diff --git a/contracts/staking/contracts/src/vaults/StakingPoolRewardVault.sol b/contracts/staking/contracts/src/vaults/StakingPoolRewardVault.sol index c62916d781..110f5040ef 100644 --- a/contracts/staking/contracts/src/vaults/StakingPoolRewardVault.sol +++ b/contracts/staking/contracts/src/vaults/StakingPoolRewardVault.sol @@ -30,7 +30,7 @@ import "../immutable/MixinConstants.sol"; /// @dev This vault manages staking pool rewards. /// Rewards can be deposited and withdraw by the staking contract. /// There is a "Catastrophic Failure Mode" that, when invoked, only -/// allows withdrawals to be made. Once this vault is in catostrophic +/// allows withdrawals to be made. Once this vault is in catastrophic /// failure mode, it cannot be returned to normal mode; this prevents /// corruption of related state in the staking contract. /// @@ -55,7 +55,7 @@ contract StakingPoolRewardVault is external payable onlyStakingContract - onlyNotInCatostrophicFailure + onlyNotInCatastrophicFailure { emit RewardDeposited(UNKNOWN_STAKING_POOL_ID, msg.value); } @@ -68,7 +68,7 @@ contract StakingPoolRewardVault is external payable onlyStakingContract - onlyNotInCatostrophicFailure + onlyNotInCatastrophicFailure { // update balance of pool uint256 amount = msg.value; @@ -89,7 +89,7 @@ contract StakingPoolRewardVault is function recordDepositFor(bytes32 poolId, uint256 amount) external onlyStakingContract - onlyNotInCatostrophicFailure + onlyNotInCatastrophicFailure { // update balance of pool Balance memory balance = balanceByPoolId[poolId]; @@ -155,7 +155,7 @@ contract StakingPoolRewardVault is function registerStakingPool(bytes32 poolId, uint8 poolOperatorShare) external onlyStakingContract - onlyNotInCatostrophicFailure + onlyNotInCatastrophicFailure { // operator share must be a valid percentage if (poolOperatorShare > 100) { diff --git a/contracts/staking/contracts/src/vaults/ZrxVault.sol b/contracts/staking/contracts/src/vaults/ZrxVault.sol index 675d3850a0..163d6d9a4b 100644 --- a/contracts/staking/contracts/src/vaults/ZrxVault.sol +++ b/contracts/staking/contracts/src/vaults/ZrxVault.sol @@ -29,7 +29,7 @@ import "./MixinVaultCore.sol"; /// When a user mints stake, their Zrx Tokens are deposited into this vault. /// Similarly, when they burn stake, their Zrx Tokens are withdrawn from this vault. /// There is a "Catastrophic Failure Mode" that, when invoked, only -/// allows withdrawals to be made. Once this vault is in catostrophic +/// allows withdrawals to be made. Once this vault is in catastrophic /// failure mode, it cannot be returned to normal mode; this prevents /// corruption of related state in the staking contract. contract ZrxVault is @@ -70,12 +70,12 @@ contract ZrxVault is /// @dev Sets the ERC20 proxy. /// Note that only the contract owner can call this. - /// Note that this can only be called when *not* in Catostrophic Failure mode. + /// Note that this can only be called when *not* in Catastrophic Failure mode. /// @param erc20ProxyAddress Address of the 0x ERC20 Proxy. function setErc20Proxy(address erc20ProxyAddress) external onlyOwner - onlyNotInCatostrophicFailure + onlyNotInCatastrophicFailure { erc20Proxy = IAssetProxy(erc20ProxyAddress); emit Erc20ProxyChanged(erc20ProxyAddress); @@ -83,12 +83,12 @@ contract ZrxVault is /// @dev Sets the Zrx Asset Data. /// Note that only the contract owner can call this. - /// Note that this can only be called when *not* in Catostrophic Failure mode. + /// Note that this can only be called when *not* in Catastrophic Failure mode. /// @param _zrxAssetData Zrx asset data for the ERC20 Proxy. function setZrxAssetData(bytes calldata _zrxAssetData) external onlyOwner - onlyNotInCatostrophicFailure + onlyNotInCatastrophicFailure { zrxAssetData = _zrxAssetData; emit ZrxAssetDataChanged(_zrxAssetData); @@ -96,13 +96,13 @@ contract ZrxVault is /// @dev Deposit an `amount` of Zrx Tokens from `owner` into the vault. /// Note that only the Staking contract can call this. - /// Note that this can only be called when *not* in Catostrophic Failure mode. + /// Note that this can only be called when *not* in Catastrophic Failure mode. /// @param owner of Zrx Tokens. /// @param amount of Zrx Tokens to deposit. function depositFrom(address owner, uint256 amount) external onlyStakingContract - onlyNotInCatostrophicFailure + onlyNotInCatastrophicFailure { // update balance balances[owner] = balances[owner]._add(amount); @@ -121,23 +121,23 @@ contract ZrxVault is /// @dev Withdraw an `amount` of Zrx Tokens to `owner` from the vault. /// Note that only the Staking contract can call this. - /// Note that this can only be called when *not* in Catostrophic Failure mode. + /// Note that this can only be called when *not* in Catastrophic Failure mode. /// @param owner of Zrx Tokens. /// @param amount of Zrx Tokens to withdraw. function withdrawFrom(address owner, uint256 amount) external onlyStakingContract - onlyNotInCatostrophicFailure + onlyNotInCatastrophicFailure { _withdrawFrom(owner, amount); } /// @dev Withdraw ALL Zrx Tokens to `owner` from the vault. - /// Note that this can only be called when *in* Catostrophic Failure mode. + /// Note that this can only be called when *in* Catastrophic Failure mode. /// @param owner of Zrx Tokens. function withdrawAllFrom(address owner) external - onlyInCatostrophicFailure + onlyInCatastrophicFailure returns (uint256) { // get total balance diff --git a/contracts/staking/package.json b/contracts/staking/package.json index e51f5d6016..c6f17c1771 100644 --- a/contracts/staking/package.json +++ b/contracts/staking/package.json @@ -36,7 +36,7 @@ "compile:truffle": "truffle compile" }, "config": { - "abis": "./generated-artifacts/@(IStaking|IStakingEvents|IStakingPoolRewardVault|IStakingProxy|IStructs|IVaultCore|IWallet|IZrxVault|LibEIP712Hash|LibFeeMath|LibFeeMathTest|LibRewardMath|LibSafeMath|LibSafeMath64|LibSafeMath96|LibSignatureValidator|MixinConstants|MixinDelegatedStake|MixinDeploymentConstants|MixinExchangeFees|MixinExchangeManager|MixinOwnable|MixinScheduler|MixinStake|MixinStakeBalances|MixinStakingPool|MixinStakingPoolRewardVault|MixinStakingPoolRewards|MixinStorage|MixinTimeLockedStake|MixinVaultCore|MixinZrxVault|Staking|StakingPoolRewardVault|StakingProxy|ZrxVault).json", + "abis": "./generated-artifacts/@(IStaking|IStakingEvents|IStakingPoolRewardVault|IStakingProxy|IStructs|IVaultCore|IWallet|IZrxVault|LibEIP712Hash|LibFeeMath|LibFeeMathTest|LibRewardMath|LibSafeMath|LibSafeMath64|LibSafeMath96|LibSignatureValidator|LibStakingRichErrors|MixinConstants|MixinDelegatedStake|MixinDeploymentConstants|MixinExchangeFees|MixinExchangeManager|MixinOwnable|MixinScheduler|MixinStake|MixinStakeBalances|MixinStakingPool|MixinStakingPoolRewardVault|MixinStakingPoolRewards|MixinStorage|MixinTimeLockedStake|MixinVaultCore|MixinZrxVault|Staking|StakingPoolRewardVault|StakingProxy|ZrxVault).json", "abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually." }, "repository": { diff --git a/contracts/staking/src/artifacts.ts b/contracts/staking/src/artifacts.ts index c555b07a8c..d9a03db0cc 100644 --- a/contracts/staking/src/artifacts.ts +++ b/contracts/staking/src/artifacts.ts @@ -21,6 +21,7 @@ import * as LibSafeMath from '../generated-artifacts/LibSafeMath.json'; import * as LibSafeMath64 from '../generated-artifacts/LibSafeMath64.json'; import * as LibSafeMath96 from '../generated-artifacts/LibSafeMath96.json'; import * as LibSignatureValidator from '../generated-artifacts/LibSignatureValidator.json'; +import * as LibStakingRichErrors from '../generated-artifacts/LibStakingRichErrors.json'; import * as MixinConstants from '../generated-artifacts/MixinConstants.json'; import * as MixinDelegatedStake from '../generated-artifacts/MixinDelegatedStake.json'; import * as MixinDeploymentConstants from '../generated-artifacts/MixinDeploymentConstants.json'; @@ -64,6 +65,7 @@ export const artifacts = { LibSafeMath64: LibSafeMath64 as ContractArtifact, LibSafeMath96: LibSafeMath96 as ContractArtifact, LibSignatureValidator: LibSignatureValidator as ContractArtifact, + LibStakingRichErrors: LibStakingRichErrors as ContractArtifact, MixinDelegatedStake: MixinDelegatedStake as ContractArtifact, MixinStake: MixinStake as ContractArtifact, MixinStakeBalances: MixinStakeBalances as ContractArtifact, diff --git a/contracts/staking/src/wrappers.ts b/contracts/staking/src/wrappers.ts index 9c2c67a80f..ad630224d3 100644 --- a/contracts/staking/src/wrappers.ts +++ b/contracts/staking/src/wrappers.ts @@ -19,6 +19,7 @@ export * from '../generated-wrappers/lib_safe_math'; export * from '../generated-wrappers/lib_safe_math64'; export * from '../generated-wrappers/lib_safe_math96'; export * from '../generated-wrappers/lib_signature_validator'; +export * from '../generated-wrappers/lib_staking_rich_errors'; export * from '../generated-wrappers/mixin_constants'; export * from '../generated-wrappers/mixin_delegated_stake'; export * from '../generated-wrappers/mixin_deployment_constants'; diff --git a/contracts/staking/test/utils/staking_wrapper.ts b/contracts/staking/test/utils/staking_wrapper.ts index 9f58024432..44ecd0ba5f 100644 --- a/contracts/staking/test/utils/staking_wrapper.ts +++ b/contracts/staking/test/utils/staking_wrapper.ts @@ -660,7 +660,7 @@ export class StakingWrapper { public async rewardVaultEnterCatastrophicFailureModeAsync( zeroExMultisigAddress: string, ): Promise { - const calldata = this.getStakingPoolRewardVaultContract().enterCatostrophicFailure.getABIEncodedTransactionData(); + const calldata = this.getStakingPoolRewardVaultContract().enterCatastrophicFailure.getABIEncodedTransactionData(); const txReceipt = await this._executeTransactionAsync(calldata, zeroExMultisigAddress); return txReceipt; } diff --git a/contracts/staking/tsconfig.json b/contracts/staking/tsconfig.json index e922c985aa..7a7cbfab60 100644 --- a/contracts/staking/tsconfig.json +++ b/contracts/staking/tsconfig.json @@ -19,6 +19,7 @@ "generated-artifacts/LibSafeMath64.json", "generated-artifacts/LibSafeMath96.json", "generated-artifacts/LibSignatureValidator.json", + "generated-artifacts/LibStakingRichErrors.json", "generated-artifacts/MixinConstants.json", "generated-artifacts/MixinDelegatedStake.json", "generated-artifacts/MixinDeploymentConstants.json",