Sitelet https://github.com/ethereum-optimism/optimism/commit/4317c093fbe951c57c0e36037a9aa281e8e0795c
Skip to content

Commit 4317c09

Browse files
refactor: single source of truth for DerivationVersion (#11901)
* single source of truth for DerivationVersion * op-node/rollup: fix imports --------- Co-authored-by: protolambda <proto@protolambda.com>
1 parent cf1ce68 commit 4317c09

12 files changed

Lines changed: 34 additions & 28 deletions

File tree

‎op-alt-da/commitment.go‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"errors"
77
"fmt"
88

9+
"github.com/ethereum-optimism/optimism/op-node/rollup/derive/params"
910
"github.com/ethereum/go-ethereum/crypto"
1011
)
1112

@@ -115,7 +116,7 @@ func (c Keccak256Commitment) Encode() []byte {
115116

116117
// TxData adds an extra version byte to signal it's a commitment.
117118
func (c Keccak256Commitment) TxData() []byte {
118-
return append([]byte{TxDataVersion1}, c.Encode()...)
119+
return append([]byte{params.DerivationVersion1}, c.Encode()...)
119120
}
120121

121122
// Verify checks if the commitment matches the given input.
@@ -155,7 +156,7 @@ func (c GenericCommitment) Encode() []byte {
155156

156157
// TxData adds an extra version byte to signal it's a commitment.
157158
func (c GenericCommitment) TxData() []byte {
158-
return append([]byte{TxDataVersion1}, c.Encode()...)
159+
return append([]byte{params.DerivationVersion1}, c.Encode()...)
159160
}
160161

161162
// Verify always returns true for GenericCommitment because the DA Server must validate the data before returning it to the op-node.

‎op-alt-da/commitment_test.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package altda
33
import (
44
"testing"
55

6+
"github.com/ethereum-optimism/optimism/op-node/rollup/derive/params"
67
"github.com/stretchr/testify/require"
78
)
89

@@ -54,7 +55,7 @@ func TestCommitmentData(t *testing.T) {
5455
// Test that reencoding the commitment returns the same data
5556
require.Equal(t, tc.commData, comm.Encode())
5657
// Test that TxData() returns the same data as the original, prepended with a version byte
57-
require.Equal(t, append([]byte{TxDataVersion1}, tc.commData...), comm.TxData())
58+
require.Equal(t, append([]byte{params.DerivationVersion1}, tc.commData...), comm.TxData())
5859

5960
// Test that Verify() returns no error for the correct data
6061
require.NoError(t, comm.Verify(tc.commData))

‎op-alt-da/params.go‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,3 @@ package altda
44
// challenge in the Data Availability Challenge contract. Value in number of bytes.
55
// This value can only be changed in a hard fork.
66
const MaxInputSize = 130672
7-
8-
// TxDataVersion1 is the version number for batcher transactions containing
9-
// altDA commitments. It should not collide with DerivationVersion which is still
10-
// used downstream when parsing the frames.
11-
const TxDataVersion1 = 1

‎op-batcher/batcher/tx_data.go‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"strings"
66

77
"github.com/ethereum-optimism/optimism/op-node/rollup/derive"
8+
"github.com/ethereum-optimism/optimism/op-node/rollup/derive/params"
89
"github.com/ethereum-optimism/optimism/op-service/eth"
910
)
1011

@@ -35,7 +36,7 @@ func (td *txData) ID() txID {
3536
// It's a version byte (0) followed by the concatenated frames for this transaction.
3637
func (td *txData) CallData() []byte {
3738
data := make([]byte, 1, 1+td.Len())
38-
data[0] = derive.DerivationVersion0
39+
data[0] = params.DerivationVersion0
3940
for _, f := range td.frames {
4041
data = append(data, f.data...)
4142
}
@@ -46,7 +47,7 @@ func (td *txData) Blobs() ([]*eth.Blob, error) {
4647
blobs := make([]*eth.Blob, 0, len(td.frames))
4748
for _, f := range td.frames {
4849
var blob eth.Blob
49-
if err := blob.FromData(append([]byte{derive.DerivationVersion0}, f.data...)); err != nil {
50+
if err := blob.FromData(append([]byte{params.DerivationVersion0}, f.data...)); err != nil {
5051
return nil, err
5152
}
5253
blobs = append(blobs, &blob)

‎op-e2e/actions/helpers/l2_batcher.go‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils"
2727
"github.com/ethereum-optimism/optimism/op-node/rollup"
2828
"github.com/ethereum-optimism/optimism/op-node/rollup/derive"
29+
derive_params "github.com/ethereum-optimism/optimism/op-node/rollup/derive/params"
2930
"github.com/ethereum-optimism/optimism/op-service/eth"
3031
"github.com/ethereum-optimism/optimism/op-service/txmgr"
3132
)
@@ -295,7 +296,7 @@ func (s *L2Batcher) ReadNextOutputFrame(t Testing) []byte {
295296
}
296297
// Collect the output frame
297298
data := new(bytes.Buffer)
298-
data.WriteByte(derive.DerivationVersion0)
299+
data.WriteByte(derive_params.DerivationVersion0)
299300
// subtract one, to account for the version byte
300301
if _, err := s.L2ChannelOut.OutputFrame(data, s.l2BatcherCfg.MaxL1TxSize-1); err == io.EOF {
301302
s.L2ChannelOut = nil
@@ -400,7 +401,7 @@ func (s *L2Batcher) ActL2BatchSubmitMultiBlob(t Testing, numBlobs int) {
400401
blobs := make([]*eth.Blob, numBlobs)
401402
for i := 0; i < numBlobs; i++ {
402403
data := new(bytes.Buffer)
403-
data.WriteByte(derive.DerivationVersion0)
404+
data.WriteByte(derive_params.DerivationVersion0)
404405
// write only a few bytes to all but the last blob
405406
l := uint64(derive.FrameV0OverHeadSize + 4) // 4 bytes content
406407
if i == numBlobs-1 {

‎op-node/rollup/derive/altda_data_source.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77

88
altda "github.com/ethereum-optimism/optimism/op-alt-da"
9+
"github.com/ethereum-optimism/optimism/op-node/rollup/derive/params"
910
"github.com/ethereum-optimism/optimism/op-service/eth"
1011
"github.com/ethereum/go-ethereum/log"
1112
)
@@ -56,7 +57,7 @@ func (s *AltDADataSource) Next(ctx context.Context) (eth.Data, error) {
5657
}
5758
// If the tx data type is not altDA, we forward it downstream to let the next
5859
// steps validate and potentially parse it as L1 DA inputs.
59-
if data[0] != altda.TxDataVersion1 {
60+
if data[0] != params.DerivationVersion1 {
6061
return data, nil
6162
}
6263

‎op-node/rollup/derive/channel_out.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"io"
99

1010
"github.com/ethereum-optimism/optimism/op-node/rollup"
11+
"github.com/ethereum-optimism/optimism/op-node/rollup/derive/params"
1112
"github.com/ethereum/go-ethereum/common/hexutil"
1213
"github.com/ethereum/go-ethereum/core/types"
1314
"github.com/ethereum/go-ethereum/rlp"
@@ -275,7 +276,7 @@ func ForceCloseTxData(frames []Frame) ([]byte, error) {
275276
}
276277

277278
var out bytes.Buffer
278-
out.WriteByte(DerivationVersion0)
279+
out.WriteByte(params.DerivationVersion0)
279280

280281
if !closed {
281282
f := Frame{

‎op-node/rollup/derive/frame.go‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"errors"
77
"fmt"
88
"io"
9+
10+
"github.com/ethereum-optimism/optimism/op-node/rollup/derive/params"
911
)
1012

1113
// Frames cannot be larger than 1 MB.
@@ -130,7 +132,7 @@ func ParseFrames(data []byte) ([]Frame, error) {
130132
if len(data) == 0 {
131133
return nil, errors.New("data array must not be empty")
132134
}
133-
if data[0] != DerivationVersion0 {
135+
if data[0] != params.DerivationVersion0 {
134136
return nil, fmt.Errorf("invalid derivation format byte: got %d", data[0])
135137
}
136138
buf := bytes.NewBuffer(data[1:])

‎op-node/rollup/derive/frame_queue_test.go‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ import (
77
"log/slog"
88
"testing"
99

10+
"github.com/stretchr/testify/mock"
11+
"github.com/stretchr/testify/require"
12+
1013
"github.com/ethereum-optimism/optimism/op-node/rollup"
1114
"github.com/ethereum-optimism/optimism/op-node/rollup/derive/mocks"
15+
"github.com/ethereum-optimism/optimism/op-node/rollup/derive/params"
1216
"github.com/ethereum-optimism/optimism/op-service/eth"
1317
"github.com/ethereum-optimism/optimism/op-service/testlog"
14-
"github.com/stretchr/testify/mock"
15-
"github.com/stretchr/testify/require"
1618
)
1719

1820
func TestPruneFrameQueue(t *testing.T) {
@@ -126,7 +128,7 @@ func testFrameQueue_NextFrame(t *testing.T, holocene bool) {
126128
}
127129

128130
var inBuf bytes.Buffer
129-
inBuf.WriteByte(DerivationVersion0)
131+
inBuf.WriteByte(params.DerivationVersion0)
130132
for _, f := range inFrames {
131133
require.NoError(t, f.MarshalBinary(&inBuf))
132134
}

‎op-node/rollup/derive/frame_test.go‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ import (
99
"testing"
1010
"time"
1111

12-
"github.com/ethereum-optimism/optimism/op-service/testutils"
1312
"github.com/stretchr/testify/require"
13+
14+
"github.com/ethereum-optimism/optimism/op-node/rollup/derive/params"
15+
"github.com/ethereum-optimism/optimism/op-service/testutils"
1416
)
1517

1618
func FuzzFrameUnmarshalBinary(f *testing.F) {
@@ -164,7 +166,7 @@ func TestParseFramesInvalidVer(t *testing.T) {
164166
}
165167

166168
func TestParseFramesOnlyVersion(t *testing.T) {
167-
frames, err := ParseFrames([]byte{DerivationVersion0})
169+
frames, err := ParseFrames([]byte{params.DerivationVersion0})
168170
require.Empty(t, frames)
169171
require.Error(t, err)
170172
}
@@ -206,7 +208,7 @@ func TestParseFramesTruncated(t *testing.T) {
206208
// frames.
207209
func txMarshalFrames(frames []Frame) ([]byte, error) {
208210
var data bytes.Buffer
209-
if err := data.WriteByte(DerivationVersion0); err != nil {
211+
if err := data.WriteByte(params.DerivationVersion0); err != nil {
210212
return nil, err
211213
}
212214
for _, frame := range frames {

0 commit comments

Comments
 (0)