Skip to content

Commit 0a7efe1

Browse files
authored
fix: proper number of chunk evals (#215)
1 parent e8ace55 commit 0a7efe1

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

core/vm/interpreter.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/ethereum/go-ethereum/log"
2424
"github.com/ethereum/go-ethereum/trie"
2525
"github.com/ethereum/go-ethereum/trie/utils"
26+
"github.com/gballet/go-verkle"
2627
"github.com/holiman/uint256"
2728
)
2829

@@ -177,15 +178,15 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
177178
if in.evm.ChainConfig().IsCancun(in.evm.Context.BlockNumber) && !contract.IsDeployment {
178179
contract.Chunks = trie.ChunkifyCode(contract.Code)
179180

180-
totalEvals := len(contract.Code) / 31 / 256
181-
if len(contract.Code)%(256*31) != 0 {
182-
totalEvals += 1
183-
}
181+
// number of extra stems to evaluate after the header stem
182+
extraEvals := (len(contract.Chunks) + 127) / verkle.NodeWidth
184183

185-
chunkEvals = make([][]byte, totalEvals)
186-
for i := 0; i < totalEvals; i++ {
184+
chunkEvals = make([][]byte, extraEvals+1)
185+
for i := 1; i < extraEvals+1; i++ {
187186
chunkEvals[i] = utils.GetTreeKeyCodeChunkWithEvaluatedAddress(contract.AddressPoint(), uint256.NewInt(uint64(i)*256))
188187
}
188+
// Header account is already known, it's the header account
189+
chunkEvals[0] = utils.GetTreeKeyVersionWithEvaluatedAddress(contract.AddressPoint())
189190
}
190191

191192
// The Interpreter main run loop (contextual). This loop runs until either an

0 commit comments

Comments
 (0)