From 2c87d28e04a6861ae02e75ff3e624febc1537551 Mon Sep 17 00:00:00 2001 From: Daniel Wang Date: Thu, 3 Oct 2024 16:31:31 +0800 Subject: [PATCH 01/15] Use ring buffers in PreconfTaskManager --- SmartContracts/src/avs/PreconfTaskManager.sol | 37 +++++++++++++------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/SmartContracts/src/avs/PreconfTaskManager.sol b/SmartContracts/src/avs/PreconfTaskManager.sol index ed2c4fb..86d6e85 100644 --- a/SmartContracts/src/avs/PreconfTaskManager.sol +++ b/SmartContracts/src/avs/PreconfTaskManager.sol @@ -16,6 +16,16 @@ contract PreconfTaskManager is IPreconfTaskManager, Initializable { IPreconfRegistry internal immutable preconfRegistry; ITaikoL1 internal immutable taikoL1; + struct PosterInfo { + address poster; + uint64 epochTimestamp; + } + + struct ProposerInfo { + address proposer; + uint64 blockId; + } + // EIP-4788 uint256 internal immutable beaconGenesis; address internal immutable beaconBlockRootContract; @@ -28,11 +38,12 @@ contract PreconfTaskManager is IPreconfTaskManager, Initializable { // Maps the epoch timestamp to the lookahead poster. // If the lookahead poster has been slashed, it maps to the 0-address. // Note: This may be optimised to re-use existing slots and reduce gas cost. - mapping(uint256 epochTimestamp => address poster) internal lookaheadPosters; + // 1536 = 128 * 12 + mapping(uint256 epochTimestamp_mod_1536 => PosterInfo posterInfo) internal lookaheadPosters; // Maps the block height to the associated proposer // This is required since the stored block in Taiko has the address of this contract as the proposer - mapping(uint256 blockId => address proposer) internal blockIdToProposer; + mapping(uint256 blockId_mod_128 => ProposerInfo proposerInfo) internal blockIdToProposer; // Cannot be kept in `PreconfConstants` file because solidity expects array sizes // to be stored in the main contract file itself. @@ -104,7 +115,7 @@ contract PreconfTaskManager is IPreconfTaskManager, Initializable { // Store the proposer for the block locally // Use Taiko's block number to index (, ITaikoL1.SlotB memory slotB) = taikoL1.getStateVariables(); - blockIdToProposer[slotB.numBlocks] = msg.sender; + blockIdToProposer[slotB.numBlocks % 128] = ProposerInfo(msg.sender, uint64(slotB.numBlocks)) ; // Block the preconfer from withdrawing stake from the restaking service during the dispute window preconfServiceManager.lockStakeUntil(msg.sender, block.timestamp + PreconfConstants.DISPUTE_PERIOD); @@ -127,7 +138,7 @@ contract PreconfTaskManager is IPreconfTaskManager, Initializable { bytes calldata signature ) external { uint256 blockId = taikoBlockMetadata.id; - address proposer = blockIdToProposer[blockId]; + address proposer = getBlockProposer(blockId); // Pull the formalised block from Taiko ITaikoL1.Block memory taikoBlock = taikoL1.getBlock(uint64(blockId)); @@ -174,7 +185,7 @@ contract PreconfTaskManager is IPreconfTaskManager, Initializable { ) external { uint256 epochTimestamp = _getEpochTimestamp(slotTimestamp); - address poster = lookaheadPosters[epochTimestamp]; + address poster = getLookaheadPoster(epochTimestamp); // Poster must not have been slashed if (poster == address(0)) { @@ -271,7 +282,7 @@ contract PreconfTaskManager is IPreconfTaskManager, Initializable { } // Slash the poster - lookaheadPosters[epochTimestamp] = address(0); + lookaheadPosters[epochTimestamp % 1536].poster = address(0); preconfServiceManager.slashOperator(poster); emit ProvedIncorrectLookahead(poster, slotTimestamp, msg.sender); @@ -368,7 +379,7 @@ contract PreconfTaskManager is IPreconfTaskManager, Initializable { } lookaheadTail = _lookaheadTail; - lookaheadPosters[epochTimestamp] = msg.sender; + lookaheadPosters[epochTimestamp % 1536] = PosterInfo(msg.sender, uint64(epochTimestamp)); // We directly use the lookahead set params even in the case of a fallback preconfer to // assist the nodes in identifying an incorrect lookahead. The contents of this event can be matched against @@ -410,7 +421,7 @@ contract PreconfTaskManager is IPreconfTaskManager, Initializable { function _isLookaheadRequired(uint256 epochTimestamp, uint256 nextEpochTimestamp) internal view returns (bool) { // If it's the first slot of current epoch, we don't need the lookahead since the offchain // node may not have access to it yet. - return block.timestamp != epochTimestamp && lookaheadPosters[nextEpochTimestamp] == address(0); + return block.timestamp != epochTimestamp && getLookaheadPoster(nextEpochTimestamp) == address(0); } //======= @@ -557,11 +568,13 @@ contract PreconfTaskManager is IPreconfTaskManager, Initializable { return lookahead; } - function getLookaheadPoster(uint256 epochTimestamp) external view returns (address) { - return lookaheadPosters[epochTimestamp]; + function getLookaheadPoster(uint256 epochTimestamp) public view returns (address) { + PosterInfo memory pi = lookaheadPosters[epochTimestamp % 1536]; + return pi.epochTimestamp == epochTimestamp ? pi.poster : address(0); } - function getBlockProposer(uint256 blockId) external view returns (address) { - return blockIdToProposer[blockId]; + function getBlockProposer(uint256 blockId) public view returns (address) { + ProposerInfo memory pi = blockIdToProposer[blockId % 128]; + return pi.blockId == blockId ? pi.proposer : address(0); } } From 7f0e31753862f1b109b4a56524811befa1e8c568 Mon Sep 17 00:00:00 2001 From: Daniel Wang Date: Thu, 3 Oct 2024 16:35:00 +0800 Subject: [PATCH 02/15] more --- SmartContracts/src/avs/PreconfTaskManager.sol | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/SmartContracts/src/avs/PreconfTaskManager.sol b/SmartContracts/src/avs/PreconfTaskManager.sol index 86d6e85..417388b 100644 --- a/SmartContracts/src/avs/PreconfTaskManager.sol +++ b/SmartContracts/src/avs/PreconfTaskManager.sol @@ -12,6 +12,10 @@ import {IERC20} from "openzeppelin-contracts/token/ERC20/IERC20.sol"; import {Initializable} from "openzeppelin-contracts-upgradeable/proxy/utils/Initializable.sol"; contract PreconfTaskManager is IPreconfTaskManager, Initializable { + uint256 internal constant BLOCK_ID_TO_PROPOSER_BUFFER_SIZE = 128; + uint256 internal constant LOOKAHEAD_POSTER_BUFFER_SIZE = 12 * BLOCK_ID_TO_PROPOSER_BUFFER_SIZE; + uint256 internal constant LOOKAHEAD_BUFFER_SIZE = 64; + IPreconfServiceManager internal immutable preconfServiceManager; IPreconfRegistry internal immutable preconfRegistry; ITaikoL1 internal immutable taikoL1; @@ -32,18 +36,19 @@ contract PreconfTaskManager is IPreconfTaskManager, Initializable { // A ring buffer of upcoming preconfers (who are also the L1 validators) uint256 internal lookaheadTail; - uint256 internal constant LOOKAHEAD_BUFFER_SIZE = 64; + LookaheadBufferEntry[LOOKAHEAD_BUFFER_SIZE] internal lookahead; // Maps the epoch timestamp to the lookahead poster. // If the lookahead poster has been slashed, it maps to the 0-address. // Note: This may be optimised to re-use existing slots and reduce gas cost. - // 1536 = 128 * 12 - mapping(uint256 epochTimestamp_mod_1536 => PosterInfo posterInfo) internal lookaheadPosters; + + mapping(uint256 epochTimestamp_mod_LOOKAHEAD_POSTER_BUFFER_SIZE => PosterInfo posterInfo) internal lookaheadPosters; // Maps the block height to the associated proposer // This is required since the stored block in Taiko has the address of this contract as the proposer - mapping(uint256 blockId_mod_128 => ProposerInfo proposerInfo) internal blockIdToProposer; + mapping(uint256 blockId_mod_BLOCK_ID_TO_PROPOSER_BUFFER_SIZE => ProposerInfo proposerInfo) internal + blockIdToProposer; // Cannot be kept in `PreconfConstants` file because solidity expects array sizes // to be stored in the main contract file itself. @@ -115,7 +120,8 @@ contract PreconfTaskManager is IPreconfTaskManager, Initializable { // Store the proposer for the block locally // Use Taiko's block number to index (, ITaikoL1.SlotB memory slotB) = taikoL1.getStateVariables(); - blockIdToProposer[slotB.numBlocks % 128] = ProposerInfo(msg.sender, uint64(slotB.numBlocks)) ; + blockIdToProposer[slotB.numBlocks % BLOCK_ID_TO_PROPOSER_BUFFER_SIZE] = + ProposerInfo(msg.sender, uint64(slotB.numBlocks)); // Block the preconfer from withdrawing stake from the restaking service during the dispute window preconfServiceManager.lockStakeUntil(msg.sender, block.timestamp + PreconfConstants.DISPUTE_PERIOD); @@ -282,7 +288,7 @@ contract PreconfTaskManager is IPreconfTaskManager, Initializable { } // Slash the poster - lookaheadPosters[epochTimestamp % 1536].poster = address(0); + lookaheadPosters[epochTimestamp % LOOKAHEAD_POSTER_BUFFER_SIZE].poster = address(0); preconfServiceManager.slashOperator(poster); emit ProvedIncorrectLookahead(poster, slotTimestamp, msg.sender); @@ -379,7 +385,7 @@ contract PreconfTaskManager is IPreconfTaskManager, Initializable { } lookaheadTail = _lookaheadTail; - lookaheadPosters[epochTimestamp % 1536] = PosterInfo(msg.sender, uint64(epochTimestamp)); + lookaheadPosters[epochTimestamp % LOOKAHEAD_POSTER_BUFFER_SIZE] = PosterInfo(msg.sender, uint64(epochTimestamp)); // We directly use the lookahead set params even in the case of a fallback preconfer to // assist the nodes in identifying an incorrect lookahead. The contents of this event can be matched against @@ -569,12 +575,12 @@ contract PreconfTaskManager is IPreconfTaskManager, Initializable { } function getLookaheadPoster(uint256 epochTimestamp) public view returns (address) { - PosterInfo memory pi = lookaheadPosters[epochTimestamp % 1536]; + PosterInfo memory pi = lookaheadPosters[epochTimestamp % LOOKAHEAD_POSTER_BUFFER_SIZE]; return pi.epochTimestamp == epochTimestamp ? pi.poster : address(0); } function getBlockProposer(uint256 blockId) public view returns (address) { - ProposerInfo memory pi = blockIdToProposer[blockId % 128]; + ProposerInfo memory pi = blockIdToProposer[blockId % BLOCK_ID_TO_PROPOSER_BUFFER_SIZE]; return pi.blockId == blockId ? pi.proposer : address(0); } } From b5fcd45ea113441e440342b1d5b6f1081ab8a28d Mon Sep 17 00:00:00 2001 From: Daniel Wang Date: Thu, 3 Oct 2024 16:37:38 +0800 Subject: [PATCH 03/15] Update PreconfTaskManager.sol --- SmartContracts/src/avs/PreconfTaskManager.sol | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/SmartContracts/src/avs/PreconfTaskManager.sol b/SmartContracts/src/avs/PreconfTaskManager.sol index 417388b..06e803e 100644 --- a/SmartContracts/src/avs/PreconfTaskManager.sol +++ b/SmartContracts/src/avs/PreconfTaskManager.sol @@ -12,9 +12,10 @@ import {IERC20} from "openzeppelin-contracts/token/ERC20/IERC20.sol"; import {Initializable} from "openzeppelin-contracts-upgradeable/proxy/utils/Initializable.sol"; contract PreconfTaskManager is IPreconfTaskManager, Initializable { - uint256 internal constant BLOCK_ID_TO_PROPOSER_BUFFER_SIZE = 128; - uint256 internal constant LOOKAHEAD_POSTER_BUFFER_SIZE = 12 * BLOCK_ID_TO_PROPOSER_BUFFER_SIZE; uint256 internal constant LOOKAHEAD_BUFFER_SIZE = 64; + uint256 internal constant BLOCK_ID_TO_PROPOSER_BUFFER_SIZE = LOOKAHEAD_BUFFER_SIZE * 2; + uint256 internal constant LOOKAHEAD_POSTER_BUFFER_SIZE = + PreconfConstants.SECONDS_IN_SLOT * BLOCK_ID_TO_PROPOSER_BUFFER_SIZE; IPreconfServiceManager internal immutable preconfServiceManager; IPreconfRegistry internal immutable preconfRegistry; From 287aa649b80466eb03d0dab2a8e2d0c8f481f5bc Mon Sep 17 00:00:00 2001 From: Daniel Wang Date: Thu, 3 Oct 2024 16:38:18 +0800 Subject: [PATCH 04/15] Update PreconfTaskManager.sol --- SmartContracts/src/avs/PreconfTaskManager.sol | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/SmartContracts/src/avs/PreconfTaskManager.sol b/SmartContracts/src/avs/PreconfTaskManager.sol index 06e803e..8992c8b 100644 --- a/SmartContracts/src/avs/PreconfTaskManager.sol +++ b/SmartContracts/src/avs/PreconfTaskManager.sol @@ -12,6 +12,10 @@ import {IERC20} from "openzeppelin-contracts/token/ERC20/IERC20.sol"; import {Initializable} from "openzeppelin-contracts-upgradeable/proxy/utils/Initializable.sol"; contract PreconfTaskManager is IPreconfTaskManager, Initializable { + // Cannot be kept in `PreconfConstants` file because solidity expects array sizes + // to be stored in the main contract file itself. + uint256 internal constant SLOTS_IN_EPOCH = 32; + uint256 internal constant LOOKAHEAD_BUFFER_SIZE = 64; uint256 internal constant BLOCK_ID_TO_PROPOSER_BUFFER_SIZE = LOOKAHEAD_BUFFER_SIZE * 2; uint256 internal constant LOOKAHEAD_POSTER_BUFFER_SIZE = @@ -51,9 +55,6 @@ contract PreconfTaskManager is IPreconfTaskManager, Initializable { mapping(uint256 blockId_mod_BLOCK_ID_TO_PROPOSER_BUFFER_SIZE => ProposerInfo proposerInfo) internal blockIdToProposer; - // Cannot be kept in `PreconfConstants` file because solidity expects array sizes - // to be stored in the main contract file itself. - uint256 internal constant SLOTS_IN_EPOCH = 32; uint256[133] private __gap; // = 200 - 67 From eee20bdc2284c5ecda18d2f9651e430baaac8eb7 Mon Sep 17 00:00:00 2001 From: AnshuJalan Date: Thu, 3 Oct 2024 17:23:11 +0530 Subject: [PATCH 05/15] feat: use ring buffers for lookahead posters and blocks --- SmartContracts/src/avs/PreconfTaskManager.sol | 45 +++++++------------ .../src/interfaces/IPreconfTaskManager.sol | 14 ++++++ 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/SmartContracts/src/avs/PreconfTaskManager.sol b/SmartContracts/src/avs/PreconfTaskManager.sol index 8992c8b..3a892dd 100644 --- a/SmartContracts/src/avs/PreconfTaskManager.sol +++ b/SmartContracts/src/avs/PreconfTaskManager.sol @@ -16,45 +16,31 @@ contract PreconfTaskManager is IPreconfTaskManager, Initializable { // to be stored in the main contract file itself. uint256 internal constant SLOTS_IN_EPOCH = 32; - uint256 internal constant LOOKAHEAD_BUFFER_SIZE = 64; - uint256 internal constant BLOCK_ID_TO_PROPOSER_BUFFER_SIZE = LOOKAHEAD_BUFFER_SIZE * 2; - uint256 internal constant LOOKAHEAD_POSTER_BUFFER_SIZE = - PreconfConstants.SECONDS_IN_SLOT * BLOCK_ID_TO_PROPOSER_BUFFER_SIZE; - IPreconfServiceManager internal immutable preconfServiceManager; IPreconfRegistry internal immutable preconfRegistry; ITaikoL1 internal immutable taikoL1; - struct PosterInfo { - address poster; - uint64 epochTimestamp; - } - - struct ProposerInfo { - address proposer; - uint64 blockId; - } - // EIP-4788 uint256 internal immutable beaconGenesis; address internal immutable beaconBlockRootContract; // A ring buffer of upcoming preconfers (who are also the L1 validators) uint256 internal lookaheadTail; - + uint256 internal constant LOOKAHEAD_BUFFER_SIZE = 64; LookaheadBufferEntry[LOOKAHEAD_BUFFER_SIZE] internal lookahead; - // Maps the epoch timestamp to the lookahead poster. - // If the lookahead poster has been slashed, it maps to the 0-address. - // Note: This may be optimised to re-use existing slots and reduce gas cost. - - mapping(uint256 epochTimestamp_mod_LOOKAHEAD_POSTER_BUFFER_SIZE => PosterInfo posterInfo) internal lookaheadPosters; - - // Maps the block height to the associated proposer + // A ring buffer that maps the block height to the associated proposer // This is required since the stored block in Taiko has the address of this contract as the proposer + // Stores 2 epochs worth of L2 blocks = 256 (4 blocks / slot) + uint256 internal constant BLOCK_ID_TO_PROPOSER_BUFFER_SIZE = LOOKAHEAD_BUFFER_SIZE * 4; mapping(uint256 blockId_mod_BLOCK_ID_TO_PROPOSER_BUFFER_SIZE => ProposerInfo proposerInfo) internal blockIdToProposer; + // A ring buffer that maps beginning timestamp of an epoch to the lookahead poster for that epoch + // If the lookahead poster has been slashed or the lookahead is not yet posted, the poster is the 0-address + // Stores posters for 4 latest epochs + uint256 internal constant LOOKAHEAD_POSTER_BUFFER_SIZE = PreconfConstants.SECONDS_IN_EPOCH * 4; + mapping(uint256 epochTimestamp_mod_LOOKAHEAD_POSTER_BUFFER_SIZE => PosterInfo posterInfo) internal lookaheadPosters; uint256[133] private __gap; // = 200 - 67 @@ -123,7 +109,7 @@ contract PreconfTaskManager is IPreconfTaskManager, Initializable { // Use Taiko's block number to index (, ITaikoL1.SlotB memory slotB) = taikoL1.getStateVariables(); blockIdToProposer[slotB.numBlocks % BLOCK_ID_TO_PROPOSER_BUFFER_SIZE] = - ProposerInfo(msg.sender, uint64(slotB.numBlocks)); + ProposerInfo({proposer: msg.sender, blockId: uint64(slotB.numBlocks)}); // Block the preconfer from withdrawing stake from the restaking service during the dispute window preconfServiceManager.lockStakeUntil(msg.sender, block.timestamp + PreconfConstants.DISPUTE_PERIOD); @@ -387,7 +373,8 @@ contract PreconfTaskManager is IPreconfTaskManager, Initializable { } lookaheadTail = _lookaheadTail; - lookaheadPosters[epochTimestamp % LOOKAHEAD_POSTER_BUFFER_SIZE] = PosterInfo(msg.sender, uint64(epochTimestamp)); + lookaheadPosters[epochTimestamp % LOOKAHEAD_POSTER_BUFFER_SIZE] = + PosterInfo({poster: msg.sender, epochTimestamp: uint64(epochTimestamp)}); // We directly use the lookahead set params even in the case of a fallback preconfer to // assist the nodes in identifying an incorrect lookahead. The contents of this event can be matched against @@ -577,12 +564,12 @@ contract PreconfTaskManager is IPreconfTaskManager, Initializable { } function getLookaheadPoster(uint256 epochTimestamp) public view returns (address) { - PosterInfo memory pi = lookaheadPosters[epochTimestamp % LOOKAHEAD_POSTER_BUFFER_SIZE]; - return pi.epochTimestamp == epochTimestamp ? pi.poster : address(0); + PosterInfo memory posterInfo = lookaheadPosters[epochTimestamp % LOOKAHEAD_POSTER_BUFFER_SIZE]; + return posterInfo.epochTimestamp == epochTimestamp ? posterInfo.poster : address(0); } function getBlockProposer(uint256 blockId) public view returns (address) { - ProposerInfo memory pi = blockIdToProposer[blockId % BLOCK_ID_TO_PROPOSER_BUFFER_SIZE]; - return pi.blockId == blockId ? pi.proposer : address(0); + ProposerInfo memory proposerInfo = blockIdToProposer[blockId % BLOCK_ID_TO_PROPOSER_BUFFER_SIZE]; + return proposerInfo.blockId == blockId ? proposerInfo.proposer : address(0); } } diff --git a/SmartContracts/src/interfaces/IPreconfTaskManager.sol b/SmartContracts/src/interfaces/IPreconfTaskManager.sol index ed5f97d..cc98dca 100644 --- a/SmartContracts/src/interfaces/IPreconfTaskManager.sol +++ b/SmartContracts/src/interfaces/IPreconfTaskManager.sol @@ -43,6 +43,20 @@ interface IPreconfTaskManager { address fallbackPreconfer; } + struct PosterInfo { + // Address of lookahead poster + address poster; + // Start timestamp of the epoch for which the lookahead was posted + uint64 epochTimestamp; + } + + struct ProposerInfo { + // Address of the Taiko block proposer + address proposer; + // Height of the L2 block + uint64 blockId; + } + event LookaheadUpdated(LookaheadSetParam[]); event ProvedIncorrectPreconfirmation(address indexed preconfer, uint256 indexed blockId, address indexed disputer); event ProvedIncorrectLookahead(address indexed poster, uint256 indexed timestamp, address indexed disputer); From f352d503f3f1c29d994bec4110464df32127cd7a Mon Sep 17 00:00:00 2001 From: AnshuJalan Date: Thu, 3 Oct 2024 22:02:29 +0530 Subject: [PATCH 06/15] feat: updated lookahead buffer size --- SmartContracts/src/avs/PreconfTaskManager.sol | 4 ++-- SmartContracts/src/interfaces/IPreconfTaskManager.sol | 2 +- SmartContracts/test/blocks/BlockProposing.t.sol | 2 +- SmartContracts/test/lookahead/IncorrectLookahead.t.sol | 4 ++-- SmartContracts/test/lookahead/LookaheadPosting.t.sol | 10 +++++----- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/SmartContracts/src/avs/PreconfTaskManager.sol b/SmartContracts/src/avs/PreconfTaskManager.sol index 3a892dd..8be7674 100644 --- a/SmartContracts/src/avs/PreconfTaskManager.sol +++ b/SmartContracts/src/avs/PreconfTaskManager.sol @@ -26,13 +26,13 @@ contract PreconfTaskManager is IPreconfTaskManager, Initializable { // A ring buffer of upcoming preconfers (who are also the L1 validators) uint256 internal lookaheadTail; - uint256 internal constant LOOKAHEAD_BUFFER_SIZE = 64; + uint256 internal constant LOOKAHEAD_BUFFER_SIZE = 128; LookaheadBufferEntry[LOOKAHEAD_BUFFER_SIZE] internal lookahead; // A ring buffer that maps the block height to the associated proposer // This is required since the stored block in Taiko has the address of this contract as the proposer // Stores 2 epochs worth of L2 blocks = 256 (4 blocks / slot) - uint256 internal constant BLOCK_ID_TO_PROPOSER_BUFFER_SIZE = LOOKAHEAD_BUFFER_SIZE * 4; + uint256 internal constant BLOCK_ID_TO_PROPOSER_BUFFER_SIZE = PreconfConstants.TWO_EPOCHS * 4; mapping(uint256 blockId_mod_BLOCK_ID_TO_PROPOSER_BUFFER_SIZE => ProposerInfo proposerInfo) internal blockIdToProposer; diff --git a/SmartContracts/src/interfaces/IPreconfTaskManager.sol b/SmartContracts/src/interfaces/IPreconfTaskManager.sol index cc98dca..79e9726 100644 --- a/SmartContracts/src/interfaces/IPreconfTaskManager.sol +++ b/SmartContracts/src/interfaces/IPreconfTaskManager.sol @@ -130,7 +130,7 @@ interface IPreconfTaskManager { function getLookaheadTail() external view returns (uint256); /// @dev Returns the entire lookahead buffer - function getLookaheadBuffer() external view returns (LookaheadBufferEntry[64] memory); + function getLookaheadBuffer() external view returns (LookaheadBufferEntry[128] memory); /// @dev Returns the lookahead poster for an epoch function getLookaheadPoster(uint256 epochTimestamp) external view returns (address); diff --git a/SmartContracts/test/blocks/BlockProposing.t.sol b/SmartContracts/test/blocks/BlockProposing.t.sol index 4cdefe5..1daee9b 100644 --- a/SmartContracts/test/blocks/BlockProposing.t.sol +++ b/SmartContracts/test/blocks/BlockProposing.t.sol @@ -166,7 +166,7 @@ contract BlockProposing is BlocksFixtures { preconfTaskManager.newBlockProposal("Block Params", "Txn List", 1, lookaheadSetParams); // Verify that the lookahead for the next epoch has been updated - IPreconfTaskManager.LookaheadBufferEntry[64] memory lookaheadBuffer = preconfTaskManager.getLookaheadBuffer(); + IPreconfTaskManager.LookaheadBufferEntry[128] memory lookaheadBuffer = preconfTaskManager.getLookaheadBuffer(); // Check the first entry vm.assertEq(lookaheadBuffer[3].preconfer, addr_1); diff --git a/SmartContracts/test/lookahead/IncorrectLookahead.t.sol b/SmartContracts/test/lookahead/IncorrectLookahead.t.sol index 9ea29dc..edfccd7 100644 --- a/SmartContracts/test/lookahead/IncorrectLookahead.t.sol +++ b/SmartContracts/test/lookahead/IncorrectLookahead.t.sol @@ -277,7 +277,7 @@ contract IncorrectLookahead is LookaheadFixtures { nextEpochStart + PreconfConstants.SECONDS_IN_EPOCH - PreconfConstants.SECONDS_IN_SLOT; // Verify that the lookahead has the fallback preconfer - IPreconfTaskManager.LookaheadBufferEntry[64] memory lookaheadBuffer = preconfTaskManager.getLookaheadBuffer(); + IPreconfTaskManager.LookaheadBufferEntry[128] memory lookaheadBuffer = preconfTaskManager.getLookaheadBuffer(); vm.assertEq(lookaheadBuffer[3].preconfer, addr_4); vm.assertEq(lookaheadBuffer[3].timestamp, lastSlotTimestamp); vm.assertEq(lookaheadBuffer[3].prevTimestamp, nextEpochStart - PreconfConstants.SECONDS_IN_SLOT); @@ -343,7 +343,7 @@ contract IncorrectLookahead is LookaheadFixtures { nextEpochStart + PreconfConstants.SECONDS_IN_EPOCH - PreconfConstants.SECONDS_IN_SLOT; // Verify that the lookahead has the fallback preconfer - IPreconfTaskManager.LookaheadBufferEntry[64] memory lookaheadBuffer = preconfTaskManager.getLookaheadBuffer(); + IPreconfTaskManager.LookaheadBufferEntry[128] memory lookaheadBuffer = preconfTaskManager.getLookaheadBuffer(); vm.assertEq(lookaheadBuffer[3].preconfer, addr_4); vm.assertEq(lookaheadBuffer[3].timestamp, lastSlotTimestamp); vm.assertEq(lookaheadBuffer[3].prevTimestamp, nextEpochStart - PreconfConstants.SECONDS_IN_SLOT); diff --git a/SmartContracts/test/lookahead/LookaheadPosting.t.sol b/SmartContracts/test/lookahead/LookaheadPosting.t.sol index 0df2c26..13fc362 100644 --- a/SmartContracts/test/lookahead/LookaheadPosting.t.sol +++ b/SmartContracts/test/lookahead/LookaheadPosting.t.sol @@ -34,7 +34,7 @@ contract LookaheadPosting is LookaheadFixtures { uint256 lookaheadTail = preconfTaskManager.getLookaheadTail(); vm.assertEq(lookaheadTail, 1); - IPreconfTaskManager.LookaheadBufferEntry[64] memory lookaheadBuffer = preconfTaskManager.getLookaheadBuffer(); + IPreconfTaskManager.LookaheadBufferEntry[128] memory lookaheadBuffer = preconfTaskManager.getLookaheadBuffer(); vm.assertEq(lookaheadBuffer[1].preconfer, addr_1); vm.assertEq(lookaheadBuffer[1].timestamp, nextEpochStart); vm.assertEq(lookaheadBuffer[1].prevTimestamp, 0); @@ -69,7 +69,7 @@ contract LookaheadPosting is LookaheadFixtures { uint256 lookaheadTail = preconfTaskManager.getLookaheadTail(); vm.assertEq(lookaheadTail, 2); - IPreconfTaskManager.LookaheadBufferEntry[64] memory lookaheadBuffer = preconfTaskManager.getLookaheadBuffer(); + IPreconfTaskManager.LookaheadBufferEntry[128] memory lookaheadBuffer = preconfTaskManager.getLookaheadBuffer(); vm.assertEq(lookaheadBuffer[1].preconfer, addr_1); vm.assertEq(lookaheadBuffer[1].timestamp, nextEpochStart); vm.assertEq(lookaheadBuffer[1].prevTimestamp, 0); @@ -112,7 +112,7 @@ contract LookaheadPosting is LookaheadFixtures { uint256 lookaheadTail = preconfTaskManager.getLookaheadTail(); vm.assertEq(lookaheadTail, 3); - IPreconfTaskManager.LookaheadBufferEntry[64] memory lookaheadBuffer = preconfTaskManager.getLookaheadBuffer(); + IPreconfTaskManager.LookaheadBufferEntry[128] memory lookaheadBuffer = preconfTaskManager.getLookaheadBuffer(); vm.assertEq(lookaheadBuffer[1].preconfer, addr_1); vm.assertEq(lookaheadBuffer[1].timestamp, nextEpochStart); vm.assertEq(lookaheadBuffer[1].prevTimestamp, 0); @@ -161,7 +161,7 @@ contract LookaheadPosting is LookaheadFixtures { vm.assertEq(lookaheadTail, 1); // Verify that addr_4 is inserted as fallback preconfer in lookahead buffer - IPreconfTaskManager.LookaheadBufferEntry[64] memory lookaheadBuffer = preconfTaskManager.getLookaheadBuffer(); + IPreconfTaskManager.LookaheadBufferEntry[128] memory lookaheadBuffer = preconfTaskManager.getLookaheadBuffer(); vm.assertEq(lookaheadBuffer[1].preconfer, addr_4); vm.assertEq(lookaheadBuffer[1].timestamp, lastSlotTimestampInNextEpoch); vm.assertEq(lookaheadBuffer[1].prevTimestamp, 0); @@ -201,7 +201,7 @@ contract LookaheadPosting is LookaheadFixtures { vm.assertEq(lookaheadTail, 1); // Verify that addr_4 is inserted as fallback preconfer in lookahead buffer - IPreconfTaskManager.LookaheadBufferEntry[64] memory lookaheadBuffer = preconfTaskManager.getLookaheadBuffer(); + IPreconfTaskManager.LookaheadBufferEntry[128] memory lookaheadBuffer = preconfTaskManager.getLookaheadBuffer(); vm.assertEq(lookaheadBuffer[1].preconfer, addr_4); vm.assertEq(lookaheadBuffer[1].timestamp, lastSlotTimestampInNextEpoch); vm.assertEq(lookaheadBuffer[1].prevTimestamp, 0); From 4493244723e74d9445b19fd665291afbaecfe6be Mon Sep 17 00:00:00 2001 From: AnshuJalan Date: Fri, 4 Oct 2024 14:53:57 +0530 Subject: [PATCH 07/15] feat: increase buffer sizes --- SmartContracts/src/avs/PreconfTaskManager.sol | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/SmartContracts/src/avs/PreconfTaskManager.sol b/SmartContracts/src/avs/PreconfTaskManager.sol index 8be7674..fd929d7 100644 --- a/SmartContracts/src/avs/PreconfTaskManager.sol +++ b/SmartContracts/src/avs/PreconfTaskManager.sol @@ -31,15 +31,15 @@ contract PreconfTaskManager is IPreconfTaskManager, Initializable { // A ring buffer that maps the block height to the associated proposer // This is required since the stored block in Taiko has the address of this contract as the proposer - // Stores 2 epochs worth of L2 blocks = 256 (4 blocks / slot) - uint256 internal constant BLOCK_ID_TO_PROPOSER_BUFFER_SIZE = PreconfConstants.TWO_EPOCHS * 4; + // Stores 4 epochs worth of L2 blocks = 512 (32 slots * 4 blocks a slot * 4 epochs) + uint256 internal constant BLOCK_ID_TO_PROPOSER_BUFFER_SIZE = SLOTS_IN_EPOCH * 16; mapping(uint256 blockId_mod_BLOCK_ID_TO_PROPOSER_BUFFER_SIZE => ProposerInfo proposerInfo) internal blockIdToProposer; // A ring buffer that maps beginning timestamp of an epoch to the lookahead poster for that epoch // If the lookahead poster has been slashed or the lookahead is not yet posted, the poster is the 0-address - // Stores posters for 4 latest epochs - uint256 internal constant LOOKAHEAD_POSTER_BUFFER_SIZE = PreconfConstants.SECONDS_IN_EPOCH * 4; + // Stores posters for 16 latest epochs + uint256 internal constant LOOKAHEAD_POSTER_BUFFER_SIZE = PreconfConstants.SECONDS_IN_EPOCH * 16; mapping(uint256 epochTimestamp_mod_LOOKAHEAD_POSTER_BUFFER_SIZE => PosterInfo posterInfo) internal lookaheadPosters; uint256[133] private __gap; // = 200 - 67 From fd36c2a2233df58bdba7a9489c75c183d204b54c Mon Sep 17 00:00:00 2001 From: AnshuJalan Date: Sun, 6 Oct 2024 13:58:11 +0530 Subject: [PATCH 08/15] feat: change lookahead array to mapping --- SmartContracts/src/avs/PreconfTaskManager.sol | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/SmartContracts/src/avs/PreconfTaskManager.sol b/SmartContracts/src/avs/PreconfTaskManager.sol index fd929d7..83ee8a4 100644 --- a/SmartContracts/src/avs/PreconfTaskManager.sol +++ b/SmartContracts/src/avs/PreconfTaskManager.sol @@ -27,7 +27,7 @@ contract PreconfTaskManager is IPreconfTaskManager, Initializable { // A ring buffer of upcoming preconfers (who are also the L1 validators) uint256 internal lookaheadTail; uint256 internal constant LOOKAHEAD_BUFFER_SIZE = 128; - LookaheadBufferEntry[LOOKAHEAD_BUFFER_SIZE] internal lookahead; + mapping(uint256 lookaheadIndex => LookaheadBufferEntry lookaheadBufferEntry) internal lookahead; // A ring buffer that maps the block height to the associated proposer // This is required since the stored block in Taiko has the address of this contract as the proposer @@ -560,7 +560,11 @@ contract PreconfTaskManager is IPreconfTaskManager, Initializable { } function getLookaheadBuffer() external view returns (LookaheadBufferEntry[LOOKAHEAD_BUFFER_SIZE] memory) { - return lookahead; + LookaheadBufferEntry[LOOKAHEAD_BUFFER_SIZE] memory _lookahead; + for (uint256 i; i < LOOKAHEAD_BUFFER_SIZE; ++i) { + _lookahead[i] = lookahead[i]; + } + return _lookahead; } function getLookaheadPoster(uint256 epochTimestamp) public view returns (address) { From 33204bdfa6e5c00669320edd496283a1ab961f5d Mon Sep 17 00:00:00 2001 From: AnshuJalan Date: Sun, 6 Oct 2024 14:03:07 +0530 Subject: [PATCH 09/15] feat: modify storage gaps --- SmartContracts/src/avs/PreconfRegistry.sol | 2 +- SmartContracts/src/avs/PreconfServiceManager.sol | 2 +- SmartContracts/src/avs/PreconfTaskManager.sol | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/SmartContracts/src/avs/PreconfRegistry.sol b/SmartContracts/src/avs/PreconfRegistry.sol index c419600..bdcb961 100644 --- a/SmartContracts/src/avs/PreconfRegistry.sol +++ b/SmartContracts/src/avs/PreconfRegistry.sol @@ -28,7 +28,7 @@ contract PreconfRegistry is IPreconfRegistry, BLSSignatureChecker, Initializable // Maps a validator's BLS pub key hash to the validator's details mapping(bytes32 publicKeyHash => Validator) internal validators; - uint256[196] private __gap; // = 200 - 4 + uint256[46] private __gap; // = 50 - 4 constructor(IPreconfServiceManager _preconfServiceManager) { preconfServiceManager = _preconfServiceManager; diff --git a/SmartContracts/src/avs/PreconfServiceManager.sol b/SmartContracts/src/avs/PreconfServiceManager.sol index 787477d..74099a8 100644 --- a/SmartContracts/src/avs/PreconfServiceManager.sol +++ b/SmartContracts/src/avs/PreconfServiceManager.sol @@ -20,7 +20,7 @@ contract PreconfServiceManager is IPreconfServiceManager, ReentrancyGuard { /// @dev This is currently just a flag and not actually being used to lock the stake. mapping(address operator => uint256 timestamp) public stakeLockedUntil; - uint256[199] private __gap; // 200 - 1 + uint256[49] private __gap; // 50 - 1 constructor(address _preconfRegistry, address _preconfTaskManager, IAVSDirectory _avsDirectory, ISlasher _slasher) { preconfRegistry = _preconfRegistry; diff --git a/SmartContracts/src/avs/PreconfTaskManager.sol b/SmartContracts/src/avs/PreconfTaskManager.sol index 83ee8a4..d4cbe17 100644 --- a/SmartContracts/src/avs/PreconfTaskManager.sol +++ b/SmartContracts/src/avs/PreconfTaskManager.sol @@ -42,7 +42,7 @@ contract PreconfTaskManager is IPreconfTaskManager, Initializable { uint256 internal constant LOOKAHEAD_POSTER_BUFFER_SIZE = PreconfConstants.SECONDS_IN_EPOCH * 16; mapping(uint256 epochTimestamp_mod_LOOKAHEAD_POSTER_BUFFER_SIZE => PosterInfo posterInfo) internal lookaheadPosters; - uint256[133] private __gap; // = 200 - 67 + uint256[46] private __gap; // = 50 - 4 constructor( IPreconfServiceManager _serviceManager, From 8d9f7282246a101502e354c7fbf54244747bb074 Mon Sep 17 00:00:00 2001 From: AnshuJalan Date: Sun, 6 Oct 2024 16:04:28 +0530 Subject: [PATCH 10/15] feat: add helper for lookahead setting and access --- SmartContracts/src/avs/PreconfTaskManager.sol | 88 +++++++++++-------- 1 file changed, 53 insertions(+), 35 deletions(-) diff --git a/SmartContracts/src/avs/PreconfTaskManager.sol b/SmartContracts/src/avs/PreconfTaskManager.sol index d4cbe17..4f3900f 100644 --- a/SmartContracts/src/avs/PreconfTaskManager.sol +++ b/SmartContracts/src/avs/PreconfTaskManager.sol @@ -80,7 +80,7 @@ contract PreconfTaskManager is IPreconfTaskManager, Initializable { uint256 lookaheadPointer, LookaheadSetParam[] calldata lookaheadSetParams ) external payable { - LookaheadBufferEntry memory lookaheadEntry = lookahead[lookaheadPointer % LOOKAHEAD_BUFFER_SIZE]; + LookaheadBufferEntry memory lookaheadEntry = _getLookaheadEntry(lookaheadPointer); uint256 epochTimestamp = _getEpochTimestamp(block.timestamp); @@ -194,7 +194,7 @@ contract PreconfTaskManager is IPreconfTaskManager, Initializable { // Verify that the sent validator is the one in Beacon state EIP4788.verifyValidator(validatorBLSPubKey, _getBeaconBlockRoot(slotTimestamp), validatorInclusionProof); - LookaheadBufferEntry memory lookaheadEntry = lookahead[lookaheadPointer % LOOKAHEAD_BUFFER_SIZE]; + LookaheadBufferEntry memory lookaheadEntry = _getLookaheadEntry(lookaheadPointer); // Validate lookahead pointer if (slotTimestamp > lookaheadEntry.timestamp || slotTimestamp <= lookaheadEntry.prevTimestamp) { @@ -245,9 +245,9 @@ contract PreconfTaskManager is IPreconfTaskManager, Initializable { uint256 lastSlotTimestamp = epochEndTimestamp - PreconfConstants.SECONDS_IN_SLOT; // If the lookahead for next epoch is available - if (lookahead[_lookaheadTail % LOOKAHEAD_BUFFER_SIZE].timestamp >= epochEndTimestamp) { + if (_getLookaheadEntry(_lookaheadTail).timestamp >= epochEndTimestamp) { // Get to the entry in the next epoch that connects to a slot in the current epoch - while (lookahead[_lookaheadTail % LOOKAHEAD_BUFFER_SIZE].prevTimestamp >= epochEndTimestamp) { + while (_getLookaheadEntry(_lookaheadTail).prevTimestamp >= epochEndTimestamp) { _lookaheadTail -= 1; } @@ -258,19 +258,24 @@ contract PreconfTaskManager is IPreconfTaskManager, Initializable { _lookaheadTail -= 1; } - lookahead[_lookaheadTail % LOOKAHEAD_BUFFER_SIZE] = LookaheadBufferEntry({ - isFallback: true, - timestamp: uint40(lastSlotTimestamp), - prevTimestamp: uint40(epochTimestamp - PreconfConstants.SECONDS_IN_SLOT), - preconfer: getFallbackPreconfer(epochTimestamp) - }); + _setLookaheadEntry( + _lookaheadTail, + LookaheadBufferEntry({ + isFallback: true, + timestamp: uint40(lastSlotTimestamp), + prevTimestamp: uint40(epochTimestamp - PreconfConstants.SECONDS_IN_SLOT), + preconfer: getFallbackPreconfer(epochTimestamp) + }) + ); _lookaheadTail -= 1; // Nullify the rest of the lookahead entries for this epoch - while (lookahead[_lookaheadTail % LOOKAHEAD_BUFFER_SIZE].timestamp >= epochTimestamp) { - lookahead[_lookaheadTail % LOOKAHEAD_BUFFER_SIZE] = - LookaheadBufferEntry({isFallback: false, timestamp: 0, prevTimestamp: 0, preconfer: address(0)}); + while (_getLookaheadEntry(_lookaheadTail).timestamp >= epochTimestamp) { + _setLookaheadEntry( + _lookaheadTail, + LookaheadBufferEntry({isFallback: false, timestamp: 0, prevTimestamp: 0, preconfer: address(0)}) + ); _lookaheadTail -= 1; } } @@ -327,7 +332,7 @@ contract PreconfTaskManager is IPreconfTaskManager, Initializable { // Here, P2 may start preconfing and proposing blocks from slot 4 itself // uint256 _lookaheadTail = lookaheadTail; - uint256 prevSlotTimestamp = lookahead[_lookaheadTail % LOOKAHEAD_BUFFER_SIZE].timestamp; + uint256 prevSlotTimestamp = _getLookaheadEntry(_lookaheadTail).timestamp; if (lookaheadSetParams.length == 0) { // If no preconfers are present in the lookahead, we use the fallback preconfer for the entire epoch @@ -335,12 +340,15 @@ contract PreconfTaskManager is IPreconfTaskManager, Initializable { _lookaheadTail += 1; // and, insert it in the last slot of the epoch so that it may start preconfing in advanced - lookahead[_lookaheadTail % LOOKAHEAD_BUFFER_SIZE] = LookaheadBufferEntry({ - isFallback: true, - timestamp: uint40(epochEndTimestamp - PreconfConstants.SECONDS_IN_SLOT), - prevTimestamp: uint40(prevSlotTimestamp), - preconfer: fallbackPreconfer - }); + _setLookaheadEntry( + _lookaheadTail, + LookaheadBufferEntry({ + isFallback: true, + timestamp: uint40(epochEndTimestamp - PreconfConstants.SECONDS_IN_SLOT), + prevTimestamp: uint40(prevSlotTimestamp), + preconfer: fallbackPreconfer + }) + ); } else { for (uint256 i; i < lookaheadSetParams.length; ++i) { _lookaheadTail += 1; @@ -362,12 +370,15 @@ contract PreconfTaskManager is IPreconfTaskManager, Initializable { } // Update the lookahead entry - lookahead[_lookaheadTail % LOOKAHEAD_BUFFER_SIZE] = LookaheadBufferEntry({ - isFallback: false, - timestamp: uint40(slotTimestamp), - prevTimestamp: uint40(prevSlotTimestamp), - preconfer: preconfer - }); + _setLookaheadEntry( + _lookaheadTail, + LookaheadBufferEntry({ + isFallback: false, + timestamp: uint40(slotTimestamp), + prevTimestamp: uint40(prevSlotTimestamp), + preconfer: preconfer + }) + ); prevSlotTimestamp = slotTimestamp; } } @@ -413,6 +424,14 @@ contract PreconfTaskManager is IPreconfTaskManager, Initializable { return bytes32(0); } + function _getLookaheadEntry(uint256 index) internal view returns (LookaheadBufferEntry memory) { + return lookahead[index % LOOKAHEAD_BUFFER_SIZE]; + } + + function _setLookaheadEntry(uint256 index, LookaheadBufferEntry memory entry) internal { + lookahead[index % LOOKAHEAD_BUFFER_SIZE] = entry; + } + function _isLookaheadRequired(uint256 epochTimestamp, uint256 nextEpochTimestamp) internal view returns (bool) { // If it's the first slot of current epoch, we don't need the lookahead since the offchain // node may not have access to it yet. @@ -455,25 +474,24 @@ contract PreconfTaskManager is IPreconfTaskManager, Initializable { // Take the tail to the entry that fills the last slot of the epoch. // This may be an entry in the next epoch who starts preconfing in advanced. // This may also be an empty slot since the lookahead for next epoch is not yet posted. - while (lookahead[_lookaheadTail % LOOKAHEAD_BUFFER_SIZE].prevTimestamp >= lastSlotTimestamp) { + while (_getLookaheadEntry(_lookaheadTail).prevTimestamp >= lastSlotTimestamp) { _lookaheadTail -= 1; } - address preconfer = lookahead[_lookaheadTail % LOOKAHEAD_BUFFER_SIZE].preconfer; - uint256 prevTimestamp = lookahead[_lookaheadTail % LOOKAHEAD_BUFFER_SIZE].prevTimestamp; - uint256 timestamp = uint256(lookahead[_lookaheadTail % LOOKAHEAD_BUFFER_SIZE].timestamp); + LookaheadBufferEntry memory _entry = _getLookaheadEntry(_lookaheadTail); // Iterate backwards and fill in the slots for (uint256 i = SLOTS_IN_EPOCH; i > 0; --i) { - if (timestamp >= lastSlotTimestamp) { - lookaheadForEpoch[i - 1] = preconfer; + if (_entry.timestamp >= lastSlotTimestamp) { + lookaheadForEpoch[i - 1] = _entry.preconfer; } lastSlotTimestamp -= PreconfConstants.SECONDS_IN_SLOT; - if (lastSlotTimestamp == prevTimestamp) { + if (lastSlotTimestamp == _entry.prevTimestamp) { _lookaheadTail -= 1; - preconfer = lookahead[_lookaheadTail % LOOKAHEAD_BUFFER_SIZE].preconfer; - prevTimestamp = lookahead[_lookaheadTail % LOOKAHEAD_BUFFER_SIZE].prevTimestamp; + // Reuse the memory space of _entry + _entry.preconfer = _getLookaheadEntry(_lookaheadTail).preconfer; + _entry.prevTimestamp = _getLookaheadEntry(_lookaheadTail).prevTimestamp; } } From 4e7aa81cf189c1c7498bce607c514ec8171bce29 Mon Sep 17 00:00:00 2001 From: AnshuJalan Date: Sun, 6 Oct 2024 16:11:08 +0530 Subject: [PATCH 11/15] feat: ad helper for hashingof validator key in task manager --- SmartContracts/src/avs/PreconfTaskManager.sol | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/SmartContracts/src/avs/PreconfTaskManager.sol b/SmartContracts/src/avs/PreconfTaskManager.sol index 4f3900f..208a8d2 100644 --- a/SmartContracts/src/avs/PreconfTaskManager.sol +++ b/SmartContracts/src/avs/PreconfTaskManager.sol @@ -215,7 +215,7 @@ contract PreconfTaskManager is IPreconfTaskManager, Initializable { } // Reduce validator's BLS pub key to the pub key hash expected by the registry - bytes32 validatorPubKeyHash = keccak256(abi.encodePacked(bytes16(0), validatorBLSPubKey)); + bytes32 validatorPubKeyHash = _getValidatorPubKeyHash(validatorBLSPubKey); // Retrieve the validator object IPreconfRegistry.Validator memory validatorInRegistry = preconfRegistry.getValidator(validatorPubKeyHash); @@ -438,6 +438,14 @@ contract PreconfTaskManager is IPreconfTaskManager, Initializable { return block.timestamp != epochTimestamp && getLookaheadPoster(nextEpochTimestamp) == address(0); } + /** + * @dev Assumes that validatorBLSPubKey is 48 bytes long. + * Puts 16 empty bytes infront to make it equivalent to 48-byte long pub key stored in uint256[2] + */ + function _getValidatorPubKeyHash(bytes memory validatorBLSPubKey) internal pure returns (bytes32) { + return keccak256(abi.encodePacked(bytes16(0), validatorBLSPubKey)); + } + //======= // Views //======= @@ -519,7 +527,7 @@ contract PreconfTaskManager is IPreconfTaskManager, Initializable { // Fetch the validator object from the registry IPreconfRegistry.Validator memory validator = - preconfRegistry.getValidator(keccak256(abi.encodePacked(bytes16(0), validatorBLSPubKeys[i]))); + preconfRegistry.getValidator(_getValidatorPubKeyHash(validatorBLSPubKeys[i])); // Skip deregistered preconfers if (preconfRegistry.getPreconferIndex(validator.preconfer) == 0) { From 0f2a5c43395b610759bbbfb9f0f3f0545b7466e5 Mon Sep 17 00:00:00 2001 From: AnshuJalan Date: Sun, 6 Oct 2024 16:46:43 +0530 Subject: [PATCH 12/15] feat: fix fallback selection math --- SmartContracts/src/avs/PreconfTaskManager.sol | 13 +++++++----- .../src/interfaces/IPreconfTaskManager.sol | 2 ++ .../test/fixtures/LookaheadFixtures.sol | 4 ++++ .../test/lookahead/IncorrectLookahead.t.sol | 16 +++++++++++---- .../test/lookahead/LookaheadPosting.t.sol | 20 +++++++++++++------ 5 files changed, 40 insertions(+), 15 deletions(-) diff --git a/SmartContracts/src/avs/PreconfTaskManager.sol b/SmartContracts/src/avs/PreconfTaskManager.sol index 208a8d2..2352e7b 100644 --- a/SmartContracts/src/avs/PreconfTaskManager.sol +++ b/SmartContracts/src/avs/PreconfTaskManager.sol @@ -453,14 +453,17 @@ contract PreconfTaskManager is IPreconfTaskManager, Initializable { /// @dev We use the beacon block root at the first block in the last epoch as randomness to /// decide on the preconfer for the given epoch function getFallbackPreconfer(uint256 epochTimestamp) public view returns (address) { + uint256 nextPreconferIndex = preconfRegistry.getNextPreconferIndex(); + + // Registry must have at least one preconfer + if (nextPreconferIndex == 1) { + revert NoRegisteredPreconfer(); + } + // Start of the last epoch uint256 lastEpochTimestamp = epochTimestamp - PreconfConstants.SECONDS_IN_EPOCH; uint256 randomness = uint256(_getBeaconBlockRoot(lastEpochTimestamp)); - uint256 preconferIndex = randomness % preconfRegistry.getNextPreconferIndex(); - - if (preconferIndex == 0) { - preconferIndex = 1; - } + uint256 preconferIndex = randomness % (nextPreconferIndex - 1) + 1; return preconfRegistry.getPreconferAtIndex(preconferIndex); } diff --git a/SmartContracts/src/interfaces/IPreconfTaskManager.sol b/SmartContracts/src/interfaces/IPreconfTaskManager.sol index 79e9726..d60c17c 100644 --- a/SmartContracts/src/interfaces/IPreconfTaskManager.sol +++ b/SmartContracts/src/interfaces/IPreconfTaskManager.sol @@ -83,6 +83,8 @@ interface IPreconfTaskManager { error LookaheadEntryIsCorrect(); /// @dev Cannot force push a lookahead since it is not lagging behind error LookaheadIsNotRequired(); + /// @dev The registry does not have a single registered preconfer + error NoRegisteredPreconfer(); /// @dev Accepts block proposal by an operator and forwards it to TaikoL1 contract function newBlockProposal( diff --git a/SmartContracts/test/fixtures/LookaheadFixtures.sol b/SmartContracts/test/fixtures/LookaheadFixtures.sol index 6b41fba..78abf69 100644 --- a/SmartContracts/test/fixtures/LookaheadFixtures.sol +++ b/SmartContracts/test/fixtures/LookaheadFixtures.sol @@ -40,4 +40,8 @@ contract LookaheadFixtures is BaseTest { preconfRegistry.registerPreconfer(vm.addr(i)); } } + + function computeFallbackPreconfer(bytes32 randomness, uint256 nextPreconferIndex) internal view returns (address) { + return vm.addr(uint256(randomness) % (nextPreconferIndex - 1) + 1); + } } diff --git a/SmartContracts/test/lookahead/IncorrectLookahead.t.sol b/SmartContracts/test/lookahead/IncorrectLookahead.t.sol index edfccd7..9e63baf 100644 --- a/SmartContracts/test/lookahead/IncorrectLookahead.t.sol +++ b/SmartContracts/test/lookahead/IncorrectLookahead.t.sol @@ -263,9 +263,11 @@ contract IncorrectLookahead is LookaheadFixtures { // This beacon proposer is not added as a validator for our preconfer in lookahead bytes memory beaconProposer = BeaconProofs.validator(); + bytes32 randomness = bytes32(uint256(4)); + // Set beacon block root such that addr_4 is randomly selected beaconBlockRootContract.set( - PreconfConstants.MAINNET_BEACON_GENESIS + PreconfConstants.SECONDS_IN_SLOT, bytes32(uint256(4)) + PreconfConstants.MAINNET_BEACON_GENESIS + PreconfConstants.SECONDS_IN_SLOT, randomness ); // Prove the lookahead to be incorrect @@ -278,7 +280,9 @@ contract IncorrectLookahead is LookaheadFixtures { // Verify that the lookahead has the fallback preconfer IPreconfTaskManager.LookaheadBufferEntry[128] memory lookaheadBuffer = preconfTaskManager.getLookaheadBuffer(); - vm.assertEq(lookaheadBuffer[3].preconfer, addr_4); + vm.assertEq( + lookaheadBuffer[3].preconfer, computeFallbackPreconfer(randomness, preconfRegistry.getNextPreconferIndex()) + ); vm.assertEq(lookaheadBuffer[3].timestamp, lastSlotTimestamp); vm.assertEq(lookaheadBuffer[3].prevTimestamp, nextEpochStart - PreconfConstants.SECONDS_IN_SLOT); vm.assertEq(lookaheadBuffer[3].isFallback, true); @@ -329,9 +333,11 @@ contract IncorrectLookahead is LookaheadFixtures { // This beacon proposer is not added as a validator for our preconfer in lookahead bytes memory beaconProposer = BeaconProofs.validator(); + bytes32 randomness = bytes32(uint256(4)); + // Set beacon block root such that addr_4 is randomly selected beaconBlockRootContract.set( - PreconfConstants.MAINNET_BEACON_GENESIS + PreconfConstants.SECONDS_IN_SLOT, bytes32(uint256(4)) + PreconfConstants.MAINNET_BEACON_GENESIS + PreconfConstants.SECONDS_IN_SLOT, randomness ); // Prove the lookahead to be incorrect @@ -344,7 +350,9 @@ contract IncorrectLookahead is LookaheadFixtures { // Verify that the lookahead has the fallback preconfer IPreconfTaskManager.LookaheadBufferEntry[128] memory lookaheadBuffer = preconfTaskManager.getLookaheadBuffer(); - vm.assertEq(lookaheadBuffer[3].preconfer, addr_4); + vm.assertEq( + lookaheadBuffer[3].preconfer, computeFallbackPreconfer(randomness, preconfRegistry.getNextPreconferIndex()) + ); vm.assertEq(lookaheadBuffer[3].timestamp, lastSlotTimestamp); vm.assertEq(lookaheadBuffer[3].prevTimestamp, nextEpochStart - PreconfConstants.SECONDS_IN_SLOT); vm.assertEq(lookaheadBuffer[3].isFallback, true); diff --git a/SmartContracts/test/lookahead/LookaheadPosting.t.sol b/SmartContracts/test/lookahead/LookaheadPosting.t.sol index 13fc362..14c2bb4 100644 --- a/SmartContracts/test/lookahead/LookaheadPosting.t.sol +++ b/SmartContracts/test/lookahead/LookaheadPosting.t.sol @@ -146,10 +146,12 @@ contract LookaheadPosting is LookaheadFixtures { IPreconfTaskManager.LookaheadSetParam[] memory emptyLookaheadSetParams = new IPreconfTaskManager.LookaheadSetParam[](0); + bytes32 randomness = bytes32(uint256(4)); + // Push a required root to the mock beacon block root contract // This root as a source of randomness selects the preconfer with index 4 beaconBlockRootContract.set( - PreconfConstants.MAINNET_BEACON_GENESIS + PreconfConstants.SECONDS_IN_SLOT, bytes32(uint256(4)) + PreconfConstants.MAINNET_BEACON_GENESIS + PreconfConstants.SECONDS_IN_SLOT, randomness ); // Address 2 pushes the empty lookahead @@ -160,9 +162,11 @@ contract LookaheadPosting is LookaheadFixtures { uint256 lookaheadTail = preconfTaskManager.getLookaheadTail(); vm.assertEq(lookaheadTail, 1); - // Verify that addr_4 is inserted as fallback preconfer in lookahead buffer + // Verify that correct preconfer is inserted as fallback in lookahead buffer IPreconfTaskManager.LookaheadBufferEntry[128] memory lookaheadBuffer = preconfTaskManager.getLookaheadBuffer(); - vm.assertEq(lookaheadBuffer[1].preconfer, addr_4); + vm.assertEq( + lookaheadBuffer[1].preconfer, computeFallbackPreconfer(randomness, preconfRegistry.getNextPreconferIndex()) + ); vm.assertEq(lookaheadBuffer[1].timestamp, lastSlotTimestampInNextEpoch); vm.assertEq(lookaheadBuffer[1].prevTimestamp, 0); vm.assertEq(lookaheadBuffer[1].isFallback, true); @@ -186,10 +190,12 @@ contract LookaheadPosting is LookaheadFixtures { IPreconfTaskManager.LookaheadSetParam[] memory emptyLookaheadSetParams = new IPreconfTaskManager.LookaheadSetParam[](0); + bytes32 randomness = bytes32(uint256(4)); + // Unlike Case 1, we push the root at a later timestamp to simulate "skipped blocks" and see // if the contract iterates forward and finds the required root beaconBlockRootContract.set( - PreconfConstants.MAINNET_BEACON_GENESIS + 3 * PreconfConstants.SECONDS_IN_SLOT, bytes32(uint256(4)) + PreconfConstants.MAINNET_BEACON_GENESIS + 3 * PreconfConstants.SECONDS_IN_SLOT, randomness ); // Address 2 pushes the empty lookahead @@ -200,9 +206,11 @@ contract LookaheadPosting is LookaheadFixtures { uint256 lookaheadTail = preconfTaskManager.getLookaheadTail(); vm.assertEq(lookaheadTail, 1); - // Verify that addr_4 is inserted as fallback preconfer in lookahead buffer + // Verify that correct preconfer is inserted as fallback in lookahead buffer IPreconfTaskManager.LookaheadBufferEntry[128] memory lookaheadBuffer = preconfTaskManager.getLookaheadBuffer(); - vm.assertEq(lookaheadBuffer[1].preconfer, addr_4); + vm.assertEq( + lookaheadBuffer[1].preconfer, computeFallbackPreconfer(randomness, preconfRegistry.getNextPreconferIndex()) + ); vm.assertEq(lookaheadBuffer[1].timestamp, lastSlotTimestampInNextEpoch); vm.assertEq(lookaheadBuffer[1].prevTimestamp, 0); vm.assertEq(lookaheadBuffer[1].isFallback, true); From afc89210e4c08cba4f45c5a85d43bec6b727ea6f Mon Sep 17 00:00:00 2001 From: AnshuJalan Date: Sun, 6 Oct 2024 21:56:37 +0530 Subject: [PATCH 13/15] feat: add validation for epoch timestamp --- SmartContracts/src/avs/PreconfTaskManager.sol | 14 ++++++++++++++ .../src/interfaces/IPreconfTaskManager.sol | 2 ++ 2 files changed, 16 insertions(+) diff --git a/SmartContracts/src/avs/PreconfTaskManager.sol b/SmartContracts/src/avs/PreconfTaskManager.sol index 2352e7b..7f344b1 100644 --- a/SmartContracts/src/avs/PreconfTaskManager.sol +++ b/SmartContracts/src/avs/PreconfTaskManager.sol @@ -446,6 +446,13 @@ contract PreconfTaskManager is IPreconfTaskManager, Initializable { return keccak256(abi.encodePacked(bytes16(0), validatorBLSPubKey)); } + function _validateEpochTimestamp(uint256 epochTimestamp) internal view { + if (epochTimestamp < beaconGenesis || (epochTimestamp - beaconGenesis) % PreconfConstants.SECONDS_IN_EPOCH != 0) + { + revert InvalidEpochTimestamp(); + } + } + //======= // Views //======= @@ -453,6 +460,8 @@ contract PreconfTaskManager is IPreconfTaskManager, Initializable { /// @dev We use the beacon block root at the first block in the last epoch as randomness to /// decide on the preconfer for the given epoch function getFallbackPreconfer(uint256 epochTimestamp) public view returns (address) { + _validateEpochTimestamp(epochTimestamp); + uint256 nextPreconferIndex = preconfRegistry.getNextPreconferIndex(); // Registry must have at least one preconfer @@ -476,6 +485,8 @@ contract PreconfTaskManager is IPreconfTaskManager, Initializable { * @param epochTimestamp The start timestamp of the epoch for which the lookahead is to be generated */ function getLookaheadForEpoch(uint256 epochTimestamp) external view returns (address[SLOTS_IN_EPOCH] memory) { + _validateEpochTimestamp(epochTimestamp); + address[SLOTS_IN_EPOCH] memory lookaheadForEpoch; uint256 _lookaheadTail = lookaheadTail; @@ -522,6 +533,8 @@ contract PreconfTaskManager is IPreconfTaskManager, Initializable { view returns (LookaheadSetParam[] memory) { + _validateEpochTimestamp(epochTimestamp); + uint256 index; LookaheadSetParam[32] memory lookaheadSetParamsTemp; @@ -597,6 +610,7 @@ contract PreconfTaskManager is IPreconfTaskManager, Initializable { } function getLookaheadPoster(uint256 epochTimestamp) public view returns (address) { + _validateEpochTimestamp(epochTimestamp); PosterInfo memory posterInfo = lookaheadPosters[epochTimestamp % LOOKAHEAD_POSTER_BUFFER_SIZE]; return posterInfo.epochTimestamp == epochTimestamp ? posterInfo.poster : address(0); } diff --git a/SmartContracts/src/interfaces/IPreconfTaskManager.sol b/SmartContracts/src/interfaces/IPreconfTaskManager.sol index d60c17c..5abfc07 100644 --- a/SmartContracts/src/interfaces/IPreconfTaskManager.sol +++ b/SmartContracts/src/interfaces/IPreconfTaskManager.sol @@ -67,6 +67,8 @@ interface IPreconfTaskManager { error SenderIsNotThePreconfer(); /// @dev Preconfer is not present in the registry error PreconferNotRegistered(); + /// @dev Epoch timestamp is incorrect + error InvalidEpochTimestamp(); /// @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 From 988a9eaaa05e6cc5137c66eab6e7ca671baeb249 Mon Sep 17 00:00:00 2001 From: AnshuJalan Date: Mon, 7 Oct 2024 13:20:25 +0530 Subject: [PATCH 14/15] fix: remove redundant else statement to set preconferInLookahead --- SmartContracts/src/avs/PreconfTaskManager.sol | 5 ----- 1 file changed, 5 deletions(-) diff --git a/SmartContracts/src/avs/PreconfTaskManager.sol b/SmartContracts/src/avs/PreconfTaskManager.sol index 7f344b1..52ec71b 100644 --- a/SmartContracts/src/avs/PreconfTaskManager.sol +++ b/SmartContracts/src/avs/PreconfTaskManager.sol @@ -207,11 +207,6 @@ contract PreconfTaskManager is IPreconfTaskManager, Initializable { if (lookaheadEntry.timestamp == slotTimestamp && !lookaheadEntry.isFallback) { // The slot was dedicated to a specific preconfer preconferInLookahead = lookaheadEntry.preconfer; - } else { - // The slot was empty and it was the next preconfer who was expected to preconf in advanced, OR - // the slot was empty and the preconfer was expected to be the fallback preconfer for the epoch. - // We still use the zero address because technically the slot itself was empty in the lookahead. - preconferInLookahead = address(0); } // Reduce validator's BLS pub key to the pub key hash expected by the registry From e305d899dde028acf94f5232047fd7f615c447ce Mon Sep 17 00:00:00 2001 From: AnshuJalan Date: Mon, 7 Oct 2024 13:29:52 +0530 Subject: [PATCH 15/15] chore: add license --- LICENSE.md | 9 +++++++++ SmartContracts/scripts/BaseScript.sol | 2 +- SmartContracts/scripts/deployment/DeployAVS.s.sol | 2 +- .../scripts/deployment/DeployEigenlayerMVP.s.sol | 2 +- .../scripts/deployment/mock/DeployMockAVS.s.sol | 2 +- .../scripts/deployment/mock/DeployMockTaikoToken.s.sol | 2 +- SmartContracts/scripts/misc/EmptyContract.sol | 2 +- SmartContracts/src/avs/PreconfConstants.sol | 2 +- SmartContracts/src/avs/PreconfRegistry.sol | 2 +- SmartContracts/src/avs/PreconfServiceManager.sol | 2 +- SmartContracts/src/avs/PreconfTaskManager.sol | 2 +- SmartContracts/src/avs/utils/BLSSignatureChecker.sol | 2 +- SmartContracts/src/eigenlayer-mvp/AVSDirectory.sol | 2 +- SmartContracts/src/eigenlayer-mvp/DelegationManager.sol | 2 +- SmartContracts/src/eigenlayer-mvp/Slasher.sol | 2 +- SmartContracts/src/eigenlayer-mvp/StrategyManager.sol | 2 +- SmartContracts/src/interfaces/IPreconfRegistry.sol | 2 +- SmartContracts/src/interfaces/IPreconfServiceManager.sol | 2 +- SmartContracts/src/interfaces/IPreconfTaskManager.sol | 2 +- .../src/interfaces/eigenlayer-mvp/IAVSDirectory.sol | 2 +- .../src/interfaces/eigenlayer-mvp/IDelegationManager.sol | 2 +- .../src/interfaces/eigenlayer-mvp/ISlasher.sol | 2 +- .../src/interfaces/eigenlayer-mvp/IStrategyManager.sol | 2 +- SmartContracts/src/interfaces/taiko/ITaikoL1.sol | 2 +- SmartContracts/src/libraries/BLS12381.sol | 2 +- SmartContracts/src/libraries/EIP4788.sol | 2 +- SmartContracts/src/libraries/MerkleUtils.sol | 2 +- SmartContracts/src/mock/MockPreconfRegistry.sol | 2 +- SmartContracts/src/mock/MockTaikoToken.sol | 5 ++--- SmartContracts/test/BaseTest.sol | 2 +- SmartContracts/test/beacon/BeaconProofsVerification.sol | 2 +- SmartContracts/test/blocks/BlockProposing.t.sol | 2 +- .../test/blocks/IncorrectPreconfirmations.t.sol | 2 +- SmartContracts/test/bls/BLSExpandMsgXmd.t.sol | 2 +- SmartContracts/test/bls/BLSHashToFieldFp2.t.sol | 2 +- SmartContracts/test/bls/script-test/BLSHashToCurveG2.sol | 2 +- .../test/bls/script-test/BLSVerifySignature.sol | 2 +- SmartContracts/test/fixtures/BeaconProofs.sol | 2 +- SmartContracts/test/fixtures/BlocksFixtures.sol | 2 +- SmartContracts/test/fixtures/LookaheadFixtures.sol | 2 +- SmartContracts/test/lookahead/IncorrectLookahead.t.sol | 2 +- SmartContracts/test/lookahead/LookaheadPosting.t.sol | 2 +- SmartContracts/test/mocks/MockBeaconBlockRoot.sol | 2 +- SmartContracts/test/mocks/MockPreconfRegistry.sol | 2 +- SmartContracts/test/mocks/MockPreconfServiceManager.sol | 2 +- SmartContracts/test/mocks/MockTaikoL1.sol | 2 +- 46 files changed, 55 insertions(+), 47 deletions(-) create mode 100644 LICENSE.md diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..6bdda86 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,9 @@ +MIT License + +Copyright 2024 Nethermind + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/SmartContracts/scripts/BaseScript.sol b/SmartContracts/scripts/BaseScript.sol index b0271f7..97e2a3c 100644 --- a/SmartContracts/scripts/BaseScript.sol +++ b/SmartContracts/scripts/BaseScript.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity 0.8.25; import {Script} from "forge-std/Script.sol"; diff --git a/SmartContracts/scripts/deployment/DeployAVS.s.sol b/SmartContracts/scripts/deployment/DeployAVS.s.sol index 11a93c4..5824020 100644 --- a/SmartContracts/scripts/deployment/DeployAVS.s.sol +++ b/SmartContracts/scripts/deployment/DeployAVS.s.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity 0.8.25; import {BaseScript} from "../BaseScript.sol"; diff --git a/SmartContracts/scripts/deployment/DeployEigenlayerMVP.s.sol b/SmartContracts/scripts/deployment/DeployEigenlayerMVP.s.sol index 8fe8644..e0592ea 100644 --- a/SmartContracts/scripts/deployment/DeployEigenlayerMVP.s.sol +++ b/SmartContracts/scripts/deployment/DeployEigenlayerMVP.s.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity 0.8.25; import {BaseScript} from "../BaseScript.sol"; diff --git a/SmartContracts/scripts/deployment/mock/DeployMockAVS.s.sol b/SmartContracts/scripts/deployment/mock/DeployMockAVS.s.sol index 78328e9..8e4ea7c 100644 --- a/SmartContracts/scripts/deployment/mock/DeployMockAVS.s.sol +++ b/SmartContracts/scripts/deployment/mock/DeployMockAVS.s.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity 0.8.25; import {BaseScript} from "../../BaseScript.sol"; diff --git a/SmartContracts/scripts/deployment/mock/DeployMockTaikoToken.s.sol b/SmartContracts/scripts/deployment/mock/DeployMockTaikoToken.s.sol index 3a61063..4198f3e 100644 --- a/SmartContracts/scripts/deployment/mock/DeployMockTaikoToken.s.sol +++ b/SmartContracts/scripts/deployment/mock/DeployMockTaikoToken.s.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity 0.8.25; import {BaseScript} from "../../BaseScript.sol"; diff --git a/SmartContracts/scripts/misc/EmptyContract.sol b/SmartContracts/scripts/misc/EmptyContract.sol index 4858c39..a509725 100644 --- a/SmartContracts/scripts/misc/EmptyContract.sol +++ b/SmartContracts/scripts/misc/EmptyContract.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity 0.8.25; /// @dev This is solely used as a placeholder during empty proxy deployment diff --git a/SmartContracts/src/avs/PreconfConstants.sol b/SmartContracts/src/avs/PreconfConstants.sol index b348531..31c85a9 100644 --- a/SmartContracts/src/avs/PreconfConstants.sol +++ b/SmartContracts/src/avs/PreconfConstants.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity 0.8.25; library PreconfConstants { diff --git a/SmartContracts/src/avs/PreconfRegistry.sol b/SmartContracts/src/avs/PreconfRegistry.sol index bdcb961..128b77f 100644 --- a/SmartContracts/src/avs/PreconfRegistry.sol +++ b/SmartContracts/src/avs/PreconfRegistry.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity 0.8.25; import {BLS12381} from "../libraries/BLS12381.sol"; diff --git a/SmartContracts/src/avs/PreconfServiceManager.sol b/SmartContracts/src/avs/PreconfServiceManager.sol index 74099a8..4cd995c 100644 --- a/SmartContracts/src/avs/PreconfServiceManager.sol +++ b/SmartContracts/src/avs/PreconfServiceManager.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity 0.8.25; import {IPreconfServiceManager} from "../interfaces/IPreconfServiceManager.sol"; diff --git a/SmartContracts/src/avs/PreconfTaskManager.sol b/SmartContracts/src/avs/PreconfTaskManager.sol index 52ec71b..7471caf 100644 --- a/SmartContracts/src/avs/PreconfTaskManager.sol +++ b/SmartContracts/src/avs/PreconfTaskManager.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity 0.8.25; import {ITaikoL1} from "../interfaces/taiko/ITaikoL1.sol"; diff --git a/SmartContracts/src/avs/utils/BLSSignatureChecker.sol b/SmartContracts/src/avs/utils/BLSSignatureChecker.sol index 6775131..ccab6ad 100644 --- a/SmartContracts/src/avs/utils/BLSSignatureChecker.sol +++ b/SmartContracts/src/avs/utils/BLSSignatureChecker.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity 0.8.25; import {BLS12381} from "../../libraries/BLS12381.sol"; diff --git a/SmartContracts/src/eigenlayer-mvp/AVSDirectory.sol b/SmartContracts/src/eigenlayer-mvp/AVSDirectory.sol index 8689a76..c3d46c4 100644 --- a/SmartContracts/src/eigenlayer-mvp/AVSDirectory.sol +++ b/SmartContracts/src/eigenlayer-mvp/AVSDirectory.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity 0.8.25; import {IAVSDirectory} from "../interfaces/eigenlayer-mvp/IAVSDirectory.sol"; diff --git a/SmartContracts/src/eigenlayer-mvp/DelegationManager.sol b/SmartContracts/src/eigenlayer-mvp/DelegationManager.sol index dc33e85..b3a3417 100644 --- a/SmartContracts/src/eigenlayer-mvp/DelegationManager.sol +++ b/SmartContracts/src/eigenlayer-mvp/DelegationManager.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity 0.8.25; import {IDelegationManager} from "../interfaces/eigenlayer-mvp/IDelegationManager.sol"; diff --git a/SmartContracts/src/eigenlayer-mvp/Slasher.sol b/SmartContracts/src/eigenlayer-mvp/Slasher.sol index 52831d5..8e2d0dd 100644 --- a/SmartContracts/src/eigenlayer-mvp/Slasher.sol +++ b/SmartContracts/src/eigenlayer-mvp/Slasher.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity 0.8.25; import {ISlasher} from "../interfaces/eigenlayer-mvp/ISlasher.sol"; diff --git a/SmartContracts/src/eigenlayer-mvp/StrategyManager.sol b/SmartContracts/src/eigenlayer-mvp/StrategyManager.sol index eb43570..44f3047 100644 --- a/SmartContracts/src/eigenlayer-mvp/StrategyManager.sol +++ b/SmartContracts/src/eigenlayer-mvp/StrategyManager.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity 0.8.25; import {IStrategyManager} from "../interfaces/eigenlayer-mvp/IStrategyManager.sol"; diff --git a/SmartContracts/src/interfaces/IPreconfRegistry.sol b/SmartContracts/src/interfaces/IPreconfRegistry.sol index cd691a9..2dd1b9b 100644 --- a/SmartContracts/src/interfaces/IPreconfRegistry.sol +++ b/SmartContracts/src/interfaces/IPreconfRegistry.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity 0.8.25; import {BLS12381} from "../libraries/BLS12381.sol"; diff --git a/SmartContracts/src/interfaces/IPreconfServiceManager.sol b/SmartContracts/src/interfaces/IPreconfServiceManager.sol index c4d57a5..dc8db09 100644 --- a/SmartContracts/src/interfaces/IPreconfServiceManager.sol +++ b/SmartContracts/src/interfaces/IPreconfServiceManager.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity 0.8.25; import {IAVSDirectory} from "./eigenlayer-mvp/IAVSDirectory.sol"; diff --git a/SmartContracts/src/interfaces/IPreconfTaskManager.sol b/SmartContracts/src/interfaces/IPreconfTaskManager.sol index 5abfc07..e90d9c8 100644 --- a/SmartContracts/src/interfaces/IPreconfTaskManager.sol +++ b/SmartContracts/src/interfaces/IPreconfTaskManager.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity 0.8.25; import {EIP4788} from "../libraries/EIP4788.sol"; diff --git a/SmartContracts/src/interfaces/eigenlayer-mvp/IAVSDirectory.sol b/SmartContracts/src/interfaces/eigenlayer-mvp/IAVSDirectory.sol index 393d742..bd9c051 100644 --- a/SmartContracts/src/interfaces/eigenlayer-mvp/IAVSDirectory.sol +++ b/SmartContracts/src/interfaces/eigenlayer-mvp/IAVSDirectory.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity 0.8.25; interface IAVSDirectory { diff --git a/SmartContracts/src/interfaces/eigenlayer-mvp/IDelegationManager.sol b/SmartContracts/src/interfaces/eigenlayer-mvp/IDelegationManager.sol index 8f20eb3..a7380c0 100644 --- a/SmartContracts/src/interfaces/eigenlayer-mvp/IDelegationManager.sol +++ b/SmartContracts/src/interfaces/eigenlayer-mvp/IDelegationManager.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity 0.8.25; interface IDelegationManager { diff --git a/SmartContracts/src/interfaces/eigenlayer-mvp/ISlasher.sol b/SmartContracts/src/interfaces/eigenlayer-mvp/ISlasher.sol index 28609d1..b6186d6 100644 --- a/SmartContracts/src/interfaces/eigenlayer-mvp/ISlasher.sol +++ b/SmartContracts/src/interfaces/eigenlayer-mvp/ISlasher.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity 0.8.25; interface ISlasher { diff --git a/SmartContracts/src/interfaces/eigenlayer-mvp/IStrategyManager.sol b/SmartContracts/src/interfaces/eigenlayer-mvp/IStrategyManager.sol index 077a6e8..7343421 100644 --- a/SmartContracts/src/interfaces/eigenlayer-mvp/IStrategyManager.sol +++ b/SmartContracts/src/interfaces/eigenlayer-mvp/IStrategyManager.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity 0.8.25; interface IStrategyManager { diff --git a/SmartContracts/src/interfaces/taiko/ITaikoL1.sol b/SmartContracts/src/interfaces/taiko/ITaikoL1.sol index abf7118..84f54db 100644 --- a/SmartContracts/src/interfaces/taiko/ITaikoL1.sol +++ b/SmartContracts/src/interfaces/taiko/ITaikoL1.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity 0.8.25; interface ITaikoL1 { diff --git a/SmartContracts/src/libraries/BLS12381.sol b/SmartContracts/src/libraries/BLS12381.sol index 25edf6e..4051084 100644 --- a/SmartContracts/src/libraries/BLS12381.sol +++ b/SmartContracts/src/libraries/BLS12381.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT // Functions in this library have been adapted from: // https://github.com/ethyla/bls12-381-hash-to-curve/blob/main/src/HashToCurve.sol pragma solidity 0.8.25; diff --git a/SmartContracts/src/libraries/EIP4788.sol b/SmartContracts/src/libraries/EIP4788.sol index 1c37b3c..fb2a1c0 100644 --- a/SmartContracts/src/libraries/EIP4788.sol +++ b/SmartContracts/src/libraries/EIP4788.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT // Referenced from: https://ethresear.ch/t/slashing-proofoor-on-chain-slashed-validator-proofs/19421 pragma solidity 0.8.25; diff --git a/SmartContracts/src/libraries/MerkleUtils.sol b/SmartContracts/src/libraries/MerkleUtils.sol index 1f1add3..5bb7039 100644 --- a/SmartContracts/src/libraries/MerkleUtils.sol +++ b/SmartContracts/src/libraries/MerkleUtils.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity 0.8.25; diff --git a/SmartContracts/src/mock/MockPreconfRegistry.sol b/SmartContracts/src/mock/MockPreconfRegistry.sol index 0fde062..18ad36e 100644 --- a/SmartContracts/src/mock/MockPreconfRegistry.sol +++ b/SmartContracts/src/mock/MockPreconfRegistry.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity 0.8.25; import {BLS12381} from "../libraries/BLS12381.sol"; diff --git a/SmartContracts/src/mock/MockTaikoToken.sol b/SmartContracts/src/mock/MockTaikoToken.sol index fe80719..4b24e7e 100644 --- a/SmartContracts/src/mock/MockTaikoToken.sol +++ b/SmartContracts/src/mock/MockTaikoToken.sol @@ -1,8 +1,7 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity 0.8.25; contract MockTaikoToken { - address public lastAddr; uint256 public lastAmount; @@ -11,4 +10,4 @@ contract MockTaikoToken { lastAmount = amount; return true; } -} \ No newline at end of file +} diff --git a/SmartContracts/test/BaseTest.sol b/SmartContracts/test/BaseTest.sol index 21bd9d8..462cc07 100644 --- a/SmartContracts/test/BaseTest.sol +++ b/SmartContracts/test/BaseTest.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity 0.8.25; import {Test} from "forge-std/Test.sol"; diff --git a/SmartContracts/test/beacon/BeaconProofsVerification.sol b/SmartContracts/test/beacon/BeaconProofsVerification.sol index c15f6a1..a78aae0 100644 --- a/SmartContracts/test/beacon/BeaconProofsVerification.sol +++ b/SmartContracts/test/beacon/BeaconProofsVerification.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity 0.8.25; import {BaseTest} from "../BaseTest.sol"; diff --git a/SmartContracts/test/blocks/BlockProposing.t.sol b/SmartContracts/test/blocks/BlockProposing.t.sol index 1daee9b..4ab5126 100644 --- a/SmartContracts/test/blocks/BlockProposing.t.sol +++ b/SmartContracts/test/blocks/BlockProposing.t.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity 0.8.25; import {BlocksFixtures} from "../fixtures/BlocksFixtures.sol"; diff --git a/SmartContracts/test/blocks/IncorrectPreconfirmations.t.sol b/SmartContracts/test/blocks/IncorrectPreconfirmations.t.sol index df4ea0a..9bf84c6 100644 --- a/SmartContracts/test/blocks/IncorrectPreconfirmations.t.sol +++ b/SmartContracts/test/blocks/IncorrectPreconfirmations.t.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity 0.8.25; import {BlocksFixtures} from "../fixtures/BlocksFixtures.sol"; diff --git a/SmartContracts/test/bls/BLSExpandMsgXmd.t.sol b/SmartContracts/test/bls/BLSExpandMsgXmd.t.sol index 7f1bef1..7c602ed 100644 --- a/SmartContracts/test/bls/BLSExpandMsgXmd.t.sol +++ b/SmartContracts/test/bls/BLSExpandMsgXmd.t.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT // Test has been referenced from https://github.com/ethyla/bls12-381-hash-to-curve/blob/main/test/expandMsgXmd.sol pragma solidity 0.8.25; diff --git a/SmartContracts/test/bls/BLSHashToFieldFp2.t.sol b/SmartContracts/test/bls/BLSHashToFieldFp2.t.sol index eee525d..b00caa0 100644 --- a/SmartContracts/test/bls/BLSHashToFieldFp2.t.sol +++ b/SmartContracts/test/bls/BLSHashToFieldFp2.t.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT // Test has been referenced from https://github.com/ethyla/bls12-381-hash-to-curve/blob/main/test/hashToField.sol pragma solidity 0.8.25; diff --git a/SmartContracts/test/bls/script-test/BLSHashToCurveG2.sol b/SmartContracts/test/bls/script-test/BLSHashToCurveG2.sol index 128f242..828739f 100644 --- a/SmartContracts/test/bls/script-test/BLSHashToCurveG2.sol +++ b/SmartContracts/test/bls/script-test/BLSHashToCurveG2.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT // solhint-disable-next-line pragma solidity 0.8.25; diff --git a/SmartContracts/test/bls/script-test/BLSVerifySignature.sol b/SmartContracts/test/bls/script-test/BLSVerifySignature.sol index f1ce33e..5f5bf50 100644 --- a/SmartContracts/test/bls/script-test/BLSVerifySignature.sol +++ b/SmartContracts/test/bls/script-test/BLSVerifySignature.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT // solhint-disable-next-line pragma solidity 0.8.25; diff --git a/SmartContracts/test/fixtures/BeaconProofs.sol b/SmartContracts/test/fixtures/BeaconProofs.sol index 10754c1..ec96fb2 100644 --- a/SmartContracts/test/fixtures/BeaconProofs.sol +++ b/SmartContracts/test/fixtures/BeaconProofs.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity 0.8.25; import {EIP4788} from "src/libraries/EIP4788.sol"; diff --git a/SmartContracts/test/fixtures/BlocksFixtures.sol b/SmartContracts/test/fixtures/BlocksFixtures.sol index 36aaf3b..28230d2 100644 --- a/SmartContracts/test/fixtures/BlocksFixtures.sol +++ b/SmartContracts/test/fixtures/BlocksFixtures.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity 0.8.25; import {BaseTest} from "../BaseTest.sol"; diff --git a/SmartContracts/test/fixtures/LookaheadFixtures.sol b/SmartContracts/test/fixtures/LookaheadFixtures.sol index 78abf69..d10dc17 100644 --- a/SmartContracts/test/fixtures/LookaheadFixtures.sol +++ b/SmartContracts/test/fixtures/LookaheadFixtures.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity 0.8.25; import {BaseTest} from "../BaseTest.sol"; diff --git a/SmartContracts/test/lookahead/IncorrectLookahead.t.sol b/SmartContracts/test/lookahead/IncorrectLookahead.t.sol index 9e63baf..c6b24b1 100644 --- a/SmartContracts/test/lookahead/IncorrectLookahead.t.sol +++ b/SmartContracts/test/lookahead/IncorrectLookahead.t.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity 0.8.25; import {BeaconProofs} from "../fixtures/BeaconProofs.sol"; diff --git a/SmartContracts/test/lookahead/LookaheadPosting.t.sol b/SmartContracts/test/lookahead/LookaheadPosting.t.sol index 14c2bb4..1c3cc21 100644 --- a/SmartContracts/test/lookahead/LookaheadPosting.t.sol +++ b/SmartContracts/test/lookahead/LookaheadPosting.t.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity 0.8.25; import {LookaheadFixtures} from "../fixtures/LookaheadFixtures.sol"; diff --git a/SmartContracts/test/mocks/MockBeaconBlockRoot.sol b/SmartContracts/test/mocks/MockBeaconBlockRoot.sol index 0bd8b49..8487966 100644 --- a/SmartContracts/test/mocks/MockBeaconBlockRoot.sol +++ b/SmartContracts/test/mocks/MockBeaconBlockRoot.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity 0.8.25; contract MockBeaconBlockRoot { diff --git a/SmartContracts/test/mocks/MockPreconfRegistry.sol b/SmartContracts/test/mocks/MockPreconfRegistry.sol index 5becf43..ed7a261 100644 --- a/SmartContracts/test/mocks/MockPreconfRegistry.sol +++ b/SmartContracts/test/mocks/MockPreconfRegistry.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity 0.8.25; contract MockPreconfRegistry { diff --git a/SmartContracts/test/mocks/MockPreconfServiceManager.sol b/SmartContracts/test/mocks/MockPreconfServiceManager.sol index 6cdc917..a7bba83 100644 --- a/SmartContracts/test/mocks/MockPreconfServiceManager.sol +++ b/SmartContracts/test/mocks/MockPreconfServiceManager.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity 0.8.25; contract MockPreconfServiceManager { diff --git a/SmartContracts/test/mocks/MockTaikoL1.sol b/SmartContracts/test/mocks/MockTaikoL1.sol index 3288c8a..43a8712 100644 --- a/SmartContracts/test/mocks/MockTaikoL1.sol +++ b/SmartContracts/test/mocks/MockTaikoL1.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity 0.8.25; import {ITaikoL1} from "src/interfaces/taiko/ITaikoL1.sol";