Skip to content

evmasm test case #16012

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 23, 2025
Merged

evmasm test case #16012

merged 5 commits into from
Apr 23, 2025

Conversation

cameel
Copy link
Member

@cameel cameel commented Apr 19, 2025

Adds a new custom test case that accepts EVM assembly as input, which allows inspecting the results of assembly import and evmasm optimizer. It should replace the Boost-based optimizer tests from test/libevmasm/Optimiser.cpp as well as the command-line tests for assembly import.

The test case can take the assembly in JSON format as well as a simplified text format that can be easily post-processed into JSON ("plain assembly"). Plain assembly is currently very limited, but should still be enough to cover #15935. It allows using all opcodes as well as tags and jumps. It does not yet support subassemblies, data, metadata or the less common types of assembly items, but the format is designed to accommodate them and I'm going to add them in subsequent PRs.

@cameel cameel requested review from clonker and nikola-matic April 19, 2025 07:33
@cameel cameel self-assigned this Apr 19, 2025
Comment on lines +96 to +98
// TODO: Enable when assembly import for EOF is implemented.
if (CommonOptions::get().eofVersion().has_value())
m_shouldRun = false;
Copy link
Member Author

Choose a reason for hiding this comment

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

The test case can easily be extended support EOF, but we need to implement assembly import for EOF first.

Comment on lines +70 to +74
if (!immediateArgument.starts_with("0x"))
BOOST_THROW_EXCEPTION(std::runtime_error(formatError("The immediate argument to PUSH must be a hex number prefixed with '0x'.")));

immediateArgument.remove_prefix("0x"s.size());
codeJSON.push_back({{"name", "PUSH"}, {"value", immediateArgument}});
Copy link
Member Author

@cameel cameel Apr 19, 2025

Choose a reason for hiding this comment

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

It's quite annoying that the JSON format accepts only hex numbers here but without the 0x prefix. On the other hand for tag it accepts both and the ones without 0x are actually decimal.

Copy link
Member

@clonker clonker left a comment

Choose a reason for hiding this comment

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

Didn't find anything wrong, just a few nitpicks and suggestions

@moh-eulith
Copy link

moh-eulith commented Apr 23, 2025

@cameel question about the settings: I'm trying to change the expected runs, but it's not working as I expect. What am I doing wrong here?

PUSH 0x0
PUSH 0x1
PUSH 0x0123456789ABCDEF
PUSH 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
// ====
// optimizationPreset: none
// optimizer.constantOptimizer: true
// optimizer.expectedExecutionsPerDeployment: 2000000
// outputs: Assembly,Opcodes
// ----
// Assembly:
//   0x00
//   0x01
//   0x0123456789abcdef
//   not(0x00)
// Opcodes: PUSH0 PUSH1 0x1 PUSH8 0x123456789ABCDEF PUSH0 NOT

(at a high run, the last one should be a PUSH32)

@cameel
Copy link
Member Author

cameel commented Apr 23, 2025

@moh-eulith It's because the top-level object contains the initcode, which runs only once so the compiler uses expectedExecutionsPerDeployment of 1 for it. The value you specify is only used for the runtime objects. Basically, you need to put your code in a sub-object. You can't do that using this simplified syntax yet, but that's the next extension I'm working on. Will come in a PR once I merge this.

Right now it's still possible to test this, but you have to use the full JSON syntax (see settings_optimizer_expected_executions_per_deployment.asmjson).

@cameel cameel force-pushed the evmasm-test-case branch from f1723b6 to fe39551 Compare April 23, 2025 19:16
@cameel cameel enabled auto-merge April 23, 2025 19:17
@cameel cameel merged commit 6d62ea0 into develop Apr 23, 2025
74 checks passed
@cameel cameel deleted the evmasm-test-case branch April 23, 2025 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants