@@ -10,13 +10,18 @@ import {BitmapUtils} from "../libraries/BitmapUtils.sol";
10
10
import {BN254} from "../libraries/BN254.sol " ;
11
11
import {BN256G2} from "./BN256G2.sol " ;
12
12
import {OperatorStateRetriever} from "../OperatorStateRetriever.sol " ;
13
+ import {ECUtils} from "./ECUtils.sol " ;
13
14
14
15
/**
15
16
* @title BLSSigCheckOperatorStateRetriever with view functions that allow to retrieve the state of an AVSs registry system.
16
17
* @dev This contract inherits from OperatorStateRetriever and adds the getNonSignerStakesAndSignature function.
17
18
* @author Bread coop
18
19
*/
19
20
contract BLSSigCheckOperatorStateRetriever is OperatorStateRetriever {
21
+ using ECUtils for BN254.G1Point;
22
+ using BN254 for BN254.G1Point;
23
+ using BitmapUtils for uint256 ;
24
+
20
25
/// @dev Thrown when the signature is not on the curve.
21
26
error InvalidSigma ();
22
27
// avoid stack too deep
@@ -61,7 +66,7 @@ contract BLSSigCheckOperatorStateRetriever is OperatorStateRetriever {
61
66
m.blsApkRegistry = registryCoordinator.blsApkRegistry ();
62
67
63
68
// Safe guard AVSs from generating NonSignerStakesAndSignature with invalid sigma
64
- require (_isOnCurve ( sigma), InvalidSigma ());
69
+ require (sigma. isOnCurve ( ), InvalidSigma ());
65
70
66
71
// Compute the g2 APK of the signing operator set
67
72
m.signingOperatorIds = new bytes32 [](operators.length );
@@ -84,13 +89,17 @@ contract BLSSigCheckOperatorStateRetriever is OperatorStateRetriever {
84
89
{
85
90
uint32 [] memory signingOperatorQuorumBitmapIndices = registryCoordinator
86
91
.getQuorumBitmapIndicesAtBlockNumber (blockNumber, m.signingOperatorIds);
92
+ uint256 bitmap = BitmapUtils.orderedBytesArrayToBitmap (quorumNumbers);
87
93
// Check that all operators are registered (this is like the check in getCheckSignaturesIndices, but we check against _signing_ operators)
88
94
for (uint256 i = 0 ; i < operators.length ; i++ ) {
89
95
uint192 signingOperatorQuorumBitmap = registryCoordinator
90
96
.getQuorumBitmapAtBlockNumberByIndex (
91
97
m.signingOperatorIds[i], blockNumber, signingOperatorQuorumBitmapIndices[i]
92
98
);
93
- require (signingOperatorQuorumBitmap != 0 , OperatorNotRegistered ());
99
+ require (
100
+ ! uint256 (signingOperatorQuorumBitmap).noBitsInCommon (bitmap),
101
+ OperatorNotRegistered ()
102
+ );
94
103
}
95
104
}
96
105
@@ -141,12 +150,9 @@ contract BLSSigCheckOperatorStateRetriever is OperatorStateRetriever {
141
150
142
151
// Trim the nonSignerOperatorIds array to the actual count
143
152
bytes32 [] memory trimmedNonSignerOperatorIds = new bytes32 [](nonSignerOperatorsCount);
144
- for (uint256 i = 0 ; i < nonSignerOperatorsCount; i++ ) {
145
- trimmedNonSignerOperatorIds[i] = nonSignerOperatorIds[i];
146
- }
147
-
148
153
BN254.G1Point[] memory nonSignerPubkeys = new BN254.G1Point [](nonSignerOperatorsCount);
149
154
for (uint256 i = 0 ; i < nonSignerOperatorsCount; i++ ) {
155
+ trimmedNonSignerOperatorIds[i] = nonSignerOperatorIds[i];
150
156
address nonSignerOperator =
151
157
registryCoordinator.getOperatorFromId (trimmedNonSignerOperatorIds[i]);
152
158
(nonSignerPubkeys[i],) = m.blsApkRegistry.getRegisteredPubkey (nonSignerOperator);
@@ -184,24 +190,8 @@ contract BLSSigCheckOperatorStateRetriever is OperatorStateRetriever {
184
190
address operator = registryCoordinator.getOperatorFromId (operatorIds[i]);
185
191
BN254.G1Point memory operatorPk;
186
192
(operatorPk.X, operatorPk.Y) = blsApkRegistry.operatorToPubkey (operator);
187
- apk = BN254 .plus (apk, operatorPk);
193
+ apk = apk .plus (operatorPk);
188
194
}
189
195
return apk;
190
196
}
191
-
192
- /**
193
- * @notice Checks if a point lies on the BN254 elliptic curve
194
- * @dev The curve equation is y^2 = x^3 + 3 (mod p)
195
- * @param p The point to check, in G1
196
- * @return true if the point lies on the curve, false otherwise
197
- */
198
- function _isOnCurve (
199
- BN254.G1Point memory p
200
- ) internal pure returns (bool ) {
201
- uint256 y2 = mulmod (p.Y, p.Y, BN254.FP_MODULUS);
202
- uint256 x2 = mulmod (p.X, p.X, BN254.FP_MODULUS);
203
- uint256 x3 = mulmod (p.X, x2, BN254.FP_MODULUS);
204
- uint256 rhs = addmod (x3, 3 , BN254.FP_MODULUS);
205
- return y2 == rhs;
206
- }
207
197
}
0 commit comments