Commit 4dd44c5a authored by clabby's avatar clabby

Add random bytes `GarbageKind`; Remove `MALFORM_RLP` & `INVALID_COMPRESSION` are WIP

parent 6b34dedd
...@@ -4,9 +4,9 @@ import ( ...@@ -4,9 +4,9 @@ import (
"bytes" "bytes"
"context" "context"
"crypto/ecdsa" "crypto/ecdsa"
"encoding/hex"
"io" "io"
"math/big" "math/big"
"math/rand"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
...@@ -14,7 +14,6 @@ import ( ...@@ -14,7 +14,6 @@ import (
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/ethereum-optimism/optimism/op-node/eth" "github.com/ethereum-optimism/optimism/op-node/eth"
...@@ -202,14 +201,18 @@ type GarbageKind int64 ...@@ -202,14 +201,18 @@ type GarbageKind int64
const ( const (
STRIP_VERSION GarbageKind = iota STRIP_VERSION GarbageKind = iota
RANDOM
MALFORM_RLP MALFORM_RLP
INVALID_COMPRESSION
TRUNCATE_END TRUNCATE_END
DIRTY_APPEND DIRTY_APPEND
) )
var GarbageKinds = []GarbageKind{ var GarbageKinds = []GarbageKind{
STRIP_VERSION, STRIP_VERSION,
RANDOM,
// MALFORM_RLP, // MALFORM_RLP,
// INVALID_COMPRESSION,
TRUNCATE_END, TRUNCATE_END,
DIRTY_APPEND, DIRTY_APPEND,
} }
...@@ -226,6 +229,7 @@ func (s *L2Batcher) ActL2BatchSubmitGarbage(t Testing, kind GarbageKind) { ...@@ -226,6 +229,7 @@ func (s *L2Batcher) ActL2BatchSubmitGarbage(t Testing, kind GarbageKind) {
// Collect the output frame // Collect the output frame
data := new(bytes.Buffer) data := new(bytes.Buffer)
data.WriteByte(derive.DerivationVersion0) data.WriteByte(derive.DerivationVersion0)
// subtract one, to account for the version byte // subtract one, to account for the version byte
if err := s.l2ChannelOut.OutputFrame(data, s.l2BatcherCfg.MaxL1TxSize-1); err == io.EOF { if err := s.l2ChannelOut.OutputFrame(data, s.l2BatcherCfg.MaxL1TxSize-1); err == io.EOF {
s.l2ChannelOut = nil s.l2ChannelOut = nil
...@@ -242,9 +246,12 @@ func (s *L2Batcher) ActL2BatchSubmitGarbage(t Testing, kind GarbageKind) { ...@@ -242,9 +246,12 @@ func (s *L2Batcher) ActL2BatchSubmitGarbage(t Testing, kind GarbageKind) {
// Strip the derivation version byte from the output frame // Strip the derivation version byte from the output frame
case STRIP_VERSION: case STRIP_VERSION:
outputFrame = outputFrame[1:] outputFrame = outputFrame[1:]
case MALFORM_RLP: // Replace the output frame with random bytes of length [1, 512]
// WIP case RANDOM:
t.Log("output frame", hex.EncodeToString(outputFrame), rlp.Decode(bytes.NewReader(outputFrame[1:len(outputFrame)-47]), &derive.BatchData{})) buf := make([]byte, rand.Intn(512)+1)
_, err := rand.Read(buf)
require.NoError(t, err, "error generating random bytes")
outputFrame = buf
// Remove 4 bytes from the tail end of the output frame // Remove 4 bytes from the tail end of the output frame
case TRUNCATE_END: case TRUNCATE_END:
outputFrame = outputFrame[:len(outputFrame)-4] outputFrame = outputFrame[:len(outputFrame)-4]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment