Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add tx data version byte #9845

Merged
merged 3 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion op-batcher/batcher/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,8 @@ func (l *BatchSubmitter) sendTransaction(ctx context.Context, txdata txData, que
l.recordFailedTx(txdata, err)
return nil
}
data = comm.Encode()
// signal plasma commitment tx with TxDataVersion1
data = comm.TxData(derive.TxDataVersion1)
}
candidate = l.calldataTxCandidate(data)
}
Expand Down
2 changes: 1 addition & 1 deletion op-e2e/actions/l2_batcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func (s *L2Batcher) ActL2BatchSubmit(t Testing, txOpts ...func(tx *types.Dynamic
if s.l2BatcherCfg.UsePlasma {
comm, err := s.l2BatcherCfg.PlasmaDA.SetInput(t.Ctx(), payload)
require.NoError(t, err, "failed to set input for plasma")
payload = comm.Encode()
payload = comm.TxData(derive.TxDataVersion1)
}

nonce, err := s.l1.PendingNonceAt(t.Ctx(), s.batcherAddr)
Expand Down
3 changes: 2 additions & 1 deletion op-e2e/actions/plasma_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ func (a *L2PlasmaDA) ActNewL2Tx(t Testing) {
a.batcher.ActL2BatchBuffer(t)
a.batcher.ActL2ChannelClose(t)
a.batcher.ActL2BatchSubmit(t, func(tx *types.DynamicFeeTx) {
a.lastComm = tx.Data
// skip txdata version byte
a.lastComm = tx.Data[1:]
})

a.miner.ActL1StartBlock(3)(t)
Expand Down
5 changes: 5 additions & 0 deletions op-node/rollup/derive/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ func frameSize(frame Frame) uint64 {

const DerivationVersion0 = 0

// TxDataVersion1 is the version number for batcher transactions containing
// plasma inputs. It should not collide with DerivationVersion which is still
// used downstream when parsing the frames.
const TxDataVersion1 = 1

// MaxSpanBatchSize is the maximum amount of bytes that will be needed
// to decode every span batch field. This value cannot be larger than
// MaxRLPBytesPerChannel because single batch cannot be larger than channel size.
Expand Down
9 changes: 7 additions & 2 deletions op-node/rollup/derive/plasma_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,19 @@ func (s *PlasmaDataSource) Next(ctx context.Context) (eth.Data, error) {
}

if s.comm == nil {
var err error
// the l1 source returns the input commitment for the batch.
data, err := s.src.Next(ctx)
if err != nil {
return nil, err
}
// If the tx data type is not plasma, we forward it downstream to let the next
// steps validate and potentially parse it as L1 DA inputs.
trianglesphere marked this conversation as resolved.
Show resolved Hide resolved
if data[0] != TxDataVersion1 {
return data, nil
}

// validate batcher inbox data is a commitment.
comm, err := plasma.DecodeKeccak256(data)
comm, err := plasma.DecodeKeccak256(data[1:])
tchardin marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
s.log.Warn("invalid commitment", "commitment", data, "err", err)
return s.Next(ctx)
Expand Down
20 changes: 12 additions & 8 deletions op-node/rollup/derive/plasma_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func TestPlasmaDataSource(t *testing.T) {
Gas: 100_000,
To: &batcherInbox,
Value: big.NewInt(int64(0)),
Data: comm.Encode(),
Data: comm.TxData(TxDataVersion1),
})
require.NoError(t, err)

Expand Down Expand Up @@ -234,7 +234,7 @@ func TestPlasmaDataSource(t *testing.T) {
Gas: 100_000,
To: &batcherInbox,
Value: big.NewInt(int64(0)),
Data: comm.Encode(),
Data: comm.TxData(TxDataVersion1),
})
require.NoError(t, err)

Expand Down Expand Up @@ -351,7 +351,7 @@ func TestPlasmaDataSourceStall(t *testing.T) {
Gas: 100_000,
To: &batcherInbox,
Value: big.NewInt(int64(0)),
Data: comm.Encode(),
Data: comm.TxData(TxDataVersion1),
})
require.NoError(t, err)

Expand Down Expand Up @@ -466,7 +466,7 @@ func TestPlasmaDataSourceInvalidData(t *testing.T) {
Gas: 100_000,
To: &batcherInbox,
Value: big.NewInt(int64(0)),
Data: comm.Encode(),
Data: comm.TxData(TxDataVersion1),
})
require.NoError(t, err)

Expand All @@ -481,11 +481,11 @@ func TestPlasmaDataSourceInvalidData(t *testing.T) {
Gas: 100_000,
To: &batcherInbox,
Value: big.NewInt(int64(0)),
Data: comm2.Encode(),
Data: comm2.TxData(TxDataVersion1),
})
require.NoError(t, err)

// invalid commitment
// regular input instead of commitment
input3 := testutils.RandomData(rng, 32)
tx3, err := types.SignNewTx(batcherPriv, signer, &types.DynamicFeeTx{
ChainID: signer.ChainID(),
Expand All @@ -506,12 +506,16 @@ func TestPlasmaDataSourceInvalidData(t *testing.T) {
src, err := factory.OpenData(ctx, ref, batcherAddr)
require.NoError(t, err)

// oversized input should be skipped
// oversized input is skipped and returns input2 directly
data, err := src.Next(ctx)
require.NoError(t, err)
require.Equal(t, hexutil.Bytes(input2), data)

// invalid commitment is skipped so should return an EOF
// regular input is passed through
data, err = src.Next(ctx)
require.NoError(t, err)
require.Equal(t, hexutil.Bytes(input3), data)

_, err = src.Next(ctx)
require.ErrorIs(t, err, io.EOF)

Expand Down
5 changes: 5 additions & 0 deletions op-plasma/commitment.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ func (c Keccak256Commitment) Encode() []byte {
return append([]byte{byte(Keccak256CommitmentType)}, c...)
}

// TxData adds an extra version byte to signal it's a commitment.
func (c Keccak256Commitment) TxData(version uint8) []byte {
tchardin marked this conversation as resolved.
Show resolved Hide resolved
return append([]byte{version}, c.Encode()...)
}

// Verify checks if the commitment matches the given input.
func (c Keccak256Commitment) Verify(input []byte) error {
if !bytes.Equal(c, crypto.Keccak256(input)) {
Expand Down