Skip to content

Commit 1ce7094

Browse files
davidtaikochaGustavo Gonzalezggonzalez94dantaik
authored
feat(taiko-client,taiko-client-rs): remove blockIndex in anchorV4 (#20610)
Co-authored-by: Gustavo Gonzalez <gustavo@taiko.xyz> Co-authored-by: ggonzalez94 <17907743+ggonzalez94@users.noreply.github.com> Co-authored-by: Daniel Wang <99078276+dantaik@users.noreply.github.com>
1 parent 2f8e9b4 commit 1ce7094

File tree

18 files changed

+286
-258
lines changed

18 files changed

+286
-258
lines changed

packages/protocol/contracts/layer1/devnet/DevnetInbox.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ contract DevnetInbox is InboxOptimized2 {
5050
ringBufferSize: _RING_BUFFER_SIZE,
5151
basefeeSharingPctg: 75,
5252
minForcedInclusionCount: 1,
53-
forcedInclusionDelay: 384, // 1 epoch
53+
forcedInclusionDelay: 0,
5454
forcedInclusionFeeInGwei: 10_000_000, // 0.01 ETH base fee
5555
forcedInclusionFeeDoubleThreshold: 50, // fee doubles at 50 pending
5656
minCheckpointDelay: 384 seconds, // 1 epoch

packages/taiko-client-rs/crates/bindings/src/anchor.rs

Lines changed: 81 additions & 82 deletions
Large diffs are not rendered by default.

packages/taiko-client-rs/crates/bindings/src/codec_optimized.rs

Lines changed: 4 additions & 4 deletions
Large diffs are not rendered by default.

packages/taiko-client-rs/crates/bindings/src/i_inbox.rs

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ interface IInbox {
1818
uint256 minForcedInclusionCount;
1919
uint16 forcedInclusionDelay;
2020
uint64 forcedInclusionFeeInGwei;
21+
uint64 forcedInclusionFeeDoubleThreshold;
2122
uint16 minCheckpointDelay;
2223
uint8 permissionlessInclusionMultiplier;
2324
uint16 compositeKeyVersion;
@@ -119,6 +120,11 @@ interface IInbox {
119120
"type": "uint64",
120121
"internalType": "uint64"
121122
},
123+
{
124+
"name": "forcedInclusionFeeDoubleThreshold",
125+
"type": "uint64",
126+
"internalType": "uint64"
127+
},
122128
{
123129
"name": "minCheckpointDelay",
124130
"type": "uint16",
@@ -296,7 +302,7 @@ pub mod IInbox {
296302
#[derive(serde::Serialize, serde::Deserialize)]
297303
#[derive(Default, Debug, PartialEq, Eq, Hash)]
298304
/**```solidity
299-
struct Config { address codec; address bondToken; address checkpointStore; address proofVerifier; address proposerChecker; uint48 provingWindow; uint48 extendedProvingWindow; uint256 maxFinalizationCount; uint48 finalizationGracePeriod; uint256 ringBufferSize; uint8 basefeeSharingPctg; uint256 minForcedInclusionCount; uint16 forcedInclusionDelay; uint64 forcedInclusionFeeInGwei; uint16 minCheckpointDelay; uint8 permissionlessInclusionMultiplier; uint16 compositeKeyVersion; }
305+
struct Config { address codec; address bondToken; address checkpointStore; address proofVerifier; address proposerChecker; uint48 provingWindow; uint48 extendedProvingWindow; uint256 maxFinalizationCount; uint48 finalizationGracePeriod; uint256 ringBufferSize; uint8 basefeeSharingPctg; uint256 minForcedInclusionCount; uint16 forcedInclusionDelay; uint64 forcedInclusionFeeInGwei; uint64 forcedInclusionFeeDoubleThreshold; uint16 minCheckpointDelay; uint8 permissionlessInclusionMultiplier; uint16 compositeKeyVersion; }
300306
```*/
301307
#[allow(non_camel_case_types, non_snake_case, clippy::pub_underscore_fields)]
302308
#[derive(Clone)]
@@ -330,6 +336,8 @@ struct Config { address codec; address bondToken; address checkpointStore; addre
330336
#[allow(missing_docs)]
331337
pub forcedInclusionFeeInGwei: u64,
332338
#[allow(missing_docs)]
339+
pub forcedInclusionFeeDoubleThreshold: u64,
340+
#[allow(missing_docs)]
333341
pub minCheckpointDelay: u16,
334342
#[allow(missing_docs)]
335343
pub permissionlessInclusionMultiplier: u8,
@@ -360,6 +368,7 @@ struct Config { address codec; address bondToken; address checkpointStore; addre
360368
alloy::sol_types::sol_data::Uint<256>,
361369
alloy::sol_types::sol_data::Uint<16>,
362370
alloy::sol_types::sol_data::Uint<64>,
371+
alloy::sol_types::sol_data::Uint<64>,
363372
alloy::sol_types::sol_data::Uint<16>,
364373
alloy::sol_types::sol_data::Uint<8>,
365374
alloy::sol_types::sol_data::Uint<16>,
@@ -380,6 +389,7 @@ struct Config { address codec; address bondToken; address checkpointStore; addre
380389
alloy::sol_types::private::primitives::aliases::U256,
381390
u16,
382391
u64,
392+
u64,
383393
u16,
384394
u8,
385395
u16,
@@ -414,6 +424,7 @@ struct Config { address codec; address bondToken; address checkpointStore; addre
414424
value.minForcedInclusionCount,
415425
value.forcedInclusionDelay,
416426
value.forcedInclusionFeeInGwei,
427+
value.forcedInclusionFeeDoubleThreshold,
417428
value.minCheckpointDelay,
418429
value.permissionlessInclusionMultiplier,
419430
value.compositeKeyVersion,
@@ -439,9 +450,10 @@ struct Config { address codec; address bondToken; address checkpointStore; addre
439450
minForcedInclusionCount: tuple.11,
440451
forcedInclusionDelay: tuple.12,
441452
forcedInclusionFeeInGwei: tuple.13,
442-
minCheckpointDelay: tuple.14,
443-
permissionlessInclusionMultiplier: tuple.15,
444-
compositeKeyVersion: tuple.16,
453+
forcedInclusionFeeDoubleThreshold: tuple.14,
454+
minCheckpointDelay: tuple.15,
455+
permissionlessInclusionMultiplier: tuple.16,
456+
compositeKeyVersion: tuple.17,
445457
}
446458
}
447459
}
@@ -504,6 +516,11 @@ struct Config { address codec; address bondToken; address checkpointStore; addre
504516
> as alloy_sol_types::SolType>::tokenize(
505517
&self.forcedInclusionFeeInGwei,
506518
),
519+
<alloy::sol_types::sol_data::Uint<
520+
64,
521+
> as alloy_sol_types::SolType>::tokenize(
522+
&self.forcedInclusionFeeDoubleThreshold,
523+
),
507524
<alloy::sol_types::sol_data::Uint<
508525
16,
509526
> as alloy_sol_types::SolType>::tokenize(&self.minCheckpointDelay),
@@ -589,7 +606,7 @@ struct Config { address codec; address bondToken; address checkpointStore; addre
589606
#[inline]
590607
fn eip712_root_type() -> alloy_sol_types::private::Cow<'static, str> {
591608
alloy_sol_types::private::Cow::Borrowed(
592-
"Config(address codec,address bondToken,address checkpointStore,address proofVerifier,address proposerChecker,uint48 provingWindow,uint48 extendedProvingWindow,uint256 maxFinalizationCount,uint48 finalizationGracePeriod,uint256 ringBufferSize,uint8 basefeeSharingPctg,uint256 minForcedInclusionCount,uint16 forcedInclusionDelay,uint64 forcedInclusionFeeInGwei,uint16 minCheckpointDelay,uint8 permissionlessInclusionMultiplier,uint16 compositeKeyVersion)",
609+
"Config(address codec,address bondToken,address checkpointStore,address proofVerifier,address proposerChecker,uint48 provingWindow,uint48 extendedProvingWindow,uint256 maxFinalizationCount,uint48 finalizationGracePeriod,uint256 ringBufferSize,uint8 basefeeSharingPctg,uint256 minForcedInclusionCount,uint16 forcedInclusionDelay,uint64 forcedInclusionFeeInGwei,uint64 forcedInclusionFeeDoubleThreshold,uint16 minCheckpointDelay,uint8 permissionlessInclusionMultiplier,uint16 compositeKeyVersion)",
593610
)
594611
}
595612
#[inline]
@@ -677,6 +694,12 @@ struct Config { address codec; address bondToken; address checkpointStore; addre
677694
&self.forcedInclusionFeeInGwei,
678695
)
679696
.0,
697+
<alloy::sol_types::sol_data::Uint<
698+
64,
699+
> as alloy_sol_types::SolType>::eip712_data_word(
700+
&self.forcedInclusionFeeDoubleThreshold,
701+
)
702+
.0,
680703
<alloy::sol_types::sol_data::Uint<
681704
16,
682705
> as alloy_sol_types::SolType>::eip712_data_word(
@@ -764,6 +787,11 @@ struct Config { address codec; address bondToken; address checkpointStore; addre
764787
> as alloy_sol_types::EventTopic>::topic_preimage_length(
765788
&rust.forcedInclusionFeeInGwei,
766789
)
790+
+ <alloy::sol_types::sol_data::Uint<
791+
64,
792+
> as alloy_sol_types::EventTopic>::topic_preimage_length(
793+
&rust.forcedInclusionFeeDoubleThreshold,
794+
)
767795
+ <alloy::sol_types::sol_data::Uint<
768796
16,
769797
> as alloy_sol_types::EventTopic>::topic_preimage_length(
@@ -862,6 +890,12 @@ struct Config { address codec; address bondToken; address checkpointStore; addre
862890
&rust.forcedInclusionFeeInGwei,
863891
out,
864892
);
893+
<alloy::sol_types::sol_data::Uint<
894+
64,
895+
> as alloy_sol_types::EventTopic>::encode_topic_preimage(
896+
&rust.forcedInclusionFeeDoubleThreshold,
897+
out,
898+
);
865899
<alloy::sol_types::sol_data::Uint<
866900
16,
867901
> as alloy_sol_types::EventTopic>::encode_topic_preimage(

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@ pub enum DerivationError {
6767
/// Failed to fetch the propose transaction from L1.
6868
#[error("failed to fetch propose transaction for proposal {proposal_id}: {reason}")]
6969
ProposeTransactionQuery { proposal_id: u64, reason: String },
70-
/// Block index exceeded the supported range.
71-
#[error("block index {index} exceeds u16 range")]
72-
BlockIndexOverflow { index: usize },
7370
/// Failed to query the anchor block fields.
7471
#[error("failed to fetch anchor block {block_number}: {reason}")]
7572
AnchorBlockQuery { block_number: u64, reason: String },

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ pub struct AnchorV4Input {
4242
pub prover_auth: Vec<u8>,
4343
pub bond_instructions_hash: B256,
4444
pub bond_instructions: Vec<BondInstruction>,
45-
pub block_index: u16,
4645
pub anchor_block_number: u64,
4746
pub anchor_block_hash: B256,
4847
pub anchor_state_root: B256,
@@ -91,7 +90,6 @@ where
9190
prover_auth,
9291
bond_instructions_hash,
9392
bond_instructions,
94-
block_index,
9593
anchor_block_number,
9694
anchor_block_hash,
9795
anchor_state_root,
@@ -128,9 +126,11 @@ where
128126
info!(
129127
l2_height,
130128
proposal_id,
131-
block_index,
129+
?prover_auth,
130+
?anchor_block_number,
132131
?anchor_block_hash,
133132
?anchor_state_root,
133+
?base_fee,
134134
"assembling shasta anchor anchorV4 transaction",
135135
);
136136

@@ -143,7 +143,6 @@ where
143143
};
144144

145145
let block_params = BlockParams {
146-
blockIndex: block_index,
147146
anchorBlockNumber: U48::from(anchor_block_number),
148147
anchorBlockHash: anchor_block_hash,
149148
anchorStateRoot: anchor_state_root,

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

Lines changed: 16 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,10 @@ struct SegmentContext<'a> {
4646
proposal_origin_block_hash: B256,
4747
/// Fork height for Shasta activation.
4848
shasta_fork_height: u64,
49-
/// Positional data describing where the segment sits within the proposal.
50-
position: SegmentPosition,
51-
}
52-
53-
/// Tracks the absolute position of a segment within the proposal bundle.
54-
#[derive(Clone, Copy)]
55-
struct SegmentPosition {
5649
/// Index of the segment within the proposal bundle.
57-
index: usize,
50+
segment_index: usize,
5851
/// Total number of segments in the proposal bundle.
59-
total: usize,
60-
/// Number of blocks included prior to this segment.
61-
blocks_before: usize,
52+
segments_total: usize,
6253
}
6354

6455
/// Position metadata passed down to block-level processing.
@@ -72,8 +63,6 @@ struct BlockPosition {
7263
block_index: usize,
7364
/// Total number of blocks in the segment.
7465
blocks_len: usize,
75-
/// Global offset of the first block in the segment.
76-
blocks_before_segment: usize,
7766
/// Whether the block originates from a forced inclusion segment.
7867
forced_inclusion: bool,
7968
}
@@ -126,8 +115,6 @@ struct BondInstructionData {
126115
struct AnchorTxInputs<'a> {
127116
/// Manifest-provided block metadata.
128117
block: &'a BlockManifest,
129-
/// Positional data describing where the block sits within the proposal.
130-
position: &'a BlockPosition,
131118
/// Height of the block being built.
132119
block_number: u64,
133120
/// Base fee target for the upcoming block.
@@ -152,25 +139,6 @@ fn manifest_is_default(manifest: &DerivationSourceManifest) -> bool {
152139
block.transactions.is_empty()
153140
}
154141

155-
impl SegmentPosition {
156-
// Convert the segment position into a block position for a specific block within the segment.
157-
fn into_block_position(
158-
self,
159-
block_index: usize,
160-
blocks_len: usize,
161-
forced_inclusion: bool,
162-
) -> BlockPosition {
163-
BlockPosition {
164-
segment_index: self.index,
165-
segments_total: self.total,
166-
block_index,
167-
blocks_len,
168-
blocks_before_segment: self.blocks_before,
169-
forced_inclusion,
170-
}
171-
}
172-
}
173-
174142
impl BlockPosition {
175143
// Check if this is the final block of the final segment.
176144
fn is_final(&self) -> bool {
@@ -181,11 +149,6 @@ impl BlockPosition {
181149
fn is_forced_inclusion(&self) -> bool {
182150
self.forced_inclusion
183151
}
184-
185-
// Compute the global index of this block within the entire proposal bundle.
186-
fn global_index(&self) -> usize {
187-
self.blocks_before_segment + self.block_index
188-
}
189152
}
190153

191154
impl<P> ShastaDerivationPipeline<P>
@@ -204,7 +167,6 @@ where
204167
) -> Result<Vec<EngineBlockOutcome>, DerivationError> {
205168
// Each source can expand into multiple payloads; accumulate their engine outcomes in order.
206169
let segments_total = sources.len();
207-
let mut blocks_before = 0usize;
208170
let mut outcomes = Vec::new();
209171
let parent_hash = state.header.hash_slow();
210172
let mut forkchoice_state = ForkchoiceState {
@@ -218,11 +180,8 @@ where
218180
meta,
219181
proposal_origin_block_hash,
220182
shasta_fork_height,
221-
position: SegmentPosition {
222-
index: segment_index,
223-
total: segments_total,
224-
blocks_before,
225-
},
183+
segment_index,
184+
segments_total,
226185
};
227186
let segment_outcomes = self
228187
.process_manifest_segment(
@@ -234,9 +193,7 @@ where
234193
)
235194
.await?;
236195

237-
let blocks_produced = segment_outcomes.len();
238196
outcomes.extend(segment_outcomes);
239-
blocks_before += blocks_produced;
240197
}
241198

242199
// Ensure the derived bond instruction hash matches what the proposal advertised.
@@ -259,7 +216,13 @@ where
259216
applier: &(dyn PayloadApplier + Send + Sync),
260217
forkchoice_state: &mut ForkchoiceState,
261218
) -> Result<Vec<EngineBlockOutcome>, DerivationError> {
262-
let SegmentContext { meta, proposal_origin_block_hash, shasta_fork_height, position } = ctx;
219+
let SegmentContext {
220+
meta,
221+
proposal_origin_block_hash,
222+
shasta_fork_height,
223+
segment_index,
224+
segments_total,
225+
} = ctx;
263226

264227
// Sanitize the manifest before deriving payload attributes.
265228
let mut decoded_manifest = segment.manifest;
@@ -296,11 +259,13 @@ where
296259
meta,
297260
origin_block_hash: proposal_origin_block_hash,
298261
shasta_fork_height,
299-
position: position.into_block_position(
262+
position: BlockPosition {
263+
segment_index,
264+
segments_total,
300265
block_index,
301266
blocks_len,
302-
segment.is_forced_inclusion,
303-
),
267+
forced_inclusion: segment.is_forced_inclusion,
268+
},
304269
is_low_bond_proposal,
305270
};
306271
let outcome = self
@@ -337,7 +302,6 @@ where
337302

338303
let anchor_inputs = AnchorTxInputs {
339304
block,
340-
position: &position,
341305
block_number,
342306
block_base_fee,
343307
bond_instructions: &bond_data.instructions,
@@ -564,7 +528,6 @@ where
564528
) -> Result<TxEnvelope, DerivationError> {
565529
let AnchorTxInputs {
566530
block,
567-
position,
568531
block_number,
569532
block_base_fee,
570533
bond_instructions,
@@ -574,9 +537,6 @@ where
574537
let (anchor_block_hash, anchor_state_root) =
575538
self.resolve_anchor_block_fields(block.anchor_block_number).await?;
576539

577-
let block_index = u16::try_from(position.global_index())
578-
.map_err(|_| DerivationError::BlockIndexOverflow { index: position.global_index() })?;
579-
580540
let tx = self
581541
.anchor_constructor
582542
.assemble_anchor_v4_tx(
@@ -587,7 +547,6 @@ where
587547
prover_auth: meta.prover_auth_bytes.clone().to_vec(),
588548
bond_instructions_hash,
589549
bond_instructions: bond_instructions.to_vec(),
590-
block_index,
591550
anchor_block_number: block.anchor_block_number,
592551
anchor_block_hash,
593552
anchor_state_root,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
311ed4e1a28ecf76490687a58f0a6f46b879b59c
1+
526ba18b88f0adc00504ddabc7b54dbe7a564353

0 commit comments

Comments
 (0)