Skip to content

Commit 409d3ef

Browse files
committed
feat: hourglass (task-based AVS framework) (#1534)
**Motivation:** We need to migrate the hourglass core contracts from https://github.com/Layr-Labs/hourglass-monorepo/tree/master/contracts. This is due to the following reasons: * Better security posture of the core contracts repository * Automatic support of Zeus for contract upgrades * Easier maintainability along with other core contracts which will be governed by the protocol council. **Modifications:** * TaskMailbox and interface * Extensive unit tests for the TaskMailbox (with appropriate Mock contracts) * Updated bindings (Including stale bindings from Multichain) * Smart contract documentation for the TaskMailbox **Result:** The Hourglass core contract migration.
1 parent eeb0839 commit 409d3ef

17 files changed

+11030
-0
lines changed

docs/avs/task/TaskMailbox.md

Lines changed: 416 additions & 0 deletions
Large diffs are not rendered by default.

pkg/bindings/IAVSTaskHook/binding.go

Lines changed: 325 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/bindings/ITaskMailbox/binding.go

Lines changed: 1785 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/bindings/TaskMailbox/binding.go

Lines changed: 2413 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/bindings/TaskMailboxStorage/binding.go

Lines changed: 1979 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/contracts/avs/task/TaskMailbox.sol

Lines changed: 480 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// SPDX-License-Identifier: BUSL-1.1
2+
pragma solidity ^0.8.27;
3+
4+
import {ITaskMailbox} from "../../interfaces/ITaskMailbox.sol";
5+
import {IKeyRegistrarTypes} from "../../interfaces/IKeyRegistrar.sol";
6+
7+
/**
8+
* @title TaskMailboxStorage
9+
* @author Layr Labs, Inc.
10+
* @notice Storage contract for the TaskMailbox contract.
11+
*/
12+
abstract contract TaskMailboxStorage is ITaskMailbox {
13+
/// @notice Equivalent to 100%, but in basis points.
14+
uint16 internal constant ONE_HUNDRED_IN_BIPS = 10_000;
15+
16+
/// @notice Immutable BN254 certificate verifier
17+
address public immutable BN254_CERTIFICATE_VERIFIER;
18+
19+
/// @notice Immutable ECDSA certificate verifier
20+
address public immutable ECDSA_CERTIFICATE_VERIFIER;
21+
22+
/// @notice Global counter for tasks created across the TaskMailbox
23+
uint256 internal _globalTaskCount;
24+
25+
/// @notice Mapping from task hash to task details
26+
mapping(bytes32 taskHash => Task task) internal _tasks;
27+
28+
/// @notice Mapping to track registered executor operator sets by their keys
29+
mapping(bytes32 operatorSetKey => bool isRegistered) public isExecutorOperatorSetRegistered;
30+
31+
/// @notice Mapping from executor operator set key to its task configuration
32+
mapping(bytes32 operatorSetKey => ExecutorOperatorSetTaskConfig config) internal _executorOperatorSetTaskConfigs;
33+
34+
/// @notice The fee split percentage in basis points (0-10000)
35+
uint16 public feeSplit;
36+
37+
/// @notice The address that receives the fee split
38+
address public feeSplitCollector;
39+
40+
/**
41+
* @notice Constructor for TaskMailboxStorage
42+
* @param _bn254CertificateVerifier Address of the BN254 certificate verifier
43+
* @param _ecdsaCertificateVerifier Address of the ECDSA certificate verifier
44+
*/
45+
constructor(address _bn254CertificateVerifier, address _ecdsaCertificateVerifier) {
46+
BN254_CERTIFICATE_VERIFIER = _bn254CertificateVerifier;
47+
ECDSA_CERTIFICATE_VERIFIER = _ecdsaCertificateVerifier;
48+
}
49+
50+
/**
51+
* @dev This empty reserved space is put in place to allow future versions to add new
52+
* variables without shifting down storage in the inheritance chain.
53+
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
54+
*/
55+
uint256[45] private __gap;
56+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// SPDX-License-Identifier: BUSL-1.1
2+
pragma solidity ^0.8.27;
3+
4+
import {ITaskMailboxTypes} from "./ITaskMailbox.sol";
5+
import {OperatorSet} from "../libraries/OperatorSetLib.sol";
6+
7+
/**
8+
* @title IAVSTaskHook
9+
* @author Layr Labs, Inc.
10+
* @notice Interface for AVS-specific task lifecycle hooks.
11+
* @dev This interface allows AVSs to implement custom validation logic for tasks.
12+
*/
13+
interface IAVSTaskHook {
14+
/**
15+
* @notice Validates a task before it is created
16+
* @param caller Address that is creating the task
17+
* @param taskParams Task parameters
18+
* @dev This function should revert if the task should not be created
19+
*/
20+
function validatePreTaskCreation(address caller, ITaskMailboxTypes.TaskParams memory taskParams) external view;
21+
22+
/**
23+
* @notice Handles a task after it is created
24+
* @param taskHash Unique identifier of the task
25+
* @dev This function can be used to perform additional validation or update AVS-specific state
26+
*/
27+
function handlePostTaskCreation(
28+
bytes32 taskHash
29+
) external;
30+
31+
/**
32+
* @notice Validates a task before it is submitted for verification
33+
* @param caller Address that is submitting the result
34+
* @param taskHash Unique identifier of the task
35+
* @param cert Certificate proving the validity of the result
36+
* @param result Task execution result data
37+
* @dev This function should revert if the task should not be verified
38+
*/
39+
function validatePreTaskResultSubmission(
40+
address caller,
41+
bytes32 taskHash,
42+
bytes memory cert,
43+
bytes memory result
44+
) external view;
45+
46+
/**
47+
* @notice Handles a task result submission
48+
* @param taskHash Unique identifier of the task
49+
* @dev This function can be used to perform additional validation or update AVS-specific state
50+
*/
51+
function handlePostTaskResultSubmission(
52+
bytes32 taskHash
53+
) external;
54+
55+
/**
56+
* @notice Calculates the fee for a task payload against a specific fee market
57+
* @param taskParams The task parameters
58+
* @return The fee for the task
59+
*/
60+
function calculateTaskFee(
61+
ITaskMailboxTypes.TaskParams memory taskParams
62+
) external view returns (uint96);
63+
}

0 commit comments

Comments
 (0)