Skip to content

Commit

Permalink
add commitAndFinalizeBatch method to L1Reader to support enforced bat…
Browse files Browse the repository at this point in the history
…ches in L1 follower and rollup verifier
  • Loading branch information
jonastheis committed Mar 8, 2025
1 parent 61cfff3 commit 54cb493
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
17 changes: 17 additions & 0 deletions rollup/l1/abi.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const (
commitBatchMethodName = "commitBatch"
commitBatchWithBlobProofMethodName = "commitBatchWithBlobProof"
commitBatchesV7MethodName = "commitBatches"
commitAndFinalizeBatch = "commitAndFinalizeBatch"

finalizeBundlePostEuclidV2MethodName = "finalizeBundlePostEuclidV2"

Expand Down Expand Up @@ -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
}
1 change: 1 addition & 0 deletions rollup/l1/abi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
24 changes: 24 additions & 0 deletions rollup/l1/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 54cb493

Please sign in to comment.