diff --git a/fuzzing/coverage/coverage_maps.go b/fuzzing/coverage/coverage_maps.go index 9841b975..60db6fa8 100644 --- a/fuzzing/coverage/coverage_maps.go +++ b/fuzzing/coverage/coverage_maps.go @@ -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 @@ -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 } diff --git a/fuzzing/coverage/coverage_tracer.go b/fuzzing/coverage/coverage_tracer.go index 5f4ac2a3..9f80db25 100644 --- a/fuzzing/coverage/coverage_tracer.go +++ b/fuzzing/coverage/coverage_tracer.go @@ -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. @@ -69,8 +72,9 @@ type coverageTracerCallFrameState struct { // NewCoverageTracer returns a new CoverageTracer. func NewCoverageTracer() *CoverageTracer { tracer := &CoverageTracer{ - coverageMaps: NewCoverageMaps(), - callFrameStates: make([]*coverageTracerCallFrameState, 0), + coverageMaps: NewCoverageMaps(), + gethCodeHashToCodeHash: make(map[common.Hash]*common.Hash), + callFrameStates: make([]*coverageTracerCallFrameState, 0), } nativeTracer := &tracers.Tracer{ Hooks: &tracing.Hooks{ @@ -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 } }