Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2 interfaces #920

Merged
merged 2 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion contracts/script/EigenDADeployer.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import {IBLSApkRegistry} from "eigenlayer-middleware/interfaces/IBLSApkRegistry.
import {EigenDAServiceManager, IAVSDirectory, IRewardsCoordinator} from "../src/core/EigenDAServiceManager.sol";
import {EigenDAHasher} from "../src/libraries/EigenDAHasher.sol";
import {ISocketRegistry, SocketRegistry} from "eigenlayer-middleware/SocketRegistry.sol";
import {IEigenDAThresholdRegistry} from "../src/interfaces/IEigenDAThresholdRegistry.sol";
import {IEigenDARelayRegistry} from "../src/interfaces/IEigenDARelayRegistry.sol";

import {DeployOpenEigenLayer, ProxyAdmin, ERC20PresetFixedSupply, TransparentUpgradeableProxy, IPauserRegistry} from "./DeployOpenEigenLayer.s.sol";
import "forge-std/Test.sol";
Expand Down Expand Up @@ -202,7 +204,9 @@ contract EigenDADeployer is DeployOpenEigenLayer {
avsDirectory,
rewardsCoordinator,
registryCoordinator,
stakeRegistry
stakeRegistry,
IEigenDAThresholdRegistry(address(0)),
IEigenDARelayRegistry(address(0))
);

address[] memory confirmers = new address[](1);
Expand Down
12 changes: 6 additions & 6 deletions contracts/script/GenerateUnitTestHashes.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "../src/interfaces/IEigenDAServiceManager.sol";

import "forge-std/Script.sol";
import "forge-std/console.sol";

import "../src/interfaces/IEigenDAStructs.sol";

