Skip to content

Commit

Permalink
feat(contracts/script): register validators script
Browse files Browse the repository at this point in the history
  • Loading branch information
mempirate committed Oct 20, 2024
1 parent 8299323 commit 675cf09
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 2 deletions.
3 changes: 3 additions & 0 deletions bolt-contracts/config/holesky/deployments.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"bolt": {
"validators": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
},
"symbiotic": {
"network": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"operatorRegistry": "0xAdFC41729fF447974cE27DdFa358A0f2096c3F39",
Expand Down
8 changes: 8 additions & 0 deletions bolt-contracts/config/holesky/validators.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"maxCommittedGasLimit": 10000000,
"authorizedOperator": "0x",
"pubkeys": [
"0xad02df40e24e8534dc4c175163f7a034f99f2e81c43b7ea19904006cb05d001b5301d3444f1812b101803b7f72e340fa",
"0xa4c0a8b5dd70d0fe8f05580143bea4c40badb176c2b0c20001cddf897a11bb832137fa4050af1d0420a7dc27568697df"
]
}
6 changes: 4 additions & 2 deletions bolt-contracts/docs/admin/deploying.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ forge script script/holesky/admin/Deploy.s.sol --rpc-url $HOLESKY_RPC --private-

This will deploy all the contracts. The address corresponding to the private key will be the system admin.

Now update `deployments.json` with the Symbiotic and EigenLayer middleware contracts, because we'll need to register it
in the next step.
Now update `deployments.json` with the Symbiotic and EigenLayer middleware contracts, because we'll need to register it in the next step. Also update the `bolt` section with the correct addresses.

### Post-deployment

Expand All @@ -69,3 +68,6 @@ Also set the AVS metadata in the EigenLayer AVS Directory, needs to be run with
forge script script/holesky/admin/helpers/RegisterAVS.s.sol --rpc-url $HOLESKY_RPC --private-key $ADMIN_PRIVATE_KEY --broadcast -vvvv
```

> [!IMPORTANT]
> After the `deployments.json` file has been fully updated with the correct contract addresses, push it to Github.
79 changes: 79 additions & 0 deletions bolt-contracts/script/holesky/validators/RegisterValidators.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;

import {IBoltValidatorsV1} from "../../../src/interfaces/IBoltValidatorsV1.sol";
import {BLS12381} from "../../../src/lib/bls/BLS12381.sol";

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

/// @notice Script to register Ethereum validators to Bolt
/// @dev this script reads from the config file in /config/holesky/register_validators.json
contract RegisterValidators is Script {
struct RegisterValidatorsConfig {
uint128 maxCommittedGasLimit;
address authorizedOperator;
BLS12381.G1Point[] pubkeys;
}

function run() public {
address controller = msg.sender;

console.log("Registering validators to Bolt");
console.log("Controller address: ", controller);

IBoltValidatorsV1 validators = _readValidators();
RegisterValidatorsConfig memory config = _parseConfig();

vm.startBroadcast(controller);
validators.batchRegisterValidatorsUnsafe(config.pubkeys, config.maxCommittedGasLimit, config.authorizedOperator);
vm.stopBroadcast();

console.log("Validators registered successfully");
}

function _readValidators() public view returns (IBoltValidatorsV1) {
string memory root = vm.projectRoot();
string memory path = string.concat(root, "/config/holesky/deployments.json");
string memory json = vm.readFile(path);

return IBoltValidatorsV1(vm.parseJsonAddress(json, ".bolt.validators"));
}

function _parseConfig() public view returns (RegisterValidatorsConfig memory config) {
string memory root = vm.projectRoot();
string memory path = string.concat(root, "/config/holesky/validators.json");
string memory json = vm.readFile(path);

config.authorizedOperator = vm.parseJsonAddress(json, ".authorizedOperator");
config.maxCommittedGasLimit = uint128(vm.parseJsonUint(json, ".maxCommittedGasLimit"));

bytes[] memory pubkeysRaw = vm.parseJsonBytesArray(json, ".pubkeys");
BLS12381.G1Point[] memory pubkeys = new BLS12381.G1Point[](pubkeysRaw.length);

for (uint256 i = 0; i < pubkeysRaw.length; i++) {
bytes memory pubkey = pubkeysRaw[i];
require(pubkey.length == 96, "Invalid pubkey length");

uint256[2] memory x;
uint256[2] memory y;

// Assuming each coordinate is split into two 32 bytes
x[0] = uint256(bytes32(_slice(pubkey, 0, 32)));
x[1] = uint256(bytes32(_slice(pubkey, 32, 32)));
y[0] = uint256(bytes32(_slice(pubkey, 64, 32)));
y[1] = uint256(bytes32(_slice(pubkey, 96, 32)));

pubkeys[i] = BLS12381.G1Point(x, y);
}

config.pubkeys = pubkeys;
}

function _slice(bytes memory data, uint256 start, uint256 length) internal pure returns (bytes memory) {
bytes memory part = new bytes(length);
for (uint256 i = 0; i < length; i++) {
part[i] = data[i + start];
}
return part;
}
}

0 comments on commit 675cf09

Please sign in to comment.