foundry-rs / foundry

Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.
https://getfoundry.sh
Apache License 2.0
8.09k stars 1.67k forks source link

`panicked at 'byte index 15045 is out of bounds of pragma solidity ^0.8.4;` on debug mode #3463

Closed 0xbok closed 1 month ago

0xbok commented 1 year ago

Component

Forge

Have you ensured that all of these are up to date?

What version of Foundry are you on?

forge 0.2.0 (d95f309 2022-10-07T00:08:29.38237Z)

What command(s) is the bug in?

forge test --debug testDuplicateMintClone

Operating System

macOS (Apple Silicon)

Describe the bug

I am not able to isolate the bug to create a smaller PoC, but on this repo https://github.com/ditto-lab/ditto/tree/gas, forge test -m testDuplicateMintClone passes, but forge test --debug testDuplicateMintClone fails with

panicked at 'byte index 15045 is out of bounds of `pragma solidity ^0.8.4;

import {ERC721} from "@rari-capital/solmate/src/tokens/ERC721.sol";
import {ERC1155} from "@rari-capital/solmate/src/tokens/ERC1155.sol";
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";

contract UnderlyingNFT is`[...]', library/core/src/str/mod.rs:107:9
[1]    50668 abort      ~/.foundry/bin/forge test --debug testDuplicateMintClone

This is the link to the test: https://github.com/ditto-lab/ditto/blob/gas/src/test/DittoMachine.t.sol#L109

So there is a discrepancy between the debug mode and the usual test pipeline. Any pointers on how I can create a PoC for this for easier debugging?

mattsse commented 1 year ago

@rkrasiuk I first thought this might be related to parsing, but I suspect this is somehow related to sourcemaps

@0xbok could you please share the logs you get when you run with RUST_LOG=ethers,forge,foundry_cli,ui forge test ...

rkrasiuk commented 1 year ago

@0xbok ran forge test --debug testDuplicateMintClone on the gas branch successfully. are there any uncommitted changes?

Screenshot 2022-10-07 at 20 30 33
0xbok commented 1 year ago

@rkrasiuk If you keep pressing C until it stops and then s, you should see debugger crashing with this error. There were new commits on this branch, so the error is now "panicked at 'byte index 36467 is out of bounds of `pragma solidity ^0.8.4;"

@mattsse here are the logs (replaced some absolute local file path prefixes with ...).

