Skip to content

Commit

Permalink
Merge branch 'm2-mainnet' into stevennevins-patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
stevennevins authored Dec 8, 2023
2 parents 4fe9799 + 7cb2d09 commit 51443d2
Show file tree
Hide file tree
Showing 21 changed files with 258 additions and 265 deletions.
6 changes: 3 additions & 3 deletions script/DeploySharedContracts.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity =0.8.12;

import "../src/BLSPublicKeyCompendium.sol";
import "../src/BLSOperatorStateRetriever.sol";
import "../src/OperatorStateRetriever.sol";

import "forge-std/Script.sol";
import "forge-std/Test.sol";
Expand All @@ -16,12 +16,12 @@ contract DeploySharedContracts is Script, Test {
Vm cheats = Vm(HEVM_ADDRESS);

BLSPublicKeyCompendium public blsPublicKeyCompendium;
BLSOperatorStateRetriever public blsOperatorStateRetriever;
OperatorStateRetriever public blsOperatorStateRetriever;

function run() external {
vm.startBroadcast();
blsPublicKeyCompendium = new BLSPublicKeyCompendium();
blsOperatorStateRetriever = new BLSOperatorStateRetriever();
blsOperatorStateRetriever = new OperatorStateRetriever();
vm.stopBroadcast();

string memory deployed_addresses = "addresses";
Expand Down
18 changes: 9 additions & 9 deletions src/BLSPubkeyRegistry.sol → src/BLSApkRegistry.sol
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.8.12;

import {BLSPubkeyRegistryStorage} from "src/BLSPubkeyRegistryStorage.sol";
import {BLSApkRegistryStorage} from "src/BLSApkRegistryStorage.sol";

import {IBLSPublicKeyCompendium} from "src/interfaces/IBLSPublicKeyCompendium.sol";
import {IRegistryCoordinator} from "src/interfaces/IRegistryCoordinator.sol";

import {BN254} from "src/libraries/BN254.sol";

contract BLSPubkeyRegistry is BLSPubkeyRegistryStorage {
contract BLSApkRegistry is BLSApkRegistryStorage {
using BN254 for BN254.G1Point;

/// @notice when applied to a function, only allows the RegistryCoordinator to call it
modifier onlyRegistryCoordinator() {
require(
msg.sender == address(registryCoordinator),
"BLSPubkeyRegistry.onlyRegistryCoordinator: caller is not the registry coordinator"
"BLSApkRegistry.onlyRegistryCoordinator: caller is not the registry coordinator"
);
_;
}
Expand All @@ -24,7 +24,7 @@ contract BLSPubkeyRegistry is BLSPubkeyRegistryStorage {
constructor(
IRegistryCoordinator _registryCoordinator,
IBLSPublicKeyCompendium _pubkeyCompendium
) BLSPubkeyRegistryStorage(_registryCoordinator, _pubkeyCompendium) {}
) BLSApkRegistryStorage(_registryCoordinator, _pubkeyCompendium) {}

/*******************************************************************************
EXTERNAL FUNCTIONS - REGISTRY COORDINATOR
Expand Down Expand Up @@ -86,7 +86,7 @@ contract BLSPubkeyRegistry is BLSPubkeyRegistryStorage {
* @param quorumNumber The number of the new quorum
*/
function initializeQuorum(uint8 quorumNumber) public virtual onlyRegistryCoordinator {
require(apkHistory[quorumNumber].length == 0, "BLSPubkeyRegistry.initializeQuorum: quorum already exists");
require(apkHistory[quorumNumber].length == 0, "BLSApkRegistry.initializeQuorum: quorum already exists");

apkHistory[quorumNumber].push(ApkUpdate({
apkHash: bytes24(0),
Expand All @@ -106,7 +106,7 @@ contract BLSPubkeyRegistry is BLSPubkeyRegistryStorage {
// Validate quorum exists and get history length
uint8 quorumNumber = uint8(quorumNumbers[i]);
uint256 historyLength = apkHistory[quorumNumber].length;
require(historyLength != 0, "BLSPubkeyRegistry._processQuorumApkUpdate: quorum does not exist");
require(historyLength != 0, "BLSApkRegistry._processQuorumApkUpdate: quorum does not exist");

// Update aggregate public key for this quorum
newApk = currentApk[quorumNumber].plus(point);
Expand All @@ -133,15 +133,15 @@ contract BLSPubkeyRegistry is BLSPubkeyRegistryStorage {
function _validateApkHashAtBlockNumber(ApkUpdate memory apkUpdate, uint32 blockNumber) internal pure {
require(
blockNumber >= apkUpdate.updateBlockNumber,
"BLSPubkeyRegistry._validateApkHashAtBlockNumber: index too recent"
"BLSApkRegistry._validateApkHashAtBlockNumber: index too recent"
);
/**
* if there is a next update, check that the blockNumber is before the next update or if
* there is no next update, then apkUpdate.nextUpdateBlockNumber is 0.
*/
require(
apkUpdate.nextUpdateBlockNumber == 0 || blockNumber < apkUpdate.nextUpdateBlockNumber,
"BLSPubkeyRegistry._validateApkHashAtBlockNumber: not latest apk update"
"BLSApkRegistry._validateApkHashAtBlockNumber: not latest apk update"
);
}

Expand All @@ -164,7 +164,7 @@ contract BLSPubkeyRegistry is BLSPubkeyRegistryStorage {

if (quorumApkUpdatesLength == 0 || blockNumber < apkHistory[quorumNumber][0].updateBlockNumber) {
revert(
"BLSPubkeyRegistry.getApkIndicesAtBlockNumber: blockNumber is before the first update"
"BLSApkRegistry.getApkIndicesAtBlockNumber: blockNumber is before the first update"
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.8.12;

import {IBLSPubkeyRegistry} from "src/interfaces/IBLSPubkeyRegistry.sol";
import {IBLSApkRegistry} from "src/interfaces/IBLSApkRegistry.sol";
import {IRegistryCoordinator} from "src/interfaces/IRegistryCoordinator.sol";
import {IBLSPublicKeyCompendium} from "src/interfaces/IBLSPublicKeyCompendium.sol";
import {BN254} from "src/libraries/BN254.sol";

import {Initializable} from "@openzeppelin-upgrades/contracts/proxy/utils/Initializable.sol";

abstract contract BLSPubkeyRegistryStorage is Initializable, IBLSPubkeyRegistry {
import {BN254} from "src/libraries/BN254.sol";

abstract contract BLSApkRegistryStorage is Initializable, IBLSApkRegistry {
/// @notice the registry coordinator contract
IRegistryCoordinator public immutable registryCoordinator;
/// @notice the BLSPublicKeyCompendium contract against which pubkey ownership is checked
Expand Down
11 changes: 5 additions & 6 deletions src/BLSSignatureChecker.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.8.12;

import {IBLSRegistryCoordinatorWithIndices} from "src/interfaces/IBLSRegistryCoordinatorWithIndices.sol";
import {IBLSSignatureChecker} from "src/interfaces/IBLSSignatureChecker.sol";
import {IRegistryCoordinator} from "src/interfaces/IRegistryCoordinator.sol";
import {IBLSPubkeyRegistry} from "src/interfaces/IBLSPubkeyRegistry.sol";
import {IBLSApkRegistry} from "src/interfaces/IBLSApkRegistry.sol";
import {IStakeRegistry} from "src/interfaces/IStakeRegistry.sol";

import {BitmapUtils} from "src/libraries/BitmapUtils.sol";
Expand All @@ -26,12 +25,12 @@ contract BLSSignatureChecker is IBLSSignatureChecker {

IRegistryCoordinator public immutable registryCoordinator;
IStakeRegistry public immutable stakeRegistry;
IBLSPubkeyRegistry public immutable blsPubkeyRegistry;
IBLSApkRegistry public immutable blsApkRegistry;

constructor(IBLSRegistryCoordinatorWithIndices _registryCoordinator) {
constructor(IRegistryCoordinator _registryCoordinator) {
registryCoordinator = IRegistryCoordinator(_registryCoordinator);
stakeRegistry = _registryCoordinator.stakeRegistry();
blsPubkeyRegistry = _registryCoordinator.blsPubkeyRegistry();
blsApkRegistry = _registryCoordinator.blsApkRegistry();
}

/**
Expand Down Expand Up @@ -75,7 +74,7 @@ contract BLSSignatureChecker is IBLSSignatureChecker {
for (uint i = 0; i < quorumNumbers.length; i++) {
require(
bytes24(nonSignerStakesAndSignature.quorumApks[i].hashG1Point()) ==
IBLSPubkeyRegistry(blsPubkeyRegistry).getApkHashAtBlockNumberAndIndex(
blsApkRegistry.getApkHashAtBlockNumberAndIndex(
uint8(quorumNumbers[i]),
referenceBlockNumber,
nonSignerStakesAndSignature.quorumApkIndices[i]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.8.12;

import {IBLSRegistryCoordinatorWithIndices} from "src/interfaces/IBLSRegistryCoordinatorWithIndices.sol";
import {IBLSPubkeyRegistry} from "src/interfaces/IBLSPubkeyRegistry.sol";
import {IRegistryCoordinator} from "src/interfaces/IRegistryCoordinator.sol";
import {IBLSApkRegistry} from "src/interfaces/IBLSApkRegistry.sol";
import {IStakeRegistry} from "src/interfaces/IStakeRegistry.sol";
import {IIndexRegistry} from "src/interfaces/IIndexRegistry.sol";

import {BitmapUtils} from "src/libraries/BitmapUtils.sol";

/**
* @title BLSOperatorStateRetriever with view functions that allow to retrieve the state of an AVSs registry system.
* @title OperatorStateRetriever with view functions that allow to retrieve the state of an AVSs registry system.
* @author Layr Labs Inc.
*/
contract BLSOperatorStateRetriever {
contract OperatorStateRetriever {
struct Operator {
bytes32 operatorId;
uint96 stake;
Expand All @@ -37,7 +37,7 @@ contract BLSOperatorStateRetriever {
* was a part of at `blockNumber`, an ordered list of operators.
*/
function getOperatorState(
IBLSRegistryCoordinatorWithIndices registryCoordinator,
IRegistryCoordinator registryCoordinator,
bytes32 operatorId,
uint32 blockNumber
) external view returns (uint256, Operator[][] memory) {
Expand All @@ -61,7 +61,7 @@ contract BLSOperatorStateRetriever {
* @return 2d array of operators. For each quorum, an ordered list of operators
*/
function getOperatorState(
IBLSRegistryCoordinatorWithIndices registryCoordinator,
IRegistryCoordinator registryCoordinator,
bytes memory quorumNumbers,
uint32 blockNumber
) public view returns(Operator[][] memory) {
Expand Down Expand Up @@ -100,7 +100,7 @@ contract BLSOperatorStateRetriever {
* 4) the indices of the quorum apks for each of the provided quorums at the given blocknumber
*/
function getCheckSignaturesIndices(
IBLSRegistryCoordinatorWithIndices registryCoordinator,
IRegistryCoordinator registryCoordinator,
uint32 referenceBlockNumber,
bytes calldata quorumNumbers,
bytes32[] calldata nonSignerOperatorIds
Expand Down Expand Up @@ -148,9 +148,9 @@ contract BLSOperatorStateRetriever {
checkSignaturesIndices.nonSignerStakeIndices[quorumNumberIndex] = nonSignerStakeIndicesForQuorum;
}

IBLSPubkeyRegistry blsPubkeyRegistry = registryCoordinator.blsPubkeyRegistry();
IBLSApkRegistry blsApkRegistry = registryCoordinator.blsApkRegistry();
// get the indices of the quorum apks for each of the provided quorums at the given blocknumber
checkSignaturesIndices.quorumApkIndices = blsPubkeyRegistry.getApkIndicesAtBlockNumber(quorumNumbers, referenceBlockNumber);
checkSignaturesIndices.quorumApkIndices = blsApkRegistry.getApkIndicesAtBlockNumber(quorumNumbers, referenceBlockNumber);

return checkSignaturesIndices;
}
Expand Down
Loading

0 comments on commit 51443d2

Please sign in to comment.