Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/evm/opcode_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/evm/opcode_handlers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Comment on lines +48 to +49
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is specifically intended to prevent cross-thread races by moving execution context into TLS, but there doesn’t appear to be any regression test covering concurrent interpreter execution. Please add a unit/integration test that runs two interpreters in parallel threads with different frames/contexts and asserts opcode execution reads the correct per-thread context (i.e., no cross-contamination).

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bug occured in inner multithread test frame.


static void setExecutionContext(EVMFrame *Frame,
InterpreterExecContext *Context) {
Expand Down Expand Up @@ -211,7 +211,7 @@ DEFINE_BINARY_OP(Sgt, intx::slt(B, A));
#define DEFINE_MULTIOPCODE_UNIMPLEMENT_HANDLER(OpName) \
class OpName##Handler : public EVMOpcodeHandlerBase<OpName##Handler> { \
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(); \
Expand Down
Loading