Skip to content

Commit

Permalink
Remove errors interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike-CZ committed Oct 24, 2024
1 parent fad15b2 commit 0bae479
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 107 deletions.
92 changes: 0 additions & 92 deletions contracts/IErrors.sol

This file was deleted.

8 changes: 3 additions & 5 deletions contracts/common/Initializable.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;

import {IErrors} from "../IErrors.sol";

/**
* @title Initializable
*
Expand All @@ -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.
*/
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions contracts/common/ReentrancyGuard.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -42,7 +42,7 @@ contract ReentrancyGuard is Initializable {
uint256 localCounter = _guardCounter;
_;
if (localCounter != _guardCounter) {
revert ReentrantCall();
revert ReentrancyGuardReentrantCall();
}
}

Expand Down
3 changes: 3 additions & 0 deletions contracts/sfc/NodeDriver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 8 additions & 2 deletions contracts/sfc/NodeDriverAuth.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
79 changes: 77 additions & 2 deletions contracts/sfc/SFCBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
9 changes: 7 additions & 2 deletions contracts/sfc/Updater.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions contracts/test/UnitTestSFC.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -114,7 +113,7 @@ contract UnitTestNetworkInitializer {
}
}

interface SFCUnitTestI is IErrors {
interface SFCUnitTestI {
function currentSealedEpoch() external view returns (uint256);

function getEpochSnapshot(
Expand Down

0 comments on commit 0bae479

Please sign in to comment.