Skip to content

Commit

Permalink
Remove unnecessary genesis params and migration func (#85)
Browse files Browse the repository at this point in the history
* Remove unnecessary genesis params and migration func

* Add mappings params names

* Remove unused ReentrancyGuard

* Use locked pragma, security contact, cancun

* npm run lint:fix
  • Loading branch information
thaarok authored Nov 1, 2024
1 parent 1bc06aa commit 20fc210
Show file tree
Hide file tree
Showing 24 changed files with 108 additions and 302 deletions.
5 changes: 4 additions & 1 deletion contracts/common/Decimal.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;
pragma solidity 0.8.27;

/**
* @custom:security-contact [email protected]
*/
library Decimal {
// unit is used for decimals, e.g. 0.123456
function unit() internal pure returns (uint256) {
Expand Down
4 changes: 3 additions & 1 deletion contracts/common/Initializable.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;
pragma solidity 0.8.27;

/**
* @title Initializable
Expand All @@ -12,6 +12,8 @@ pragma solidity ^0.8.9;
* WARNING: When used with inheritance, manual care must be taken to not invoke
* a parent initializer twice, or ensure that all initializers are idempotent,
* because this is not dealt with automatically as with constructors.
*
* @custom:security-contact [email protected]
*/
contract Initializable {
/**
Expand Down
50 changes: 0 additions & 50 deletions contracts/common/ReentrancyGuard.sol

This file was deleted.

5 changes: 4 additions & 1 deletion contracts/interfaces/IEVMWriter.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;
pragma solidity 0.8.27;

/**
* @custom:security-contact [email protected]
*/
interface IEVMWriter {
function setBalance(address acc, uint256 value) external;

Expand Down
5 changes: 4 additions & 1 deletion contracts/interfaces/INodeDriver.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;
pragma solidity 0.8.27;

/**
* @custom:security-contact [email protected]
*/
interface INodeDriver {
function setGenesisValidator(
address _auth,
Expand Down
5 changes: 4 additions & 1 deletion contracts/interfaces/INodeDriverExecutable.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;
pragma solidity 0.8.27;

/**
* @custom:security-contact [email protected]
*/
interface INodeDriverExecutable {
function execute() external;
}
21 changes: 6 additions & 15 deletions contracts/interfaces/ISFC.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;
pragma solidity 0.8.27;

/**
* @custom:security-contact [email protected]
*/
interface ISFC {
event CreatedValidator(
uint256 indexed validatorID,
Expand Down Expand Up @@ -32,9 +35,7 @@ interface ISFC {
uint256 endTime,
uint256 endBlock,
uint256 epochFee,
uint256 totalBaseRewardWeight,
uint256 totalTxRewardWeight,
uint256 _baseRewardPerSecond,
uint256 baseRewardPerSecond,
uint256 totalStake,
uint256 totalSupply
);
Expand Down Expand Up @@ -138,10 +139,6 @@ interface ISFC {

function restakeRewards(uint256 toValidatorID) external;

function updateBaseRewardPerSecond(uint256 value) external;

function updateOfflinePenaltyThreshold(uint256 blocksNum, uint256 time) external;

function updateSlashingRefundRatio(uint256 validatorID, uint256 refundRatio) external;

function updateTreasuryAddress(address v) external;
Expand Down Expand Up @@ -170,11 +167,7 @@ interface ISFC {
address auth,
uint256 validatorID,
bytes calldata pubkey,
uint256 status,
uint256 createdEpoch,
uint256 createdTime,
uint256 deactivatedEpoch,
uint256 deactivatedTime
uint256 createdTime
) external;

function setGenesisDelegation(address delegator, uint256 toValidatorID, uint256 stake) external;
Expand All @@ -185,8 +178,6 @@ interface ISFC {

function updateValidatorPubkey(bytes calldata pubkey) external;

function migrateValidatorPubkeyUniquenessFlag(uint256 start, uint256 end) external;

function setRedirectionAuthorizer(address v) external;

function announceRedirection(address to) external;
Expand Down
4 changes: 3 additions & 1 deletion contracts/ownership/Ownable.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;
pragma solidity 0.8.27;

import {Initializable} from "../common/Initializable.sol";

Expand All @@ -11,6 +11,8 @@ import {Initializable} from "../common/Initializable.sol";
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be aplied to your functions to restrict their use to
* the owner.
*
* @custom:security-contact [email protected]
*/
contract Ownable is Initializable {
address private _owner;
Expand Down
5 changes: 4 additions & 1 deletion contracts/sfc/ConstantsManager.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;
pragma solidity 0.8.27;

import {Ownable} from "../ownership/Ownable.sol";
import {Decimal} from "../common/Decimal.sol";

/**
* @custom:security-contact [email protected]
*/
contract ConstantsManager is Ownable {
// Minimum amount of stake for a validator, i.e., 500000 FTM
uint256 public minSelfStake;
Expand Down
5 changes: 4 additions & 1 deletion contracts/sfc/GasPriceConstants.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;
pragma solidity 0.8.27;

import {Decimal} from "../common/Decimal.sol";

/**
* @custom:security-contact [email protected]
*/
library GP {
function trimGasPriceChangeRatio(uint256 x) internal pure returns (uint256) {
if (x > (Decimal.unit() * 105) / 100) {
Expand Down
5 changes: 4 additions & 1 deletion contracts/sfc/Migrations.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;
pragma solidity 0.8.27;

/**
* @custom:security-contact [email protected]
*/
contract Migrations {
address public owner;
uint256 public lastCompletedMigration;
Expand Down
5 changes: 4 additions & 1 deletion contracts/sfc/NetworkInitializer.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;
pragma solidity 0.8.27;

import {ISFC} from "../interfaces/ISFC.sol";
import {NodeDriver, NodeDriverAuth} from "./NodeDriver.sol";
import {ConstantsManager} from "./ConstantsManager.sol";
import {Decimal} from "../common/Decimal.sol";

/**
* @custom:security-contact [email protected]
*/
contract NetworkInitializer {
// Initialize NodeDriverAuth, NodeDriver and SFC in one call to allow fewer genesis transactions
function initializeAll(
Expand Down
24 changes: 7 additions & 17 deletions contracts/sfc/NodeDriver.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;
pragma solidity 0.8.27;

import {Initializable} from "../common/Initializable.sol";
import {NodeDriverAuth} from "./NodeDriverAuth.sol";
import {IEVMWriter} from "../interfaces/IEVMWriter.sol";

/**
* @custom:security-contact [email protected]
*/
contract NodeDriver is Initializable {
NodeDriverAuth internal backend;
IEVMWriter internal evmWriter;
Expand Down Expand Up @@ -89,25 +92,12 @@ contract NodeDriver is Initializable {
// Methods which are called only by the node

function setGenesisValidator(
address _auth,
address auth,
uint256 validatorID,
bytes calldata pubkey,
uint256 status,
uint256 createdEpoch,
uint256 createdTime,
uint256 deactivatedEpoch,
uint256 deactivatedTime
uint256 createdTime
) external onlyNode {
backend.setGenesisValidator(
_auth,
validatorID,
pubkey,
status,
createdEpoch,
createdTime,
deactivatedEpoch,
deactivatedTime
);
backend.setGenesisValidator(auth, validatorID, pubkey, createdTime);
}

function setGenesisDelegation(address delegator, uint256 toValidatorID, uint256 stake) external onlyNode {
Expand Down
24 changes: 7 additions & 17 deletions contracts/sfc/NodeDriverAuth.sol
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;
pragma solidity 0.8.27;

import {Initializable} from "../common/Initializable.sol";
import {Ownable} from "../ownership/Ownable.sol";
import {ISFC} from "../interfaces/ISFC.sol";
import {NodeDriver} from "./NodeDriver.sol";
import {INodeDriverExecutable} from "../interfaces/INodeDriverExecutable.sol";

/**
* @custom:security-contact [email protected]
*/
contract NodeDriverAuth is Initializable, Ownable {
ISFC internal sfc;
NodeDriver internal driver;
Expand Down Expand Up @@ -117,25 +120,12 @@ contract NodeDriverAuth is Initializable, Ownable {
}

function setGenesisValidator(
address _auth,
address auth,
uint256 validatorID,
bytes calldata pubkey,
uint256 status,
uint256 createdEpoch,
uint256 createdTime,
uint256 deactivatedEpoch,
uint256 deactivatedTime
uint256 createdTime
) external onlyDriver {
sfc.setGenesisValidator(
_auth,
validatorID,
pubkey,
status,
createdEpoch,
createdTime,
deactivatedEpoch,
deactivatedTime
);
sfc.setGenesisValidator(auth, validatorID, pubkey, createdTime);
}

function setGenesisDelegation(address delegator, uint256 toValidatorID, uint256 stake) external onlyDriver {
Expand Down
Loading

0 comments on commit 20fc210

Please sign in to comment.