Skip to content

Commit

Permalink
Merge pull request #27 from NethermindEth/anshu/task-manager-preconfi…
Browse files Browse the repository at this point in the history
…rmation-challenge

Add preconfirmation challenge
  • Loading branch information
smartprogrammer93 authored Jun 25, 2024
2 parents b0a77f9 + c3ad4d5 commit 299377d
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
[submodule "SmartContracts/lib/openzeppelin-contracts-upgradeable"]
path = SmartContracts/lib/openzeppelin-contracts-upgradeable
url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable
[submodule "SmartContracts/lib/openzeppelin-contracts"]
path = SmartContracts/lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
1 change: 1 addition & 0 deletions SmartContracts/lib/openzeppelin-contracts
Submodule openzeppelin-contracts added at 54b3f1
1 change: 1 addition & 0 deletions SmartContracts/remappings.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
eigenlayer-middleware/=lib/eigenlayer-middleware/src
forge-std/=lib/forge-std/src/
openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts
openzeppelin-contracts/=lib/openzeppelin-contracts/contracts
34 changes: 33 additions & 1 deletion SmartContracts/src/avs/PreconfTaskManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {IPreconfTaskManager} from "../interfaces/IPreconfTaskManager.sol";
import {IPreconfServiceManager} from "../interfaces/IPreconfServiceManager.sol";
import {IRegistryCoordinator} from "eigenlayer-middleware/interfaces/IRegistryCoordinator.sol";
import {IIndexRegistry} from "eigenlayer-middleware/interfaces/IIndexRegistry.sol";
import {ECDSA} from "openzeppelin-contracts/utils/cryptography/ECDSA.sol";

contract PreconfTaskManager is IPreconfTaskManager {
IPreconfServiceManager internal immutable preconfServiceManager;
Expand Down Expand Up @@ -131,7 +132,38 @@ contract PreconfTaskManager is IPreconfTaskManager {
taikoL1.proposeBlock{value: msg.value}(blockParams, txList);
}

function proveIncorrectPreconfirmation(PreconfirmationHeader memory header, bytes memory signature) external {}
/**
* @notice Slashes an operator if their preconfirmation has not been respected onchain
* @dev The ECDSA signature expected by this function must be from a library that prevents malleable
* signatures i.e `s` value is in the lower half order, and the `v` value is either 27 or 28.
* @param header The header of the preconfirmation sent to the AVS P2P
* @param signature ECDSA-signed hash of the preconfirmation header
*/
function proveIncorrectPreconfirmation(PreconfirmationHeader calldata header, bytes calldata signature) external {
IPreconfTaskManager.ProposedBlock memory proposedBlock = proposedBlocks[header.blockId];

if (block.timestamp - proposedBlock.timestamp >= DISPUTE_PERIOD) {
// Revert if the dispute window has been missed
revert IPreconfTaskManager.MissedDisputeWindow();
} else if (header.chainId != block.chainid) {
// Revert if the preconfirmation was provided on another chain
revert IPreconfTaskManager.PreconfirmationChainIdMismatch();
}

bytes32 headerHash = keccak256(abi.encodePacked(header.blockId, header.chainId, header.txListHash));
address preconfSigner = ECDSA.recover(headerHash, signature);

// Note: It is not required to verify that the preconfSigner is a valid operator. That is implicitly
// verified by EL.

// Slash if the preconfirmation was given offchain, but block proposal was missed OR
// the preconfirmed set of transactions is different from the transactions in the proposed block.
if (preconfSigner != proposedBlock.proposer || header.txListHash != proposedBlock.txListHash) {
preconfServiceManager.slashOperator(preconfSigner);
} else {
revert IPreconfTaskManager.PreconfirmationIsCorrect();
}
}

function proveIncorrectLookahead(
uint256 offset,
Expand Down
6 changes: 6 additions & 0 deletions SmartContracts/src/interfaces/IPreconfTaskManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ interface IPreconfTaskManager {
error SenderNotRegisteredInAVS();
/// @dev The timestamp in the lookahead is not of a valid future slot in the present epoch
error InvalidSlotTimestamp();
/// @dev The chain id on which the preconfirmation was signed is different from the current chain's id
error PreconfirmationChainIdMismatch();
/// @dev The dispute window for proving incorretc lookahead or preconfirmation is over
error MissedDisputeWindow();
/// @dev The disputed preconfirmation is correct
error PreconfirmationIsCorrect();

/// @dev Accepts block proposal by an operator and forwards it to TaikoL1 contract
function newBlockProposal(
Expand Down

0 comments on commit 299377d

Please sign in to comment.