Skip to content
Open
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
14 changes: 8 additions & 6 deletions src/compiler/evm_frontend/evm_analyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,15 @@ struct JITSuitabilityResult {
size_t DupFeedbackPatternCount = 0; // DUPn immediately before RA-expensive
};

/// Thresholds for JIT suitability fallback. Normal contracts have <20
/// RA-expensive ops per block; these values are conservatively high.
/// Thresholds for JIT suitability fallback. Keep the bytecode size cap intact,
/// but raise the MIR / RA pattern limits high enough that the current evmone
/// benchmark corpus stays on the JIT path (including the pathological
/// signextend micro benchmark).
Comment on lines +114 to +117
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

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

The new threshold comment hard-codes a policy goal tied to the current evmone benchmark corpus (and a specific micro-benchmark). That’s likely to go stale and makes it harder to reason about the safety goal of this fallback (avoiding pathological JIT compile-time blowups). Consider rewriting this comment to describe the invariant being protected (e.g., cap compile-time / RA complexity) and, if needed, reference the benchmark corpus in a higher-level tuning doc or commit/benchmark notes rather than as the normative requirement in a public header.

Suggested change
/// Thresholds for JIT suitability fallback. Keep the bytecode size cap intact,
/// but raise the MIR / RA pattern limits high enough that the current evmone
/// benchmark corpus stays on the JIT path (including the pathological
/// signextend micro benchmark).
/// Thresholds for JIT suitability fallback. These limits bound bytecode size
/// and estimated MIR / RA complexity to avoid pathological JIT compile-time
/// blowups (e.g., superlinear register allocation on dense RA-expensive
/// instruction patterns), while keeping typical contracts on the JIT path.

Copilot uses AI. Check for mistakes.
static constexpr size_t MAX_JIT_BYTECODE_SIZE = 0x6000;
static constexpr size_t MAX_JIT_MIR_ESTIMATE = 50000;
static constexpr size_t MAX_CONSECUTIVE_RA_EXPENSIVE = 128;
static constexpr size_t MAX_BLOCK_RA_EXPENSIVE = 256;
static constexpr size_t MAX_DUP_FEEDBACK_PATTERN = 64;
static constexpr size_t MAX_JIT_MIR_ESTIMATE = 0x50000;
static constexpr size_t MAX_CONSECUTIVE_RA_EXPENSIVE = 0x3000;
static constexpr size_t MAX_BLOCK_RA_EXPENSIVE = 0x3000;
static constexpr size_t MAX_DUP_FEEDBACK_PATTERN = 0x3000;
Comment on lines 118 to +122
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

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

These new limits (0x3000 RA-expensive ops per block / consecutive run, and 0x50000 MIR estimate) are orders of magnitude above the “hundreds cause compilation times to explode” rationale described earlier in this file. With MAX_JIT_BYTECODE_SIZE still at 0x6000, this effectively allows extremely RA-dense single-block bytecode to stay on the JIT path, which undermines the fallback’s purpose and can increase worst-case compile-time (and potential DoS surface) for attacker-controlled contracts. Can we (a) justify these specific magnitudes with data in a comment, and/or (b) tie these thresholds to MAX_JIT_BYTECODE_SIZE or a measured compile-time budget so the guard remains meaningful as workloads change?

Copilot uses AI. Check for mistakes.

class EVMAnalyzer {
using Byte = zen::common::Byte;
Expand Down
Loading