diff --git a/contracts/IErrors.sol b/contracts/IErrors.sol deleted file mode 100644 index 03d43a2..0000000 --- a/contracts/IErrors.sol +++ /dev/null @@ -1,92 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.9; - -interface IErrors { - // auth - error NotOwner(); - error NotBackend(); - error NotNode(); - error NotSFC(); - error NotDriver(); - error NotDriverAuth(); - error NotContract(); - error NotAuthorized(); - - // initialization - error ContractInitialized(); - - // reentrancy - error ReentrantCall(); - - // addresses - error ZeroAddress(); - error SameAddress(); - error RecipientNotSFC(); - - // values - error ZeroAmount(); - error ZeroRewards(); - - // pubkeys - error PubkeyExists(); - error MalformedPubkey(); - error SamePubkey(); - error EmptyPubkey(); - error PubkeyAllowedOnlyOnce(); - - // redirections - error SameRedirectionAuthorizer(); - error Redirected(); - - // validators - error ValidatorNotExists(); - error ValidatorExists(); - error ValidatorNotActive(); - error ValidatorDelegationLimitExceeded(); - error WrongValidatorStatus(); - - // requests - error RequestedCompleted(); - error RequestExists(); - error RequestNotExists(); - - // transfers - error TransfersNotAllowed(); - error TransferFailed(); - - // updater - error SFCAlreadyUpdated(); - error SFCWrongVersion(); - error SFCGovAlreadyUpdated(); - error SFCWrongGovVersion(); - - // node driver - error SelfCodeHashMismatch(); - error DriverCodeHashMismatch(); - - // governance - error GovVotesRecountFailed(); - - // staking - error LockedStakeGreaterThanTotalStake(); - error InsufficientSelfStake(); - error NotEnoughUnlockedStake(); - error NotEnoughLockedStake(); - error NotEnoughTimePassed(); - error NotEnoughEpochsPassed(); - error StakeIsFullySlashed(); - error IncorrectDuration(); - error ValidatorLockupTooShort(); - error TooManyReLocks(); - error TooFrequentReLocks(); - error LockupDurationDecreased(); - error AlreadyLockedUp(); - error NotLockedUp(); - - // stashing - error NothingToStash(); - - // slashing - error ValidatorNotSlashed(); - error RefundRatioTooHigh(); -} diff --git a/contracts/common/Initializable.sol b/contracts/common/Initializable.sol index d8d0dbe..97d2ff7 100644 --- a/contracts/common/Initializable.sol +++ b/contracts/common/Initializable.sol @@ -1,8 +1,6 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.9; -import {IErrors} from "../IErrors.sol"; - /** * @title Initializable * @@ -15,7 +13,7 @@ import {IErrors} from "../IErrors.sol"; * a parent initializer twice, or ensure that all initializers are idempotent, * because this is not dealt with automatically as with constructors. */ -contract Initializable is IErrors { +contract Initializable { /** * @dev Indicates that the contract has been initialized. */ @@ -29,14 +27,14 @@ contract Initializable is IErrors { /** * @dev The contract instance has already been initialized. */ - error ContractInitialized(); + error InvalidInitialization(); /** * @dev Modifier to use in the initializer function of a contract. */ modifier initializer() { if (!initializing && initialized) { - revert ContractInitialized(); + revert InvalidInitialization(); } bool isTopLevelCall = !initializing; diff --git a/contracts/common/ReentrancyGuard.sol b/contracts/common/ReentrancyGuard.sol index 3c7f1d2..5919a27 100644 --- a/contracts/common/ReentrancyGuard.sol +++ b/contracts/common/ReentrancyGuard.sol @@ -22,7 +22,7 @@ contract ReentrancyGuard is Initializable { /** * @dev Reentrant call. */ - error ReentrantCall(); + error ReentrancyGuardReentrantCall(); function initialize() internal initializer { // The counter starts at one to prevent changing it from zero to a non-zero @@ -42,7 +42,7 @@ contract ReentrancyGuard is Initializable { uint256 localCounter = _guardCounter; _; if (localCounter != _guardCounter) { - revert ReentrantCall(); + revert ReentrancyGuardReentrantCall(); } } diff --git a/contracts/sfc/NodeDriver.sol b/contracts/sfc/NodeDriver.sol index d6e3203..c58e44c 100644 --- a/contracts/sfc/NodeDriver.sol +++ b/contracts/sfc/NodeDriver.sol @@ -9,6 +9,9 @@ contract NodeDriver is Initializable { NodeDriverAuth internal backend; IEvmWriter internal evmWriter; + error NotNode(); + error NotBackend(); + event UpdatedBackend(address indexed backend); function setBackend(address _backend) external onlyBackend { diff --git a/contracts/sfc/NodeDriverAuth.sol b/contracts/sfc/NodeDriverAuth.sol index 73dd5ff..2801fff 100644 --- a/contracts/sfc/NodeDriverAuth.sol +++ b/contracts/sfc/NodeDriverAuth.sol @@ -5,16 +5,22 @@ import {Initializable} from "../common/Initializable.sol"; import {Ownable} from "../ownership/Ownable.sol"; import {SFCI} from "./SFCI.sol"; import {NodeDriver} from "./NodeDriver.sol"; -import {IErrors} from "../IErrors.sol"; interface NodeDriverExecutable { function execute() external; } -contract NodeDriverAuth is IErrors, Initializable, Ownable { +contract NodeDriverAuth is Initializable, Ownable { SFCI internal sfc; NodeDriver internal driver; + error NotSFC(); + error NotDriver(); + error NotContract(); + error SelfCodeHashMismatch(); + error DriverCodeHashMismatch(); + error RecipientNotSFC(); + // Initialize NodeDriverAuth, NodeDriver and SFC in one call to allow fewer genesis transactions function initialize(address payable _sfc, address _driver, address _owner) external initializer { Ownable.initialize(_owner); diff --git a/contracts/sfc/SFCBase.sol b/contracts/sfc/SFCBase.sol index cd6215d..74e4c44 100644 --- a/contracts/sfc/SFCBase.sol +++ b/contracts/sfc/SFCBase.sol @@ -3,15 +3,90 @@ pragma solidity ^0.8.9; import {Decimal} from "../common/Decimal.sol"; import {SFCState} from "./SFCState.sol"; -import {IErrors} from "../IErrors.sol"; -contract SFCBase is IErrors, SFCState { +contract SFCBase is SFCState { uint256 internal constant OK_STATUS = 0; uint256 internal constant WITHDRAWN_BIT = 1; uint256 internal constant OFFLINE_BIT = 1 << 3; uint256 internal constant DOUBLESIGN_BIT = 1 << 7; uint256 internal constant CHEATER_MASK = DOUBLESIGN_BIT; + // auth + error NotDriverAuth(); + error NotAuthorized(); + + // addresses + error ZeroAddress(); + error SameAddress(); + error RecipientNotSFC(); + + // values + error ZeroAmount(); + error ZeroRewards(); + + // pubkeys + error PubkeyExists(); + error MalformedPubkey(); + error SamePubkey(); + error EmptyPubkey(); + error PubkeyAllowedOnlyOnce(); + + // redirections + error SameRedirectionAuthorizer(); + error Redirected(); + + // validators + error ValidatorNotExists(); + error ValidatorExists(); + error ValidatorNotActive(); + error ValidatorDelegationLimitExceeded(); + error WrongValidatorStatus(); + + // requests + error RequestedCompleted(); + error RequestExists(); + error RequestNotExists(); + + // transfers + error TransfersNotAllowed(); + error TransferFailed(); + + // updater + error SFCAlreadyUpdated(); + error SFCWrongVersion(); + error SFCGovAlreadyUpdated(); + error SFCWrongGovVersion(); + + // node driver + error SelfCodeHashMismatch(); + error DriverCodeHashMismatch(); + + // governance + error GovVotesRecountFailed(); + + // staking + error LockedStakeGreaterThanTotalStake(); + error InsufficientSelfStake(); + error NotEnoughUnlockedStake(); + error NotEnoughLockedStake(); + error NotEnoughTimePassed(); + error NotEnoughEpochsPassed(); + error StakeIsFullySlashed(); + error IncorrectDuration(); + error ValidatorLockupTooShort(); + error TooManyReLocks(); + error TooFrequentReLocks(); + error LockupDurationDecreased(); + error AlreadyLockedUp(); + error NotLockedUp(); + + // stashing + error NothingToStash(); + + // slashing + error ValidatorNotSlashed(); + error RefundRatioTooHigh(); + event DeactivatedValidator(uint256 indexed validatorID, uint256 deactivatedEpoch, uint256 deactivatedTime); event ChangedValidatorStatus(uint256 indexed validatorID, uint256 status); diff --git a/contracts/sfc/Updater.sol b/contracts/sfc/Updater.sol index d4516cb..634167a 100644 --- a/contracts/sfc/Updater.sol +++ b/contracts/sfc/Updater.sol @@ -8,7 +8,6 @@ import {ConstantsManager} from "./ConstantsManager.sol"; import {SFC} from "./SFC.sol"; import {SFCI} from "./SFCI.sol"; import {Version} from "../version/Version.sol"; -import {IErrors} from "../IErrors.sol"; interface GovI { function upgrade(address v) external; @@ -22,7 +21,7 @@ interface GovVersion { function version() external pure returns (bytes4); } -contract Updater is IErrors { +contract Updater { address public sfcFrom; address public sfcLib; address public sfcConsts; @@ -31,6 +30,12 @@ contract Updater is IErrors { address public voteBook; address public owner; + error ZeroAddress(); + error SFCAlreadyUpdated(); + error SFCWrongVersion(); + error SFCGovAlreadyUpdated(); + error SFCWrongGovVersion(); + constructor( address _sfcFrom, address _sfcLib, diff --git a/contracts/test/UnitTestSFC.sol b/contracts/test/UnitTestSFC.sol index ca9f2d4..ef7d24d 100644 --- a/contracts/test/UnitTestSFC.sol +++ b/contracts/test/UnitTestSFC.sol @@ -5,7 +5,6 @@ import {Decimal} from "../common/Decimal.sol"; import {SFC} from "../sfc/SFC.sol"; import {SFCBase} from "../sfc/SFCBase.sol"; import {SFCLib} from "../sfc/SFCLib.sol"; -import {IErrors} from "../IErrors.sol"; import {NodeDriverAuth} from "../sfc/NodeDriverAuth.sol"; import {NodeDriver} from "../sfc/NodeDriver.sol"; import {UnitTestConstantsManager} from "./UnitTestConstantsManager.sol"; @@ -114,7 +113,7 @@ contract UnitTestNetworkInitializer { } } -interface SFCUnitTestI is IErrors { +interface SFCUnitTestI { function currentSealedEpoch() external view returns (uint256); function getEpochSnapshot(