diff --git a/op-alt-da/commitment.go b/op-alt-da/commitment.go index a6fa5424665b1..157eb8b185434 100644 --- a/op-alt-da/commitment.go +++ b/op-alt-da/commitment.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" + "github.com/ethereum-optimism/optimism/op-node/rollup/derive/params" "github.com/ethereum/go-ethereum/crypto" ) @@ -115,7 +116,7 @@ func (c Keccak256Commitment) Encode() []byte { // TxData adds an extra version byte to signal it's a commitment. func (c Keccak256Commitment) TxData() []byte { - return append([]byte{TxDataVersion1}, c.Encode()...) + return append([]byte{params.DerivationVersion1}, c.Encode()...) } // Verify checks if the commitment matches the given input. @@ -155,7 +156,7 @@ func (c GenericCommitment) Encode() []byte { // TxData adds an extra version byte to signal it's a commitment. func (c GenericCommitment) TxData() []byte { - return append([]byte{TxDataVersion1}, c.Encode()...) + return append([]byte{params.DerivationVersion1}, c.Encode()...) } // Verify always returns true for GenericCommitment because the DA Server must validate the data before returning it to the op-node. diff --git a/op-alt-da/commitment_test.go b/op-alt-da/commitment_test.go index 52abc5d886570..e4656133d69e0 100644 --- a/op-alt-da/commitment_test.go +++ b/op-alt-da/commitment_test.go @@ -3,6 +3,7 @@ package altda import ( "testing" + "github.com/ethereum-optimism/optimism/op-node/rollup/derive/params" "github.com/stretchr/testify/require" ) @@ -54,7 +55,7 @@ func TestCommitmentData(t *testing.T) { // Test that reencoding the commitment returns the same data require.Equal(t, tc.commData, comm.Encode()) // Test that TxData() returns the same data as the original, prepended with a version byte - require.Equal(t, append([]byte{TxDataVersion1}, tc.commData...), comm.TxData()) + require.Equal(t, append([]byte{params.DerivationVersion1}, tc.commData...), comm.TxData()) // Test that Verify() returns no error for the correct data require.NoError(t, comm.Verify(tc.commData)) diff --git a/op-alt-da/params.go b/op-alt-da/params.go index 86339200f7fc2..bc0762ba13193 100644 --- a/op-alt-da/params.go +++ b/op-alt-da/params.go @@ -4,8 +4,3 @@ package altda // challenge in the Data Availability Challenge contract. Value in number of bytes. // This value can only be changed in a hard fork. const MaxInputSize = 130672 - -// TxDataVersion1 is the version number for batcher transactions containing -// altDA commitments. It should not collide with DerivationVersion which is still -// used downstream when parsing the frames. -const TxDataVersion1 = 1 diff --git a/op-batcher/batcher/tx_data.go b/op-batcher/batcher/tx_data.go index d0f5474fd5f25..0165f85f079ed 100644 --- a/op-batcher/batcher/tx_data.go +++ b/op-batcher/batcher/tx_data.go @@ -5,6 +5,7 @@ import ( "strings" "github.com/ethereum-optimism/optimism/op-node/rollup/derive" + "github.com/ethereum-optimism/optimism/op-node/rollup/derive/params" "github.com/ethereum-optimism/optimism/op-service/eth" ) @@ -35,7 +36,7 @@ func (td *txData) ID() txID { // It's a version byte (0) followed by the concatenated frames for this transaction. func (td *txData) CallData() []byte { data := make([]byte, 1, 1+td.Len()) - data[0] = derive.DerivationVersion0 + data[0] = params.DerivationVersion0 for _, f := range td.frames { data = append(data, f.data...) } @@ -46,7 +47,7 @@ func (td *txData) Blobs() ([]*eth.Blob, error) { blobs := make([]*eth.Blob, 0, len(td.frames)) for _, f := range td.frames { var blob eth.Blob - if err := blob.FromData(append([]byte{derive.DerivationVersion0}, f.data...)); err != nil { + if err := blob.FromData(append([]byte{params.DerivationVersion0}, f.data...)); err != nil { return nil, err } blobs = append(blobs, &blob) diff --git a/op-e2e/actions/helpers/l2_batcher.go b/op-e2e/actions/helpers/l2_batcher.go index 9fc9971a26e26..88fde9bd9a9a3 100644 --- a/op-e2e/actions/helpers/l2_batcher.go +++ b/op-e2e/actions/helpers/l2_batcher.go @@ -26,6 +26,7 @@ import ( "github.com/ethereum-optimism/optimism/op-e2e/e2eutils" "github.com/ethereum-optimism/optimism/op-node/rollup" "github.com/ethereum-optimism/optimism/op-node/rollup/derive" + derive_params "github.com/ethereum-optimism/optimism/op-node/rollup/derive/params" "github.com/ethereum-optimism/optimism/op-service/eth" "github.com/ethereum-optimism/optimism/op-service/txmgr" ) @@ -295,7 +296,7 @@ func (s *L2Batcher) ReadNextOutputFrame(t Testing) []byte { } // Collect the output frame data := new(bytes.Buffer) - data.WriteByte(derive.DerivationVersion0) + data.WriteByte(derive_params.DerivationVersion0) // subtract one, to account for the version byte if _, err := s.L2ChannelOut.OutputFrame(data, s.l2BatcherCfg.MaxL1TxSize-1); err == io.EOF { s.L2ChannelOut = nil @@ -400,7 +401,7 @@ func (s *L2Batcher) ActL2BatchSubmitMultiBlob(t Testing, numBlobs int) { blobs := make([]*eth.Blob, numBlobs) for i := 0; i < numBlobs; i++ { data := new(bytes.Buffer) - data.WriteByte(derive.DerivationVersion0) + data.WriteByte(derive_params.DerivationVersion0) // write only a few bytes to all but the last blob l := uint64(derive.FrameV0OverHeadSize + 4) // 4 bytes content if i == numBlobs-1 { diff --git a/op-node/rollup/derive/altda_data_source.go b/op-node/rollup/derive/altda_data_source.go index 829d9399a4d2f..2945a2a9e57b2 100644 --- a/op-node/rollup/derive/altda_data_source.go +++ b/op-node/rollup/derive/altda_data_source.go @@ -6,6 +6,7 @@ import ( "fmt" altda "github.com/ethereum-optimism/optimism/op-alt-da" + "github.com/ethereum-optimism/optimism/op-node/rollup/derive/params" "github.com/ethereum-optimism/optimism/op-service/eth" "github.com/ethereum/go-ethereum/log" ) @@ -56,7 +57,7 @@ func (s *AltDADataSource) Next(ctx context.Context) (eth.Data, error) { } // If the tx data type is not altDA, we forward it downstream to let the next // steps validate and potentially parse it as L1 DA inputs. - if data[0] != altda.TxDataVersion1 { + if data[0] != params.DerivationVersion1 { return data, nil } diff --git a/op-node/rollup/derive/channel_out.go b/op-node/rollup/derive/channel_out.go index 87f39d2eb0928..7a97d7708efac 100644 --- a/op-node/rollup/derive/channel_out.go +++ b/op-node/rollup/derive/channel_out.go @@ -8,6 +8,7 @@ import ( "io" "github.com/ethereum-optimism/optimism/op-node/rollup" + "github.com/ethereum-optimism/optimism/op-node/rollup/derive/params" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/rlp" @@ -275,7 +276,7 @@ func ForceCloseTxData(frames []Frame) ([]byte, error) { } var out bytes.Buffer - out.WriteByte(DerivationVersion0) + out.WriteByte(params.DerivationVersion0) if !closed { f := Frame{ diff --git a/op-node/rollup/derive/frame.go b/op-node/rollup/derive/frame.go index 0baa1e120a14e..e18562560e796 100644 --- a/op-node/rollup/derive/frame.go +++ b/op-node/rollup/derive/frame.go @@ -6,6 +6,8 @@ import ( "errors" "fmt" "io" + + "github.com/ethereum-optimism/optimism/op-node/rollup/derive/params" ) // Frames cannot be larger than 1 MB. @@ -130,7 +132,7 @@ func ParseFrames(data []byte) ([]Frame, error) { if len(data) == 0 { return nil, errors.New("data array must not be empty") } - if data[0] != DerivationVersion0 { + if data[0] != params.DerivationVersion0 { return nil, fmt.Errorf("invalid derivation format byte: got %d", data[0]) } buf := bytes.NewBuffer(data[1:]) diff --git a/op-node/rollup/derive/frame_queue_test.go b/op-node/rollup/derive/frame_queue_test.go index a0a57f4f387dc..14ca377f6a686 100644 --- a/op-node/rollup/derive/frame_queue_test.go +++ b/op-node/rollup/derive/frame_queue_test.go @@ -7,12 +7,14 @@ import ( "log/slog" "testing" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" + "github.com/ethereum-optimism/optimism/op-node/rollup" "github.com/ethereum-optimism/optimism/op-node/rollup/derive/mocks" + "github.com/ethereum-optimism/optimism/op-node/rollup/derive/params" "github.com/ethereum-optimism/optimism/op-service/eth" "github.com/ethereum-optimism/optimism/op-service/testlog" - "github.com/stretchr/testify/mock" - "github.com/stretchr/testify/require" ) func TestPruneFrameQueue(t *testing.T) { @@ -126,7 +128,7 @@ func testFrameQueue_NextFrame(t *testing.T, holocene bool) { } var inBuf bytes.Buffer - inBuf.WriteByte(DerivationVersion0) + inBuf.WriteByte(params.DerivationVersion0) for _, f := range inFrames { require.NoError(t, f.MarshalBinary(&inBuf)) } diff --git a/op-node/rollup/derive/frame_test.go b/op-node/rollup/derive/frame_test.go index 240cc0a58d8d3..277e976fccae7 100644 --- a/op-node/rollup/derive/frame_test.go +++ b/op-node/rollup/derive/frame_test.go @@ -9,8 +9,10 @@ import ( "testing" "time" - "github.com/ethereum-optimism/optimism/op-service/testutils" "github.com/stretchr/testify/require" + + "github.com/ethereum-optimism/optimism/op-node/rollup/derive/params" + "github.com/ethereum-optimism/optimism/op-service/testutils" ) func FuzzFrameUnmarshalBinary(f *testing.F) { @@ -164,7 +166,7 @@ func TestParseFramesInvalidVer(t *testing.T) { } func TestParseFramesOnlyVersion(t *testing.T) { - frames, err := ParseFrames([]byte{DerivationVersion0}) + frames, err := ParseFrames([]byte{params.DerivationVersion0}) require.Empty(t, frames) require.Error(t, err) } @@ -206,7 +208,7 @@ func TestParseFramesTruncated(t *testing.T) { // frames. func txMarshalFrames(frames []Frame) ([]byte, error) { var data bytes.Buffer - if err := data.WriteByte(DerivationVersion0); err != nil { + if err := data.WriteByte(params.DerivationVersion0); err != nil { return nil, err } for _, frame := range frames { diff --git a/op-node/rollup/derive/params.go b/op-node/rollup/derive/params.go index 385c4087930b9..c4511d950882a 100644 --- a/op-node/rollup/derive/params.go +++ b/op-node/rollup/derive/params.go @@ -4,8 +4,6 @@ import ( "encoding/hex" "errors" "fmt" - - altda "github.com/ethereum-optimism/optimism/op-alt-da" ) // count the tagging info as 200 in terms of buffer size. @@ -19,11 +17,6 @@ func frameSize(frame Frame) uint64 { return uint64(len(frame.Data)) + frameOverhead } -const DerivationVersion0 = 0 - -// DerivationVersion1 is reserved for batcher transactions containing altDA commitments. -const DerivationVersion1 = altda.TxDataVersion1 - // MaxSpanBatchElementCount is the maximum number of blocks, transactions in total, // or transaction per block allowed in a span batch. const MaxSpanBatchElementCount = 10_000_000 diff --git a/op-node/rollup/derive/params/versions.go b/op-node/rollup/derive/params/versions.go new file mode 100644 index 0000000000000..0c723e8a9c23d --- /dev/null +++ b/op-node/rollup/derive/params/versions.go @@ -0,0 +1,6 @@ +package params + +const DerivationVersion0 = 0 + +// DerivationVersion1 is reserved for batcher transactions containing altDA commitments. +const DerivationVersion1 = 1