foundry
foundry copied to clipboard
Ability to read private immutables
Component
Forge
Describe the feature you would like
It is currently impossible to read private immutable variables in Foundry because of how they work.
Immutables are, similarly to constants, inlined in the bytecode directly and PUSH
ed where they are needed.
The issue is that immutables are, as opposed to constants, not known before the contract construction.
This makes them, even more tricky to read if private. Because that would imply reading the code and parsing what's of interest, making it not scalable as the code change, or optimizations.
Example:
contract HardToRead {
uint256 private immutable val;
constructor(uint256 _val) {
val = _val;
}
}
My proposition would be to add a cheatcode to read immutables, and constants directly from the code called codeLoad
(very open to propositions).
It would work by using the solc output, probably the bytecode to source code mapping in order to generate bindings for the immutables and constants that are defined in the contract and expose them through the cheatcode.
Additional context
No response