-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
feat: Blackbox code from compiler #12951
Comments
This seems related to this earlier issue from @cgewecke and @Ferparishuertas: #10354. That issue is about something else (getting "stack too deep" with optimizer disabled) but the underlying use case is very similar - needing to insert some "instrumentation" code that should go through the optimizer unmodified - for the purpose of tracking coverage in that specific case. @brockelmore Do you need to be able to do this at Solidity level or would compiling first to Yul, then inserting your snippet and finally assembling to bytecode be enough? If it's the latter then I guess
Yeah, there's another optimization pass on EVM assembly after Yul optimizer finishes. It's basically the same optimizer that's used in the legacy non-Yul pipeline. We have fine-grained settings for selecting optimizations done at this stage. You can disable the peephole optimizer by setting |
I think this function is really about @brockelmore can this be closed or do you think |
This issue has been marked as stale due to inactivity for the last 90 days. |
Hi everyone! This issue has been automatically closed due to inactivity. |
Abstract
As the compiler gets smarter at inlining, const evaling, and keeping variables around (with stack-to-deep avoidance and the like), there is a growing need to hide/blackbox chunks of code from the compiler for testing and profiling reasons.
Motivation
I am extremely encouraged that I need to make this request. Effectively, the optimizer (especially with
viaIR
) is getting so smart there is a growing need to be able to tell the compiler "dont touch this". For example: foundry-rs/foundry#1373Foundry allows users to change global variables like block parameters in a test. The issue is the optimizer now is smart enough that later usage of
block.timestamp
is compiled away after the first usage and duped, because in normal circumstances, this is constant throughout a transaction. There have also been times when trying to gas profile a library that underviaIR
, it gets const evaled (in these tests for example: https://github.com/recmo/experiment-solexp/blob/main/src/test/FixedPointMathLib.t.sol).Specification
Blackboxing would take an expression/code block and not perform any constant evaluation on it or perform optimizations on its output.
One option is to add a
blackbox
code block similar tounchecked
orassembly
blocks:The above would never evaluate the function at compile time and would always effectively generate:
Or whatever. I am not entirely sure of optimizations that occur on raw bytecode, but if peephole optimizations may still take place on it, one way you might avoid that is basically just trick the peephole optimizer into thinking its a sort of link reference (i.e.
_$blackboxRef1$_
)? Then as the last step, fill in any references with the associated blackbox opcodes.Backwards Compatibility
Would add a new keyword
blackbox
The text was updated successfully, but these errors were encountered: