Skip to content

evm: Add abort_unless() for API contract violations in all builds - #1884

Merged
chfast merged 1 commit into
mainfrom
evm/check
Dec 3, 2026
Merged

chfast merged 1 commit into
mainfrom
evm/check

Conversation

@chfast

@chfast chfast commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Add abort_unless(condition, message), an inline test that calls the cold, out-of-line fatal_error(), which prints the message to stderr and aborts. Unlike assert(), it stays in release builds. Use it for violations of the API contract by the caller and for resource exhaustion.

Check the call depth of an execution: a caller passing a message with depth above 1024 now aborts the process. Previously, the execution state was taken from outside the reserved storage. The memory allocation failure now aborts via fatal_error() instead of std::terminate().

@codecov

codecov Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.23%. Comparing base (04408c0) to head (f765611).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1884      +/-   ##
==========================================
+ Coverage   98.21%   98.23%   +0.01%     
==========================================
  Files         189      191       +2     
  Lines       17410    17423      +13     
  Branches     3976     3977       +1     
==========================================
+ Hits        17099    17115      +16     
+ Misses        239      237       -2     
+ Partials       72       71       -1     
Flag Coverage Δ
eest-develop-gmp 27.13% <12.50%> (-0.02%) ⬇️
eest-legacy 17.06% <12.50%> (-0.01%) ⬇️
eest-libsecp256k1 28.95% <12.50%> (-0.02%) ⬇️
eest-stable 83.84% <16.66%> (-0.03%) ⬇️
evmone-unittests 94.10% <100.00%> (+0.02%) ⬆️
riscv64 94.96% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
core 96.63% <100.00%> (+0.05%) ⬆️
tooling 94.80% <ø> (ø)
tests 99.80% <100.00%> (+<0.01%) ⬆️
Files with missing lines Coverage Δ
lib/evmone/execution_state.hpp 100.00% <100.00%> (+4.83%) ⬆️
lib/evmone/fatal_error.cpp 100.00% <100.00%> (ø)
lib/evmone/fatal_error.hpp 100.00% <100.00%> (ø)
lib/evmone/vm_context.cpp 100.00% <100.00%> (ø)
test/unittests/evmone_test.cpp 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codspeed

codspeed Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will regress 1 benchmark

1 warning

⚠️ 6 benchmarks with a significant change ran on different hardware

Their base and head results were measured on machines with a different CPU, core count or memory, so the changes might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

⚡ 5 improved benchmarks
❌ 1 regressed benchmark
✅ 1040 untouched benchmarks
⏩ 770 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ test_callvalue_from_call[fork_Amsterdam-blockchain_test-non_zero_value_False-benchmark-gas-value_1M] 17.2 ms 17.5 ms -1.68%
⚡ test_calldatasize[fork_Amsterdam-blockchain_test-zero_data_False-calldata_size_1024-benchmark-gas-value_1M] 14.5 ms 14.2 ms +2.47%
⚡ test_calldatasize[fork_Amsterdam-blockchain_test-zero_data_True-calldata_size_32-benchmark-gas-value_1M] 14.8 ms 14.5 ms +1.99%
⚡ test_calldatasize[fork_Amsterdam-blockchain_test-zero_data_True-calldata_size_0-benchmark-gas-value_1M] 14.6 ms 14.3 ms +1.82%
⚡ test_calldatasize[fork_Amsterdam-blockchain_test-zero_data_True-calldata_size_1024-benchmark-gas-value_1M] 14.5 ms 14.3 ms +1.44%
⚡ test_returndatasize_zero[fork_Amsterdam-blockchain_test-benchmark-gas-value_1M] 15.3 ms 15.2 ms +1.11%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing evm/check (f765611) with main (04408c0)

Open in CodSpeed

Footnotes

  1. 770 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

Comment thread lib/evmone/vm_context.cpp Resolved
Comment thread lib/evmone/vm_context.hpp Resolved
@chfast chfast changed the title evm: Add abort_unless() for host contract violations in all builds evm: Add abort_unless() for API contract violations in all builds Dec 3, 2026
@chfast
chfast requested a balanced review from Copilot December 3, 2026 15:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approved

No active review issues are reported for the release-build contract and resource-exhaustion checks.

No open issues 🎉

What changed in this PR

Adds release-build checks for API contract violations and resource exhaustion, with consistent diagnostics before aborting.

Changes:

  • Introduces abort_unless() and an out-of-line fatal_error() handler.
  • Applies fatal checks to excessive call depth and memory allocation failure.
  • Adds a death test for call depth above 1024.
File Description
test/​unittests/​evmone_test.cpp Tests rejection of excessive call depth.
lib/​evmone/​vm_context.cpp Checks depth in all builds.
lib/​evmone/​fatal_error.hpp Declares fatal handling and defines abort_unless().
lib/​evmone/​fatal_error.cpp Prints diagnostics to stderr and aborts.
lib/​evmone/​execution_state.hpp Routes allocation failure through the fatal handler.
lib/​evmone/​CMakeLists.txt Registers the new source files.

Review effort: Balanced

Add abort_unless(condition, message), an inline test that calls the
cold, out-of-line fatal_error(), which prints the message to stderr and
aborts. Unlike assert(), it stays in release builds. Use it for
violations of the API contract by the caller and for resource
exhaustion.

Check the call depth of an execution: a caller passing a message with
depth above 1024 now aborts the process. Previously, the execution state
was taken from outside the reserved storage. The memory allocation
failure now aborts via fatal_error() instead of std::terminate().
@chfast
chfast merged commit 4554961 into main Dec 3, 2026
32 of 33 checks passed
@chfast
chfast deleted the evm/check branch December 3, 2026 17:37
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