Skip to content

Commit 0f705e3

Browse files
committed
feat: IncredibleSquaringTemplate
1 parent d13e714 commit 0f705e3

File tree

2 files changed

+114
-0
lines changed

2 files changed

+114
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity ^0.8.0;
3+
4+
import {BN254} from "eigenlayer-middleware/src/libraries/BN254.sol";
5+
6+
interface IIncredibleSquaringTaskManager {
7+
// EVENTS
8+
event NewTaskCreated(uint32 indexed taskIndex, Task task);
9+
10+
event TaskResponded(TaskResponse taskResponse, TaskResponseMetadata taskResponseMetadata);
11+
12+
event TaskCompleted(uint32 indexed taskIndex);
13+
14+
event TaskChallengedSuccessfully(uint32 indexed taskIndex, address indexed challenger);
15+
16+
event TaskChallengedUnsuccessfully(uint32 indexed taskIndex, address indexed challenger);
17+
18+
event AggregatorUpdated(address indexed oldAggregator, address indexed newAggregator);
19+
20+
event GeneratorUpdated(address indexed oldGenerator, address indexed newGenerator);
21+
22+
// STRUCTS
23+
struct Task {
24+
uint256 numberToBeSquared;
25+
uint32 taskCreatedBlock;
26+
// task submitter decides on the criteria for a task to be completed
27+
// note that this does not mean the task was "correctly" answered (i.e. the number was squared correctly)
28+
// this is for the challenge logic to verify
29+
// task is completed (and contract will accept its TaskResponse) when each quorumNumbers specified here
30+
// are signed by at least quorumThresholdPercentage of the operators
31+
// note that we set the quorumThresholdPercentage to be the same for all quorumNumbers, but this could be changed
32+
bytes quorumNumbers;
33+
uint32 quorumThresholdPercentage;
34+
}
35+
36+
// Task response is hashed and signed by operators.
37+
// these signatures are aggregated and sent to the contract as response.
38+
struct TaskResponse {
39+
// Can be obtained by the operator from the event NewTaskCreated.
40+
uint32 referenceTaskIndex;
41+
// This is just the response that the operator has to compute by itself.
42+
uint256 numberSquared;
43+
}
44+
45+
// Extra information related to taskResponse, which is filled inside the contract.
46+
// It thus cannot be signed by operators, so we keep it in a separate struct than TaskResponse
47+
// This metadata is needed by the challenger, so we emit it in the TaskResponded event
48+
struct TaskResponseMetadata {
49+
uint32 taskResponsedBlock;
50+
bytes32 hashOfNonSigners;
51+
}
52+
53+
// FUNCTIONS
54+
// NOTE: this function creates new task.
55+
function createNewTask(uint256 numberToBeSquared, uint32 quorumThresholdPercentage, bytes calldata quorumNumbers)
56+
external;
57+
58+
/// @notice Returns the current 'taskNumber' for the middleware
59+
function taskNumber() external view returns (uint32);
60+
61+
// // NOTE: this function raises challenge to existing tasks.
62+
function raiseAndResolveChallenge(
63+
Task calldata task,
64+
TaskResponse calldata taskResponse,
65+
TaskResponseMetadata calldata taskResponseMetadata,
66+
BN254.G1Point[] memory pubkeysOfNonSigningOperators
67+
) external;
68+
69+
/// @notice Returns the TASK_RESPONSE_WINDOW_BLOCK
70+
function getTaskResponseWindowBlock() external view returns (uint32);
71+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity ^0.8.9;
3+
4+
import {ServiceManagerBase} from "eigenlayer-middleware/src/ServiceManagerBase.sol";
5+
import {IIncredibleSquaringTaskManager} from "../interfaces/IIncredibleSquaringTaskManager.sol";
6+
import {IAVSDirectory} from "eigenlayer-core/contracts/interfaces/IAVSDirectory.sol";
7+
import {IRegistryCoordinator} from "eigenlayer-middleware/src/interfaces/IRegistryCoordinator.sol";
8+
import {IStakeRegistry} from "eigenlayer-middleware/src/interfaces/IStakeRegistry.sol";
9+
import {IRewardsCoordinator} from "eigenlayer-core/contracts/interfaces/IRewardsCoordinator.sol";
10+
11+
/**
12+
* @title Primary entrypoint for procuring services from IncredibleSquaring.
13+
* @author Layr Labs, Inc.
14+
*/
15+
contract IncredibleSquaringTemplate is ServiceManagerBase {
16+
IIncredibleSquaringTaskManager public immutable incredibleSquaringTaskManager;
17+
18+
/// @notice when applied to a function, ensures that the function is only callable by the `registryCoordinator`.
19+
modifier onlyIncredibleSquaringTaskManager() {
20+
require(
21+
msg.sender == address(incredibleSquaringTaskManager),
22+
"onlyIncredibleSquaringTaskManager: not from credible squaring task manager"
23+
);
24+
_;
25+
}
26+
27+
constructor(
28+
IAVSDirectory __avsDirectory,
29+
IRewardsCoordinator __rewardsCoordinator,
30+
IRegistryCoordinator __registryCoordinator,
31+
IStakeRegistry __stakeRegistry,
32+
IIncredibleSquaringTaskManager __incredibleSquaringTaskManager
33+
) ServiceManagerBase(__avsDirectory, __rewardsCoordinator, __registryCoordinator, __stakeRegistry) {
34+
incredibleSquaringTaskManager = __incredibleSquaringTaskManager;
35+
}
36+
37+
/// @notice Called in the event of challenge resolution, in order to forward a call to the Slasher, which 'freezes' the `operator`.
38+
/// @dev The Slasher contract is under active development and its interface expected to change.
39+
/// We recommend writing slashing logic without integrating with the Slasher at this point in time.
40+
function freezeOperator(address operatorAddr) external onlyIncredibleSquaringTaskManager {
41+
// slasher.freezeOperator(operatorAddr);
42+
}
43+
}

0 commit comments

Comments
 (0)