2022-10-08T07:20:51.366252Z TRACE forge::test: executing test command
2022-10-08T07:20:51.378533Z TRACE forge::test: using filter filter=Filter { match: None, match-test: None, no-match-test: None, match-contract: None, no-match-contract: None, match-path: None, no-match-path: None, .. }
[⠃] Compiling...2022-10-08T07:20:51.563821Z TRACE compile_with:compile: ethers_solc: found 22 sources to compile: [".../ditto/script/DittoMachine.s.sol", ".../ditto/src/BlockRefund.sol", ".../ditto/src/CloneList.sol", ".../ditto/src/DittoMachine.sol", ".../ditto/src/DittoMachineSvg.sol", ".../ditto/src/Oracle.sol", ".../ditto/src/TimeCurve.sol", ".../ditto/src/test/Bidder.sol", ".../ditto/src/test/BidderWithEjector.sol", ".../ditto/src/test/BlockRefund.t.sol", ".../ditto/src/test/DittoMachine.t.sol", ".../ditto/src/test/Ejector.t.sol", ".../ditto/src/test/Floor.t.sol", ".../ditto/src/test/Heat.t.sol", ".../ditto/src/test/MultidimentionalClone.t.sol", ".../ditto/src/test/Oracle.t.sol", ".../ditto/src/test/OracleWrapper.sol", ".../ditto/src/test/TestBase.sol", ".../ditto/src/test/TimeCurve.t.sol", ".../ditto/src/test/UnderlyingNFT.sol", ".../ditto/src/test/UnderlyingNFTWithRoyalties.sol", ".../ditto/src/test/Voucher.t.sol"]
2022-10-08T07:20:51.580423Z TRACE compile_with:compile: ethers_solc::compile::project: preprocessing
2022-10-08T07:20:51.580446Z TRACE compile_with:compile:sol-files-cache::read: ethers_solc::cache: reading solfiles cache at .../ditto/cache/solidity-files-cache.json
2022-10-08T07:20:51.581054Z TRACE compile_with:compile:sol-files-cache::read: ethers_solc::cache: read cache "ethers-rs-sol-cache-3" with 40 entries
2022-10-08T07:20:51.581089Z TRACE compile_with:compile: ethers_solc::cache: remove non existing files from cache
2022-10-08T07:20:51.581150Z TRACE compile_with:compile: ethers_solc::cache: reading artifacts from cache...
[⠊] Compiling...2022-10-08T07:20:51.677641Z TRACE compile_with:compile: ethers_solc::cache: read 50 artifacts from cache
2022-10-08T07:20:51.678417Z TRACE compile_with:compile: ethers_solc::compile::project: Filtering 40 sources for 0.8.17+commit.8df45f5f.Darwin.appleclang
2022-10-08T07:20:51.679615Z TRACE compile_with:compile: ethers_solc::compile::project: Detected 0 dirty sources []
2022-10-08T07:20:51.679620Z TRACE compile_with:compile: ethers_solc::compile::project: compiling
2022-10-08T07:20:51.679623Z TRACE compile_with:compile: ethers_solc::compile::project: compiling 1 jobs sequentially
2022-10-08T07:20:51.679626Z TRACE compile_with:compile: ethers_solc::compile::project: skip solc /Users/dev/.svm/0.8.17/solc-0.8.17 0.8.17+commit.8df45f5f.Darwin.appleclang for empty sources set
2022-10-08T07:20:51.679632Z TRACE compile_with:compile:write-artifacts: ethers_solc::compile::project: handling artifact output for 0 contracts and 0 sources
2022-10-08T07:20:51.679699Z TRACE compile_with:compile: ethers_solc::compile::project: write cache
2022-10-08T07:20:51.679899Z TRACE compile_with:compile: ethers_solc::cache: writing cache with 40 entries to json file: ".../ditto/cache/solidity-files-cache.json"
2022-10-08T07:20:51.707043Z TRACE compile_with:compile: ethers_solc::cache: cache file located: ".../ditto/cache/solidity-files-cache.json"
[⠒] Compiling...
No files changed, compilation skipped
2022-10-08T07:20:51.824027Z TRACE forge::multi_runner: start all tests
2022-10-08T07:20:51.826074Z TRACE forge::multi_runner: start executing all tests in contract contract="src/test/DittoMachine.t.sol:ContractTest"
2022-10-08T07:20:51.826108Z  INFO contract{name=src/test/DittoMachine.t.sol:ContractTest}: forge::runner: starting tests
2022-10-08T07:20:51.826116Z TRACE contract{name=src/test/DittoMachine.t.sol:ContractTest}: forge::runner: Setting test contract setup=true
2022-10-08T07:20:51.827612Z TRACE contract{name=src/test/DittoMachine.t.sol:ContractTest}: forge::runner: setting up
2022-10-08T07:20:51.828268Z TRACE contract{name=src/test/DittoMachine.t.sol:ContractTest}: forge::runner: successfully setUp test contract=0x62d69f6867a0a084c6d313943dc22023bc263691
2022-10-08T07:20:51.828457Z DEBUG contract{name=src/test/DittoMachine.t.sol:ContractTest}:test{name=testDuplicateMintClone() should_fail=false}: forge::runner: duration=171.166µs success=true gas=456776
2022-10-08T07:20:51.828481Z  INFO contract{name=src/test/DittoMachine.t.sol:ContractTest}: forge::runner: done. 1/1 successful duration=2.369708ms
2022-10-08T07:20:51.828491Z TRACE forge::multi_runner: executed all tests in contract contract="src/test/DittoMachine.t.sol:ContractTest"
2022-10-08T07:20:51.828702Z TRACE foundry_cli::cmd::forge::script::cmd: executing script command
[⠃] Compiling...2022-10-08T07:20:51.857274Z TRACE compile_with:compile: ethers_solc: found 22 sources to compile: [".../ditto/script/DittoMachine.s.sol", ".../ditto/src/BlockRefund.sol", ".../ditto/src/CloneList.sol", ".../ditto/src/DittoMachine.sol", ".../ditto/src/DittoMachineSvg.sol", ".../ditto/src/Oracle.sol", ".../ditto/src/TimeCurve.sol", ".../ditto/src/test/Bidder.sol", ".../ditto/src/test/BidderWithEjector.sol", ".../ditto/src/test/BlockRefund.t.sol", ".../ditto/src/test/DittoMachine.t.sol", ".../ditto/src/test/Ejector.t.sol", ".../ditto/src/test/Floor.t.sol", ".../ditto/src/test/Heat.t.sol", ".../ditto/src/test/MultidimentionalClone.t.sol", ".../ditto/src/test/Oracle.t.sol", ".../ditto/src/test/OracleWrapper.sol", ".../ditto/src/test/TestBase.sol", ".../ditto/src/test/TimeCurve.t.sol", ".../ditto/src/test/UnderlyingNFT.sol", ".../ditto/src/test/UnderlyingNFTWithRoyalties.sol", ".../ditto/src/test/Voucher.t.sol"]
2022-10-08T07:20:51.873869Z TRACE compile_with:compile: ethers_solc::compile::project: preprocessing
2022-10-08T07:20:51.873889Z TRACE compile_with:compile:sol-files-cache::read: ethers_solc::cache: reading solfiles cache at .../ditto/cache/solidity-files-cache.json
2022-10-08T07:20:51.874478Z TRACE compile_with:compile:sol-files-cache::read: ethers_solc::cache: read cache "ethers-rs-sol-cache-3" with 40 entries
2022-10-08T07:20:51.874507Z TRACE compile_with:compile: ethers_solc::cache: remove non existing files from cache
2022-10-08T07:20:51.874557Z TRACE compile_with:compile: ethers_solc::cache: reading artifacts from cache...
[⠊] Compiling...2022-10-08T07:20:51.963171Z TRACE compile_with:compile: ethers_solc::cache: read 50 artifacts from cache
2022-10-08T07:20:51.963957Z TRACE compile_with:compile: ethers_solc::compile::project: Filtering 40 sources for 0.8.17+commit.8df45f5f.Darwin.appleclang
2022-10-08T07:20:51.965143Z TRACE compile_with:compile: ethers_solc::compile::project: Detected 0 dirty sources []
2022-10-08T07:20:51.965149Z TRACE compile_with:compile: ethers_solc::compile::project: compiling
2022-10-08T07:20:51.965152Z TRACE compile_with:compile: ethers_solc::compile::project: compiling 1 jobs sequentially
2022-10-08T07:20:51.965154Z TRACE compile_with:compile: ethers_solc::compile::project: skip solc /Users/dev/.svm/0.8.17/solc-0.8.17 0.8.17+commit.8df45f5f.Darwin.appleclang for empty sources set
2022-10-08T07:20:51.965161Z TRACE compile_with:compile:write-artifacts: ethers_solc::compile::project: handling artifact output for 0 contracts and 0 sources
2022-10-08T07:20:51.965219Z TRACE compile_with:compile: ethers_solc::compile::project: write cache
2022-10-08T07:20:51.965407Z TRACE compile_with:compile: ethers_solc::cache: writing cache with 40 entries to json file: ".../ditto/cache/solidity-files-cache.json"
2022-10-08T07:20:51.992630Z TRACE compile_with:compile: ethers_solc::cache: cache file located: ".../ditto/cache/solidity-files-cache.json"
[⠒] Compiling...
No files changed, compilation skipped
2022-10-08T07:20:52.175201Z TRACE foundry_cli::cmd::forge::script::executor: start executing script
2022-10-08T07:20:52.175214Z TRACE foundry_cli::cmd::forge::script::executor: preparing script runner
2022-10-08T07:20:52.200530Z TRACE etherscanidentifier: using etherscan identifier chain=Some(Named(Mainnet)) url="https://api.etherscan.io/api"
2022-10-08T07:20:52.202104Z TRACE etherscanidentifier: identify 0 addresses
2022-10-08T07:20:52.202553Z TRACE etherscanidentifier: identify 0 addresses
2022-10-08T07:20:52.202754Z TRACE etherscanidentifier: identify 1 addresses
2022-10-08T07:20:52.202757Z TRACE etherscanidentifier: fetching info for 0x7109709ecfa91a80626ff3989d68f67f5b1dd12d
2022-10-08T07:20:52.202781Z  WARN etherscanidentifier: could not get etherscan info: ContractCodeNotVerified(0x7109709ecfa91a80626ff3989d68f67f5b1dd12d)
2022-10-08T07:20:52.202788Z TRACE etherscanidentifier: identify 1 addresses
2022-10-08T07:20:52.202789Z TRACE etherscanidentifier: fetching info for 0x7109709ecfa91a80626ff3989d68f67f5b1dd12d
2022-10-08T07:20:52.202800Z  WARN etherscanidentifier: could not get etherscan info: ContractCodeNotVerified(0x7109709ecfa91a80626ff3989d68f67f5b1dd12d)
panicked at 'byte index 36467 is out of bounds of `pragma solidity ^0.8.4;

