Skip to content

Commit

Permalink
sm interface
Browse files Browse the repository at this point in the history
  • Loading branch information
0x0aa0 committed Jan 5, 2024
1 parent c94e852 commit 0f1a5ca
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 57 deletions.
2 changes: 1 addition & 1 deletion contracts/lib/eigenlayer-contracts
2 changes: 1 addition & 1 deletion contracts/lib/eigenlayer-middleware
Submodule eigenlayer-middleware updated 82 files
+34 −0 .github/ISSUE_TEMPLATE/bug_report.md
+30 −0 .github/ISSUE_TEMPLATE/design.md
+24 −0 .github/ISSUE_TEMPLATE/feature_request.md
+26 −0 .github/ISSUE_TEMPLATE/test.md
+1 −0 .github/workflows/tests.yml
+3 −0 .gitignore
+1 −0 .gitmodules
+0 −2 CONTRIBUTING.md
+39 −79 README.md
+0 −21 docs/BLSOperatorStateRetriever.md
+0 −36 docs/BLSPubkeyRegistry.md
+0 −27 docs/BLSPublicKeyCompendium.md
+0 −86 docs/BLSRegistryCoordinatorWithIndices.md
+185 −29 docs/BLSSignatureChecker.md
+0 −48 docs/IndexRegistry.md
+0 −15 docs/Middleware-registration-operator-flow.md
+152 −0 docs/README.md
+334 −0 docs/RegistryCoordinator.md
+68 −0 docs/ServiceManagerBase.md
+0 −56 docs/StakeRegistry.md
+4 −4 docs/experimental/AVS-Guide.md
+161 −0 docs/registries/BLSApkRegistry.md
+166 −0 docs/registries/IndexRegistry.md
+339 −0 docs/registries/StakeRegistry.md
+3 −0 foundry.toml
+1 −1 lib/eigenlayer-contracts
+0 −2 script/AVSContractsDeploy.s.sol
+9 −12 script/DeploySharedContracts.s.sol
+104 −39 src/BLSApkRegistry.sol
+40 −0 src/BLSApkRegistryStorage.sol
+0 −32 src/BLSPubkeyRegistryStorage.sol
+0 −116 src/BLSPublicKeyCompendium.sol
+167 −90 src/BLSSignatureChecker.sol
+2 −1 src/IndexRegistry.sol
+5 −5 src/IndexRegistryStorage.sol
+12 −12 src/OperatorStateRetriever.sol
+254 −128 src/RegistryCoordinator.sol
+122 −68 src/ServiceManagerBase.sol
+34 −27 src/StakeRegistry.sol
+6 −12 src/StakeRegistryStorage.sol
+66 −16 src/interfaces/IBLSApkRegistry.sol
+0 −49 src/interfaces/IBLSPublicKeyCompendium.sol
+0 −70 src/interfaces/IBLSRegistry.sol
+0 −65 src/interfaces/IBLSRegistryCoordinatorWithIndices.sol
+13 −7 src/interfaces/IBLSSignatureChecker.sol
+1 −1 src/interfaces/IIndexRegistry.sol
+0 −155 src/interfaces/IQuorumRegistry.sol
+1 −3 src/interfaces/IRegistry.sol
+70 −3 src/interfaces/IRegistryCoordinator.sol
+38 −11 src/interfaces/IServiceManager.sol
+1 −5 src/interfaces/IStakeRegistry.sol
+8 −4 src/libraries/BN254.sol
+13 −3 src/libraries/BitmapUtils.sol
+18 −16 test/ffi/BLSPubKeyCompendiumFFI.t.sol
+7 −7 test/ffi/BLSSignatureCheckerFFI.t.sol
+1 −1 test/ffi/util/G2Operations.sol
+21 −0 test/harnesses/BLSApkRegistryHarness.sol
+3 −3 test/harnesses/BitmapUtilsWrapper.sol
+8 −6 test/harnesses/RegistryCoordinatorHarness.t.sol
+3 −4 test/harnesses/StakeRegistryHarness.sol
+188 −0 test/integration/CoreRegistration.t.sol
+0 −63 test/mocks/BLSPublicKeyCompendiumMock.sol
+185 −0 test/mocks/DelegationMock.sol
+0 −39 test/mocks/MiddlewareRegistryMock.sol
+24 −1 test/mocks/RegistryCoordinatorMock.sol
+0 −31 test/mocks/ServiceManagerMock.sol
+4 −5 test/mocks/StakeRegistryMock.sol
+120 −52 test/unit/BLSApkRegistryUnit.t.sol
+0 −80 test/unit/BLSPublicKeyCompendiumUnit.t.sol
+4 −4 test/unit/BLSSignatureCheckerUnit.t.sol
+7 −7 test/unit/BitmapUtils.t.sol
+0 −82 test/unit/DelegationManager.tree
+4 −4 test/unit/IndexRegistryUnit.t.sol
+5 −5 test/unit/OperatorStateRetrieverUnit.t.sol
+128 −70 test/unit/RegistryCoordinatorUnit.t.sol
+21 −31 test/unit/StakeRegistryUnit.t.sol
+8 −12 test/unit/VoteWeigherBaseUnit.t.sol
+6 −6 test/utils/BLSMockAVSDeployer.sol
+81 −64 test/utils/MockAVSDeployer.sol
+8 −8 test/utils/Operators.sol
+2 −2 test/utils/Owners.sol
+14 −14 test/utils/ProofParsing.sol
6 changes: 3 additions & 3 deletions contracts/src/Imports.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Imports used for compiling for bindings for clients

