From 72f655d4217bf36c7d98e765e26842ffc0f68dff Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Wed, 3 Oct 2018 08:57:38 +0200 Subject: [PATCH] core/vm: save jumpdest analysis locally --- core/vm/contract.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/core/vm/contract.go b/core/vm/contract.go index ab654fd7ba..3537e62010 100644 --- a/core/vm/contract.go +++ b/core/vm/contract.go @@ -50,6 +50,7 @@ type Contract struct { self ContractRef jumpdests destinations // Aggregated result of JUMPDEST analysis. + analysis bitvec // Locally cached result of JUMPDEST analysis Code []byte CodeHash *common.Hash @@ -105,10 +106,14 @@ func (c *Contract) validJumpdest(dest *big.Int) bool { } return analysis.codeSegment(udest) } - //Don't have the hash, most likely a piece of initcode not already in state trie - analysis = codeBitmap(c.Code) - // Don't bother saving this - 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) + } + return c.analysis.codeSegment(udest) } // AsDelegate sets the contract to be a delegate call and returns the current