Skip to content

Commit bc1a348

Browse files
committed
chore: forge fmt
1 parent 6797f38 commit bc1a348

File tree

92 files changed

+6176
-4231
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+6176
-4231
lines changed

src/BLSApkRegistry.sol

Lines changed: 104 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ contract BLSApkRegistry is BLSApkRegistryStorage {
2121
IRegistryCoordinator _registryCoordinator
2222
) BLSApkRegistryStorage(_registryCoordinator) {}
2323

24-
/*******************************************************************************
25-
EXTERNAL FUNCTIONS - REGISTRY COORDINATOR
26-
*******************************************************************************/
24+
/**
25+
*
26+
* EXTERNAL FUNCTIONS - REGISTRY COORDINATOR
27+
*
28+
*/
2729

2830
/**
2931
* @notice Registers the `operator`'s pubkey for the specified `quorumNumbers`.
@@ -41,7 +43,7 @@ contract BLSApkRegistry is BLSApkRegistryStorage {
4143
bytes memory quorumNumbers
4244
) public virtual onlyRegistryCoordinator {
4345
// Get the operator's pubkey. Reverts if they have not registered a key
44-
(BN254.G1Point memory pubkey, ) = getRegisteredPubkey(operator);
46+
(BN254.G1Point memory pubkey,) = getRegisteredPubkey(operator);
4547

4648
// Update each quorum's aggregate pubkey
4749
_processQuorumApkUpdate(quorumNumbers, pubkey);
@@ -67,7 +69,7 @@ contract BLSApkRegistry is BLSApkRegistryStorage {
6769
bytes memory quorumNumbers
6870
) public virtual onlyRegistryCoordinator {
6971
// Get the operator's pubkey. Reverts if they have not registered a key
70-
(BN254.G1Point memory pubkey, ) = getRegisteredPubkey(operator);
72+
(BN254.G1Point memory pubkey,) = getRegisteredPubkey(operator);
7173

7274
// Update each quorum's aggregate pubkey
7375
_processQuorumApkUpdate(quorumNumbers, pubkey.negate());
@@ -78,14 +80,21 @@ contract BLSApkRegistry is BLSApkRegistryStorage {
7880
* @notice Initializes a new quorum by pushing its first apk update
7981
* @param quorumNumber The number of the new quorum
8082
*/
81-
function initializeQuorum(uint8 quorumNumber) public virtual onlyRegistryCoordinator {
82-
require(apkHistory[quorumNumber].length == 0, "BLSApkRegistry.initializeQuorum: quorum already exists");
83-
84-
apkHistory[quorumNumber].push(ApkUpdate({
85-
apkHash: bytes24(0),
86-
updateBlockNumber: uint32(block.number),
87-
nextUpdateBlockNumber: 0
88-
}));
83+
function initializeQuorum(
84+
uint8 quorumNumber
85+
) public virtual onlyRegistryCoordinator {
86+
require(
87+
apkHistory[quorumNumber].length == 0,
88+
"BLSApkRegistry.initializeQuorum: quorum already exists"
89+
);
90+
91+
apkHistory[quorumNumber].push(
92+
ApkUpdate({
93+
apkHash: bytes24(0),
94+
updateBlockNumber: uint32(block.number),
95+
nextUpdateBlockNumber: 0
96+
})
97+
);
8998
}
9099

91100
/**
@@ -101,7 +110,8 @@ contract BLSApkRegistry is BLSApkRegistryStorage {
101110
) external onlyRegistryCoordinator returns (bytes32 operatorId) {
102111
bytes32 pubkeyHash = BN254.hashG1Point(params.pubkeyG1);
103112
require(
104-
pubkeyHash != ZERO_PK_HASH, "BLSApkRegistry.registerBLSPublicKey: cannot register zero pubkey"
113+
pubkeyHash != ZERO_PK_HASH,
114+
"BLSApkRegistry.registerBLSPublicKey: cannot register zero pubkey"
105115
);
106116
require(
107117
operatorToPubkeyHash[operator] == bytes32(0),
@@ -113,24 +123,31 @@ contract BLSApkRegistry is BLSApkRegistryStorage {
113123
);
114124

115125
// gamma = h(sigma, P, P', H(m))
116-
uint256 gamma = uint256(keccak256(abi.encodePacked(
117-
params.pubkeyRegistrationSignature.X,
118-
params.pubkeyRegistrationSignature.Y,
119-
params.pubkeyG1.X,
120-
params.pubkeyG1.Y,
121-
params.pubkeyG2.X,
122-
params.pubkeyG2.Y,
123-
pubkeyRegistrationMessageHash.X,
124-
pubkeyRegistrationMessageHash.Y
125-
))) % BN254.FR_MODULUS;
126-
127-
// e(sigma + P * gamma, [-1]_2) = e(H(m) + [1]_1 * gamma, P')
128-
require(BN254.pairing(
129-
params.pubkeyRegistrationSignature.plus(params.pubkeyG1.scalar_mul(gamma)),
130-
BN254.negGeneratorG2(),
131-
pubkeyRegistrationMessageHash.plus(BN254.generatorG1().scalar_mul(gamma)),
132-
params.pubkeyG2
133-
), "BLSApkRegistry.registerBLSPublicKey: either the G1 signature is wrong, or G1 and G2 private key do not match");
126+
uint256 gamma = uint256(
127+
keccak256(
128+
abi.encodePacked(
129+
params.pubkeyRegistrationSignature.X,
130+
params.pubkeyRegistrationSignature.Y,
131+
params.pubkeyG1.X,
132+
params.pubkeyG1.Y,
133+
params.pubkeyG2.X,
134+
params.pubkeyG2.Y,
135+
pubkeyRegistrationMessageHash.X,
136+
pubkeyRegistrationMessageHash.Y
137+
)
138+
)
139+
) % BN254.FR_MODULUS;
140+
141+
// e(sigma + P * gamma, [-1]_2) = e(H(m) + [1]_1 * gamma, P')
142+
require(
143+
BN254.pairing(
144+
params.pubkeyRegistrationSignature.plus(params.pubkeyG1.scalar_mul(gamma)),
145+
BN254.negGeneratorG2(),
146+
pubkeyRegistrationMessageHash.plus(BN254.generatorG1().scalar_mul(gamma)),
147+
params.pubkeyG2
148+
),
149+
"BLSApkRegistry.registerBLSPublicKey: either the G1 signature is wrong, or G1 and G2 private key do not match"
150+
);
134151

135152
operatorToPubkey[operator] = params.pubkeyG1;
136153
operatorToPubkeyHash[operator] = pubkeyHash;
@@ -140,18 +157,24 @@ contract BLSApkRegistry is BLSApkRegistryStorage {
140157
return pubkeyHash;
141158
}
142159

143-
/*******************************************************************************
144-
INTERNAL FUNCTIONS
145-
*******************************************************************************/
146-
147-
function _processQuorumApkUpdate(bytes memory quorumNumbers, BN254.G1Point memory point) internal {
160+
/**
161+
*
162+
* INTERNAL FUNCTIONS
163+
*
164+
*/
165+
function _processQuorumApkUpdate(
166+
bytes memory quorumNumbers,
167+
BN254.G1Point memory point
168+
) internal {
148169
BN254.G1Point memory newApk;
149170

150171
for (uint256 i = 0; i < quorumNumbers.length; i++) {
151172
// Validate quorum exists and get history length
152173
uint8 quorumNumber = uint8(quorumNumbers[i]);
153174
uint256 historyLength = apkHistory[quorumNumber].length;
154-
require(historyLength != 0, "BLSApkRegistry._processQuorumApkUpdate: quorum does not exist");
175+
require(
176+
historyLength != 0, "BLSApkRegistry._processQuorumApkUpdate: quorum does not exist"
177+
);
155178

156179
// Update aggregate public key for this quorum
157180
newApk = currentApk[quorumNumber].plus(point);
@@ -165,31 +188,37 @@ contract BLSApkRegistry is BLSApkRegistryStorage {
165188
lastUpdate.apkHash = newApkHash;
166189
} else {
167190
lastUpdate.nextUpdateBlockNumber = uint32(block.number);
168-
apkHistory[quorumNumber].push(ApkUpdate({
169-
apkHash: newApkHash,
170-
updateBlockNumber: uint32(block.number),
171-
nextUpdateBlockNumber: 0
172-
}));
191+
apkHistory[quorumNumber].push(
192+
ApkUpdate({
193+
apkHash: newApkHash,
194+
updateBlockNumber: uint32(block.number),
195+
nextUpdateBlockNumber: 0
196+
})
197+
);
173198
}
174199
}
175200
}
176201

177-
/*******************************************************************************
178-
VIEW FUNCTIONS
179-
*******************************************************************************/
202+
/**
203+
*
204+
* VIEW FUNCTIONS
205+
*
206+
*/
180207
/**
181208
* @notice Returns the pubkey and pubkey hash of an operator
182209
* @dev Reverts if the operator has not registered a valid pubkey
183210
*/
184-
function getRegisteredPubkey(address operator) public view returns (BN254.G1Point memory, bytes32) {
211+
function getRegisteredPubkey(
212+
address operator
213+
) public view returns (BN254.G1Point memory, bytes32) {
185214
BN254.G1Point memory pubkey = operatorToPubkey[operator];
186215
bytes32 pubkeyHash = operatorToPubkeyHash[operator];
187216

188217
require(
189218
pubkeyHash != bytes32(0),
190219
"BLSApkRegistry.getRegisteredPubkey: operator is not registered"
191220
);
192-
221+
193222
return (pubkey, pubkeyHash);
194223
}
195224

@@ -202,13 +231,18 @@ contract BLSApkRegistry is BLSApkRegistryStorage {
202231
uint256 blockNumber
203232
) external view returns (uint32[] memory) {
204233
uint32[] memory indices = new uint32[](quorumNumbers.length);
205-
234+
206235
for (uint256 i = 0; i < quorumNumbers.length; i++) {
207236
uint8 quorumNumber = uint8(quorumNumbers[i]);
208-
237+
209238
uint256 quorumApkUpdatesLength = apkHistory[quorumNumber].length;
210-
if (quorumApkUpdatesLength == 0 || blockNumber < apkHistory[quorumNumber][0].updateBlockNumber) {
211-
revert("BLSApkRegistry.getApkIndicesAtBlockNumber: blockNumber is before the first update");
239+
if (
240+
quorumApkUpdatesLength == 0
241+
|| blockNumber < apkHistory[quorumNumber][0].updateBlockNumber
242+
) {
243+
revert(
244+
"BLSApkRegistry.getApkIndicesAtBlockNumber: blockNumber is before the first update"
245+
);
212246
}
213247

214248
// Loop backward through apkHistory until we find an entry that preceeds `blockNumber`
@@ -223,12 +257,17 @@ contract BLSApkRegistry is BLSApkRegistryStorage {
223257
}
224258

225259
/// @notice Returns the current APK for the provided `quorumNumber `
226-
function getApk(uint8 quorumNumber) external view returns (BN254.G1Point memory) {
260+
function getApk(
261+
uint8 quorumNumber
262+
) external view returns (BN254.G1Point memory) {
227263
return currentApk[quorumNumber];
228264
}
229265

230266
/// @notice Returns the `ApkUpdate` struct at `index` in the list of APK updates for the `quorumNumber`
231-
function getApkUpdateAtIndex(uint8 quorumNumber, uint256 index) external view returns (ApkUpdate memory) {
267+
function getApkUpdateAtIndex(
268+
uint8 quorumNumber,
269+
uint256 index
270+
) external view returns (ApkUpdate memory) {
232271
return apkHistory[quorumNumber][index];
233272
}
234273

@@ -256,26 +295,33 @@ contract BLSApkRegistry is BLSApkRegistryStorage {
256295
"BLSApkRegistry._validateApkHashAtBlockNumber: index too recent"
257296
);
258297
require(
259-
quorumApkUpdate.nextUpdateBlockNumber == 0 || blockNumber < quorumApkUpdate.nextUpdateBlockNumber,
298+
quorumApkUpdate.nextUpdateBlockNumber == 0
299+
|| blockNumber < quorumApkUpdate.nextUpdateBlockNumber,
260300
"BLSApkRegistry._validateApkHashAtBlockNumber: not latest apk update"
261301
);
262302

263303
return quorumApkUpdate.apkHash;
264304
}
265305

266306
/// @notice Returns the length of ApkUpdates for the provided `quorumNumber`
267-
function getApkHistoryLength(uint8 quorumNumber) external view returns (uint32) {
307+
function getApkHistoryLength(
308+
uint8 quorumNumber
309+
) external view returns (uint32) {
268310
return uint32(apkHistory[quorumNumber].length);
269311
}
270312

271313
/// @notice Returns the operator address for the given `pubkeyHash`
272-
function getOperatorFromPubkeyHash(bytes32 pubkeyHash) public view returns (address) {
314+
function getOperatorFromPubkeyHash(
315+
bytes32 pubkeyHash
316+
) public view returns (address) {
273317
return pubkeyHashToOperator[pubkeyHash];
274318
}
275319

276320
/// @notice returns the ID used to identify the `operator` within this AVS
277321
/// @dev Returns zero in the event that the `operator` has never registered for the AVS
278-
function getOperatorId(address operator) public view returns (bytes32) {
322+
function getOperatorId(
323+
address operator
324+
) public view returns (bytes32) {
279325
return operatorToPubkeyHash[operator];
280326
}
281327

src/BLSApkRegistryStorage.sol

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import {BN254} from "./libraries/BN254.sol";
1010

1111
abstract contract BLSApkRegistryStorage is Initializable, IBLSApkRegistry {
1212
/// @notice the hash of the zero pubkey aka BN254.G1Point(0,0)
13-
bytes32 internal constant ZERO_PK_HASH = hex"ad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5";
13+
bytes32 internal constant ZERO_PK_HASH =
14+
hex"ad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5";
1415

1516
/// @notice the registry coordinator contract
1617
address public immutable registryCoordinator;
@@ -29,7 +30,9 @@ abstract contract BLSApkRegistryStorage is Initializable, IBLSApkRegistry {
2930
/// @notice maps quorumNumber => current aggregate pubkey of quorum
3031
mapping(uint8 => BN254.G1Point) public currentApk;
3132

32-
constructor(IRegistryCoordinator _registryCoordinator) {
33+
constructor(
34+
IRegistryCoordinator _registryCoordinator
35+
) {
3336
registryCoordinator = address(_registryCoordinator);
3437
// disable initializers so that the implementation contract cannot be initialized
3538
_disableInitializers();

0 commit comments

Comments
 (0)