import "eigenlayer-middleware/BLSOperatorStateRetriever.sol";
import "eigenlayer-middleware/BLSPublicKeyCompendium.sol";
import "eigenlayer-middleware/BLSRegistryCoordinatorWithIndices.sol";
import "eigenlayer-middleware/OperatorStateRetriever.sol";
import "eigenlayer-middleware/BLSApkRegistry.sol";
import "eigenlayer-middleware/RegistryCoordinator.sol";
128 changes: 90 additions & 38 deletions contracts/src/core/EigenDAServiceManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ import {Pausable} from "eigenlayer-core/contracts/permissions/Pausable.sol";
import {IStrategyManager} from "eigenlayer-core/contracts/interfaces/IStrategyManager.sol";
import {ISlasher} from "eigenlayer-core/contracts/interfaces/ISlasher.sol";
import {IPauserRegistry} from "eigenlayer-core/contracts/interfaces/IPauserRegistry.sol";
import {BLSSignatureChecker, IBLSRegistryCoordinatorWithIndices} from "eigenlayer-middleware/BLSSignatureChecker.sol";
import {ISignatureUtils} from "eigenlayer-core/contracts/interfaces/ISignatureUtils.sol";

import {BLSSignatureChecker, IRegistryCoordinator} from "eigenlayer-middleware/BLSSignatureChecker.sol";
import {IServiceManager} from "eigenlayer-middleware/interfaces/IServiceManager.sol";
import {IStakeRegistry} from "eigenlayer-middleware/interfaces/IStakeRegistry.sol";
import {BitmapUtils} from "eigenlayer-middleware/libraries/BitmapUtils.sol";
import {EigenDAServiceManagerStorage} from "./EigenDAServiceManagerStorage.sol";
import {EigenDAHasher} from "../libraries/EigenDAHasher.sol";


/**
/**b
* @title Primary entrypoint for procuring services from EigenDA.
* @author Layr Labs, Inc.
* @notice This contract is used for:
Expand Down Expand Up @@ -51,7 +55,7 @@ contract EigenDAServiceManager is Initializable, OwnableUpgradeable, EigenDAServ
}

constructor(
IBLSRegistryCoordinatorWithIndices _registryCoordinator,
IRegistryCoordinator _registryCoordinator,
IStrategyManager _strategyManager,
IDelegationManager _delegationMananger,
ISlasher _slasher
Expand Down Expand Up @@ -134,47 +138,35 @@ contract EigenDAServiceManager is Initializable, OwnableUpgradeable, EigenDAServ
batchId = batchIdMemory + 1;
}

/// @notice Called in the event of challenge resolution, in order to forward a call to the Slasher, which 'freezes' the `operator`.
function freezeOperator(address /*operator*/) external {
revert("EigenDAServiceManager.freezeOperator: not implemented");
// require(
// msg.sender == address(eigenDAChallenge)
// || msg.sender == address(eigenDABombVerifier),
// "EigenDAServiceManager.freezeOperator: Only challenge resolvers can slash operators"
// );
// slasher.freezeOperator(operator);
}

