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

Improve span batch limit tests #10916

Closed
sebastianst opened this issue May 7, 2024 · 1 comment
Closed

Improve span batch limit tests #10916

sebastianst opened this issue May 7, 2024 · 1 comment
Labels
T-protocol Team: changes to node components (op-node, op-reth, etc.) implemented by go/rust/etc. devs

Comments

@sebastianst
Copy link
Member

If we add MaxSpanBatchElementCount to the chain spec, we can test the sad-path span batch decoding code better with black-box tests. Where we consume the spec, we would consume an interface of the value getters that we need to set low limits during tests.

Following tests should be improved:

func TestSpanBatchTxsMaxContractCreationBitsLength(t *testing.T) {
var sbt spanBatchTxs
sbt.totalBlockTxCount = 0xFFFFFFFFFFFFFFFF
r := bytes.NewReader([]byte{})
err := sbt.decodeContractCreationBits(r)
require.ErrorIs(t, err, ErrTooBigSpanBatchSize)
}
func TestSpanBatchTxsMaxYParityBitsLength(t *testing.T) {
var sb RawSpanBatch
sb.blockCount = 0xFFFFFFFFFFFFFFFF
r := bytes.NewReader([]byte{})
err := sb.decodeOriginBits(r)
require.ErrorIs(t, err, ErrTooBigSpanBatchSize)
}
func TestSpanBatchTxsMaxProtectedBitsLength(t *testing.T) {
var sb RawSpanBatch
sb.txs = &spanBatchTxs{}
sb.txs.totalLegacyTxCount = 0xFFFFFFFFFFFFFFFF
r := bytes.NewReader([]byte{})
err := sb.txs.decodeProtectedBits(r)
require.ErrorIs(t, err, ErrTooBigSpanBatchSize)
}

func TestSpanBatchMaxTxData(t *testing.T) {
rng := rand.New(rand.NewSource(0x177288))
invalidTx := types.NewTx(&types.DynamicFeeTx{
Data: testutils.RandomData(rng, MaxSpanBatchElementCount+1),
})
txEncoded, err := invalidTx.MarshalBinary()
require.NoError(t, err)
r := bytes.NewReader(txEncoded)
_, _, err = ReadTxData(r)
require.ErrorIs(t, err, ErrTooBigSpanBatchSize)
}
func TestSpanBatchMaxOriginBitsLength(t *testing.T) {
var sb RawSpanBatch
sb.blockCount = math.MaxUint64
r := bytes.NewReader([]byte{})
err := sb.decodeOriginBits(r)
require.ErrorIs(t, err, ErrTooBigSpanBatchSize)
}
func TestSpanBatchMaxBlockCount(t *testing.T) {
rng := rand.New(rand.NewSource(0x77556691))
chainID := big.NewInt(rng.Int63n(1000))
rawSpanBatch := RandomRawSpanBatch(rng, chainID)
rawSpanBatch.blockCount = math.MaxUint64
var buf bytes.Buffer
err := rawSpanBatch.encodeBlockCount(&buf)
require.NoError(t, err)
result := buf.Bytes()
r := bytes.NewReader(result)
var sb RawSpanBatch
err = sb.decodeBlockCount(r)
require.ErrorIs(t, err, ErrTooBigSpanBatchSize)
}
func TestSpanBatchMaxBlockTxCount(t *testing.T) {
rng := rand.New(rand.NewSource(0x77556692))
chainID := big.NewInt(rng.Int63n(1000))
rawSpanBatch := RandomRawSpanBatch(rng, chainID)
rawSpanBatch.blockTxCounts[0] = math.MaxUint64
var buf bytes.Buffer
err := rawSpanBatch.encodeBlockTxCounts(&buf)
require.NoError(t, err)
result := buf.Bytes()
r := bytes.NewReader(result)
var sb RawSpanBatch
sb.blockCount = rawSpanBatch.blockCount
err = sb.decodeBlockTxCounts(r)
require.ErrorIs(t, err, ErrTooBigSpanBatchSize)
}
func TestSpanBatchTotalBlockTxCountNotOverflow(t *testing.T) {
rng := rand.New(rand.NewSource(0x77556693))
chainID := big.NewInt(rng.Int63n(1000))
rawSpanBatch := RandomRawSpanBatch(rng, chainID)
rawSpanBatch.blockTxCounts[0] = MaxSpanBatchElementCount - 1
rawSpanBatch.blockTxCounts[1] = MaxSpanBatchElementCount - 1
// we are sure that totalBlockTxCount will overflow on uint64
var buf bytes.Buffer
err := rawSpanBatch.encodeBlockTxCounts(&buf)
require.NoError(t, err)
result := buf.Bytes()
r := bytes.NewReader(result)
var sb RawSpanBatch
sb.blockTxCounts = rawSpanBatch.blockTxCounts
err = sb.decodeTxs(r)
require.ErrorIs(t, err, ErrTooBigSpanBatchSize)
}

  • make them more black-box, by creating span batches with a mocked spec that allows higher number of elements, then lower the limits and test all paths that should return ErrTooBigSpanBatchSize

Source comment @sebastianst in #10357 (comment)

@BlocksOnAChain BlocksOnAChain transferred this issue from another repository Jun 18, 2024
@BlocksOnAChain BlocksOnAChain transferred this issue from ethereum-optimism/Node-temp_repo-for-public-issue-migration Jun 18, 2024
@BlocksOnAChain BlocksOnAChain added the T-protocol Team: changes to node components (op-node, op-reth, etc.) implemented by go/rust/etc. devs label Jun 21, 2024
@BlocksOnAChain
Copy link

@sebastianst ok to close, since it's looking stale?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-protocol Team: changes to node components (op-node, op-reth, etc.) implemented by go/rust/etc. devs
Projects
None yet
Development

No branches or pull requests

2 participants