fix(evm): fix ZEN_LOG format string mismatch - #457
Conversation
…out of range'
ZEN_LOG_* macros use snprintf (printf-style %s/%d), but several log calls
in evm_test_host.hpp and evm_test_helpers.h used fmt-style {} placeholders.
snprintf ignores {}, leaving them in the output string. When spdlog then
parses the message as a fmt format string, it triggers 'argument index out
of range' error.
Fixed by replacing all {} with %s in ZEN_LOG_* calls.
Also fixed a mixed {%d} format in action/interpreter.cpp.
Fixes DTVMStack#450, DTVMStack#452
⚡ Performance Regression Check Results✅ Performance Check Passed (interpreter)Performance Benchmark Results (threshold: 25%)
Summary: 194 benchmarks, 0 regressions ✅ Performance Check Passed (multipass)Performance Benchmark Results (threshold: 25%)
Summary: 194 benchmarks, 0 regressions |
There was a problem hiding this comment.
Pull request overview
Fixes EVM/test logging format strings to align with ZEN_LOG_*’s snprintf-based (printf-style) formatting, preventing spdlog {argument index out of range} errors caused by leftover {} placeholders.
Changes:
- Replaced fmt-style
{}placeholders with printf-style format specifiers in severalZEN_LOG_*calls in EVM test utilities. - Fixed a mixed/incorrect format string in the action interpreter’s “unimplemented opcode” log.
- Standardized some messages to use
%sfor string inputs (e.g.,ModName.c_str(),E.what()).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/tests/evm_test_host.hpp | Updates multiple ZEN_LOG_* callsites to printf-style formatting; however, at least one {} remains and one new %s/argument type mismatch is introduced. |
| src/tests/evm_test_helpers.h | Updates several ZEN_LOG_ERROR strings, but additional {} placeholders remain in other ZEN_LOG_ERROR calls in the same function. |
| src/action/interpreter.cpp | Fixes the “unimplemented opcode” log format to a printf-style hex format. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ZEN_LOG_ERROR("Insufficient balance for CREATE: have %s, need %s", | ||
| SenderBalance, Value); |
There was a problem hiding this comment.
Format string/argument mismatch: the message uses %s placeholders but passes intx::uint256 values (SenderBalance, Value). With snprintf-style formatting this is undefined behavior and may not compile (or may crash at runtime). Convert these uint256 values to strings (decimal or hex) and pass .c_str(), or change the format specifiers to match the actual argument types.
| ZEN_LOG_ERROR("Insufficient balance for CREATE: have %s, need %s", | |
| SenderBalance, Value); | |
| const auto SenderBalanceStr = intx::to_string(SenderBalance); | |
| const auto ValueStr = intx::to_string(Value); | |
| ZEN_LOG_ERROR("Insufficient balance for CREATE: have %s, need %s", | |
| SenderBalanceStr.c_str(), ValueStr.c_str()); |
ZEN_LOG_* macros use snprintf (printf-style %s/%d), but several log calls in evm_test_host.hpp and evm_test_helpers.h used fmt-style {} placeholders. snprintf ignores {}, leaving them in the output string. When spdlog then parses the message as a fmt format string, it triggers 'argument index out of range' error.
Fixed by replacing all {} with %s in ZEN_LOG_* calls. Also fixed a mixed {%d} format in action/interpreter.cpp.
1. Does this PR affect any open issues?(Y/N) and add issue references (e.g. "fix #123", "re #123".):
fix A bug in EVM (both interpreter mode and multi-pass JIT mode) #450
fix A possible bug in EVM (both interpreter mode and multi-pass JIT mode) #452
2. What is the scope of this PR (e.g. component or file name):
3. Provide a description of the PR(e.g. more details, effects, motivations or doc link):
4. Are there any breaking changes?(Y/N) and describe the breaking changes(e.g. more details, motivations or doc link):
5. Are there test cases for these changes?(Y/N) select and add more details, references or doc links:
6. Release note