From 06ba0c9e1aa09e2510e3b84f91a7f09d09272cde Mon Sep 17 00:00:00 2001 From: itsdevbear Date: Fri, 12 Apr 2024 01:28:50 -0400 Subject: [PATCH 1/5] optimize-push --- core/vm/instructions.go | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/core/vm/instructions.go b/core/vm/instructions.go index 990bdbf925a..3c004c1733c 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -875,13 +875,12 @@ func makeLog(size int) executionFunc { func opPush1(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) { var ( codeLen = uint64(len(scope.Contract.Code)) - integer = new(uint256.Int) ) *pc += 1 if *pc < codeLen { - scope.Stack.push(integer.SetUint64(uint64(scope.Contract.Code[*pc]))) + scope.Stack.push(new(uint256.Int).SetUint64(uint64(scope.Contract.Code[*pc]))) } else { - scope.Stack.push(integer.Clear()) + scope.Stack.push(new(uint256.Int).Clear()) } return nil, nil } @@ -890,20 +889,14 @@ func opPush1(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]by func makePush(size uint64, pushByteSize int) executionFunc { return func(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) { codeLen := len(scope.Contract.Code) - - startMin := codeLen - if int(*pc+1) < startMin { - startMin = int(*pc + 1) - } - - endMin := codeLen - if startMin+pushByteSize < endMin { - endMin = startMin + pushByteSize - } - - integer := new(uint256.Int) - scope.Stack.push(integer.SetBytes(common.RightPadBytes( - scope.Contract.Code[startMin:endMin], pushByteSize))) + startMin := min(codeLen, int(*pc+1)) + endMin := min(startMin+pushByteSize, codeLen) + scope.Stack.push(new(uint256.Int).SetBytes( + common.RightPadBytes( + scope.Contract.Code[startMin:endMin], + pushByteSize, + )), + ) *pc += size return nil, nil From fc8c27a5cad263955d74e1946512d60e46fc327b Mon Sep 17 00:00:00 2001 From: itsdevbear Date: Fri, 12 Apr 2024 01:42:24 -0400 Subject: [PATCH 2/5] revert push1 change --- core/vm/instructions.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/core/vm/instructions.go b/core/vm/instructions.go index 3c004c1733c..7e7d92e2e38 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -875,12 +875,13 @@ func makeLog(size int) executionFunc { func opPush1(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) { var ( codeLen = uint64(len(scope.Contract.Code)) + integer = new(uint256.Int) ) *pc += 1 if *pc < codeLen { - scope.Stack.push(new(uint256.Int).SetUint64(uint64(scope.Contract.Code[*pc]))) + scope.Stack.push(integer.SetUint64(uint64(scope.Contract.Code[*pc]))) } else { - scope.Stack.push(new(uint256.Int).Clear()) + scope.Stack.push(integer.Clear()) } return nil, nil } @@ -888,9 +889,12 @@ func opPush1(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]by // make push instruction function func makePush(size uint64, pushByteSize int) executionFunc { return func(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) { - codeLen := len(scope.Contract.Code) - startMin := min(codeLen, int(*pc+1)) - endMin := min(startMin+pushByteSize, codeLen) + var ( + codeLen = len(scope.Contract.Code) + startMin = min(codeLen, int(*pc+1)) + endMin = min(startMin+pushByteSize, codeLen) + ) + scope.Stack.push(new(uint256.Int).SetBytes( common.RightPadBytes( scope.Contract.Code[startMin:endMin], From 5b48bdd72b8c604d12c1f90bc24ad50abacbe046 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Mon, 15 Apr 2024 14:57:36 +0200 Subject: [PATCH 3/5] Update instructions.go --- core/vm/instructions.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/core/vm/instructions.go b/core/vm/instructions.go index 7e7d92e2e38..0729d3a7f73 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -891,17 +891,15 @@ func makePush(size uint64, pushByteSize int) executionFunc { return func(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) { var ( codeLen = len(scope.Contract.Code) - startMin = min(codeLen, int(*pc+1)) - endMin = min(startMin+pushByteSize, codeLen) + start = min(codeLen, int(*pc+1)) + end = min(start+pushByteSize, codeLen) ) - scope.Stack.push(new(uint256.Int).SetBytes( common.RightPadBytes( - scope.Contract.Code[startMin:endMin], + scope.Contract.Code[start:end], pushByteSize, )), ) - *pc += size return nil, nil } From 7e2b22ec98238302e59524fba28ca6e5d2101fed Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Tue, 16 Apr 2024 12:13:33 +0200 Subject: [PATCH 4/5] core/vm: go format --- core/vm/instructions.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/vm/instructions.go b/core/vm/instructions.go index 0729d3a7f73..9321bada261 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -890,9 +890,9 @@ func opPush1(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]by func makePush(size uint64, pushByteSize int) executionFunc { return func(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) { var ( - codeLen = len(scope.Contract.Code) - start = min(codeLen, int(*pc+1)) - end = min(start+pushByteSize, codeLen) + codeLen = len(scope.Contract.Code) + start = min(codeLen, int(*pc+1)) + end = min(start+pushByteSize, codeLen) ) scope.Stack.push(new(uint256.Int).SetBytes( common.RightPadBytes( From ab95fd2354ff61f53eed8858530bf42002c692a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Tue, 16 Apr 2024 15:56:45 +0300 Subject: [PATCH 5/5] core/vm: fix nit --- core/vm/instructions.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/vm/instructions.go b/core/vm/instructions.go index 9321bada261..a062bb15ff5 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -892,7 +892,7 @@ func makePush(size uint64, pushByteSize int) executionFunc { var ( codeLen = len(scope.Contract.Code) start = min(codeLen, int(*pc+1)) - end = min(start+pushByteSize, codeLen) + end = min(codeLen, start+pushByteSize) ) scope.Stack.push(new(uint256.Int).SetBytes( common.RightPadBytes(