import {ERC721} from "@rari-capital/solmate/src/tokens/ERC721.sol";
import {ERC1155} from "@rari-capital/solmate/src/tokens/ERC1155.sol";
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";

contract UnderlyingNFT is`[...]', library/core/src/str/mod.rs:107:9
[1]    78773 abort      RUST_LOG=ethers,forge,foundry_cli,ui ~/.foundry/bin/forge test --debug
mattsse commented 1 year ago

thanks

looks like the gas branch is currently broken?

nvm, just needed to update deps.

rkrasiuk commented 1 year ago

@0xbok could you remove the duplicate import of DittoMachine within the TestBase and try running it once again?

0xbok commented 1 year ago

@rkrasiuk that would require other changes in the test as they depend on inheriting from DittoMachine. Do you want me to do that as well?

rkrasiuk commented 1 year ago

@0xbok simply change line 7 from import {Bidder, DittoMachine} from "./Bidder.sol"; to import {Bidder} from "./Bidder.sol";, since DittoMachine is already imported 2 lines above

0xbok commented 1 year ago

Done and this time debugger didn’t crash.

0xbok commented 1 year ago

So is this a bug or should we not have duplicate imports?

rkrasiuk commented 1 year ago

@0xbok it's def a bug with the source index lookup, sir. the debugger attempted to display UnderlyingNFT source file when it should've been DittoMachine. the caveat is it's nondeterministic as I haven't been able to reproduce it after removing a duplicate import and adding it back. it'll take some time to dig thru this

0xbok commented 1 year ago

Gotcha. After removing the duplicate import, I think there are some more issues. The debugger is mapping to other test functions like testSendEther() (press G to see it, also at some intermediate places) and testDissolve(). These test functions are not called from testDuplicateMintClone().

zerosnacks commented 1 month ago

Unable to reproduce a panic with the instructions:

If you keep pressing C until it stops and then s, you should see debugger crashing with this error. There were new commits on this branch, so the error is now "panicked at 'byte index 36467 is out of bounds of `pragma solidity ^0.8.4;"

Assuming this has since been resolved by https://github.com/foundry-rs/foundry/pull/7059 + https://github.com/foundry-rs/foundry/pull/7991 and general improvements over time