Skip to content

Commit e868add

Browse files
authored
core/vm: improve jumpdest lookup (#21123)
1 parent 25a661e commit e868add

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

‎core/vm/contract.go‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,25 +92,28 @@ func (c *Contract) validJumpdest(dest *big.Int) bool {
9292
if OpCode(c.Code[udest]) != JUMPDEST {
9393
return false
9494
}
95-
// Do we have a contract hash already?
95+
// Do we have it locally already?
96+
if c.analysis != nil {
97+
return c.analysis.codeSegment(udest)
98+
}
99+
// If we have the code hash (but no analysis), we should look into the
100+
// parent analysis map and see if the analysis has been made previously
96101
if c.CodeHash != (common.Hash{}) {
97-
// Does parent context have the analysis?
98102
analysis, exist := c.jumpdests[c.CodeHash]
99103
if !exist {
100104
// Do the analysis and save in parent context
101-
// We do not need to store it in c.analysis
102105
analysis = codeBitmap(c.Code)
103106
c.jumpdests[c.CodeHash] = analysis
104107
}
108+
// Also stash it in current contract for faster access
109+
c.analysis = analysis
105110
return analysis.codeSegment(udest)
106111
}
107112
// We don't have the code hash, most likely a piece of initcode not already
108113
// in state trie. In that case, we do an analysis, and save it locally, so
109114
// we don't have to recalculate it for every JUMP instruction in the execution
110115
// However, we don't save it within the parent context
111-
if c.analysis == nil {
112-
c.analysis = codeBitmap(c.Code)
113-
}
116+
c.analysis = codeBitmap(c.Code)
114117
return c.analysis.codeSegment(udest)
115118
}
116119

0 commit comments

Comments
 (0)