Skip to content

[execution/vm] Add in-tree monad_message type - #2540

Open
khordadi wants to merge 1 commit into
mainfrom
akhordadi/exe-172-port-evmc_message-and-evmc_call_kind-to-in-tree-monad-types
Open

khordadi wants to merge 1 commit into
mainfrom
akhordadi/exe-172-port-evmc_message-and-evmc_call_kind-to-in-tree-monad-types

Conversation

@khordadi

@khordadi khordadi commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Part of EXE-172 (EXE-162), reduced to the type. monad_message, with monad_call_kind and monad_call_flags, mirrors the fork's evmc_message; message.cpp asserts layout, field offsets, field types and enumerator values. Purely additive, nothing references the type yet.

The call-site migration (formerly commit 2 here) moves into the vm::Host port, EXE-173. With the vtable slot and the runtime on monad_message there is no per-call evmc_message conversion, which the adapter in EvmcHost::call needed (one out-of-line call and a 192-byte copy per nested call).

Verification. gcc-15 RelWithDebInfo build clean; clang-format-19 and clang-tidy-19 on the new files clean. message.cpp includes <evmc/evmc.h> exactly as revision.cpp and status_code.cpp already do, so the zkVM guest sees nothing new.

Conflicts trivially with #2539 on category/vm/evm/CMakeLists.txt; whichever lands first, the other rebases.

🤖 Generated with Claude Code

Copilot AI lite review requested due to automatic review settings September 5, 2026 01:48

@khordadi khordadi left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Notes for the reviewer on the non-obvious lines.

};

// Mirrors evmc_flags 1:1; values asserted equal in message.cpp.
enum monad_call_flags

@khordadi khordadi Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not in the issue title, but without it every reader of flags still needs evmc.h.

monad::Address code_address;
uint8_t *memory_handle;
uint8_t *memory;
uint32_t memory_capacity;

@khordadi khordadi Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fork layout: evmc 663a1c2 dropped code/code_size, 8533622 added the memory-pool fields. A mirror of upstream evmc_message fails the asserts in message.cpp.

static_assert(sizeof(monad_message) == sizeof(evmc_message));
static_assert(alignof(monad_message) == alignof(evmc_message));

#define MONAD_ASSERT_MESSAGE_FIELD_EQ(field) \

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Offsets only: sizeof on the pointer members trips bugprone-sizeof-expression. The type asserts below cover the narrowed-field case that offsets alone would miss.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

It changes core VM/execution message plumbing across many call sites and relies on layout-dependent bit_cast adapters, warranting final human verification.

Pull request overview

This PR continues the execution/vm “evmc leaf types” migration by introducing an in-tree monad_message (plus monad_call_kind / monad_call_flags) and switching the execution layer + VM entry points to use it, keeping EVMC types only at the ABI seams via std::bit_cast adapters with compile-time layout verification.

Changes:

  • Add category/vm/evm/message.{hpp,cpp} defining monad_message and to_evmc_message / from_evmc_message, with static assertions for enum values and struct layout.
  • Replace evmc_message with monad_message in VM APIs (VM::execute, VM::execute_bytecode) and in execution-layer message plumbing (precompiles, execute_{message,transaction}, tracing).
  • Update tests, fuzzing, and benchmarking tooling to construct and pass monad_message, bridging back to EVMC only where required.

Verdict: CORRECT

Generated with Claude Code

