foundry
foundry copied to clipboard
Debugger: No srcmap index
Component
Forge
Have you ensured that all of these are up to date?
- [X] Foundry
- [X] Foundryup
What version of Foundry are you on?
forge 0.2.0 (92f8951 2022-08-06T00:12:01.790485419Z)
What command(s) is the bug in?
forge test --debug
Operating System
WSL2 in Windows 11
Describe the bug
// Contract.t.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
import "forge-std/Test.sol";
contract ContractTest is Test {
function setUp() public {}
function noSrcMap(bytes memory in1, uint256[6] memory in2) public view returns (bool) {
return false;
}
function testNoSrcMap() public {
bytes memory in1;
uint256[6] memory in2;
noSrcMap(in1, in2);
}
}
Run forge test --debug testNoSrcMap and step through. When debugger hits the noSrcMap() function call, the source disappears and the debugger reports "No src map index"
I also tried forge debug test/Contract.t.sol which crashed the program.
forge debug test/Contract.t.sol
[⠆] Compiling...
No files changed, compilation skipped
The application panicked (crashed).
Message: Function signature not found in the ABI
Location: cli/src/cmd/forge/script/mod.rs:412
This is a bug. Consider reporting it at https://github.com/foundry-rs/foundry
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ BACKTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1: __libc_start_main<unknown>
at /build/glibc-SzIz7B/glibc-2.31/csu/../csu/libc-start.c:308
Run with COLORBT_SHOW_HIDDEN=1 environment variable to disable frame filtering.
Run with RUST_BACKTRACE=full to include source snippets.
Aborted
debug and script executes the run() function by default from the contract passed. If you don't have one or specifiy an alternative through --sig, it will give that error (which should be better).
About the original bug, is this just a simplification of what you've hit in another project?
About this specific case, this seems like an optimization made by the compiler, leading to certain srcmaps not being present. I have an impression, forge coverage has similar challenges when the optimizer is turned on (@onbjerg right..? )
I tried it locally, and once i added optimizer = false to my foundry.toml, i was able to step through everything nicely.
Weird, optimizer = false doesn't seem to help me. Right now I have this in my foundry.toml and still getting the no srcmap issue.
[profile.default]
src = 'src'
out = 'out'
libs = ['lib']
via_ir = false
optimizer = false
optimizer_runs = 0
optimizer_steps = 0
# See more config options https://github.com/foundry-rs/foundry/tree/master/config
And yes this snippet is coming from the signature in this contract https://github.com/tornadocash/tornado-core/blob/1ef6a263ac6a0e476d063fcb269a9df65a1bd56a/contracts/Verifier.sol#L192
Nevermind I think this was due to a secondary bug. Changing foundry.toml is not sufficient to trigger a recompile. You also have to make a no-op change to the contract for it to blow away the cache.
@joshieDo The source map is always present unless the contract is abstract or a library with only internal functions (those don't have bytecode). The optimizer just makes the source map not so helpful in some situations (e.g. some bytecode maps to the wrong source range, some source ranges have no associated bytecode in the source map etc.)
If the debugger didn't crash, it's likely not a bug: we added this message because we knew there is a chance that some source is not covered by the source map. Not entirely sure what the solution would be here :)
@markisus Can you report the optimizer config setting not triggering a rebuild as a separate bug? If running w/o the optimizer works, imo we should close this issue, since it's not really something we can do anything about :/
Closed since it's a source map issue in Solidity, created #2726 for the optimizer issue