-
Notifications
You must be signed in to change notification settings - Fork 331
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #102 from Layr-Labs/test-sig-checker
Test sig checker
- Loading branch information
Showing
9 changed files
with
591 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
pragma solidity =0.8.12; | ||
|
||
import "../interfaces/IBLSRegistryCoordinatorWithIndices.sol"; | ||
import "../libraries/MiddlewareUtils.sol"; | ||
import "../libraries/BN254.sol"; | ||
import "../libraries/BitmapUtils.sol"; | ||
|
||
/** | ||
* @title Used for checking BLS aggregate signatures from the operators of a EigenLayer AVS with the RegistryCoordinator/BLSPubkeyRegistry/StakeRegistry architechture. | ||
* @author Layr Labs, Inc. | ||
* @notice Terms of Service: https://docs.eigenlayer.xyz/overview/terms-of-service | ||
* @notice This is the contract for checking the validity of aggregate operator signatures. | ||
*/ | ||
interface IBLSSignatureChecker { | ||
// DATA STRUCTURES | ||
|
||
struct NonSignerStakesAndSignature { | ||
uint32[] nonSignerQuorumBitmapIndices; | ||
BN254.G1Point[] nonSignerPubkeys; | ||
BN254.G1Point[] quorumApks; | ||
BN254.G2Point apkG2; | ||
BN254.G1Point sigma; | ||
uint32[] quorumApkIndices; | ||
uint32[] totalStakeIndices; | ||
uint32[][] nonSignerStakeIndices; // nonSignerStakeIndices[quorumNumberIndex][nonSignerIndex] | ||
} | ||
|
||
/** | ||
* @notice this data structure is used for recording the details on the total stake of the registered | ||
* operators and those operators who are part of the quorum for a particular taskNumber | ||
*/ | ||
|
||
struct QuorumStakeTotals { | ||
// total stake of the operators in each quorum | ||
uint96[] signedStakeForQuorum; | ||
// total amount staked by all operators in each quorum | ||
uint96[] totalStakeForQuorum; | ||
} | ||
|
||
// CONSTANTS & IMMUTABLES | ||
|
||
function registryCoordinator() external view returns (IRegistryCoordinator); | ||
function stakeRegistry() external view returns (IStakeRegistry); | ||
function blsPubkeyRegistry() external view returns (IBLSPubkeyRegistry); | ||
|
||
/** | ||
* @notice This function is called by disperser when it has aggregated all the signatures of the operators | ||
* that are part of the quorum for a particular taskNumber and is asserting them into onchain. The function | ||
* checks that the claim for aggregated signatures are valid. | ||
* | ||
* The thesis of this procedure entails: | ||
* - getting the aggregated pubkey of all registered nodes at the time of pre-commit by the | ||
* disperser (represented by apk in the parameters), | ||
* - subtracting the pubkeys of all the signers not in the quorum (nonSignerPubkeys) and storing | ||
* the output in apk to get aggregated pubkey of all operators that are part of quorum. | ||
* - use this aggregated pubkey to verify the aggregated signature under BLS scheme. | ||
* | ||
* @dev Before signature verification, the function verifies operator stake information. This includes ensuring that the provided `referenceBlockNumber` | ||
* is correct, i.e., ensure that the stake returned from the specified block number is recent enough and that the stake is either the most recent update | ||
* for the total stake (or the operator) or latest before the referenceBlockNumber. | ||
*/ | ||
function checkSignatures( | ||
bytes32 msgHash, | ||
bytes calldata quorumNumbers, | ||
uint32 referenceBlockNumber, | ||
NonSignerStakesAndSignature memory nonSignerStakesAndSignature | ||
) | ||
external | ||
view | ||
returns ( | ||
QuorumStakeTotals memory, | ||
bytes32 | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/test/harnesses/BLSRegistryCoordinatorWithIndicesHarness.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
pragma solidity =0.8.12; | ||
|
||
import "../../contracts/middleware/BLSRegistryCoordinatorWithIndices.sol"; | ||
|
||
// wrapper around the BLSRegistryCoordinatorWithIndices contract that exposes the internal functions for unit testing. | ||
contract BLSRegistryCoordinatorWithIndicesHarness is BLSRegistryCoordinatorWithIndices { | ||
constructor( | ||
ISlasher _slasher, | ||
IServiceManager _serviceManager, | ||
IStakeRegistry _stakeRegistry, | ||
IBLSPubkeyRegistry _blsPubkeyRegistry, | ||
IIndexRegistry _indexRegistry | ||
) BLSRegistryCoordinatorWithIndices(_slasher, _serviceManager, _stakeRegistry, _blsPubkeyRegistry, _indexRegistry) { | ||
} | ||
|
||
function recordOperatorQuorumBitmapUpdate(bytes32 operatorId, uint192 quorumBitmap) external { | ||
uint256 operatorQuorumBitmapHistoryLength = _operatorIdToQuorumBitmapHistory[operatorId].length; | ||
if (operatorQuorumBitmapHistoryLength != 0) { | ||
_operatorIdToQuorumBitmapHistory[operatorId][operatorQuorumBitmapHistoryLength - 1].nextUpdateBlockNumber = uint32(block.number); | ||
} | ||
|
||
_operatorIdToQuorumBitmapHistory[operatorId].push(QuorumBitmapUpdate({ | ||
updateBlockNumber: uint32(block.number), | ||
nextUpdateBlockNumber: 0, | ||
quorumBitmap: quorumBitmap | ||
})); | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.