Skip to content

Commit

Permalink
feat(taiko-client): include ParentMetaHash for better revert protec…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
Gavin “yoghurt” Yu committed Feb 19, 2025
1 parent 1d40b44 commit b66b600
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
19 changes: 17 additions & 2 deletions packages/taiko-client/proposer/transaction_builder/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,30 @@ func (b *BlobTransactionBuilder) BuildOntake(

blobs = append(blobs, blob)

encodedParams, err := encoding.EncodeBlockParamsOntake(&encoding.BlockParamsV2{
params := &encoding.BlockParamsV2{
Coinbase: b.l2SuggestedFeeRecipient,
ParentMetaHash: [32]byte{},
AnchorBlockId: 0,
Timestamp: 0,
BlobTxListOffset: 0,
BlobTxListLength: uint32(len(txListBytesArray[i])),
BlobIndex: uint8(i),
})
}

if i == 0 && b.revertProtectionEnabled {
state, err := b.rpc.GetProtocolStateVariables(nil)
if err != nil {
return nil, err
}

blockInfo, err := b.rpc.GetL2BlockInfoV2(ctx, new(big.Int).SetUint64(state.B.NumBlocks-1))
if err != nil {
return nil, err
}

params.ParentMetaHash = blockInfo.MetaHash
}
encodedParams, err := encoding.EncodeBlockParamsOntake(params)
if err != nil {
return nil, err
}
Expand Down
20 changes: 17 additions & 3 deletions packages/taiko-client/proposer/transaction_builder/calldata.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,27 @@ func (b *CalldataTransactionBuilder) BuildOntake(
encodedParamsArray [][]byte
)

for range txListBytesArray {
encodedParams, err := encoding.EncodeBlockParamsOntake(&encoding.BlockParamsV2{
for i := range txListBytesArray {
params := &encoding.BlockParamsV2{
Coinbase: b.l2SuggestedFeeRecipient,
ParentMetaHash: [32]byte{},
AnchorBlockId: 0,
Timestamp: 0,
})
}
if i == 0 && b.revertProtectionEnabled {
state, err := b.rpc.GetProtocolStateVariables(nil)
if err != nil {
return nil, err
}

blockInfo, err := b.rpc.GetL2BlockInfoV2(ctx, new(big.Int).SetUint64(state.B.NumBlocks-1))
if err != nil {
return nil, err
}

params.ParentMetaHash = blockInfo.MetaHash
}
encodedParams, err := encoding.EncodeBlockParamsOntake(params)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit b66b600

Please sign in to comment.