Skip to content

Commit da27f44

Browse files
dantaikclaude
andauthored
refactor(protocol,taiko-client-rs,taiko-client): move LibManifest constants to Derivation.md (#20545)
Co-authored-by: Claude <noreply@anthropic.com>
1 parent 244f160 commit da27f44

File tree

7 files changed

+38
-49
lines changed

7 files changed

+38
-49
lines changed

packages/protocol/contracts/layer1/core/libs/LibManifest.sol

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,9 @@ pragma solidity ^0.8.24;
44
/// @title LibManifest
55
/// @custom:security-contact security@taiko.xyz
66
library LibManifest {
7-
// ---------------------------------------------------------------
8-
// Constants
9-
// ---------------------------------------------------------------
10-
/// @notice The maximum number of blocks allowed in a proposal. If we assume block time is as
11-
/// small as one second, 384 blocks will cover an Ethereum epoch.
12-
uint256 internal constant PROPOSAL_MAX_BLOCKS = 384;
13-
14-
/// @notice The maximum anchor block number offset from the proposal origin block number.
15-
uint256 internal constant ANCHOR_MAX_OFFSET = 128;
16-
17-
/// @notice The minimum anchor block number offset from the proposal origin block number.
18-
uint256 internal constant ANCHOR_MIN_OFFSET = 2;
19-
20-
/// @notice The maximum number timestamp offset from the proposal origin timestamp.
21-
uint256 internal constant TIMESTAMP_MAX_OFFSET = 12 * 32;
22-
23-
/// @notice The maximum block gas limit change per block, in millionths (1/1,000,000).
24-
/// @dev For example, 10 = 10 / 1,000,000 = 0.001%.
25-
uint256 internal constant BLOCK_GAS_LIMIT_MAX_CHANGE = 10;
26-
27-
/// @notice The minimum block gas limit.
28-
/// @dev This ensures block gas limit never drops below a critical threshold.
29-
uint256 internal constant MIN_BLOCK_GAS_LIMIT = 15_000_000;
30-
31-
/// @notice The delay in processing bond instructions relative to the current proposal. A value
32-
/// of 1 signifies that the bond instructions of the immediate parent proposal will be
33-
/// processed.
34-
uint256 internal constant BOND_PROCESSING_DELAY = 6;
35-
367
// ---------------------------------------------------------------
378
// Structs
38-
// ---------------------------------------------------------------
9+
// ---------------------------------------------------------------
3910

4011
/// @notice Represents a signed Ethereum transaction
4112
/// @dev Follows EIP-2718 typed transaction format with EIP-1559 support

packages/protocol/docs/Derivation.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,8 @@ Anchor block validation ensures proper L1 state synchronization and may trigger
277277
**Invalidation conditions** (sets `anchorBlockNumber` to `parent.metadata.anchorBlockNumber`):
278278

279279
- **Non-monotonic progression**: `manifest.blocks[i].anchorBlockNumber < parent.metadata.anchorBlockNumber`
280-
- **Future reference**: `manifest.blocks[i].anchorBlockNumber >= proposal.originBlockNumber - ANCHOR_MIN_OFFSET`
281-
- **Excessive lag**: `manifest.blocks[i].anchorBlockNumber < proposal.originBlockNumber - ANCHOR_MAX_OFFSET`
280+
- **Future reference**: `manifest.blocks[i].anchorBlockNumber >= proposal.originBlockNumber - MIN_ANCHOR_OFFSET`
281+
- **Excessive lag**: `manifest.blocks[i].anchorBlockNumber < proposal.originBlockNumber - MAX_ANCHOR_OFFSET`
282282

283283
**Forced inclusion protection**: For non-forced derivation sources (`derivationSource.isForcedInclusion == false`), if no blocks have valid anchor numbers greater than its parent's, the entire source manifest is replaced with the default source manifest (single block with only an anchor transaction), penalizing proposers that fail to provide proper L1 anchoring. Forced inclusion sources are exempt from this penalty.
284284

@@ -564,8 +564,26 @@ The anchor transaction executes a carefully orchestrated sequence of operations:
564564
- Gas limit: Exactly 1,000,000 gas (enforced by the Taiko node software)
565565
- Caller restriction: Golden touch address (system account) only
566566

567-
### Transaction Execution
568567

569568
## Base Fee Calculation
570569

571570
The calculation of block base fee shall follow [EIP-4396](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-4396.md#specification).
571+
572+
573+
## Constants
574+
575+
The following constants govern the block derivation process:
576+
577+
| Constant | Value | Description |
578+
|----------|-------|-------------|
579+
| **PROPOSAL_MAX_BLOCKS** | `384` | The maximum number of blocks allowed in a proposal. If we assume block time is as small as one second, 384 blocks will cover an Ethereum epoch. |
580+
| **MAX_ANCHOR_OFFSET** | `128` | The maximum anchor block number offset from the proposal origin block number. |
581+
| **MIN_ANCHOR_OFFSET** | `2` | The minimum anchor block number offset from the proposal origin block number. |
582+
| **TIMESTAMP_MAX_OFFSET** | `384` (12 * 32) | The maximum number timestamp offset from the proposal origin timestamp. |
583+
| **BLOCK_GAS_LIMIT_MAX_CHANGE** | `10` | The maximum block gas limit change per block, in millionths (1/1,000,000). For example, 10 = 10 / 1,000,000 = 0.001%. |
584+
| **MIN_BLOCK_GAS_LIMIT** | `15,000,000` | The minimum block gas limit. This ensures block gas limit never drops below a critical threshold. |
585+
| **BOND_PROCESSING_DELAY** | `6` | The delay in processing bond instructions relative to the current proposal. A value of 1 signifies that the bond instructions of the immediate parent proposal will be processed. |
586+
| **INITIAL_BASE_FEE** | `0.025 gwei` (25,000,000 wei) | The initial base fee for the first Shasta block. |
587+
| **MIN_BASE_FEE** | `0.005 gwei` (5,000,000 wei) | The minimum base fee (inclusive) after Shasta fork. |
588+
| **MAX_BASE_FEE** | `1 gwei` (1,000,000,000 wei) | The maximum base fee (inclusive) after Shasta fork. |
589+
| **BLOCK_TIME_TARGET** | `2 seconds` | The block time target. |

packages/taiko-client-rs/crates/driver/src/derivation/pipeline/shasta/validation.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use alethia_reth_consensus::validation::ANCHOR_V3_GAS_LIMIT;
22
use alloy_primitives::Address;
33
use protocol::shasta::{
44
constants::{
5-
ANCHOR_MAX_OFFSET, ANCHOR_MIN_OFFSET, BLOCK_GAS_LIMIT_MAX_CHANGE, MIN_BLOCK_GAS_LIMIT,
5+
MAX_ANCHOR_OFFSET, MIN_ANCHOR_OFFSET, BLOCK_GAS_LIMIT_MAX_CHANGE, MIN_BLOCK_GAS_LIMIT,
66
TIMESTAMP_MAX_OFFSET,
77
},
88
manifest::DerivationSourceManifest,
@@ -118,13 +118,13 @@ fn adjust_anchor_numbers(
118118
block.anchor_block_number = parent_anchor;
119119
}
120120

121-
let future_reference_limit = origin_block_number.saturating_sub(ANCHOR_MIN_OFFSET);
121+
let future_reference_limit = origin_block_number.saturating_sub(MIN_ANCHOR_OFFSET);
122122
if block.anchor_block_number >= future_reference_limit {
123123
block.anchor_block_number = parent_anchor;
124124
}
125125

126-
if origin_block_number > ANCHOR_MAX_OFFSET {
127-
let min_allowed = origin_block_number - ANCHOR_MAX_OFFSET;
126+
if origin_block_number > MAX_ANCHOR_OFFSET {
127+
let min_allowed = origin_block_number - MAX_ANCHOR_OFFSET;
128128
if block.anchor_block_number < min_allowed {
129129
block.anchor_block_number = parent_anchor;
130130
}

packages/taiko-client-rs/crates/proposer/src/transaction_builder.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use bindings::codec_optimized::{IInbox::ProposeInput, LibBlobs::BlobReference};
1616
use event_indexer::{indexer::ShastaEventIndexer, interface::ShastaProposeInputReader};
1717
use protocol::shasta::{
1818
BlobCoder,
19-
constants::ANCHOR_MIN_OFFSET,
19+
constants::MIN_ANCHOR_OFFSET,
2020
manifest::{BlockManifest, DerivationSourceManifest, ProposalManifest},
2121
};
2222
use rpc::client::ClientWithWallet;
@@ -67,10 +67,10 @@ impl ShastaProposalTransactionBuilder {
6767

6868
// Ensure the current L1 head is sufficiently advanced.
6969
let current_l1_head = self.rpc_provider.l1_provider.get_block_number().await?;
70-
if current_l1_head <= ANCHOR_MIN_OFFSET {
70+
if current_l1_head <= MIN_ANCHOR_OFFSET {
7171
return Err(ProposerError::L1HeadTooLow {
7272
current: current_l1_head,
73-
minimum: ANCHOR_MIN_OFFSET,
73+
minimum: MIN_ANCHOR_OFFSET,
7474
});
7575
}
7676

@@ -83,7 +83,7 @@ impl ShastaProposalTransactionBuilder {
8383
.unwrap_or_default()
8484
.as_secs(),
8585
coinbase: self.l2_suggested_fee_recipient,
86-
anchor_block_number: current_l1_head - (ANCHOR_MIN_OFFSET + 1),
86+
anchor_block_number: current_l1_head - (MIN_ANCHOR_OFFSET + 1),
8787
gas_limit: 0, /* Use 0 for gas limit as it will be set as its parent's gas
8888
* limit during derivation. */
8989
transactions: txs.iter().map(|tx| tx.clone().into()).collect(),

packages/taiko-client-rs/crates/protocol/src/shasta/constants.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ use alloy_eips::eip4844::{FIELD_ELEMENTS_PER_BLOB, USABLE_BITS_PER_FIELD_ELEMENT
88
pub const PROPOSAL_MAX_BLOCKS: usize = 384;
99

1010
/// The maximum anchor block number offset from the proposal origin block number.
11-
/// NOTE: Should be same with `ANCHOR_MAX_OFFSET` in contracts/layer1/libs/LibManifest.sol.
12-
pub const ANCHOR_MAX_OFFSET: u64 = 128;
11+
/// NOTE: Should be same with `MAX_ANCHOR_OFFSET` in contracts/layer1/libs/LibManifest.sol.
12+
pub const MAX_ANCHOR_OFFSET: u64 = 128;
1313

1414
/// The minimum anchor block number offset from the proposal origin block number.
15-
/// NOTE: Should be same with `ANCHOR_MIN_OFFSET` in contracts/layer1/libs/LibManifest.sol.
16-
pub const ANCHOR_MIN_OFFSET: u64 = 2;
15+
/// NOTE: Should be same with `MIN_ANCHOR_OFFSET` in contracts/layer1/libs/LibManifest.sol.
16+
pub const MIN_ANCHOR_OFFSET: u64 = 2;
1717

1818
/// The maximum timestamp offset from the proposal origin timestamp.
1919
/// NOTE: Should be same with `TIMESTAMP_MAX_OFFSET` in

packages/taiko-client/bindings/manifest/manifest.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ const (
1515
ProposalMaxBlocks = 384
1616
// TimestampMaxOffset The maximum number timestamp offset from the proposal origin timestamp, refer to LibManifest.TIMESTAMP_MAX_OFFSET.
1717
TimestampMaxOffset = 12 * 32
18-
// AnchorMinOffset The minimum anchor block number offset from the proposal origin block number, refer to LibManifest.ANCHOR_MIN_OFFSET.
18+
// AnchorMinOffset The minimum anchor block number offset from the proposal origin block number, refer to LibManifest.MIN_ANCHOR_OFFSET.
1919
AnchorMinOffset = 2
20-
// AnchorMaxOffset The maximum anchor block number offset from the proposal origin block number, refer to LibManifest.ANCHOR_MAX_OFFSET.
20+
// AnchorMaxOffset The maximum anchor block number offset from the proposal origin block number, refer to LibManifest.MAX_ANCHOR_OFFSET.
2121
AnchorMaxOffset = 128
2222
// MaxBlockGasLimitChangePermyriad The maximum block gas limit change per block, in millionths (1/1,000,000), refer to LibManifest.MAX_BLOCK_GAS_LIMIT_CHANGE_PERMYRIAD.
2323
MaxBlockGasLimitChangePermyriad = 10 // 0.1%

packages/taiko-client/driver/chain_syncer/event/manifest/shasta.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ func validateAnchorBlockNumber(
378378
continue
379379
}
380380

381-
// 2. Future reference: manifest.blocks[i].anchorBlockNumber >= proposal.originBlockNumber - ANCHOR_MIN_OFFSET
381+
// 2. Future reference: manifest.blocks[i].anchorBlockNumber >= proposal.originBlockNumber - MIN_ANCHOR_OFFSET
382382
if sourcePayload.BlockPayloads[i].AnchorBlockNumber >= originBlockNumber-manifest.AnchorMinOffset {
383383
log.Info(
384384
"Invalid anchor block number: future reference",
@@ -391,7 +391,7 @@ func validateAnchorBlockNumber(
391391
continue
392392
}
393393

394-
// 3. Excessive lag: manifest.blocks[i].anchorBlockNumber < proposal.originBlockNumber - ANCHOR_MAX_OFFSET
394+
// 3. Excessive lag: manifest.blocks[i].anchorBlockNumber < proposal.originBlockNumber - MAX_ANCHOR_OFFSET
395395
if originBlockNumber > manifest.AnchorMaxOffset &&
396396
sourcePayload.BlockPayloads[i].AnchorBlockNumber < originBlockNumber-manifest.AnchorMaxOffset {
397397
log.Info(

0 commit comments

Comments
 (0)