@@ -3,11 +3,11 @@ pragma solidity ^0.8.27;
33
44import "@openzeppelin-upgrades/contracts/proxy/utils/Initializable.sol " ;
55
6- import {BN254} from "../libraries/BN254.sol " ;
7- import {BN254SignatureVerifier} from "../libraries/BN254SignatureVerifier.sol " ;
8- import {Merkle} from "../libraries/Merkle.sol " ;
9- import {OperatorSet} from "../libraries/OperatorSetLib.sol " ;
10-
6+ import "../libraries/BN254.sol " ;
7+ import "../libraries/BN254SignatureVerifier.sol " ;
8+ import "../libraries/Merkle.sol " ;
9+ import "../libraries/OperatorSetLib.sol " ;
10+ import " ../mixins/SemVerMixin.sol " ;
1111import "./BN254CertificateVerifierStorage.sol " ;
1212
1313/**
@@ -16,7 +16,7 @@ import "./BN254CertificateVerifierStorage.sol";
1616 * @dev This contract uses BN254 curves for signature verification and
1717 * caches operator information for efficient verification
1818 */
19- contract BN254CertificateVerifier is Initializable , BN254CertificateVerifierStorage {
19+ contract BN254CertificateVerifier is Initializable , BN254CertificateVerifierStorage , SemVerMixin {
2020 using Merkle for bytes ;
2121 using BN254 for BN254.G1Point;
2222
@@ -42,36 +42,20 @@ contract BN254CertificateVerifier is Initializable, BN254CertificateVerifierStor
4242 * @notice Constructor for the certificate verifier
4343 * @dev Disables initializers to prevent implementation initialization
4444 * @param _operatorTableUpdater Address authorized to update operator tables
45+ * @param _version The semantic version of the contract
4546 */
4647 constructor (
47- IOperatorTableUpdater _operatorTableUpdater
48- ) BN254CertificateVerifierStorage (_operatorTableUpdater) {
48+ IOperatorTableUpdater _operatorTableUpdater ,
49+ string memory _version
50+ ) BN254CertificateVerifierStorage (_operatorTableUpdater) SemVerMixin (_version) {
4951 _disableInitializers ();
5052 }
5153
52- ///@inheritdoc IBaseCertificateVerifier
53- function getOperatorSetOwner (
54- OperatorSet memory operatorSet
55- ) external view returns (address ) {
56- bytes32 operatorSetKey = operatorSet.key ();
57- return _operatorSetOwners[operatorSetKey];
58- }
59-
60- ///@inheritdoc IBaseCertificateVerifier
61- function maxOperatorTableStaleness (
62- OperatorSet memory operatorSet
63- ) external view returns (uint32 ) {
64- bytes32 operatorSetKey = operatorSet.key ();
65- return _maxStalenessPeriods[operatorSetKey];
66- }
67-
68- ///@inheritdoc IBaseCertificateVerifier
69- function latestReferenceTimestamp (
70- OperatorSet memory operatorSet
71- ) external view returns (uint32 ) {
72- bytes32 operatorSetKey = operatorSet.key ();
73- return _latestReferenceTimestamps[operatorSetKey];
74- }
54+ /**
55+ *
56+ * EXTERNAL FUNCTIONS
57+ *
58+ */
7559
7660 ///@inheritdoc IBN254CertificateVerifier
7761 function updateOperatorTable (
@@ -148,21 +132,13 @@ contract BN254CertificateVerifier is Initializable, BN254CertificateVerifierStor
148132 return true ;
149133 }
150134
151- /**
152- * @notice Attempts signature verification with gas limit for safety
153- * @param msgHash The message hash that was signed
154- * @param aggPubkey The aggregate public key of signers
155- * @param apkG2 The G2 point representation of the aggregate public key
156- * @param signature The BLS signature to verify
157- * @return pairingSuccessful Whether the pairing operation completed successfully
158- * @return signatureValid Whether the signature is valid
159- */
135+ ///@inheritdoc IBN254CertificateVerifier
160136 function trySignatureVerification (
161137 bytes32 msgHash ,
162138 BN254.G1Point memory aggPubkey ,
163139 BN254.G2Point memory apkG2 ,
164140 BN254.G1Point memory signature
165- ) internal view returns (bool pairingSuccessful , bool signatureValid ) {
141+ ) public view returns (bool pairingSuccessful , bool signatureValid ) {
166142 return BN254SignatureVerifier.verifySignature (
167143 msgHash,
168144 signature,
@@ -173,6 +149,12 @@ contract BN254CertificateVerifier is Initializable, BN254CertificateVerifierStor
173149 );
174150 }
175151
152+ /**
153+ *
154+ * INTERNAL FUNCTIONS
155+ *
156+ */
157+
176158 /**
177159 * @notice Internal function to verify a certificate
178160 * @param operatorSet The operator set the certificate is for
@@ -232,7 +214,7 @@ contract BN254CertificateVerifier is Initializable, BN254CertificateVerifierStor
232214 require (witness.operatorIndex < ctx.operatorSetInfo.numOperators, InvalidOperatorIndex ());
233215
234216 BN254OperatorInfo memory operatorInfo =
235- _getOrCacheOperatorInfo (ctx.operatorSetKey, cert.referenceTimestamp, witness);
217+ _getOrCacheNonsignerOperatorInfo (ctx.operatorSetKey, cert.referenceTimestamp, witness);
236218
237219 nonSignerApk = nonSignerApk.plus (operatorInfo.pubkey);
238220
@@ -252,12 +234,12 @@ contract BN254CertificateVerifier is Initializable, BN254CertificateVerifierStor
252234 * @param witness The operator info witness containing proof data
253235 * @return operatorInfo The verified operator information
254236 */
255- function _getOrCacheOperatorInfo (
237+ function _getOrCacheNonsignerOperatorInfo (
256238 bytes32 operatorSetKey ,
257239 uint32 referenceTimestamp ,
258240 BN254OperatorInfoWitness memory witness
259241 ) internal returns (BN254OperatorInfo memory operatorInfo ) {
260- BN254OperatorInfo storage cachedInfo = _operatorInfos[operatorSetKey][referenceTimestamp][witness.operatorIndex];
242+ BN254OperatorInfo memory cachedInfo = _operatorInfos[operatorSetKey][referenceTimestamp][witness.operatorIndex];
261243
262244 // Check if operator info is cached using pubkey existence (weights can be 0)
263245 bool isInfoCached = (cachedInfo.pubkey.X != 0 || cachedInfo.pubkey.Y != 0 );
@@ -317,13 +299,13 @@ contract BN254CertificateVerifier is Initializable, BN254CertificateVerifierStor
317299 }
318300
319301 /**
320- * @notice Get cached operator info
321- * @param operatorSet The operator set
322- * @param referenceTimestamp The reference timestamp
323- * @param operatorIndex The operator index
324- * @return The cached operator info
302+ *
303+ * VIEW FUNCTIONS
304+ *
325305 */
326- function getOperatorInfo (
306+
307+ ///@inheritdoc IBN254CertificateVerifier
308+ function getNonsignerOperatorInfo (
327309 OperatorSet memory operatorSet ,
328310 uint32 referenceTimestamp ,
329311 uint256 operatorIndex
@@ -332,12 +314,19 @@ contract BN254CertificateVerifier is Initializable, BN254CertificateVerifierStor
332314 return _operatorInfos[operatorSetKey][referenceTimestamp][operatorIndex];
333315 }
334316
335- /**
336- * @notice Get operator set info for a timestamp
337- * @param operatorSet The operator set
338- * @param referenceTimestamp The reference timestamp
339- * @return The operator set info
340- */
317+ ///@inheritdoc IBN254CertificateVerifier
318+ function isNonsignerCached (
319+ OperatorSet memory operatorSet ,
320+ uint32 referenceTimestamp ,
321+ uint256 operatorIndex
322+ ) external view returns (bool ) {
323+ bytes32 operatorSetKey = operatorSet.key ();
324+ BN254OperatorInfo memory operatorInfo = _operatorInfos[operatorSetKey][referenceTimestamp][operatorIndex];
325+ // Check if operator info is cached using pubkey existence (weights can be 0)
326+ return operatorInfo.pubkey.X != 0 && operatorInfo.pubkey.Y != 0 ;
327+ }
328+
329+ ///@inheritdoc IBN254CertificateVerifier
341330 function getOperatorSetInfo (
342331 OperatorSet memory operatorSet ,
343332 uint32 referenceTimestamp
@@ -346,9 +335,27 @@ contract BN254CertificateVerifier is Initializable, BN254CertificateVerifierStor
346335 return _operatorSetInfos[operatorSetKey][referenceTimestamp];
347336 }
348337
349- /// @dev Only used in a test environment
350- function setMaxStalenessPeriod (OperatorSet memory operatorSet , uint32 maxStalenessPeriod ) external {
338+ ///@inheritdoc IBaseCertificateVerifier
339+ function getOperatorSetOwner (
340+ OperatorSet memory operatorSet
341+ ) external view returns (address ) {
342+ bytes32 operatorSetKey = operatorSet.key ();
343+ return _operatorSetOwners[operatorSetKey];
344+ }
345+
346+ ///@inheritdoc IBaseCertificateVerifier
347+ function maxOperatorTableStaleness (
348+ OperatorSet memory operatorSet
349+ ) external view returns (uint32 ) {
351350 bytes32 operatorSetKey = operatorSet.key ();
352- _maxStalenessPeriods[operatorSetKey] = maxStalenessPeriod;
351+ return _maxStalenessPeriods[operatorSetKey];
352+ }
353+
354+ ///@inheritdoc IBaseCertificateVerifier
355+ function latestReferenceTimestamp (
356+ OperatorSet memory operatorSet
357+ ) external view returns (uint32 ) {
358+ bytes32 operatorSetKey = operatorSet.key ();
359+ return _latestReferenceTimestamps[operatorSetKey];
353360 }
354361}
0 commit comments