Skip to content

Commit

Permalink
first one didn't work, let's try this...
Browse files Browse the repository at this point in the history
  • Loading branch information
samalws-tob committed Sep 4, 2024
1 parent c4d807a commit 9689eec
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 7 additions & 1 deletion fuzzing/coverage/coverage_maps.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ type CoverageMaps struct {
// maps represents a structure used to track every ContractCoverageMap by a given deployed address/lookup hash.
maps map[common.Hash]map[common.Address]*ContractCoverageMap

// TODO comment this
// The assumption here is that geth codehash matches if and only if codehash matches
gethCodeHashToCodeHash map[common.Hash]*common.Hash

// TODO comment this
// The assumption here is that geth codehash matches if and only if codehash matches
cachedGethCodeHash common.Hash
Expand All @@ -40,7 +44,9 @@ type CoverageMaps struct {

// NewCoverageMaps initializes a new CoverageMaps object.
func NewCoverageMaps() *CoverageMaps {
maps := &CoverageMaps{}
maps := &CoverageMaps{
gethCodeHashToCodeHash: make(map[common.Hash]*common.Hash),
}
maps.Reset()
return maps
}
Expand Down
10 changes: 10 additions & 0 deletions fuzzing/coverage/coverage_tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ type CoverageTracer struct {

// nativeTracer is the underlying tracer used to capture EVM execution.
nativeTracer *chain.TestChainTracer

// TODO comment
gethCodeHashToCodeHash map[common.Hash]*common.Hash
}

// coverageTracerCallFrameState tracks state across call frames in the tracer.
Expand All @@ -70,6 +73,7 @@ type coverageTracerCallFrameState struct {
func NewCoverageTracer() *CoverageTracer {
tracer := &CoverageTracer{
coverageMaps: NewCoverageMaps(),
gethCodeHashToCodeHash: make(map[common.Hash]*common.Hash),
callFrameStates: make([]*coverageTracerCallFrameState, 0),
}
nativeTracer := &tracers.Tracer{
Expand Down Expand Up @@ -167,9 +171,15 @@ func (t *CoverageTracer) OnOpcode(pc uint64, op byte, gas, cost uint64, scope tr
if callFrameState.pendingCoverageMap.cachedGethCodeHash == gethCodeHash {
lookupHash := callFrameState.pendingCoverageMap.cachedCodeHash
callFrameState.lookupHash = &lookupHash
} else if t.gethCodeHashToCodeHash[gethCodeHash] != nil {
callFrameState.lookupHash = t.gethCodeHashToCodeHash[gethCodeHash]
} else if callFrameState.pendingCoverageMap.gethCodeHashToCodeHash[gethCodeHash] != nil {
callFrameState.lookupHash = t.gethCodeHashToCodeHash[gethCodeHash]
} else {
lookupHash := getContractCoverageMapHash(code, callFrameState.create)
callFrameState.lookupHash = &lookupHash
t.gethCodeHashToCodeHash[gethCodeHash] = &lookupHash
callFrameState.pendingCoverageMap.gethCodeHashToCodeHash[gethCodeHash] = &lookupHash
}
}

Expand Down

0 comments on commit 9689eec

Please sign in to comment.