// # To generate the hashes needed for core/serialization_test.go:
// forge script script/GenerateUnitTestHashes.s.sol -v
Expand All @@ -18,9 +18,9 @@ contract GenerateHashes is Script {
function run() external {


IEigenDAServiceManager.QuorumBlobParam[] memory quorumBlobParam = new IEigenDAServiceManager.QuorumBlobParam[](1);
QuorumBlobParam[] memory quorumBlobParam = new QuorumBlobParam[](1);

quorumBlobParam[0] = IEigenDAServiceManager.QuorumBlobParam({
quorumBlobParam[0] = QuorumBlobParam({
quorumNumber: 0,
adversaryThresholdPercentage: 80,
confirmationThresholdPercentage: 100,
Expand All @@ -37,14 +37,14 @@ contract GenerateHashes is Script {
});


quorumBlobParam[0] = IEigenDAServiceManager.QuorumBlobParam({
quorumBlobParam[0] = QuorumBlobParam({
quorumNumber: 1,
adversaryThresholdPercentage: 80,
confirmationThresholdPercentage: 100,
chunkLength: 10
});

IEigenDAServiceManager.BlobHeader memory header = IEigenDAServiceManager.BlobHeader({
BlobHeader memory header = BlobHeader({
commitment: commitment,
dataLength: 10,
quorumBlobParams: quorumBlobParam
Expand All @@ -59,4 +59,4 @@ contract GenerateHashes is Script {


}
}
}
57 changes: 53 additions & 4 deletions contracts/src/core/EigenDAServiceManager.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;

import {Pausable} from "eigenlayer-core/contracts/permissions/Pausable.sol";
Expand All @@ -8,9 +8,11 @@ import {ServiceManagerBase, IAVSDirectory, IRewardsCoordinator, IServiceManager}
import {BLSSignatureChecker} from "eigenlayer-middleware/BLSSignatureChecker.sol";
import {IRegistryCoordinator} from "eigenlayer-middleware/interfaces/IRegistryCoordinator.sol";
import {IStakeRegistry} from "eigenlayer-middleware/interfaces/IStakeRegistry.sol";

import {IEigenDAThresholdRegistry} from "../interfaces/IEigenDAThresholdRegistry.sol";
import {IEigenDARelayRegistry} from "../interfaces/IEigenDARelayRegistry.sol";
import {EigenDAServiceManagerStorage} from "./EigenDAServiceManagerStorage.sol";
import {EigenDAHasher} from "../libraries/EigenDAHasher.sol";
import "../interfaces/IEigenDAStructs.sol";

/**
* @title Primary entrypoint for procuring services from EigenDA.
Expand All @@ -36,10 +38,13 @@ contract EigenDAServiceManager is EigenDAServiceManagerStorage, ServiceManagerBa
IAVSDirectory __avsDirectory,
IRewardsCoordinator __rewardsCoordinator,
IRegistryCoordinator __registryCoordinator,
IStakeRegistry __stakeRegistry
IStakeRegistry __stakeRegistry,
IEigenDAThresholdRegistry __eigenDAThresholdRegistry,
IEigenDARelayRegistry __eigenDARelayRegistry
)
BLSSignatureChecker(__registryCoordinator)
ServiceManagerBase(__avsDirectory, __rewardsCoordinator, __registryCoordinator, __stakeRegistry)
EigenDAServiceManagerStorage(__eigenDAThresholdRegistry, __eigenDARelayRegistry)
{
_disableInitializers();
}
Expand Down Expand Up @@ -110,7 +115,7 @@ contract EigenDAServiceManager is EigenDAServiceManagerStorage, ServiceManagerBa
// signed stake > total stake
require(
quorumStakeTotals.signedStakeForQuorum[i] * THRESHOLD_DENOMINATOR >=
quorumStakeTotals.totalStakeForQuorum[i] * uint8(batchHeader.signedStakeForQuorums[i]),
quorumStakeTotals.totalStakeForQuorum[i] * uint8(batchHeader.signedStakeForQuorums[i]),
"EigenDAServiceManager.confirmBatch: signatories do not own at least threshold percentage of a quorum"
);
}
Expand Down Expand Up @@ -147,4 +152,48 @@ contract EigenDAServiceManager is EigenDAServiceManagerStorage, ServiceManagerBa
return referenceBlockNumber + STORE_DURATION_BLOCKS + BLOCK_STALE_MEASURE;
}

/// @notice Returns the blob params for a given blob version
function getBlobParams(uint16 version) external view returns (VersionedBlobParams memory) {
return eigenDAThresholdRegistry.getBlobParams(version);
}

/// @notice Returns the bytes array of quorumAdversaryThresholdPercentages
function quorumAdversaryThresholdPercentages() external view returns (bytes memory) {
return eigenDAThresholdRegistry.quorumAdversaryThresholdPercentages();
}

/// @notice Returns the bytes array of quorumAdversaryThresholdPercentages
function quorumConfirmationThresholdPercentages() external view returns (bytes memory) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: quorumAdversaryThresholdPercentages -> quorumConfirmationThresholdPercentages

return eigenDAThresholdRegistry.quorumConfirmationThresholdPercentages();
}

/// @notice Returns the bytes array of quorumsNumbersRequired
function quorumNumbersRequired() external view returns (bytes memory) {
return eigenDAThresholdRegistry.quorumNumbersRequired();
}

function getQuorumAdversaryThresholdPercentage(
uint8 quorumNumber
) external view returns (uint8){
return eigenDAThresholdRegistry.getQuorumAdversaryThresholdPercentage(quorumNumber);
}

/// @notice Gets the confirmation threshold percentage for a quorum
function getQuorumConfirmationThresholdPercentage(
uint8 quorumNumber
) external view returns (uint8){
return eigenDAThresholdRegistry.getQuorumConfirmationThresholdPercentage(quorumNumber);
}

/// @notice Checks if a quorum is required
function getIsQuorumRequired(
uint8 quorumNumber
) external view returns (bool){
return eigenDAThresholdRegistry.getIsQuorumRequired(quorumNumber);
}

/// @notice Gets the default security thresholds for V2
function getDefaultSecurityThresholdsV2() external view returns (SecurityThresholds memory) {
return eigenDAThresholdRegistry.getDefaultSecurityThresholdsV2();
}
}
36 changes: 13 additions & 23 deletions contracts/src/core/EigenDAServiceManagerStorage.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;

import {IEigenDAServiceManager} from "../interfaces/IEigenDAServiceManager.sol";

import {IEigenDAThresholdRegistry} from "../interfaces/IEigenDAThresholdRegistry.sol";
import {IEigenDARelayRegistry} from "../interfaces/IEigenDARelayRegistry.sol";
/**
* @title Storage variables for the `EigenDAServiceManager` contract.
* @author Layr Labs, Inc.
Expand All @@ -12,7 +13,6 @@ abstract contract EigenDAServiceManagerStorage is IEigenDAServiceManager {
// CONSTANTS
uint256 public constant THRESHOLD_DENOMINATOR = 100;

//TODO: mechanism to change any of these values?
/// @notice Unit of measure (in blocks) for which data will be stored for after confirmation.
uint32 public constant STORE_DURATION_BLOCKS = 2 weeks / 12 seconds;

Expand All @@ -36,26 +36,16 @@ abstract contract EigenDAServiceManagerStorage is IEigenDAServiceManager {
*/
uint32 public constant BLOCK_STALE_MEASURE = 300;

/**
* @notice The quorum adversary threshold percentages stored as an ordered bytes array
* this is the percentage of the total stake that must be adversarial to consider a blob invalid.
* The first byte is the threshold for quorum 0, the second byte is the threshold for quorum 1, etc.
*/
bytes public constant quorumAdversaryThresholdPercentages = hex"212121";

/**
* @notice The quorum confirmation threshold percentages stored as an ordered bytes array
* this is the percentage of the total stake needed to confirm a blob.
* The first byte is the threshold for quorum 0, the second byte is the threshold for quorum 1, etc.
*/
bytes public constant quorumConfirmationThresholdPercentages = hex"373737";
IEigenDAThresholdRegistry public immutable eigenDAThresholdRegistry;
IEigenDARelayRegistry public immutable eigenDARelayRegistry;

/**
* @notice The quorum numbers required for confirmation stored as an ordered bytes array
* these quorum numbers have respective canonical thresholds in the
* quorumConfirmationThresholdPercentages and quorumAdversaryThresholdPercentages above.
*/
bytes public constant quorumNumbersRequired = hex"0001";
constructor(
IEigenDAThresholdRegistry _eigenDAThresholdRegistry,
IEigenDARelayRegistry _eigenDARelayRegistry
) {
eigenDAThresholdRegistry = _eigenDAThresholdRegistry;
eigenDARelayRegistry = _eigenDARelayRegistry;
}

/// @notice The current batchId
uint32 public batchId;
Expand All @@ -69,4 +59,4 @@ abstract contract EigenDAServiceManagerStorage is IEigenDAServiceManager {
// storage gap for upgradeability
// slither-disable-next-line shadowing-state
uint256[47] private __GAP;
}
}
6 changes: 6 additions & 0 deletions contracts/src/interfaces/IEigenDABatchMetadataStorage.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;

interface IEigenDABatchMetadataStorage {
function batchIdToBatchMetadataHash(uint32 batchId) external view returns (bytes32);
}
141 changes: 141 additions & 0 deletions contracts/src/interfaces/IEigenDABlobVerifier.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;

import "./IEigenDAStructs.sol";
import "./IEigenDAThresholdRegistry.sol";

interface IEigenDABlobVerifier is IEigenDAThresholdRegistry {

/**
* @notice Verifies a the blob is valid for the required quorums
* @param blobHeader The blob header to verify
* @param blobVerificationProof The blob verification proof to verify the blob against
*/
function verifyBlobV1(
BlobHeader calldata blobHeader,
BlobVerificationProof calldata blobVerificationProof
) external view;

/**
* @notice Verifies that a blob is valid for the required quorums and additional quorums
* @param blobHeader The blob header to verify
* @param blobVerificationProof The blob verification proof to verify the blob against
* @param additionalQuorumNumbersRequired The additional required quorum numbers
*/
function verifyBlobV1(
BlobHeader calldata blobHeader,
BlobVerificationProof calldata blobVerificationProof,
bytes calldata additionalQuorumNumbersRequired
) external view;

/**
* @notice Verifies a batch of blobs for the required quorums
* @param blobHeaders The blob headers to verify
* @param blobVerificationProofs The blob verification proofs to verify the blobs against
*/
function verifyBlobsV1(
BlobHeader[] calldata blobHeaders,
BlobVerificationProof[] calldata blobVerificationProofs
) external view;

/**
* @notice Verifies a batch of blobs for the required quorums and additional quorums
* @param blobHeaders The blob headers to verify
* @param blobVerificationProofs The blob verification proofs to verify the blobs against
* @param additionalQuorumNumbersRequired The additional required quorum numbers
*/
function verifyBlobsV1(
BlobHeader[] calldata blobHeaders,
BlobVerificationProof[] calldata blobVerificationProofs,
bytes calldata additionalQuorumNumbersRequired
) external view;


/**
* @notice Verifies a blob for the required quorums and the default security thresholds
* @param batchHeader The batch header of the blob
* @param blobVerificationProof The blob verification proof for the blob
* @param nonSignerStakesAndSignature The nonSignerStakesAndSignature to verify the blob against
*/
function verifyBlobV2(
BatchHeaderV2 calldata batchHeader,
BlobVerificationProofV2 calldata blobVerificationProof,
NonSignerStakesAndSignature calldata nonSignerStakesAndSignature
) external view;

/**
* @notice Verifies a blob for the required quorums and additional quorums
* @param batchHeader The batch header of the blob
* @param blobVerificationProof The blob verification proof for the blob
* @param nonSignerStakesAndSignature The nonSignerStakesAndSignature to verify the blob against
* @param additionalQuorumNumbersRequired The additional required quorum numbers
*/
function verifyBlobV2(
BatchHeaderV2 calldata batchHeader,
BlobVerificationProofV2 calldata blobVerificationProof,
NonSignerStakesAndSignature calldata nonSignerStakesAndSignature,
bytes calldata additionalQuorumNumbersRequired
) external view;

/**
* @notice Verifies a blob for the required quorums and additional quorums and a custom security threshold
* @param batchHeader The batch header of the blob
* @param blobVerificationProof The blob verification proof for the blob
* @param nonSignerStakesAndSignature The nonSignerStakesAndSignature to verify the blob against
* @param securityThreshold The custom security threshold to verify the blob against
* @param additionalQuorumNumbersRequired The additional required quorum numbers
*/
function verifyBlobV2(
BatchHeaderV2 calldata batchHeader,
BlobVerificationProofV2 calldata blobVerificationProof,
NonSignerStakesAndSignature calldata nonSignerStakesAndSignature,
SecurityThresholds memory securityThreshold,
bytes calldata additionalQuorumNumbersRequired
) external view;

/**
* @notice Verifies a batch of blobs for the required quorums and additional quorums and a set of custom security threshold
* @param batchHeader The batch headers of the blobs
* @param blobVerificationProof The blob verification proofs for the blobs
* @param nonSignerStakesAndSignature The nonSignerStakesAndSignatures to verify the blobs against
* @param securityThresholds The set of custom security thresholds to verify the blobs against
* @param additionalQuorumNumbersRequired The additional required quorum numbers
*/
function verifyBlobV2(
BatchHeaderV2 calldata batchHeader,
BlobVerificationProofV2 calldata blobVerificationProof,
NonSignerStakesAndSignature calldata nonSignerStakesAndSignature,
SecurityThresholds[] memory securityThresholds,
bytes calldata additionalQuorumNumbersRequired
) external view;

/**
* @notice Returns the nonSignerStakesAndSignature for a given blob and signed batch
* @param signedBatch The signed batch to get the nonSignerStakesAndSignature for
* @param blobHeader The blob header of the blob in the signed batch
*/
function getNonSignerStakesAndSignature(
SignedBatch calldata signedBatch,
BlobHeaderV2 calldata blobHeader
) external view returns (NonSignerStakesAndSignature memory);

/**
* @notice Verifies the security parameters for a blob
* @param blobParams The blob params to verify
* @param securityThresholds The security thresholds to verify against
*/
function verifyBlobSecurityParams(
VersionedBlobParams memory blobParams,
SecurityThresholds memory securityThresholds
) external view;

/**
* @notice Verifies the security parameters for a blob
* @param version The version of the blob to verify
* @param securityThresholds The security thresholds to verify against
*/
function verifyBlobSecurityParams(
uint16 version,
SecurityThresholds memory securityThresholds
) external view;
}
15 changes: 15 additions & 0 deletions contracts/src/interfaces/IEigenDARelayRegistry.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;

interface IEigenDARelayRegistry {

event RelayAdded(address indexed relay, uint32 indexed id, string relayURL);

function setRelayURL(address relay, uint32 id, string memory relayURL) external;

function getRelayURL(uint32 id) external view returns (string memory);

function getRelayId(address relay) external view returns (uint32);

function getRelayAddress(uint32 id) external view returns (address);
}
Loading
Loading