From bd75618e15cfccab4c83da8633d5e123f31266a6 Mon Sep 17 00:00:00 2001 From: hexoscott <70711990+hexoscott@users.noreply.github.com> Date: Fri, 23 Aug 2024 13:04:49 +0100 Subject: [PATCH] Zkevm allow jumpdest in push n (#1011) * fix jumpn * hack * add docs --------- Co-authored-by: Igor Mandrigin --- core/vm/common.go | 8 ++++++++ core/vm/contract.go | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/core/vm/common.go b/core/vm/common.go index 46009cd3ffb..bc007dbf593 100644 --- a/core/vm/common.go +++ b/core/vm/common.go @@ -67,6 +67,14 @@ func getData(data []byte, start uint64, size uint64) []byte { // getDataBig returns a slice from the data based on the start and size and pads // up to size with zero's. This function is overflow safe. func getDataBig(data []byte, start *uint256.Int, size uint64) []byte { + /* + * zkEVM hack: we need to limit the size of the memory to 1GB + * for witness generation purpose we execute opcodes even if they are out of gas. + * that could lead to a huge memory allocation (in the reported case 400GB) + */ + if size >= 1*1024*1024*1024 { + size = 1 * 1024 * 1024 * 1024 + } start64, overflow := start.Uint64WithOverflow() if overflow { start64 = ^uint64(0) diff --git a/core/vm/contract.go b/core/vm/contract.go index e69d0b547de..a68887ef18d 100644 --- a/core/vm/contract.go +++ b/core/vm/contract.go @@ -102,7 +102,10 @@ func (c *Contract) validJumpdest(dest *uint256.Int) (bool, bool) { if c.skipAnalysis { return true, false } - return c.isCode(udest), true + /* + * zkEVM doesn't do dynamic jumpdest analysis. So PUSHN is not considered. + */ + return true, false } func isCodeFromAnalysis(analysis []uint64, udest uint64) bool {