-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(protocol): support delayed forced inclusion of txs #18826
Merged
Merged
Changes from 209 commits
Commits
Show all changes
250 commits
Select commit
Hold shift + click to select a range
b01e6c3
more
dantaik 2c61574
refactor(protocol): multiple improvements on implementation and tests…
dantaik 4dfebd0
forge fmt & update contract layout tables
dantaik 2086135
remove minBlocksToVerify
dantaik 5c133ec
forge fmt & update contract layout tables
dantaik 2b39162
add verifier to TransitionProvedV3 event
dantaik e6a5447
forge fmt & update contract layout tables
dantaik 5ed3284
resolved some TODOs
dantaik 485bad6
forge fmt & update contract layout tables
dantaik 91c3bca
use batch events
dantaik f7c1b91
Update ITaikoL1.sol
dantaik ff0ff24
forge fmt & update contract layout tables
dantaik a75557d
enable calldata for txList (#18540)
dantaik 8a9a23c
Merge branch 'main' into pacaya_fork
dantaik fcfa031
Delete TEST_TREE.md
dantaik eaf673a
forge fmt & update contract layout tables
dantaik 26b53ff
fix bug
dantaik 092a5e5
Update TaikoL1Test_Suite1.json
dantaik bcfc984
forge fmt & update contract layout tables
dantaik 088d46a
minor comment changes
dantaik ee2b92d
forge fmt & update contract layout tables
dantaik b88bb5b
chore(protocol): fix typos (#18537)
xiaodino 000d7f4
chore(protocol): remove MainnetTierProvider due to no found (#18536)
xiaodino a16d408
forge fmt & update contract layout tables
dantaik 073a404
Merge branch 'main' into pacaya_fork
dantaik f76ab17
chore(protocol): test Ether as bond asset (#18558)
xiaodino 04c36f5
Merge branch 'main' into ForkManager
dantaik 8978ec8
Merge branch 'main' into pacaya_fork
dantaik 7b528f0
forge fmt & update contract layout tables
dantaik b6fd111
remove supporting calldata as DA due to EIP-7623 (#18566)
dantaik f4c3185
Revert "remove supporting calldata as DA due to EIP-7623 (#18566)"
dantaik bf5ccc2
make latest config always have all fork heights & clean up verifier c…
dantaik 762e20d
remove emitTxListInCalldata and calldataUsed from metadata
dantaik 49cbdcd
more
dantaik 08fd7e6
Update TaikoL1Test_Suite1.json
dantaik 7e87f7a
chore(protocol): test bond deposit and withdrawal (#18564)
xiaodino 3b232ec
Merge branch 'main' into ForkManager
dantaik 32efe31
chore(protocol): test bond mechanics and calldata for txlist (#18575)
xiaodino b995683
Merge branch 'main' into pacaya_fork
dantaik fd96a1b
Update SP1Verifier.t.sol
dantaik ecf3e56
Update RollupResolver.sol
dantaik 78dc045
Merge branch 'main' into ForkManager
dantaik 33a0ecb
Merge branch 'ForkManager' into pacaya_fork
dantaik 7f7cd9d
fix
dantaik 9303f89
Update SP1Verifier.t.sol
dantaik 8b3b93d
Merge branch 'main' into pacaya_fork
dantaik 30b1a54
Update ForkManager.t.sol
dantaik a7abe70
forge fmt & update contract layout tables
dantaik 9f758d6
rename
dantaik b4fa3c2
Update TaikoL1.sol
dantaik 501c2fd
rename
dantaik e1eb410
chore(protocol): Add tests in SignalService.t.sol (#18599)
xiaodino eec4256
forge fmt & update contract layout tables
dantaik 1927a30
feat(protocol): allow block propose to pass a bytes32 input to L2 anc…
dantaik b7c31e9
forge fmt & update contract layout tables
dantaik 29682b7
chore(protocol): fix issues in test:coverage (#18582)
xiaodino 1673665
chore(protocol): Add tests for LibBytes (#18604)
xiaodino 5bd025c
feat(protocol): allow same-slot L1-to-L2 signalling (#18587)
dantaik a3f9818
Merge branch 'main' into pacaya_fork
dantaik 89adac2
forge fmt & update contract layout tables
dantaik 3daad26
Update TaikoL1Test_Suite1.json
dantaik 4833b2f
Update TaikoL1Test_Suite1.json
dantaik 92e7196
Update TaikoL1Test_Suite1.json
dantaik 9e54d4b
forge fmt & update contract layout tables
dantaik 0e99f65
Update ITaikoL1.sol
dantaik e4948e6
TaikoL1 -> TaikoInbox
dantaik dd1c004
forge fmt & update contract layout tables
dantaik 7ff3c0b
TaikoL2 -> TaikoAnchor
dantaik 909ac11
Delete taiko-anchor
dantaik 122ec3d
forge fmt & update contract layout tables
dantaik 9f1d7a8
fix gen-layout
dantaik 0b05e31
forge fmt & update contract layout tables
dantaik 3261a71
make TaikoAnchor generic
dantaik 10b0ffc
rename
dantaik 31060cc
rename
dantaik 2156d4f
forge fmt & update contract layout tables
dantaik 1bb9b70
fix comments
dantaik 61caf26
fix
dantaik 7a93c3c
feat(protocol): add deployment scripts for `Pacaya` (#18606)
davidtaikocha a45dd1c
feat(protocol): fix `Pacaya` genesis generation && tests (#18607)
davidtaikocha a59ee7b
improve comments
dantaik 757c083
forge fmt & update contract layout tables
dantaik 8a0bc5b
Update ProverSet.sol
dantaik 18d6ab7
chore(protocol): Add tests for proposeBlocksV3 reverts for invalid pr…
xiaodino 0d26d18
chore(protocol): add tests for LibNetwork (#18626)
xiaodino 8c1836e
Merge branch 'main' into pacaya_fork
dantaik 65041c8
introduce ITaiko.sol
dantaik 9112a28
Update gen-layouts.sh
dantaik 573797f
forge fmt & update contract layout tables
dantaik ecdf0ef
Update gen-layouts.sh
dantaik 3d4249a
forge fmt & update contract layout tables
dantaik 8518c1d
Update gen-layouts.sh
dantaik f0d8eaf
Merge branch 'clearer_layout' into pacaya_fork
dantaik 6fcf076
forge fmt & update contract layout tables
dantaik 52471ac
Merge branch 'main' into pacaya_fork
dantaik 294d265
forge fmt & update contract layout tables
dantaik e12ec5a
Update Layer1Test.sol
dantaik 1cfcb5b
Merge branch 'main' into pacaya_fork
dantaik c61bf99
Merge branch 'main' into pacaya_fork
dantaik 686f2ce
bump version to 2.0.0
dantaik 7717522
feat(protocol): add solver support to enable fast bridging of erc20 t…
AnshuJalan ccafc7d
Merge branch 'main' into pacaya_fork
dantaik 2055ea2
Merge branch 'main' into pacaya_fork
davidtaikocha 8fc2d61
chore(protocol): add tests for _validateBlockParams (#18680)
xiaodino 6cda21c
Merge branch 'main' into pacaya_fork
dantaik 0129fad
chore(protocol): add TokenUnlock_ProverSet test (#18704)
xiaodino 338f4cf
chore(protocol): add tests for BridgedTaikoToken (#18707)
xiaodino cd09adc
Update LibTrieProof.sol
dantaik 8eb5b2f
update solhint
dantaik dbf8d2b
Merge branch 'main' into pacaya_fork
dantaik 230bba0
Update TaikoAnchor.t.sol
dantaik b54d467
Merge branch 'main' into pacaya_fork
davidtaikocha 7e20c0f
forge fmt & update contract layout tables
davidtaikocha d52cf4a
feat(protocol): support smaller more frequent L2 blocks (replacing so…
dantaik d4ac84b
feat(protocol): redo ForkMananger (now ForkRouter) (#18751)
dantaik 84667f3
use bytes for proposeBatch
dantaik 7715065
abi
dantaik 9ff1c0d
Update ProverSet.sol
dantaik 65d9646
refactor
dantaik 14c71a3
feat(protocol): improve prover set to support ontake and pacaya (#18755)
dantaik 3699b07
feat(protocol): upgrade sp1 contract to v4.0.0-rc.3 (#18740)
smtmfft d6b99df
Merge branch 'main' into pacaya_fork
dantaik 9590d17
forge fmt & update contract layout tables
dantaik 2b4041c
add firstBlobIndex
dantaik 5d576b9
fix typo
dantaik 5d28e03
fix(protocol): fix block timestamp check (#18759)
dantaik 180d529
Merge branch 'main' into pacaya_fork
davidtaikocha accbe8e
Update TaikoInbox.sol
dantaik 5fd6e0c
minor improvement
dantaik 857842f
chore(protocol): test isSignalSent and SS_SIGNAL_NOT_RECEIVED error i…
xiaodino 72d658d
feat(protocol): allow anyone to prove a block before the deadline (#1…
dantaik 82f45da
chore(protocol): change maxBlocksPerBatch to 768 to support 0.5s aver…
dantaik 839804d
feat(protocol): improve liveness bond calculation to discourage empty…
dantaik 5f4f58a
feat(protocol): pause the protocol when conflicting proofs are verifi…
dantaik 9321331
Update packages/protocol/contracts/layer1/based/TaikoInbox.sol
dantaik 60592c0
feat(protocol): add `getTransition(batchID,parentHash)` method (#18780)
davidtaikocha d5a472d
Merge branch 'main' into pacaya_fork
davidtaikocha e662952
feat(protocol): add `firstBlobIndex` to `BatchMetadata` (#18785)
davidtaikocha 501f898
Merge branch 'main' into pacaya_fork
mask-pp 4d53790
chore(protocol): update pacaya test naming (#18790)
cyberhorsey 1a79dd2
fix(protocol): remove duplicated error definition (#18787)
YoGhurt111 b3541a8
feat(protocol): allow owner to write transition to rescue a block (#1…
dantaik 6a86918
fix(protocol): fix bug about stopBatchId variable (#18789)
mask-pp c0ab98f
chore(protocol): test TransitionNotFound in getTransition(_batchId, _…
xiaodino 46b8ac3
feat(protocol): introduce `SgxOrZkVerifier` to allow any valid proof …
YoGhurt111 6f6ca97
feat(protocol): fix the deployment script (#18796)
YoGhurt111 6ce5f10
fix(protocol): call `TaikoInbox.init` in deployment script (#18801)
davidtaikocha 390dfa4
chore(protocol): add tests for setQuotaPeriod in QuotaManager (#18803)
xiaodino c4c4d36
feat(protocol): add any-two-verifier (#18795)
AnshuJalan 6f8d780
Update packages/protocol/contracts/layer1/based/TaikoInbox.sol
dantaik c2acd7a
Update packages/protocol/contracts/layer1/based/TaikoInbox.sol
dantaik c84e761
fix(protocol): use batch instead of block in solver mechanism (#18808)
AnshuJalan 351d1cd
feat(protocol): make resolver an Immutable (#18800)
dantaik db5fc28
fix(protocol): return liveness bond correctly (#18797)
dantaik ef3da24
feat(protocol): add preconfirmation whitelist and router (#18791)
AnshuJalan 4e48e1a
fix test
dantaik 6c78d66
Merge branch 'main' into pacaya_fork
dantaik f7e5128
Merge branch 'main' into pacaya_fork
dantaik 06bd742
Merge branch 'main' into pacaya_fork
mask-pp 64130a8
refactor(protocol): wrap blob related parameter into `BlobParams` for…
dantaik e4a7d10
emit blob hashes in event
dantaik 56a6e93
Update TaikoInbox.sol
dantaik c38afbb
refactor
dantaik 4bde037
Update TaikoInbox.sol
dantaik bd2202f
Update Layer1Test.sol
dantaik 12de2cf
feat(protocol): add `anchorV2` back (#18820)
YoGhurt111 e723138
BatchInfo
dantaik 5a5f2b1
more
dantaik 1266339
fix
dantaik 8519a57
fix
dantaik 24d0029
Update TaikoInbox.sol
dantaik 34ea458
forge fmt & update contract layout tables
dantaik 267719e
reorder
dantaik 08356e4
Update TaikoInbox.sol
dantaik 321002d
Update ITaikoInbox.sol
dantaik 19e00ab
more
dantaik 5a59c94
more
dantaik 5b39351
more
dantaik 95df593
Update ITaikoInbox.sol
dantaik b27e27d
Merge branch 'pacaya_fork' into emit_blob_hashes_in_event
dantaik 40dcfa8
show case an idea
dantaik 84d4493
Update TaikoInboxWithForcedTxInclusion.sol
dantaik 69848fe
split
dantaik e1290d4
Update TaikoInboxWithForcedTxInclusion.sol
dantaik 6eaa54b
Update TaikoInboxWithForcedTxInclusion.sol
dantaik f38b07e
Update TaikoInbox.sol
dantaik fec04d5
forge fmt & update contract layout tables
dantaik 3095e13
more
dantaik 48479b5
support blob hashes as parameters
dantaik cc6274b
Merge branch 'emit_blob_hashes_in_event' into forced_tx_inclusion
dantaik e532efe
removed 1 TODO
dantaik 022849d
Update TaikoInboxWithForcedTxInclusion.sol
dantaik bb0a7b5
feat(protocol): whitelist addition + deploy script update (#18812)
cyberhorsey 7a8e392
Merge branch 'pacaya_fork' into emit_blob_hashes_in_event
dantaik da354f5
Merge branch 'emit_blob_hashes_in_event' into forced_tx_inclusion
dantaik f9885e9
Update ITaikoInbox.sol
dantaik 414bb95
Update IFork.sol
dantaik ece8ff9
forge fmt & update contract layout tables
dantaik 7ac4087
feat(protocol): emit blob hashes in event and split meta into 2 struc…
dantaik e5bf3f1
Merge branch 'pacaya_fork' into forced_tx_inclusion
dantaik 70efba5
fix
dantaik d661d57
Merge branch 'main' into pacaya_fork
davidtaikocha a89cbcb
fix(protocol): fix a bug in ForkRouter (#18831)
dantaik 925191c
fix(protocol): switch back to selector-based fork router (#18834)
dantaik bf62bd6
feat(protocol): add more selectors to `IOntakeFork` (#18836)
davidtaikocha 93f4272
fix(protocol): rename resolve() to resolveAddress() (#18835)
dantaik 40b0db8
feat(protocol): forced inclusion store (#18829)
cyberhorsey 8fc98eb
merge pacaya_fork branch, update resolvers
cyberhorsey cf15174
add the forced inclusion inbox as a WL proposer
cyberhorsey d55f386
refactor(protocol): make resolveAddress internal in EssentialContract…
dantaik b96c0ef
Merge branch 'pacaya_fork' into forced_tx_inclusion
dantaik c64a03b
fee => feeInGwei
dantaik f9fa4b4
move new files to a new dir
dantaik 06225d8
Update gen-layouts.sh
dantaik 77b469e
fix(protocol): use safeTransfer in TaikoInbox (reported by OpenZeppel…
dantaik 13113d8
Merge branch 'pacaya_fork' into forced_tx_inclusion
dantaik 551a3b2
Update TaikoInbox.sol
dantaik 951a404
feat(protocol): add back cooldown settings (#18853)
dantaik 9e4f417
feat(protocol): use num proposals to measure forced inclusion deadlin…
dantaik 80ee02a
Merge branch 'pacaya_fork' into forced_tx_inclusion
dantaik de73b6a
Update TaikoInbox.sol
dantaik fdde0d8
chore
dantaik 63961cc
Update deploy_protocol_on_l1.sh
dantaik e68447e
Update ForcedInclusionStore.t.sol
dantaik 5433a89
Merge branch 'pacaya_fork' into forced_tx_inclusion
dantaik dd8ea64
Update gen-layouts.sh
dantaik 22ce6b5
forge fmt & update contract layout tables
dantaik 462b64a
revert some changes
dantaik a5dcdd5
Update InboxTest_ProposeAndProve.t.sol
dantaik 7c2c2c3
Update InboxTest_ProposeAndProve.t.sol
dantaik 703cdfa
Merge branch 'main' into forced_tx_inclusion
dantaik ceaa3c9
forge fmt & update contract layout tables
dantaik 060225b
Merge branch 'main' into forced_tx_inclusion
dantaik 050b53a
more
dantaik d9f7fe5
forge fmt & update contract layout tables
dantaik 7343364
Update TaikoWrapper.sol
dantaik 5f4b092
forge fmt & update contract layout tables
dantaik 653a33e
Merge branch 'main' into forced_tx_inclusion
davidtaikocha 17d127a
typo
dantaik 0de9165
Update TaikoInbox.sol
dantaik 40efbb7
init
dantaik fb34324
Revert "init"
dantaik 2ccb06a
break into multiple require-statements
dantaik 2fa9791
Update TaikoWrapper.sol
dantaik cba91c8
Update TaikoWrapper.sol
dantaik 6fd167a
Update ForcedInclusionStore.sol
dantaik 4e13b2b
forge fmt & update contract layout tables
dantaik cccc4f2
Merge branch 'main' into forced_tx_inclusion
dantaik 17c005b
improve
dantaik a52b5df
rename
dantaik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,3 +120,4 @@ __pycache__/ | |
|
||
# Idea | ||
.idea/ | ||
packages/protocol/snapshots/InboxTest_ProposeAndProve.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
packages/protocol/contracts/layer1/based/ForcedInclusionInbox.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.24; | ||
|
||
import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
import "src/shared/common/EssentialContract.sol"; | ||
import "src/shared/based/ITaiko.sol"; | ||
import "src/shared/libs/LibMath.sol"; | ||
import "src/shared/libs/LibNetwork.sol"; | ||
import "src/shared/libs/LibStrings.sol"; | ||
import "src/shared/signal/ISignalService.sol"; | ||
import "src/layer1/verifiers/IVerifier.sol"; | ||
import "./ITaikoInbox.sol"; | ||
import "./IForcedInclusionStore.sol"; | ||
|
||
/// @title ForcedInclusionInbox | ||
/// @dev This contract is part of a delayed inbox implementation to enforce the inclusion of | ||
/// transactions. | ||
/// The current design is a simplified and can be improved with the following ideas: | ||
/// 1. **Fee-Based Request Prioritization**: | ||
/// - Proposers can selectively fulfill pending requests based on transaction fees. | ||
/// - Requests not yet due can be processed earlier if fees are attractive, incentivizing timely | ||
/// execution. | ||
/// | ||
/// 2. **Rate Limit Control**: | ||
/// - A rate-limiting mechanism ensures a minimum interval of 12*N seconds between request | ||
/// fulfillments. | ||
/// - Prevents proposers from being overwhelmed during high request volume, ensuring system | ||
/// stability. | ||
/// | ||
/// 3. **Calldata and Blob Support**: | ||
/// - Supports both calldata and blobs in the transaction list. | ||
/// | ||
/// 4. **Gas-Efficient Request Storage**: | ||
/// - Avoids storing full request data in contract storage. | ||
/// - Saves only the request hash and its timestamp. | ||
/// - Leverages Ethereum events to store request details off-chain. | ||
/// - Proposers can reconstruct requests as needed, minimizing on-chain storage and gas | ||
/// consumption. | ||
/// | ||
/// @custom:security-contact [email protected] | ||
contract ForcedInclusionInbox is EssentialContract { | ||
using LibMath for uint256; | ||
|
||
event ForcedInclusionProcessed(IForcedInclusionStore.ForcedInclusion); | ||
|
||
uint16 public constant MAX_FORCED_TXS_PER_FORCED_INCLUSION = 512; | ||
uint256[50] private __gap; | ||
|
||
constructor(address _resolver) EssentialContract(_resolver) { } | ||
|
||
function init(address _owner) external initializer { | ||
__Essential_init(_owner); | ||
} | ||
|
||
/// @notice Proposes a batch of blocks. | ||
/// @param _forcedInclusionParams An optional ABI-encoded BlockParams for the forced inclusion | ||
/// batch. | ||
/// @param _params ABI-encoded BlockParams. | ||
/// @param _txList The transaction list in calldata. If the txList is empty, blob will be used | ||
/// for data availability. | ||
function proposeBatchWithForcedInclusion( | ||
bytes calldata _forcedInclusionParams, | ||
bytes calldata _params, | ||
bytes calldata _txList | ||
) | ||
external | ||
nonReentrant | ||
returns (ITaikoInbox.BatchInfo memory info_, ITaikoInbox.BatchMetadata memory meta_) | ||
{ | ||
ITaikoInbox inbox = ITaikoInbox(resolveAddress(LibStrings.B_TAIKO, false)); | ||
(info_, meta_) = inbox.proposeBatch(_params, _txList); | ||
|
||
// Process the next forced inclusion. | ||
IForcedInclusionStore store = | ||
IForcedInclusionStore(resolveAddress(LibStrings.B_FORCED_INCLUSION_STORE, false)); | ||
|
||
IForcedInclusionStore.ForcedInclusion memory inclusion = | ||
store.consumeForcedInclusion(msg.sender); | ||
|
||
if (inclusion.createdAt != 0) { | ||
ITaikoInbox.BatchParams memory params; | ||
|
||
if (_forcedInclusionParams.length != 0) { | ||
params = abi.decode(_forcedInclusionParams, (ITaikoInbox.BatchParams)); | ||
} | ||
|
||
// Overwrite the batch params to have only 1 block and up to | ||
// MAX_FORCED_TXS_PER_FORCED_INCLUSION transactions | ||
if (params.blocks.length == 0) { | ||
params.blocks = new ITaikoInbox.BlockParams[](1); | ||
} | ||
|
||
if (params.blocks[0].numTransactions < MAX_FORCED_TXS_PER_FORCED_INCLUSION) { | ||
params.blocks[0].numTransactions = MAX_FORCED_TXS_PER_FORCED_INCLUSION; | ||
} | ||
|
||
params.blobParams.blobHashes = new bytes32[](1); | ||
params.blobParams.blobHashes[0] = inclusion.blobHash; | ||
params.blobParams.byteOffset = inclusion.blobByteOffset; | ||
params.blobParams.byteSize = inclusion.blobByteSize; | ||
|
||
inbox.proposeBatch(abi.encode(params), ""); | ||
emit ForcedInclusionProcessed(inclusion); | ||
} | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
packages/protocol/contracts/layer1/based/ForcedInclusionStore.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.24; | ||
|
||
import "src/shared/common/EssentialContract.sol"; | ||
import "src/shared/libs/LibMath.sol"; | ||
import "./IForcedInclusionStore.sol"; | ||
import "src/shared/libs/LibAddress.sol"; | ||
import "src/shared/libs/LibStrings.sol"; | ||
|
||
/// @title ForcedInclusionStore | ||
/// @dev A contract for storing and managing forced inclusion requests. Forced inclusions allow | ||
/// users to pay a fee | ||
/// to ensure their transactions are included in a block. The contract maintains a FIFO queue | ||
/// of inclusion requests. | ||
/// @custom:security-contact | ||
contract ForcedInclusionStore is EssentialContract, IForcedInclusionStore { | ||
using LibAddress for address; | ||
using LibMath for uint256; | ||
|
||
uint256 private constant SECONDS_PER_BLOCK = 12; | ||
|
||
uint256 public immutable inclusionDelay; | ||
uint256 public immutable fee; | ||
|
||
mapping(uint256 id => ForcedInclusion inclusion) public queue; // slot 1 | ||
uint64 public head; // slot 2 | ||
uint64 public tail; | ||
uint128 private __reserved1; | ||
|
||
uint256[48] private __gap; | ||
|
||
constructor( | ||
address _resolver, | ||
uint256 _inclusionDelay, | ||
uint256 _fee | ||
) | ||
EssentialContract(_resolver) | ||
{ | ||
require(_inclusionDelay != 0 && _inclusionDelay % SECONDS_PER_BLOCK == 0, InvalidParams()); | ||
require(_fee != 0, InvalidParams()); | ||
|
||
inclusionDelay = _inclusionDelay; | ||
fee = _fee; | ||
} | ||
|
||
function init(address _owner) external initializer { | ||
__Essential_init(_owner); | ||
} | ||
|
||
function storeForcedInclusion( | ||
uint8 blobIndex, | ||
uint32 blobByteOffset, | ||
uint32 blobByteSize | ||
) | ||
external | ||
payable | ||
{ | ||
bytes32 blobHash = _blobHash(blobIndex); | ||
require(blobHash != bytes32(0), BlobNotFound()); | ||
require(msg.value == fee, IncorrectFee()); | ||
|
||
ForcedInclusion memory inclusion = ForcedInclusion({ | ||
blobHash: blobHash, | ||
fee: msg.value, | ||
createdAt: uint64(block.timestamp), | ||
blobByteOffset: blobByteOffset, | ||
blobByteSize: blobByteSize | ||
}); | ||
|
||
queue[tail++] = inclusion; | ||
|
||
emit ForcedInclusionStored(inclusion); | ||
} | ||
|
||
function consumeForcedInclusion(address _feeRecipient) | ||
external | ||
onlyFromNamed(LibStrings.B_TAIKO_FORCED_INCLUSION_INBOX) | ||
returns (ForcedInclusion memory inclusion_) | ||
{ | ||
// we only need to check the first one, since it will be the oldest. | ||
uint64 _head = head; | ||
ForcedInclusion storage inclusion = queue[_head]; | ||
|
||
if (inclusion.createdAt != 0 && block.timestamp >= inclusionDelay + inclusion.createdAt) { | ||
inclusion_ = inclusion; | ||
_feeRecipient.sendEtherAndVerify(inclusion.fee); | ||
delete queue[_head]; | ||
head = _head + 1; | ||
emit ForcedInclusionConsumed(inclusion); | ||
} | ||
} | ||
|
||
// @dev Override this function for easier testing blobs | ||
function _blobHash(uint8 blobIndex) internal view virtual returns (bytes32) { | ||
return blobhash(blobIndex); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
packages/protocol/contracts/layer1/based/IForcedInclusionInbox.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.24; | ||
|
||
import "./ITaikoInbox.sol"; | ||
import "./IForcedInclusionStore.sol"; | ||
|
||
/// @title IForcedInclusionInbox | ||
/// @custom:security-contact [email protected] | ||
interface IForcedInclusionInbox { | ||
event ForcedInclusionProcessed(IForcedInclusionStore.ForcedInclusion); | ||
|
||
/// @notice Proposes a batch of blocks with forced inclusion. | ||
/// @param _forcedInclusionParams An optional ABI-encoded BlockParams for the forced inclusion | ||
/// batch. | ||
/// @param _params ABI-encoded BlockParams. | ||
/// @param _txList The transaction list in calldata. If the txList is empty, blob will be used | ||
/// for data availability. | ||
/// @return info_ The info of the proposed batch. | ||
/// @return meta_ The metadata of the proposed batch. | ||
function proposeBatchWithForcedInclusion( | ||
bytes calldata _forcedInclusionParams, | ||
bytes calldata _params, | ||
bytes calldata _txList | ||
) | ||
external | ||
returns (ITaikoInbox.BatchInfo memory info_, ITaikoInbox.BatchMetadata memory meta_); | ||
} |
47 changes: 47 additions & 0 deletions
47
packages/protocol/contracts/layer1/based/IForcedInclusionStore.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.24; | ||
|
||
/// @title IForcedInclusionStore | ||
/// @custom:security-contact [email protected] | ||
interface IForcedInclusionStore { | ||
cyberhorsey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// @dev Error thrown when a blob is not found. | ||
error BlobNotFound(); | ||
/// @dev Error thrown when the parameters are invalid. | ||
error InvalidParams(); | ||
/// @dev Error thrown when the fee is incorrect. | ||
error IncorrectFee(); | ||
|
||
/// @dev Event emitted when a forced inclusion is stored. | ||
event ForcedInclusionStored(ForcedInclusion forcedInclusion); | ||
/// @dev Event emitted when a forced inclusion is consumed. | ||
event ForcedInclusionConsumed(ForcedInclusion forcedInclusion); | ||
|
||
struct ForcedInclusion { | ||
bytes32 blobHash; | ||
uint256 fee; | ||
uint64 createdAt; | ||
uint32 blobByteOffset; | ||
uint32 blobByteSize; | ||
} | ||
|
||
/// @dev Consume a forced inclusion request. | ||
/// The inclusion request must be marked as processed and the priority fee must be paid to the | ||
/// caller. | ||
/// @return inclusion_ The forced inclusion request. | ||
function consumeForcedInclusion(address _feeRecipient) | ||
external | ||
returns (ForcedInclusion memory); | ||
|
||
/// @dev Store a forced inclusion request. | ||
/// The priority fee must be paid to the contract. | ||
/// @param blobIndex The index of the blob that contains the transaction data. | ||
/// @param blobByteOffset The byte offset in the blob | ||
/// @param blobByteSize The size of the blob in bytes | ||
function storeForcedInclusion( | ||
uint8 blobIndex, | ||
uint32 blobByteOffset, | ||
uint32 blobByteSize | ||
) | ||
external | ||
payable; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm kind of thinking that making the inclusion of these forced transactions "automatic" (as in the preconfer cannot decide easily when they are included) could be problematic for a preconfer. Because the preconfer will not always know in which L1 block its propose transaction will be included, but depending on when that happens, these forced transactions need to be inserted at the right place to be able to give preconfirmations after these are supposed to happen. It does seem to introduce a level of non-determinism that could be quite tricky for a preconfer to fully control easily.
When the preconfer can decide on his own when these transactions actually get included within a window, that seems to make the preconfers job much easier to make things 100% predictable without any tricky boundaries enforced onchai, resulting with a hard deadline on when a propose tx actually needs to be included onchain to not mess with the expected order of the preconfer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another valid point. To address this, we could shift from using timestamps as the indicator for when an inclusion request is due, and instead rely on
numBatches
in theITaikoInbox
contract. This approach would mean that every N batch proposals, the oldest inclusion request must be processed.However, one drawback of this design is that it restricts proposers from proactively processing delayed inbox requests, which is not ideal. To mitigate this, we could modify the
proposeBatchWithForcedInclusion
implementation to allow for the proactive processing of the head inclusion request, even if it isn’t technically due yet.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See an improvement idea: #18842