Skip to content

Commit

Permalink
Ignore Blob errors, sort returned methods list in Get4ByteMethodSigna…
Browse files Browse the repository at this point in the history
…tures precompile
  • Loading branch information
anodar committed Feb 27, 2024
1 parent 58e4b50 commit ee599c2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
9 changes: 7 additions & 2 deletions arbstate/inbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ const maxZeroheavyDecompressedLen = 101*MaxDecompressedLen/100 + 64
const MaxSegmentsPerSequencerMessage = 100 * 1024
const MinLifetimeSecondsForDataAvailabilityCert = 7 * 24 * 60 * 60 // one week

var (
ErrNoBlobReader = errors.New("blob batch payload was encountered but no BlobReader was configured")
ErrInvalidBlobDataFormat = errors.New("blob batch data is not a list of hashes as expected")
)

func parseSequencerMessage(ctx context.Context, batchNum uint64, batchBlockHash common.Hash, data []byte, daProviders []DataAvailabilityProvider, keysetValidationMode KeysetValidationMode) (*sequencerMessage, error) {
if len(data) < 40 {
return nil, errors.New("sequencer message missing L1 header")
Expand Down Expand Up @@ -110,7 +115,7 @@ func parseSequencerMessage(ctx context.Context, batchNum uint64, batchBlockHash
if IsDASMessageHeaderByte(payload[0]) {
log.Error("No DAS Reader configured, but sequencer message found with DAS header")
} else if IsBlobHashesHeaderByte(payload[0]) {
return nil, errors.New("blob batch payload was encountered but no BlobReader was configured")
return nil, ErrNoBlobReader
}
}
}
Expand Down Expand Up @@ -341,7 +346,7 @@ func (b *dAProviderForBlobReader) RecoverPayloadFromBatch(
) ([]byte, error) {
blobHashes := sequencerMsg[41:]
if len(blobHashes)%len(common.Hash{}) != 0 {
return nil, fmt.Errorf("blob batch data is not a list of hashes as expected")
return nil, ErrInvalidBlobDataFormat
}
versionedHashes := make([]common.Hash, len(blobHashes)/len(common.Hash{}))
for i := 0; i*32 < len(blobHashes); i += 1 {
Expand Down
5 changes: 5 additions & 0 deletions precompiles/precompile.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
package precompiles

import (
"bytes"
"errors"
"fmt"
"math/big"
"reflect"
"sort"
"strconv"
"strings"
"unicode"
Expand Down Expand Up @@ -783,6 +785,9 @@ func (p *Precompile) Get4ByteMethodSignatures() [][4]byte {
for sig := range p.methods {
ret = append(ret, sig)
}
sort.Slice(ret, func(i, j int) bool {
return bytes.Compare(ret[i][:], ret[j][:]) < 0
})
return ret
}

Expand Down
16 changes: 15 additions & 1 deletion system_tests/state_fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,20 @@ func (c noopChainContext) GetHeader(common.Hash, uint64) *types.Header {
return nil
}

var ignoreErrors = []error{
arbstate.ErrNoBlobReader,
arbstate.ErrInvalidBlobDataFormat,
}

func shouldIgnore(err error) bool {
for _, e := range ignoreErrors {
if errors.Is(err, e) {
return true
}
}
return false
}

func FuzzStateTransition(f *testing.F) {
f.Fuzz(func(t *testing.T, compressSeqMsg bool, seqMsg []byte, delayedMsg []byte) {
chainDb := rawdb.NewMemoryDatabase()
Expand Down Expand Up @@ -189,7 +203,7 @@ func FuzzStateTransition(f *testing.F) {
delayedMessages: delayedMessages,
}
_, err = BuildBlock(statedb, genesis, noopChainContext{}, params.ArbitrumOneChainConfig(), inbox, seqBatch)
if err != nil {
if err != nil && !shouldIgnore(err) {
// With the fixed header it shouldn't be possible to read a delayed message,
// and no other type of error should be possible.
panic(err)
Expand Down

0 comments on commit ee599c2

Please sign in to comment.