Skip to content

Commit 7b7ec25

Browse files
authored
chore: refactor BLS operator wallet lib (#381)
* test: add utils for testing * chore: fix remappings * chore: formatting * test: add back deployment lib and use operator keys libs * fix: core deployment lib for tests * test: clean up config structs for helper lib * chore: forge fmt * chore: refactor to avoid stack too deep
1 parent 293e919 commit 7b7ec25

6 files changed

+861
-285
lines changed

src/RegistryCoordinator.sol

+10
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,16 @@ contract RegistryCoordinator is IRegistryCoordinator, SlashingRegistryCoordinato
208208
return (1 << quorumCount) - 1;
209209
}
210210

211+
/**
212+
* @notice Returns the message hash that an operator must sign to register their BLS public key.
213+
* @param operator is the address of the operator registering their BLS public key
214+
*/
215+
function calculatePubkeyRegistrationMessageHash(
216+
address operator
217+
) public view returns (bytes32) {
218+
return _hashTypedDataV4(keccak256(abi.encode(PUBKEY_REGISTRATION_TYPEHASH, operator)));
219+
}
220+
211221
/// @dev need to override function here since its defined in both these contracts
212222
function owner()
213223
public

test/unit/RegistryCoordinatorUnit.t.sol

+36-14
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ import {IBLSApkRegistryTypes} from "../../src/interfaces/IBLSApkRegistry.sol";
1212
import {QuorumBitmapHistoryLib} from "../../src/libraries/QuorumBitmapHistoryLib.sol";
1313
import {BitmapUtils} from "../../src/libraries/BitmapUtils.sol";
1414
import {console} from "forge-std/console.sol";
15+
import {
16+
OperatorWalletLib,
17+
SigningKeyOperationsLib,
18+
OperatorKeyOperationsLib,
19+
Operator
20+
} from "../utils/OperatorWalletLib.sol";
1521

1622
contract RegistryCoordinatorUnitTests is MockAVSDeployer {
1723
using BN254 for BN254.G1Point;
@@ -2418,52 +2424,68 @@ contract RegistryCoordinatorUnitTests_AfterMigration is RegistryCoordinatorUnitT
24182424
assertTrue(registryCoordinator.operatorSetsEnabled());
24192425
}
24202426

2427+
///
24212428
function test_M2_Deregister() public {
2422-
vm.skip(true);
2423-
/// Create 2 M2 quorums
24242429
_deployMockEigenLayerAndAVS(2);
24252430

2426-
address operatorToRegister = address(420);
2431+
Operator memory operatorToRegister = OperatorWalletLib.createOperator("4");
24272432

2428-
ISignatureUtils.SignatureWithSaltAndExpiry memory emptySignature = ISignatureUtils
2429-
.SignatureWithSaltAndExpiry({signature: new bytes(0), salt: bytes32(0), expiry: 0});
2433+
/// NOTE: resolves stack too deep
2434+
{
2435+
// Set operator shares for quorum 0
2436+
(IStrategy strategy,) = stakeRegistry.strategyParams(0, 0);
2437+
delegationMock.setOperatorShares(operatorToRegister.key.addr, strategy, 1 ether);
2438+
}
2439+
bytes32 salt = bytes32(uint256(1));
2440+
uint256 expiry = block.timestamp + 1 days;
2441+
bytes32 digestHash = avsDirectory.calculateOperatorAVSRegistrationDigestHash(
2442+
operatorToRegister.key.addr, address(registryCoordinator), salt, expiry
2443+
);
2444+
bytes memory signature = OperatorKeyOperationsLib.sign(operatorToRegister.key, digestHash);
2445+
ISignatureUtils.SignatureWithSaltAndExpiry memory operatorSignature = ISignatureUtils
2446+
.SignatureWithSaltAndExpiry({signature: signature, salt: salt, expiry: expiry});
24302447

2448+
bytes32 messageHash =
2449+
registryCoordinator.calculatePubkeyRegistrationMessageHash(operatorToRegister.key.addr);
24312450
IBLSApkRegistryTypes.PubkeyRegistrationParams memory operatorRegisterApkParams =
24322451
IBLSApkRegistryTypes.PubkeyRegistrationParams({
2433-
pubkeyRegistrationSignature: BN254.G1Point({X: 0, Y: 0}),
2434-
pubkeyG1: BN254.G1Point({X: 0, Y: 0}),
2435-
pubkeyG2: BN254.G2Point({X: [uint256(0), uint256(0)], Y: [uint256(0), uint256(0)]})
2452+
pubkeyRegistrationSignature: SigningKeyOperationsLib.sign(
2453+
operatorToRegister.signingKey, messageHash
2454+
),
2455+
pubkeyG1: operatorToRegister.signingKey.publicKeyG1,
2456+
pubkeyG2: operatorToRegister.signingKey.publicKeyG2
24362457
});
24372458

24382459
string memory socket = "socket";
24392460

24402461
// register for quorum 0
2441-
vm.prank(operatorToRegister);
2462+
vm.prank(operatorToRegister.key.addr);
24422463
registryCoordinator.registerOperator(
24432464
new bytes(1), // Convert 0 to bytes1 first
24442465
socket,
24452466
operatorRegisterApkParams,
2446-
emptySignature
2467+
operatorSignature
24472468
);
24482469

24492470
/// migrate to operator sets
2471+
vm.prank(registryCoordinatorOwner);
24502472
registryCoordinator.enableOperatorSets();
24512473

24522474
/// Deregistration for m2 should for the first two operator sets
2453-
vm.prank(defaultOperator);
2475+
vm.prank(operatorToRegister.key.addr);
24542476
registryCoordinator.deregisterOperator(new bytes(1));
24552477

24562478
// Verify operator was deregistered by checking their bitmap is empty
2457-
bytes32 operatorId = registryCoordinator.getOperatorId(operatorToRegister);
2479+
bytes32 operatorId = registryCoordinator.getOperatorId(operatorToRegister.key.addr);
24582480
uint192 bitmap = registryCoordinator.getCurrentQuorumBitmap(operatorId);
24592481
assertEq(bitmap, 0, "Operator bitmap should be empty after deregistration");
24602482

24612483
// Verify operator status is NEVER_REGISTERED
24622484
ISlashingRegistryCoordinatorTypes.OperatorStatus status =
2463-
registryCoordinator.getOperatorStatus(operatorToRegister);
2485+
registryCoordinator.getOperatorStatus(operatorToRegister.key.addr);
24642486
assertEq(
24652487
uint8(status),
2466-
uint8(ISlashingRegistryCoordinatorTypes.OperatorStatus.NEVER_REGISTERED),
2488+
uint8(ISlashingRegistryCoordinatorTypes.OperatorStatus.DEREGISTERED),
24672489
"Operator status should be NEVER_REGISTERED"
24682490
);
24692491
}

0 commit comments

Comments
 (0)