File summaries
File Description
category/vm/evm/message.hpp Introduces monad_message + call kind/flags mirrors and conversion function declarations.
category/vm/evm/message.cpp Proves enum/value + layout equivalence vs evmc_message and implements bit_cast conversions.
category/vm/evm/CMakeLists.txt Adds the new message mirror sources to the EVM VM target.
category/vm/vm.hpp Updates VM public template entrypoints to accept monad_message.
category/vm/vm.cpp Adapts execute-override path to convert monad_message to evmc_message for the EVMC ABI hook.
category/vm/runtime/types.hpp Changes runtime::Context::from to accept monad_message.
category/vm/runtime/context.cpp Wires monad_message fields into runtime context construction.
category/vm/fuzzing/generator/generator.hpp Switches fuzz-message generation and flags/kind selection to monad_message types.
category/execution/ethereum/execute_transaction.hpp Updates transaction→message construction to return monad_message.
category/execution/ethereum/execute_transaction.cpp Replaces message kinds/flags and value encoding to populate monad_message.
category/execution/ethereum/execute_message.hpp Updates execute_{call,create}_message signatures to take monad_message.
category/execution/ethereum/execute_message.cpp Ports runtime message handling logic from evmc_message to monad_message.
category/execution/ethereum/precompiles.hpp Ports precompile checks to monad_message.
category/execution/ethereum/precompiles.cpp Updates flag checks (delegated/static) and signatures to monad_message.
category/execution/ethereum/evmc_host.hpp Adds call(monad_message const&) and makes the EVMC vtable slot an adapter.
category/execution/ethereum/trace/call_tracer.hpp Updates tracer interface on_enter to accept monad_message.
category/execution/ethereum/trace/call_tracer.cpp Ports call-kind handling to MONAD_* enumerators.
category/execution/ethereum/trace/call_frame.cpp Ports static-call flag checks to MONAD_STATIC.
category/execution/ethereum/process_requests.cpp Constructs system-call messages as monad_message.
category/execution/ethereum/block_hash_history_test.cpp Updates test message construction to monad_message.
category/execution/ethereum/trace/state_tracer_test.cpp Updates message construction to monad_message for tracing tests.
category/execution/ethereum/test/test_call_trace.cpp Updates trace test message type to monad_message.
category/execution/ethereum/precompiles_test.cpp Updates precompile tests to use monad_message.
category/execution/ethereum/execute_message_test.cpp Updates execution tests to use monad_message and bytes32_t values directly.
category/execution/monad/monad_precompiles.hpp Ports Monad precompile entrypoint to accept monad_message.
category/execution/monad/monad_precompiles.cpp Ports kind checks to MONAD_CALL and signature to monad_message.
category/execution/monad/execute_system_transaction.hpp Changes system-tx to_message() to return monad_message.
category/execution/monad/execute_system_transaction.cpp Constructs monad_message for system tx execution and encodes value into bytes32_t.
category/execution/monad/reserve_balance/reserve_balance_contract_test.cpp Updates reserve-balance tests and helper signatures to monad_message.
cmd/vm/mce/src/instrumentable_vm.hpp Switches microbenchmark message allocation and kinds to monad_message.
test/vm/utils/test_message.hpp Updates TestMessage helper to store a monad_message.
test/vm/vm/test_vm.cpp Adapts EVMC ABI BlockchainTestVM::execute to convert EVMC→Monad message before Context::from.
test/vm/unit/runtime/memory_tests.cpp Uses monad_message in runtime memory unit tests.
test/vm/unit/monad_vm_interface_tests.cpp Updates host mock plumbing and test lambdas to accept monad_message.
test/vm/unit/evm_fixture.hpp Keeps EVMC ABI boundary by converting monad_message back to evmc_message for evmone.
test/vm/fuzzer/fuzzer.cpp Ports fuzz transition helpers to accept monad_message.
Review details
  • Files reviewed: 36/36 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread category/vm/evm/message.hpp Outdated

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed per REVIEW.md: traits usage, FFI/ABI boundaries, C++ correctness (lifetimes, bit_cast legality, overload/name-hiding, temporary binding at every conversion seam), testing, style, and hygiene.

What I verified:

  • Layout proof is sound. message.cpp pins size (I independently recomputed the 192-byte layout: 4+4+4+pad+8+20+20+8+8+32+32+20+pad+8+8+4+pad = 192), alignment, all 14 field offsets, exact types of the 8 integer/pointer fields, and the enumerator values. Combined with is_standard_layout / is_trivially_copyable, this makes the two std::bit_casts well-defined; a mirror written from upstream evmc (or a swapped enumerator) fails to compile, as the PR description demonstrates.
  • No overload/dispatch hazards. EvmcHost is final, so the non-virtual in-tree call(monad_message const &) alongside the virtual evmc adapter cannot be bypassed by a derived override, and the adapter's from_evmc_message argument selects the monad overload with no recursion risk.
  • Temporary lifetimes are correct at every seam: to_evmc_message locals in VM::execute/execute_bytecode outlive the synchronous override call; the temporaries bound to const-ref parameters in evm_fixture.hpp, monad_vm_interface_tests.cpp, and test_vm.cpp live through the full expression / enclosing scope of their synchronous use.
  • Remaining evmc_message sites are the intended ABI boundaries (runtime/call.cpp/create.cpp feeding the evmc host table, evmc_vm callbacks, benchmark harnesses, ExecuteOverride), matching the EXE-173/EXE-161/EXE-174 scoping in the description.
  • Traits/instantiation rules respected: no macro changes, no new is_monad_trait_v branching in ethereum/, and check-trait-instantiations passes.
  • FFI: monad_message is not exposed to the Rust bindgen headers; conversions happen before crossing the evmone C ABI.

Testing via the compile-time assertion suite is appropriate for a pure layout mirror. CI builds/tests were still pending at review time; the PR's own verification record (full ctest, ASAN+UBSAN with compiler testing, fuzzer, spec tests) is thorough.

One non-blocking nit posted inline (P3: noexcept on the conversion functions).

Verdict: CORRECT

🤖 Generated with Claude Code

@khordadi
khordadi force-pushed the akhordadi/exe-172-port-evmc_message-and-evmc_call_kind-to-in-tree-monad-types branch 4 times, most recently from 9c4b807 to 1184605 Compare September 15, 2026 12:07
EXE-172, part of EXE-162. monad_message, with monad_call_kind and
monad_call_flags, mirrors the fork's evmc_message field-for-field (no
code/code_size, evmc 663a1c2; memory_handle/memory/memory_capacity, evmc
8533622). message.cpp asserts standard layout, sizeof, alignof, the offsetof
of all 14 fields, the exact type of the 8 integer/pointer fields and the
enumerator values.

Purely additive; nothing references the type yet. The call-site migration
goes with the vm::Host port (EXE-173), where the runtime builds the message
itself and no per-call evmc conversion is needed.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@khordadi
khordadi force-pushed the akhordadi/exe-172-port-evmc_message-and-evmc_call_kind-to-in-tree-monad-types branch from 1184605 to 8fe6bf2 Compare September 15, 2026 13:38
@khordadi khordadi changed the title [execution/vm] Port evmc_message and evmc_call_kind to in-tree Monad types [execution/vm] Add in-tree monad_message type Sep 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants