foundry-rs / foundry-rs/foundry
feat(`forge` / `cast`): ability to read private immutables
- Dominant language
- Rust
- Stars
- 10.6k
- Forks
- 2.6k
- Avg merge
- 18h 20m
- Merged PRs (30d)
- 510
Description
### 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:
```solidity
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_
Contributor guide
Assessment
This issue has not been assessed yet.