From add797eae6e7e09a478d5473a89ba25b1e5b49d3 Mon Sep 17 00:00:00 2001 From: cmgCr Date: Sat, 28 Feb 2026 06:43:10 +0000 Subject: [PATCH 1/2] fix(evm): make EVMResource execution context thread-local to prevent data race --- src/evm/opcode_handlers.cpp | 6 +++--- src/evm/opcode_handlers.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/evm/opcode_handlers.cpp b/src/evm/opcode_handlers.cpp index f557804c..86e12221 100644 --- a/src/evm/opcode_handlers.cpp +++ b/src/evm/opcode_handlers.cpp @@ -10,9 +10,9 @@ #include "host/evm/crypto.h" #include "runtime/evm_instance.h" -zen::evm::EVMFrame *zen::evm::EVMResource::CurrentFrame = nullptr; -zen::evm::InterpreterExecContext *zen::evm::EVMResource::CurrentContext = - nullptr; +thread_local zen::evm::EVMFrame *zen::evm::EVMResource::CurrentFrame = nullptr; +thread_local zen::evm::InterpreterExecContext + *zen::evm::EVMResource::CurrentContext = nullptr; using namespace zen; using namespace zen::evm; diff --git a/src/evm/opcode_handlers.h b/src/evm/opcode_handlers.h index 8886ceac..57014238 100644 --- a/src/evm/opcode_handlers.h +++ b/src/evm/opcode_handlers.h @@ -45,8 +45,8 @@ namespace zen::evm { class EVMResource { public: - static EVMFrame *CurrentFrame; - static InterpreterExecContext *CurrentContext; + static thread_local EVMFrame *CurrentFrame; + static thread_local InterpreterExecContext *CurrentContext; static void setExecutionContext(EVMFrame *Frame, InterpreterExecContext *Context) { From b47273005db93b5780060bad12558913495bf161 Mon Sep 17 00:00:00 2001 From: cmgCr Date: Sat, 28 Feb 2026 18:51:01 +0800 Subject: [PATCH 2/2] fix(evm): make Call/Create/Log OpCode thread_local to prevent data race --- src/evm/opcode_handlers.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/evm/opcode_handlers.h b/src/evm/opcode_handlers.h index 57014238..0287893a 100644 --- a/src/evm/opcode_handlers.h +++ b/src/evm/opcode_handlers.h @@ -211,7 +211,7 @@ DEFINE_BINARY_OP(Sgt, intx::slt(B, A)); #define DEFINE_MULTIOPCODE_UNIMPLEMENT_HANDLER(OpName) \ class OpName##Handler : public EVMOpcodeHandlerBase { \ public: \ - inline static evmc_opcode OpCode = OP_INVALID; \ + inline static thread_local evmc_opcode OpCode = OP_INVALID; \ static EVMFrame *getFrame() { return EVMResource::getCurFrame(); } \ static InterpreterExecContext *getContext() { \ return EVMResource::getInterpreterExecContext(); \