From 54cb493778c140bea1392b05251aa79db4e19bcd Mon Sep 17 00:00:00 2001 From: jonastheis <4181434+jonastheis@users.noreply.github.com> Date: Sat, 8 Mar 2025 13:26:28 +0800 Subject: [PATCH] add commitAndFinalizeBatch method to L1Reader to support enforced batches in L1 follower and rollup verifier --- rollup/l1/abi.go | 17 +++++++++++++++++ rollup/l1/abi_test.go | 1 + rollup/l1/reader.go | 24 ++++++++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/rollup/l1/abi.go b/rollup/l1/abi.go index e0d710bc84d6..3c190be12630 100644 --- a/rollup/l1/abi.go +++ b/rollup/l1/abi.go @@ -45,6 +45,7 @@ const ( commitBatchMethodName = "commitBatch" commitBatchWithBlobProofMethodName = "commitBatchWithBlobProof" commitBatchesV7MethodName = "commitBatches" + commitAndFinalizeBatch = "commitAndFinalizeBatch" finalizeBundlePostEuclidV2MethodName = "finalizeBundlePostEuclidV2" @@ -362,3 +363,19 @@ func newFinalizeBatchArgs(method *abi.Method, values []any) (*FinalizeBatchArgs, } return &args, nil } + +type commitAndFinalizeBatchArgs struct { + Version uint8 + ParentBatchHash common.Hash + FinalizeStruct FinalizeBatchArgs +} + +func newCommitAndFinalizeBatchArgs(method *abi.Method, values []any) (*commitAndFinalizeBatchArgs, error) { + var args commitAndFinalizeBatchArgs + err := method.Inputs.Copy(&args, values) + if err != nil { + return nil, err + } + + return &args, nil +} diff --git a/rollup/l1/abi_test.go b/rollup/l1/abi_test.go index 7ad874d3d8e9..43533bd68e1e 100644 --- a/rollup/l1/abi_test.go +++ b/rollup/l1/abi_test.go @@ -22,6 +22,7 @@ func TestMethodSignatures(t *testing.T) { assert.Equal(t, crypto.Keccak256Hash([]byte("commitBatch(uint8,bytes,bytes[],bytes)")).Bytes()[:4], ScrollChainABI.Methods[commitBatchMethodName].ID) assert.Equal(t, crypto.Keccak256Hash([]byte("commitBatchWithBlobProof(uint8,bytes,bytes[],bytes,bytes)")).Bytes()[:4], ScrollChainABI.Methods[commitBatchWithBlobProofMethodName].ID) assert.Equal(t, crypto.Keccak256Hash([]byte("commitBatches(uint8,bytes32,bytes32)")).Bytes()[:4], ScrollChainABI.Methods[commitBatchesV7MethodName].ID) + assert.Equal(t, crypto.Keccak256Hash([]byte("commitAndFinalizeBatch(uint8,bytes32,(bytes,uint256,bytes32,bytes32,bytes))")).Bytes()[:4], ScrollChainABI.Methods[commitAndFinalizeBatch].ID) assert.Equal(t, crypto.Keccak256Hash([]byte("finalizeBundlePostEuclidV2(bytes,uint256,bytes32,bytes32,bytes)")).Bytes()[:4], ScrollChainABI.Methods[finalizeBundlePostEuclidV2MethodName].ID) } diff --git a/rollup/l1/reader.go b/rollup/l1/reader.go index 6c39621d9120..0fffb624dadd 100644 --- a/rollup/l1/reader.go +++ b/rollup/l1/reader.go @@ -6,6 +6,8 @@ import ( "fmt" "math/big" + "github.com/scroll-tech/da-codec/encoding" + "github.com/scroll-tech/go-ethereum" "github.com/scroll-tech/go-ethereum/accounts/abi" "github.com/scroll-tech/go-ethereum/common" @@ -398,6 +400,28 @@ func (r *Reader) FetchCommitTxData(commitEvent *CommitBatchEvent) (*CommitBatchA if err != nil { return nil, fmt.Errorf("failed to decode calldata into commitBatch args %s, values: %+v, err: %w", commitBatchesV7MethodName, values, err) } + } else if method.Name == commitAndFinalizeBatch { + commitAndFinalizeArgs, err := newCommitAndFinalizeBatchArgs(method, values) + if err != nil { + return nil, fmt.Errorf("failed to decode calldata into commitAndFinalizeBatch args %s, values: %+v, err: %w", commitAndFinalizeBatch, values, err) + } + + // in commitAndFinalizeBatch, the last batch hash is encoded in the finalize struct as this is the only batch we're + // committing when calling this function. + codec, err := encoding.CodecFromVersion(encoding.CodecVersion(commitAndFinalizeArgs.Version)) + if err != nil { + return nil, fmt.Errorf("failed to get codec from version %d, err: %w", commitAndFinalizeArgs.Version, err) + } + daBatch, err := codec.NewDABatchFromBytes(commitAndFinalizeArgs.FinalizeStruct.BatchHeader) + if err != nil { + return nil, fmt.Errorf("failed to decode daBatch from bytes, err: %w", err) + } + + args = &CommitBatchArgs{ + Version: commitAndFinalizeArgs.Version, + ParentBatchHash: commitAndFinalizeArgs.ParentBatchHash, + LastBatchHash: daBatch.Hash(), + } } else { return nil, fmt.Errorf("unknown method name for commit transaction: %s", method.Name) }