Skip to content

Commit

Permalink
Test inlined map slabs are not in storage
Browse files Browse the repository at this point in the history
  • Loading branch information
fxamacker committed Sep 24, 2023
1 parent efcb2a2 commit 5af0bc4
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions map_debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,6 @@ func ValidMap(m *OrderedMap, address Address, typeInfo TypeInfo, tic TypeInfoCom
return NewFatalError(fmt.Errorf("map address %v, got %v", address, m.Address()))
}

if address != m.root.Header().slabID.address {
return NewFatalError(fmt.Errorf("map root slab address %v, got %v", address, m.root.Header().slabID.address))
}

// Verify map value ID
err := validMapValueID(m)
if err != nil {
Expand Down Expand Up @@ -370,6 +366,23 @@ func (v *mapVerifier) verifyMapSlab(

id := slab.Header().slabID

// Verify slab address (independent of map inlined status)
if v.address != id.address {
return 0, nil, nil, nil, NewFatalError(fmt.Errorf("map slab address %v, got %v", v.address, id.address))
}

// Verify that inlined slab is not in storage
if slab.Inlined() {
_, exist, err := v.storage.Retrieve(id)
if err != nil {
// Wrap err as external error (if needed) because err is returned by Storage interface.
return 0, nil, nil, nil, wrapErrorAsExternalErrorIfNeeded(err)
}
if exist {
return 0, nil, nil, nil, NewFatalError(fmt.Errorf("inlined slab %s is in storage", id))
}
}

if level > 0 {
// Verify that non-root slab doesn't have extra data.
if slab.ExtraData() != nil {
Expand Down

0 comments on commit 5af0bc4

Please sign in to comment.