/**
* @notice Called by the Registry in the event of a new registration, to forward a call to the Slasher
* @param operator The operator whose stake is being updated
* @param serveUntilBlock The block until which the stake accounted for in the first update is slashable by this middleware
*/
function recordFirstStakeUpdate(address operator, uint32 serveUntilBlock) external onlyRegistryCoordinator {
// slasher.recordFirstStakeUpdate(operator, serveUntilBlock);
* @notice Forwards a call to EigenLayer's DelegationManager contract to confirm operator registration with the AVS
* @param operator The address of the operator to register.
* @param operatorSignature The signature, salt, and expiry of the operator's signature.
*/
function registerOperatorToAVS(
address operator,
ISignatureUtils.SignatureWithSaltAndExpiry memory operatorSignature
) external {
delegationManager.registerOperatorToAVS(operator, operatorSignature);
}

/**
* @notice Called by the registryCoordinator, in order to forward a call to the Slasher, informing it of a stake update
* @param operator The operator whose stake is being updated
* @param updateBlock The block at which the update is being made
* @param serveUntilBlock The block until which the stake withdrawn from the operator in this update is slashable by this middleware
* @param prevElement The value of the previous element in the linked list of stake updates (generated offchain)
/**
* @notice Forwards a call to EigenLayer's DelegationManager contract to confirm operator deregistration from the AVS
* @param operator The address of the operator to deregister.
*/
function recordStakeUpdate(address operator, uint32 updateBlock, uint32 serveUntilBlock, uint256 prevElement) external onlyRegistryCoordinator {
// slasher.recordStakeUpdate(operator, updateBlock, serveUntilBlock, prevElement);
function deregisterOperatorFromAVS(address operator) external {
delegationManager.deregisterOperatorFromAVS(operator);
}

/**
* @notice Called by the registryCoordinator in the event of deregistration, to forward a call to the Slasher
* @param operator The operator being deregistered
* @param serveUntilBlock The block until which the stake delegated to the operator is slashable by this middleware
*/
function recordLastStakeUpdateAndRevokeSlashingAbility(address operator, uint32 serveUntilBlock) external onlyRegistryCoordinator {
// slasher.recordLastStakeUpdateAndRevokeSlashingAbility(operator, serveUntilBlock);
* @notice Sets the metadata URI for the AVS
* @param _metadataURI is the metadata URI for the AVS
*/
function setMetadataURI(string memory _metadataURI) external onlyOwner() {
metadataURI = _metadataURI;
}

// VIEW FUNCTIONS
/// @notice Returns the current batchId
function taskNumber() external view returns (uint32) {
return batchId;
}
Expand All @@ -184,8 +176,68 @@ contract EigenDAServiceManager is Initializable, OwnableUpgradeable, EigenDAServ
return uint32(block.number) + STORE_DURATION_BLOCKS + BLOCK_STALE_MEASURE;
}

/// @dev need to override function here since its defined in both these contracts
function owner() public view override(OwnableUpgradeable, IServiceManager) returns (address) {
return OwnableUpgradeable.owner();
/**
* @notice Returns the list of strategies that the operator has potentially restaked on the AVS
* @param operator The address of the operator to get restaked strategies for
* @dev This function is intended to be called off-chain
* @dev No guarantee is made on whether the operator has shares for a strategy in a quorum or uniqueness
* of each element in the returned array. The off-chain service should do that validation separately
*/
function getOperatorRestakedStrategies(address operator) external view returns (address[] memory) {
bytes32 operatorId = registryCoordinator.getOperatorId(operator);
uint256 quorumBitmap = registryCoordinator.getCurrentQuorumBitmap(operatorId);
bytes memory quorumBytesArray = BitmapUtils.bitmapToBytesArray(quorumBitmap);

uint256 strategiesLength;
for (uint i = 0; i < quorumBytesArray.length; i++) {
uint8 quorumNumber = uint8(quorumBytesArray[i]);
strategiesLength += stakeRegistry.strategyParamsLength(quorumNumber);
}

address[] memory restakedStrategies = new address[](strategiesLength);
uint256 index;
for (uint i = 0; i < quorumBytesArray.length; i++) {
uint8 quorumNumber = uint8(quorumBytesArray[i]);
uint256 strategyParamsLength = stakeRegistry.strategyParamsLength(quorumNumber);
for (uint j = 0; j < strategyParamsLength; j++) {
IStakeRegistry.StrategyParams memory strategyParams = stakeRegistry.strategyParamsByIndex(quorumNumber, j);
restakedStrategies[index] = address(strategyParams.strategy);
++index;
}
}

return restakedStrategies;
}

/**
* @notice Returns the list of strategies that the AVS supports for restaking
* @dev This function is intended to be called off-chain
* @dev No guarantee is made on uniqueness of each element in the returned array.
* The off-chain service should do that validabution separately
*/
function getRestakeableStrategies() external view returns (address[] memory) {
uint256 quorumBitmap;
uint256 strategiesLength;
for (uint8 i = 0; i < type(uint8).max; i++) {
if(stakeRegistry.minimumStakeForQuorum(i) > 0) {
quorumBitmap = BitmapUtils.setBit(quorumBitmap, i);
strategiesLength += stakeRegistry.strategyParamsLength(i);
}
}

bytes memory quorumBytesArray = BitmapUtils.bitmapToBytesArray(quorumBitmap);
address[] memory restakedStrategies = new address[](strategiesLength);
uint256 index;
for (uint i = 0; i < quorumBytesArray.length; i++) {
uint8 quorumNumber = uint8(quorumBytesArray[i]);
uint256 strategyParamsLength = stakeRegistry.strategyParamsLength(quorumNumber);
for (uint j = 0; j < strategyParamsLength; j++) {
IStakeRegistry.StrategyParams memory strategyParams = stakeRegistry.strategyParamsByIndex(quorumNumber, j);
restakedStrategies[index] = address(strategyParams.strategy);
++index;
}
}

return restakedStrategies;
}
}
3 changes: 3 additions & 0 deletions contracts/src/core/EigenDAServiceManagerStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,7 @@ abstract contract EigenDAServiceManagerStorage is IEigenDAServiceManager {

/// @notice mapping between the batchId to the hash of the metadata of the corresponding Batch
mapping(uint32 => bytes32) public batchIdToBatchMetadataHash;

/// @notice metadata URI for the EigenDA AVS
string public metadataURI;
}
2 changes: 1 addition & 1 deletion contracts/src/interfaces/IEigenDAServiceManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {BN254} from "eigenlayer-middleware/libraries/BN254.sol";
interface IEigenDAServiceManager is IServiceManager, IDelayedService {
// EVENTS

/**b
/**
* @notice Emitted when a Batch is confirmed.
* @param batchHeaderHash The hash of the batch header
* @param batchId The ID for the Batch inside of the specified duration (i.e. *not* the globalBatchId)
Expand Down
4 changes: 1 addition & 3 deletions contracts/test/MockRollup.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ contract MockRollupTest is BLSMockAVSDeployer {
abi.encodeWithSelector(
EigenDAServiceManager.initialize.selector,
pauserRegistry,
serviceManagerOwner,
feePerBytePerTime,
serviceManagerOwner
registryCoordinatorOwner
)
)
)
Expand Down
4 changes: 1 addition & 3 deletions contracts/test/unit/EigenDABlobUtils.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ contract EigenDABlobUtilsUnit is BLSMockAVSDeployer {
abi.encodeWithSelector(
EigenDAServiceManager.initialize.selector,
pauserRegistry,
serviceManagerOwner,
feePerBytePerTime,
serviceManagerOwner
registryCoordinatorOwner
)
)
)
Expand Down
8 changes: 1 addition & 7 deletions contracts/test/unit/EigenDAServiceManagerUnit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ contract EigenDAServiceManagerUnit is BLSMockAVSDeployer {
abi.encodeWithSelector(
EigenDAServiceManager.initialize.selector,
pauserRegistry,
serviceManagerOwner
registryCoordinatorOwner
)
)
)
Expand Down Expand Up @@ -155,12 +155,6 @@ contract EigenDAServiceManagerUnit is BLSMockAVSDeployer {
assertEq(eigenDAServiceManager.batchId(), batchIdToConfirm + 1);
}

function testFreezeOperator_Revert() public {
cheats.expectRevert(bytes("EigenDAServiceManager.freezeOperator: not implemented"));
eigenDAServiceManager.freezeOperator(address(0));
}


function _getHeaderandNonSigners(uint256 _nonSigners, uint256 _pseudoRandomNumber, uint8 _threshold) internal returns (IEigenDAServiceManager.BatchHeader memory, BLSSignatureChecker.NonSignerStakesAndSignature memory) {
// register a bunch of operators
uint256 quorumBitmap = 1;
Expand Down

0 comments on commit 0f1a5ca

Please sign in to comment.