Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core/vm: improve jumpdest lookup #21123

Merged
merged 1 commit into from
May 25, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions core/vm/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,25 +92,28 @@ func (c *Contract) validJumpdest(dest *big.Int) bool {
if OpCode(c.Code[udest]) != JUMPDEST {
return false
}
// Do we have a contract hash already?
// Do we have it locally already?
if c.analysis != nil {
return c.analysis.codeSegment(udest)
}
// If we have the code hash (but no analysis), we should look into the
// parent analysis map and see if the analysis has been made previously
if c.CodeHash != (common.Hash{}) {
// Does parent context have the analysis?
analysis, exist := c.jumpdests[c.CodeHash]
if !exist {
// Do the analysis and save in parent context
// We do not need to store it in c.analysis
analysis = codeBitmap(c.Code)
c.jumpdests[c.CodeHash] = analysis
}
// Also stash it in current contract for faster access
c.analysis = analysis
return analysis.codeSegment(udest)
}
// We don't have the code hash, most likely a piece of initcode not already
// in state trie. In that case, we do an analysis, and save it locally, so
// we don't have to recalculate it for every JUMP instruction in the execution
// However, we don't save it within the parent context
if c.analysis == nil {
c.analysis = codeBitmap(c.Code)
}
c.analysis = codeBitmap(c.Code)
return c.analysis.codeSegment(udest)
}

Expand Down