From dd7d144745c8928a925763648e16cdca2b95ee48 Mon Sep 17 00:00:00 2001 From: rjl493456442 Date: Fri, 4 Jul 2025 18:17:44 +0800 Subject: [PATCH 1/9] cmd/utils: update flag description of gcmode (#32145) --- cmd/utils/flags.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 3be16da6a7..328069e0f6 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -261,7 +261,7 @@ var ( } GCModeFlag = &cli.StringFlag{ Name: "gcmode", - Usage: `Blockchain garbage collection mode, only relevant in state.scheme=hash ("full", "archive")`, + Usage: `Blockchain garbage collection mode ("full", "archive")`, Value: "full", Category: flags.StateCategory, } From 7088e87dce80d742c26d4d3864c1510cd2d9771c Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Fri, 4 Jul 2025 13:02:57 +0200 Subject: [PATCH 2/9] .gitea: add workflow_dispatch for release build --- .gitea/workflows/release.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index bce418faf9..99b371e0a6 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -4,6 +4,7 @@ on: - "master" tags: - "v*" + workflow_dispatch: jobs: linux-intel: From e225983a0688f2c80f68a16df9330acfc47f84b1 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Fri, 4 Jul 2025 12:42:01 +0200 Subject: [PATCH 3/9] .gitea: update PATH --- .gitea/workflows/release.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index 99b371e0a6..27a61d9da8 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -139,16 +139,16 @@ jobs: - name: "Build (amd64)" run: | - go run build/ci.go install -dlgo -arch amd64 -cc %GETH_CC% + go run build/ci.go install -dlgo -arch amd64 -cc $env:GETH_CC env: - PATH: 'C:\msys64\mingw64\bin;C:\Program Files (x86)\NSIS\;%PATH%' + PATH: 'C:\msys64\mingw64\bin;C:\Program Files (x86)\NSIS\;$env:PATH' GETH_CC: 'C:\msys64\mingw64\bin\gcc.exe' - name: "Build (386)" run: | - go run build/ci.go install -dlgo -arch 386 -cc %GETH_CC% + go run build/ci.go install -dlgo -arch 386 -cc $env:GETH_CC env: - PATH: 'C:\msys64\mingw32\bin;C:\Program Files (x86)\NSIS\;%PATH%' + PATH: 'C:\msys64\mingw32\bin;C:\Program Files (x86)\NSIS\;$env:PATH' GETH_CC: 'C:\msys64\mingw32\bin\gcc.exe' docker: From 3f4555abc65f115f3464cb00d2017d7f118cdb71 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Fri, 4 Jul 2025 13:25:40 +0200 Subject: [PATCH 4/9] .gitea: set PATH --- .gitea/workflows/release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index 27a61d9da8..0dfc6af972 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -139,16 +139,16 @@ jobs: - name: "Build (amd64)" run: | + $env:PATH = "C:\msys64\mingw64\bin;$env:PATH" go run build/ci.go install -dlgo -arch amd64 -cc $env:GETH_CC env: - PATH: 'C:\msys64\mingw64\bin;C:\Program Files (x86)\NSIS\;$env:PATH' GETH_CC: 'C:\msys64\mingw64\bin\gcc.exe' - name: "Build (386)" run: | + $env:PATH = "C:\msys64\mingw32\bin;$env:PATH" go run build/ci.go install -dlgo -arch 386 -cc $env:GETH_CC env: - PATH: 'C:\msys64\mingw32\bin;C:\Program Files (x86)\NSIS\;$env:PATH' GETH_CC: 'C:\msys64\mingw32\bin\gcc.exe' docker: From db1806efa28fcb31eb7dc66b12cd6f3be2cb1b1b Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Fri, 4 Jul 2025 13:38:26 +0200 Subject: [PATCH 5/9] gitea: try with cmd --- .gitea/workflows/release.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index 0dfc6af972..88ea3915f7 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -138,17 +138,19 @@ jobs: # contained in PATH. - name: "Build (amd64)" + shell: cmd run: | - $env:PATH = "C:\msys64\mingw64\bin;$env:PATH" - go run build/ci.go install -dlgo -arch amd64 -cc $env:GETH_CC + go run build/ci.go install -dlgo -arch amd64 -cc %GETH_CC% env: + PATH: 'C:\msys64\mingw64\bin;%PATH%' GETH_CC: 'C:\msys64\mingw64\bin\gcc.exe' - name: "Build (386)" + shell: cmd run: | - $env:PATH = "C:\msys64\mingw32\bin;$env:PATH" - go run build/ci.go install -dlgo -arch 386 -cc $env:GETH_CC + go run build/ci.go install -dlgo -arch 386 -cc %GETH_CC% env: + PATH: 'C:\msys64\mingw32\bin;%PATH%' GETH_CC: 'C:\msys64\mingw32\bin\gcc.exe' docker: From 9efe1c16e25b3f98bfec5a614153f68f8851e711 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Fri, 4 Jul 2025 13:42:55 +0200 Subject: [PATCH 6/9] gitea: set PATH in script --- .gitea/workflows/release.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index 88ea3915f7..664b059fb8 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -140,18 +140,18 @@ jobs: - name: "Build (amd64)" shell: cmd run: | - go run build/ci.go install -dlgo -arch amd64 -cc %GETH_CC% + set PATH=%GETH_MINGW%\bin;%PATH% + go run build/ci.go install -dlgo -arch am64 -cc %GETH_MINGW%\bin\gcc.exe env: - PATH: 'C:\msys64\mingw64\bin;%PATH%' - GETH_CC: 'C:\msys64\mingw64\bin\gcc.exe' + GETH_MINGW: 'C:\msys64\mingw64' - name: "Build (386)" shell: cmd run: | - go run build/ci.go install -dlgo -arch 386 -cc %GETH_CC% + set PATH=%GETH_MINGW%\bin;%PATH% + go run build/ci.go install -dlgo -arch 386 -cc %GETH_MINGW%\bin\gcc.exe env: - PATH: 'C:\msys64\mingw32\bin;%PATH%' - GETH_CC: 'C:\msys64\mingw32\bin\gcc.exe' + GETH_MINGW: 'C:\msys64\mingw32' docker: name: Docker Image From 063033834bb9101ae896c3a42f4f799f9e9f445e Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Fri, 4 Jul 2025 13:45:29 +0200 Subject: [PATCH 7/9] .gitea: fix typo in windows workflow --- .gitea/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index 664b059fb8..f2dcc3ae96 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -141,7 +141,7 @@ jobs: shell: cmd run: | set PATH=%GETH_MINGW%\bin;%PATH% - go run build/ci.go install -dlgo -arch am64 -cc %GETH_MINGW%\bin\gcc.exe + go run build/ci.go install -dlgo -arch amd64 -cc %GETH_MINGW%\bin\gcc.exe env: GETH_MINGW: 'C:\msys64\mingw64' From bdf47f4557bb39b35ac274d341bbf317dc8d858c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20Irmak?= Date: Mon, 7 Jul 2025 11:01:29 +0300 Subject: [PATCH 8/9] core/vm: move nil-check out of the interpreter loop (#32068) Moves the jumptable nil check our of the interpreter loop. Benchmarks show a 2-10% improvement. --- core/vm/interpreter.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/core/vm/interpreter.go b/core/vm/interpreter.go index d0e5967e6e..1321888512 100644 --- a/core/vm/interpreter.go +++ b/core/vm/interpreter.go @@ -181,10 +181,11 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) ( } var ( - op OpCode // current opcode - mem = NewMemory() // bound memory - stack = newstack() // local stack - callContext = &ScopeContext{ + op OpCode // current opcode + jumpTable *JumpTable = in.table + mem = NewMemory() // bound memory + stack = newstack() // local stack + callContext = &ScopeContext{ Memory: mem, Stack: stack, Contract: contract, @@ -227,6 +228,7 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) ( // explicit STOP, RETURN or SELFDESTRUCT is executed, an error occurred during // the execution of one of the operations or until the done flag is set by the // parent context. + _ = jumpTable[0] // nil-check the jumpTable out of the loop for { if debug { // Capture pre-execution values for tracing. @@ -247,7 +249,7 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) ( // Get the operation from the jump table and validate the stack to ensure there are // enough stack items available to perform the operation. op = contract.GetOp(pc) - operation := in.table[op] + operation := jumpTable[op] cost = operation.constantGas // For tracing // Validate stack if sLen := stack.len(); sLen < operation.minStack { From 90c6197d2f73579b3378dc846b485414b3b60cd4 Mon Sep 17 00:00:00 2001 From: Giulio rebuffo Date: Mon, 7 Jul 2025 11:19:33 +0200 Subject: [PATCH 9/9] core/vm: implement EIP-7939 - CLZ opcode (#31989) https://eips.ethereum.org/EIPS/eip-7939 --------- Co-authored-by: spencer-tb Co-authored-by: Felix Lange --- core/vm/eips.go | 17 +++++++++++++++ core/vm/instructions_test.go | 40 ++++++++++++++++++++++++++++++++++++ core/vm/interpreter.go | 2 ++ core/vm/jump_table.go | 7 +++++++ core/vm/jump_table_export.go | 2 +- core/vm/opcodes.go | 3 +++ 6 files changed, 70 insertions(+), 1 deletion(-) diff --git a/core/vm/eips.go b/core/vm/eips.go index 79fd24d13e..a69946de4d 100644 --- a/core/vm/eips.go +++ b/core/vm/eips.go @@ -41,6 +41,7 @@ var activators = map[int]func(*JumpTable){ 1153: enable1153, 4762: enable4762, 7702: enable7702, + 7939: enable7939, } // EnableEIP enables the given EIP on the config. @@ -293,6 +294,13 @@ func opBlobBaseFee(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) return nil, nil } +// opCLZ implements the CLZ opcode (count leading zero bytes) +func opCLZ(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) { + x := scope.Stack.peek() + x.SetUint64(256 - uint64(x.BitLen())) + return nil, nil +} + // enable4844 applies EIP-4844 (BLOBHASH opcode) func enable4844(jt *JumpTable) { jt[BLOBHASH] = &operation{ @@ -303,6 +311,15 @@ func enable4844(jt *JumpTable) { } } +func enable7939(jt *JumpTable) { + jt[CLZ] = &operation{ + execute: opCLZ, + constantGas: GasFastestStep, + minStack: minStack(1, 1), + maxStack: maxStack(1, 1), + } +} + // enable7516 applies EIP-7516 (BLOBBASEFEE opcode) func enable7516(jt *JumpTable) { jt[BLOBBASEFEE] = &operation{ diff --git a/core/vm/instructions_test.go b/core/vm/instructions_test.go index 0902d17c54..8a82de5d8b 100644 --- a/core/vm/instructions_test.go +++ b/core/vm/instructions_test.go @@ -972,3 +972,43 @@ func TestPush(t *testing.T) { } } } + +func TestOpCLZ(t *testing.T) { + evm := NewEVM(BlockContext{}, nil, params.TestChainConfig, Config{}) + + tests := []struct { + inputHex string + want uint64 // expected CLZ result + }{ + {"0x0", 256}, + {"0x1", 255}, + {"0x6ff", 245}, // 0x6ff = 0b11011111111 (11 bits), so 256-11 = 245 + {"0xffffffffff", 216}, // 40 bits, so 256-40 = 216 + {"0x4000000000000000000000000000000000000000000000000000000000000000", 1}, + {"0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 1}, + {"0x8000000000000000000000000000000000000000000000000000000000000000", 0}, + {"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 0}, + } + for _, tc := range tests { + // prepare a fresh stack and PC + stack := newstack() + pc := uint64(0) + + // parse input + val := new(uint256.Int) + if err := val.SetFromHex(tc.inputHex); err != nil { + t.Fatal("invalid hex uint256:", tc.inputHex) + } + + stack.push(val) + opCLZ(&pc, evm.interpreter, &ScopeContext{Stack: stack}) + + if gotLen := stack.len(); gotLen != 1 { + t.Fatalf("stack length = %d; want 1", gotLen) + } + result := stack.pop() + if got := result.Uint64(); got != tc.want { + t.Fatalf("clz(%q) = %d; want %d", tc.inputHex, got, tc.want) + } + } +} diff --git a/core/vm/interpreter.go b/core/vm/interpreter.go index 1321888512..34d19008da 100644 --- a/core/vm/interpreter.go +++ b/core/vm/interpreter.go @@ -106,6 +106,8 @@ func NewEVMInterpreter(evm *EVM) *EVMInterpreter { // If jump table was not initialised we set the default one. var table *JumpTable switch { + case evm.chainRules.IsOsaka: + table = &osakaInstructionSet case evm.chainRules.IsVerkle: // TODO replace with proper instruction set when fork is specified table = &verkleInstructionSet diff --git a/core/vm/jump_table.go b/core/vm/jump_table.go index 17ac738c98..22eed8754f 100644 --- a/core/vm/jump_table.go +++ b/core/vm/jump_table.go @@ -62,6 +62,7 @@ var ( cancunInstructionSet = newCancunInstructionSet() verkleInstructionSet = newVerkleInstructionSet() pragueInstructionSet = newPragueInstructionSet() + osakaInstructionSet = newOsakaInstructionSet() ) // JumpTable contains the EVM opcodes supported at a given fork. @@ -91,6 +92,12 @@ func newVerkleInstructionSet() JumpTable { return validate(instructionSet) } +func newOsakaInstructionSet() JumpTable { + instructionSet := newPragueInstructionSet() + enable7939(&instructionSet) // EIP-7939 (CLZ opcode) + return validate(instructionSet) +} + func newPragueInstructionSet() JumpTable { instructionSet := newCancunInstructionSet() enable7702(&instructionSet) // EIP-7702 Setcode transaction type diff --git a/core/vm/jump_table_export.go b/core/vm/jump_table_export.go index b8fa6049bb..89a2ebf6f4 100644 --- a/core/vm/jump_table_export.go +++ b/core/vm/jump_table_export.go @@ -29,7 +29,7 @@ func LookupInstructionSet(rules params.Rules) (JumpTable, error) { case rules.IsVerkle: return newCancunInstructionSet(), errors.New("verkle-fork not defined yet") case rules.IsOsaka: - return newPragueInstructionSet(), errors.New("osaka-fork not defined yet") + return newOsakaInstructionSet(), nil case rules.IsPrague: return newPragueInstructionSet(), nil case rules.IsCancun: diff --git a/core/vm/opcodes.go b/core/vm/opcodes.go index 0820b20fb1..9a32126a80 100644 --- a/core/vm/opcodes.go +++ b/core/vm/opcodes.go @@ -62,6 +62,7 @@ const ( SHL OpCode = 0x1b SHR OpCode = 0x1c SAR OpCode = 0x1d + CLZ OpCode = 0x1e ) // 0x20 range - crypto. @@ -282,6 +283,7 @@ var opCodeToString = [256]string{ SHL: "SHL", SHR: "SHR", SAR: "SAR", + CLZ: "CLZ", ADDMOD: "ADDMOD", MULMOD: "MULMOD", @@ -484,6 +486,7 @@ var stringToOp = map[string]OpCode{ "SHL": SHL, "SHR": SHR, "SAR": SAR, + "CLZ": CLZ, "ADDMOD": ADDMOD, "MULMOD": MULMOD, "KECCAK256": KECCAK256,