Skip to content

Commit

Permalink
feat(contracts): read configs from files
Browse files Browse the repository at this point in the history
  • Loading branch information
mempirate committed Oct 15, 2024
1 parent 104b1e6 commit 8448b1c
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 77 deletions.
11 changes: 11 additions & 0 deletions bolt-contracts/config/config.holesky.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"epochDuration": 86400,
"slashingWindow": 604800,
"maxChallengeDuration": 604800,
"challengeBond": 1000000000000000000,
"blockhashEvmLookback": 256,
"justificationDelay": 32,
"eth2GenesisTimestamp": 1694786400,
"slotTime": 12,
"allowUnsafeRegistration": true
}
11 changes: 11 additions & 0 deletions bolt-contracts/config/config.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"epochDuration": 86400,
"slashingWindow": 604800,
"maxChallengeDuration": 604800,
"challengeBond": 1000000000000000000,
"blockhashEvmLookback": 256,
"justificationDelay": 32,
"eth2GenesisTimestamp": 1606824023,
"slotTime": 12,
"allowUnsafeRegistration": true
}
6 changes: 3 additions & 3 deletions bolt-contracts/src/contracts/BoltManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ contract BoltManager is IBoltManager, OwnableUpgradeable, UUPSUpgradeable {
/// associated Bolt Middleware contract.
EnumerableSet.AddressSet private restakingProtocols;

// --> Storage layout marker: 4 slots

/// @notice Start timestamp of the first epoch.
uint48 public START_TIMESTAMP;

// --> Storage layout marker: 5 slots (26 bytes left)

/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
Expand All @@ -54,7 +54,7 @@ contract BoltManager is IBoltManager, OwnableUpgradeable, UUPSUpgradeable {
*
* Total storage slots: 50
*/
uint256[46] private __gap;
uint256[45] private __gap;

modifier onlyMiddleware() {
if (!restakingProtocols.contains(msg.sender)) {
Expand Down
16 changes: 16 additions & 0 deletions bolt-contracts/src/lib/Config.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;

library BoltConfig {
struct ParametersConfig {
uint48 epochDuration;
uint48 slashingWindow;
uint48 maxChallengeDuration;
uint256 challengeBond;
uint256 blockhashEvmLookback;
uint256 justificationDelay;
uint256 eth2GenesisTimestamp;
uint256 slotTime;
bool allowUnsafeRegistration;
}
}
30 changes: 12 additions & 18 deletions bolt-contracts/test/BoltChallenger.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
pragma solidity 0.8.25;

import {Test, console} from "forge-std/Test.sol";
import {Utils} from "./Utils.sol";

import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";

import {BoltParameters} from "../src/contracts/BoltParameters.sol";
import {BoltChallenger} from "../src/contracts/BoltChallenger.sol";
import {BoltConfig} from "../src/lib/Config.sol";
import {IBoltChallenger} from "../src/interfaces/IBoltChallenger.sol";
import {RLPReader} from "../src/lib/rlp/RLPReader.sol";
import {RLPWriter} from "../src/lib/rlp/RLPWriter.sol";
Expand Down Expand Up @@ -56,28 +58,20 @@ contract BoltChallengerTest is Test {
vm.pauseGasMetering();
(target, targetPK) = makeAddrAndKey("target");

uint48 epochDuration = 1 days;
uint48 slashingWindow = 7 days;
uint48 maxChallengeDuration = 7 days;
bool allowUnsafeRegistration = true;
uint256 challengeBond = 1 ether;
uint256 blockhashEvmLookback = 256;
uint256 justificationDelay = 32;
uint256 eth2GenesisTimestamp = 1_606_824_023;
uint256 slotTime = 12;
BoltConfig.ParametersConfig memory config = new Utils().readParameters();

BoltParameters parameters = new BoltParameters();
parameters.initialize(
admin,
epochDuration,
slashingWindow,
maxChallengeDuration,
allowUnsafeRegistration,
challengeBond,
blockhashEvmLookback,
justificationDelay,
eth2GenesisTimestamp,
slotTime
config.epochDuration,
config.slashingWindow,
config.maxChallengeDuration,
config.allowUnsafeRegistration,
config.challengeBond,
config.blockhashEvmLookback,
config.justificationDelay,
config.eth2GenesisTimestamp,
config.slotTime
);

boltChallenger = new BoltChallengerExt();
Expand Down
31 changes: 12 additions & 19 deletions bolt-contracts/test/BoltManager.EigenLayer.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import {Test, console} from "forge-std/Test.sol";
import {BoltValidators} from "../src/contracts/BoltValidators.sol";
import {BoltManager} from "../src/contracts/BoltManager.sol";
import {BoltParameters} from "../src/contracts/BoltParameters.sol";
import {BoltConfig} from "../src/lib/Config.sol";
import {BoltEigenLayerMiddleware} from "../src/contracts/BoltEigenLayerMiddleware.sol";
import {IBoltValidators} from "../src/interfaces/IBoltValidators.sol";
import {IBoltManager} from "../src/interfaces/IBoltManager.sol";
import {IBoltMiddleware} from "../src/interfaces/IBoltMiddleware.sol";
import {Utils} from "./Utils.sol";

import {AVSDirectoryStorage} from "@eigenlayer/src/contracts/core/AVSDirectoryStorage.sol";
import {DelegationManagerStorage} from "@eigenlayer/src/contracts/core/DelegationManagerStorage.sol";
Expand Down Expand Up @@ -45,34 +47,25 @@ contract BoltManagerEigenLayerTest is Test {
// Set-up accounts
(operator, operatorSk) = makeAddrAndKey("operator");

// vm.setEnv("CHAIN_ID", "100000000");
// Deploy EigenLayer contracts.
// This also deploy a `weth` token and `wethStrat` strategy base available as properties of the contract.
eigenLayerDeployer = new EigenLayerDeployer(staker);
eigenLayerDeployer.setUp();

uint48 epochDuration = 1 days;
uint48 slashingWindow = 7 days;
uint48 maxChallengeDuration = 7 days;
bool allowUnsafeRegistration = true;
uint256 challengeBond = 1 ether;
uint256 blockhashEvmLookback = 256;
uint256 justificationDelay = 32;
uint256 eth2GenesisTimestamp = 1_606_824_023;
uint256 slotTime = 12;
BoltConfig.ParametersConfig memory config = new Utils().readParameters();

BoltParameters parameters = new BoltParameters();
parameters.initialize(
admin,
epochDuration,
slashingWindow,
maxChallengeDuration,
allowUnsafeRegistration,
challengeBond,
blockhashEvmLookback,
justificationDelay,
eth2GenesisTimestamp,
slotTime
config.epochDuration,
config.slashingWindow,
config.maxChallengeDuration,
config.allowUnsafeRegistration,
config.challengeBond,
config.blockhashEvmLookback,
config.justificationDelay,
config.eth2GenesisTimestamp,
config.slotTime
);

// Deploy Bolt contracts
Expand Down
30 changes: 12 additions & 18 deletions bolt-contracts/test/BoltManager.Symbiotic.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import {BoltValidators} from "../src/contracts/BoltValidators.sol";
import {BoltManager} from "../src/contracts/BoltManager.sol";
import {BoltSymbioticMiddleware} from "../src/contracts/BoltSymbioticMiddleware.sol";
import {BLS12381} from "../src/lib/bls/BLS12381.sol";
import {BoltConfig} from "../src/lib/Config.sol";
import {Utils} from "./Utils.sol";

import {SymbioticSetupFixture} from "./fixtures/SymbioticSetup.f.sol";

Expand Down Expand Up @@ -151,28 +153,20 @@ contract BoltManagerSymbioticTest is Test {

// --- Deploy Bolt contracts ---

uint48 epochDuration = 1 days;
uint48 slashingWindow = 7 days;
uint48 maxChallengeDuration = 7 days;
bool allowUnsafeRegistration = true;
uint256 challengeBond = 1 ether;
uint256 blockhashEvmLookback = 256;
uint256 justificationDelay = 32;
uint256 eth2GenesisTimestamp = 1_606_824_023;
uint256 slotTime = 12;
BoltConfig.ParametersConfig memory config = new Utils().readParameters();

BoltParameters parameters = new BoltParameters();
parameters.initialize(
admin,
epochDuration,
slashingWindow,
maxChallengeDuration,
allowUnsafeRegistration,
challengeBond,
blockhashEvmLookback,
justificationDelay,
eth2GenesisTimestamp,
slotTime
config.epochDuration,
config.slashingWindow,
config.maxChallengeDuration,
config.allowUnsafeRegistration,
config.challengeBond,
config.blockhashEvmLookback,
config.justificationDelay,
config.eth2GenesisTimestamp,
config.slotTime
);

validators = new BoltValidators();
Expand Down
32 changes: 13 additions & 19 deletions bolt-contracts/test/BoltValidators.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {BoltParameters} from "../src/contracts/BoltParameters.sol";
import {BoltValidators} from "../src/contracts/BoltValidators.sol";
import {IBoltValidators} from "../src/interfaces/IBoltValidators.sol";
import {BLS12381} from "../src/lib/bls/BLS12381.sol";
import {BoltConfig} from "../src/lib/Config.sol";
import {Utils} from "./Utils.sol";

contract BoltValidatorsTest is Test {
using BLS12381 for BLS12381.G1Point;
Expand All @@ -22,30 +24,22 @@ contract BoltValidatorsTest is Test {
address validator = makeAddr("validator");

function setUp() public {
uint48 epochDuration = 1 days;
uint48 slashingWindow = 7 days;
uint48 maxChallengeDuration = 7 days;
bool allowUnsafeRegistration = true;
uint256 challengeBond = 1 ether;
uint256 blockhashEvmLookback = 256;
uint256 justificationDelay = 32;
uint256 eth2GenesisTimestamp = 1_606_824_023;
uint256 slotTime = 12;
BoltConfig.ParametersConfig memory config = new Utils().readParameters();

parameters = new BoltParameters();

parameters.initialize(
admin,
epochDuration,
slashingWindow,
maxChallengeDuration,
allowUnsafeRegistration,
challengeBond,
blockhashEvmLookback,
justificationDelay,
eth2GenesisTimestamp,
slotTime
config.epochDuration,
config.slashingWindow,
config.maxChallengeDuration,
config.allowUnsafeRegistration,
config.challengeBond,
config.blockhashEvmLookback,
config.justificationDelay,
config.eth2GenesisTimestamp,
config.slotTime
);

validators = new BoltValidators();
validators.initialize(admin, address(parameters));
}
Expand Down
36 changes: 36 additions & 0 deletions bolt-contracts/test/Utils.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;

import {Test, console} from "forge-std/Test.sol";

import {BoltConfig} from "../src/lib/Config.sol";

contract Utils is Test {
function readParameters() public view returns (BoltConfig.ParametersConfig memory) {
string memory root = vm.projectRoot();
string memory path = string.concat(root, "/config/config.test.json");
string memory json = vm.readFile(path);

uint48 epochDuration = uint48(vm.parseJsonUint(json, ".epochDuration"));
uint48 slashingWindow = uint48(vm.parseJsonUint(json, ".slashingWindow"));
uint48 maxChallengeDuration = uint48(vm.parseJsonUint(json, ".maxChallengeDuration"));
bool allowUnsafeRegistration = vm.parseJsonBool(json, ".allowUnsafeRegistration");
uint256 challengeBond = vm.parseJsonUint(json, ".challengeBond");
uint256 blockhashEvmLookback = vm.parseJsonUint(json, ".blockhashEvmLookback");
uint256 justificationDelay = vm.parseJsonUint(json, ".justificationDelay");
uint256 eth2GenesisTimestamp = vm.parseJsonUint(json, ".eth2GenesisTimestamp");
uint256 slotTime = vm.parseJsonUint(json, ".slotTime");

return BoltConfig.ParametersConfig({
epochDuration: epochDuration,
slashingWindow: slashingWindow,
maxChallengeDuration: maxChallengeDuration,
challengeBond: challengeBond,
blockhashEvmLookback: blockhashEvmLookback,
justificationDelay: justificationDelay,
eth2GenesisTimestamp: eth2GenesisTimestamp,
slotTime: slotTime,
allowUnsafeRegistration: allowUnsafeRegistration
});
}
}

0 comments on commit 8448b1c

Please sign in to comment.