From 8c2efe9a4fa19a53d85b460b47e69e140c6b9ac7 Mon Sep 17 00:00:00 2001 From: nicolas <48695862+merklefruit@users.noreply.github.com> Date: Fri, 18 Oct 2024 17:36:25 +0200 Subject: [PATCH 1/3] chore: added test data --- bolt-contracts/config/holesky/validators.json | 17 ++++++ .../validators/RegisterValidators.s.sol | 55 +++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 bolt-contracts/config/holesky/validators.json create mode 100644 bolt-contracts/script/holesky/validators/RegisterValidators.s.sol diff --git a/bolt-contracts/config/holesky/validators.json b/bolt-contracts/config/holesky/validators.json new file mode 100644 index 000000000..9fbdc2c1b --- /dev/null +++ b/bolt-contracts/config/holesky/validators.json @@ -0,0 +1,17 @@ +{ + "boltValidators": "0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984", + "maxCommittedGasLimit": 10000000, + "authorizedOperator": "0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984", + "pubkeys": [ + "0xa995029d6fc41241acc4a18621204ad11db196986f44789f564652350d50b3bb995b224e998f8338f7e17620ea80531d", + "0xa9b4faba4a513626249f17e46152f1760a4616118c49694634ea0b6fde16629a064a485ec44957e41c1cc2cc33aad98e", + "0x902c8589f286f3dfc0d74775fcd8d1a580313a0711d68ecb9212eb94208cfd797bf67742adb46aee84bc67b902041326", + "0x84cb3155459fa1bda073199e1270119ddf714cd9f435c43507a287a46f334cf5937d45154b05ba3589c251845b07235f", + "0xb9048c8e89d4586f9f63152e0cb8b1b76f7392a1fc30c30eb6f9ece4a2e7b1b3ea045fecf72ae0e0a8e42a9beca2d908", + "0x81c51f8f7ad4b11d972e1fdae4702edb0b42531c4f366451962bd6097845952d136e441ec03f7cb1f463e37c2bffd1a9", + "0xa9d93a373ed9e42625b00437481eb5451f30bc23c169eca61a7d7cb55a7d517719b2f4764d9849cc220586ce3805ee4a", + "0x8c9b8ff21f6aec6c3c80df64f6afb71cdd3e566cff3d04d6fb679b3f0e4b32c85763fd78de6425df4062cad08687cbc2", + "0x977cea163cbf5e490573f46091c0e06f1961a7e277a6d923d50217dafa5963313e3c7a803691f71a724a308ccc261f30", + "0xa922472f3382bf6e0e157daaa05958cbcfd6cd00d11c6a4702d3818627b49e146af7002778174c123555a93afe0b7e9e" + ] +} diff --git a/bolt-contracts/script/holesky/validators/RegisterValidators.s.sol b/bolt-contracts/script/holesky/validators/RegisterValidators.s.sol new file mode 100644 index 000000000..547b27054 --- /dev/null +++ b/bolt-contracts/script/holesky/validators/RegisterValidators.s.sol @@ -0,0 +1,55 @@ +// SPDX-License-Identifier: MIT +pragma solidity 0.8.25; + +import {IBoltValidatorsV1} from "../interfaces/IBoltValidatorsV1.sol"; +import {BLS12381} from "../lib/bls/BLS12381.sol"; + +import {Script, console} from "forge-std/Script.sol"; + +/// @notice Script to register Ethereum validators to Bolt +contract RegisterValidators is Script { + struct RegisterValidatorsConfig { + address boltValidators; + uint128 maxCommittedGasLimit; + address authorizedOperator; + string[] pubkeys; + } + + function run( + string configPath + ) public { + address controller = msg.sender; + + console.log("Registering validators to Bolt"); + console.log("Controller address: ", controller); + + RegisterValidatorsConfig memory config = parseConfig(configPath); + + vm.startBroadcast(controller); + IBoltValidatorsV1(boltValidators).batchRegisterValidatorsUnsafe( + config.pubkeys, config.maxCommittedGasLimit, config.authorizedOperator + ); + vm.stopBroadcast(); + + console.log("Validators registered successfully"); + } + + function parseConfig( + string configPath + ) public view returns (RegisterValidatorsConfig memory config) { + string memory root = vm.projectRoot(); + string memory path = string.concat(root, "/config/holesky/register_validators.json"); + string memory json = vm.readFile(path); + + config.boltValidators = vm.parseJsonAddress(json, "boltValidators"); + config.authorizedOperator = vm.parseJsonAddress(json, "authorizedOperator"); + config.maxCommittedGasLimit = uint128(vm.parseJsonUint(json, "maxCommittedGasLimit")); + + string[] memory pubkeysRaw = vm.parseJsonStringArray(json, "pubkeys"); + BLS12381.G1Point[] memory pubkeys = new BLS12381.G1Point[](pubkeysRaw.length); + for (uint256 i = 0; i < pubkeysRaw.length; i++) { + pubkeys[i] = BLS12381.G1Point(vm.parseJsonBytes(json, pubkeysRaw[i])); + } + config.pubkeys = pubkeys; + } +} From 46934783c338acac1deaaaceae0cad231ae27d9a Mon Sep 17 00:00:00 2001 From: nicolas <48695862+merklefruit@users.noreply.github.com> Date: Fri, 18 Oct 2024 17:46:39 +0200 Subject: [PATCH 2/3] chore: update script --- .../validators/RegisterValidators.s.sol | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/bolt-contracts/script/holesky/validators/RegisterValidators.s.sol b/bolt-contracts/script/holesky/validators/RegisterValidators.s.sol index 547b27054..2fbf4d783 100644 --- a/bolt-contracts/script/holesky/validators/RegisterValidators.s.sol +++ b/bolt-contracts/script/holesky/validators/RegisterValidators.s.sol @@ -1,32 +1,31 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.25; -import {IBoltValidatorsV1} from "../interfaces/IBoltValidatorsV1.sol"; -import {BLS12381} from "../lib/bls/BLS12381.sol"; +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 { address boltValidators; uint128 maxCommittedGasLimit; address authorizedOperator; - string[] pubkeys; + BLS12381.G1Point[] pubkeys; } - function run( - string configPath - ) public { + function run() public { address controller = msg.sender; console.log("Registering validators to Bolt"); console.log("Controller address: ", controller); - RegisterValidatorsConfig memory config = parseConfig(configPath); + RegisterValidatorsConfig memory config = parseConfig(); vm.startBroadcast(controller); - IBoltValidatorsV1(boltValidators).batchRegisterValidatorsUnsafe( + IBoltValidatorsV1(config.boltValidators).batchRegisterValidatorsUnsafe( config.pubkeys, config.maxCommittedGasLimit, config.authorizedOperator ); vm.stopBroadcast(); @@ -34,9 +33,7 @@ contract RegisterValidators is Script { console.log("Validators registered successfully"); } - function parseConfig( - string configPath - ) public view returns (RegisterValidatorsConfig memory config) { + function parseConfig() public view returns (RegisterValidatorsConfig memory config) { string memory root = vm.projectRoot(); string memory path = string.concat(root, "/config/holesky/register_validators.json"); string memory json = vm.readFile(path); @@ -48,7 +45,9 @@ contract RegisterValidators is Script { string[] memory pubkeysRaw = vm.parseJsonStringArray(json, "pubkeys"); BLS12381.G1Point[] memory pubkeys = new BLS12381.G1Point[](pubkeysRaw.length); for (uint256 i = 0; i < pubkeysRaw.length; i++) { - pubkeys[i] = BLS12381.G1Point(vm.parseJsonBytes(json, pubkeysRaw[i])); + uint256[2] memory x = [uint256(0), uint256(0)]; + uint256[2] memory y = [uint256(0), uint256(0)]; + pubkeys[i] = BLS12381.G1Point(x, y); } config.pubkeys = pubkeys; } From 7e814a7dc152ed99f48cec0161cc090994b27cec Mon Sep 17 00:00:00 2001 From: nicolas <48695862+merklefruit@users.noreply.github.com> Date: Fri, 18 Oct 2024 18:18:25 +0200 Subject: [PATCH 3/3] feat: parse decompressed pubkeys --- .../config/holesky/register_validators.json | 15 +++++++++++++++ bolt-contracts/config/holesky/validators.json | 17 ----------------- .../holesky/validators/RegisterValidators.s.sol | 17 ++++++----------- 3 files changed, 21 insertions(+), 28 deletions(-) create mode 100644 bolt-contracts/config/holesky/register_validators.json delete mode 100644 bolt-contracts/config/holesky/validators.json diff --git a/bolt-contracts/config/holesky/register_validators.json b/bolt-contracts/config/holesky/register_validators.json new file mode 100644 index 000000000..581a2da3e --- /dev/null +++ b/bolt-contracts/config/holesky/register_validators.json @@ -0,0 +1,15 @@ +{ + "boltValidators": "0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984", + "maxCommittedGasLimit": 10000000, + "authorizedOperator": "0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984", + "pubkeys": [ + { + "x": [1, 2], + "y": [3, 4] + }, + { + "x": [5, 6], + "y": [7, 8] + } + ] +} diff --git a/bolt-contracts/config/holesky/validators.json b/bolt-contracts/config/holesky/validators.json deleted file mode 100644 index 9fbdc2c1b..000000000 --- a/bolt-contracts/config/holesky/validators.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "boltValidators": "0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984", - "maxCommittedGasLimit": 10000000, - "authorizedOperator": "0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984", - "pubkeys": [ - "0xa995029d6fc41241acc4a18621204ad11db196986f44789f564652350d50b3bb995b224e998f8338f7e17620ea80531d", - "0xa9b4faba4a513626249f17e46152f1760a4616118c49694634ea0b6fde16629a064a485ec44957e41c1cc2cc33aad98e", - "0x902c8589f286f3dfc0d74775fcd8d1a580313a0711d68ecb9212eb94208cfd797bf67742adb46aee84bc67b902041326", - "0x84cb3155459fa1bda073199e1270119ddf714cd9f435c43507a287a46f334cf5937d45154b05ba3589c251845b07235f", - "0xb9048c8e89d4586f9f63152e0cb8b1b76f7392a1fc30c30eb6f9ece4a2e7b1b3ea045fecf72ae0e0a8e42a9beca2d908", - "0x81c51f8f7ad4b11d972e1fdae4702edb0b42531c4f366451962bd6097845952d136e441ec03f7cb1f463e37c2bffd1a9", - "0xa9d93a373ed9e42625b00437481eb5451f30bc23c169eca61a7d7cb55a7d517719b2f4764d9849cc220586ce3805ee4a", - "0x8c9b8ff21f6aec6c3c80df64f6afb71cdd3e566cff3d04d6fb679b3f0e4b32c85763fd78de6425df4062cad08687cbc2", - "0x977cea163cbf5e490573f46091c0e06f1961a7e277a6d923d50217dafa5963313e3c7a803691f71a724a308ccc261f30", - "0xa922472f3382bf6e0e157daaa05958cbcfd6cd00d11c6a4702d3818627b49e146af7002778174c123555a93afe0b7e9e" - ] -} diff --git a/bolt-contracts/script/holesky/validators/RegisterValidators.s.sol b/bolt-contracts/script/holesky/validators/RegisterValidators.s.sol index 2fbf4d783..31b5e8180 100644 --- a/bolt-contracts/script/holesky/validators/RegisterValidators.s.sol +++ b/bolt-contracts/script/holesky/validators/RegisterValidators.s.sol @@ -38,17 +38,12 @@ contract RegisterValidators is Script { string memory path = string.concat(root, "/config/holesky/register_validators.json"); string memory json = vm.readFile(path); - config.boltValidators = vm.parseJsonAddress(json, "boltValidators"); - config.authorizedOperator = vm.parseJsonAddress(json, "authorizedOperator"); - config.maxCommittedGasLimit = uint128(vm.parseJsonUint(json, "maxCommittedGasLimit")); - - string[] memory pubkeysRaw = vm.parseJsonStringArray(json, "pubkeys"); - BLS12381.G1Point[] memory pubkeys = new BLS12381.G1Point[](pubkeysRaw.length); - for (uint256 i = 0; i < pubkeysRaw.length; i++) { - uint256[2] memory x = [uint256(0), uint256(0)]; - uint256[2] memory y = [uint256(0), uint256(0)]; - pubkeys[i] = BLS12381.G1Point(x, y); - } + config.boltValidators = vm.parseJsonAddress(json, ".boltValidators"); + config.authorizedOperator = vm.parseJsonAddress(json, ".authorizedOperator"); + config.maxCommittedGasLimit = uint128(vm.parseJsonUint(json, ".maxCommittedGasLimit")); + + bytes memory pubkeysRaw = vm.parseJson(json, ".pubkeys"); + BLS12381.G1Point[] memory pubkeys = abi.decode(pubkeysRaw, (BLS12381.G1Point[])); config.pubkeys = pubkeys; } }