matter-labs / foundry-zksync

Fork of Foundry tailored for zkSync environment
Apache License 2.0
299 stars 130 forks source link

Application panic and crash when re-compiling tests #562

Closed Chipe1 closed 2 months ago

Chipe1 commented 2 months ago

Component

Forge

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

What version of Foundry are you on?

forge 0.0.2 (6a3dc4f 2024-09-05T00:23:56.539434000Z)

What command(s) is the bug in?

forge test --zksync

Operating System

macOS (Apple Silicon)

Describe the bug

I've recently updated by running foundryup-zksync after 2 months and started seeing this new bug. Whenever I run tests with forge test --zksync the compilation fails with the following error:

The application panicked (crashed).
Message:  called `Option::unwrap()` on a `None` value
Location: crates/zksync/compiler/src/zksolc/mod.rs:136

This is a bug. Consider reporting it at https://github.com/foundry-rs/foundry

  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ BACKTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   1: __mh_execute_header<unknown>
      at <unknown source file>:<unknown line>
   2: __mh_execute_header<unknown>
      at <unknown source file>:<unknown line>
   3: __mh_execute_header<unknown>
      at <unknown source file>:<unknown line>
   4: __mh_execute_header<unknown>
      at <unknown source file>:<unknown line>
   5: __mh_execute_header<unknown>
      at <unknown source file>:<unknown line>
   6: __mh_execute_header<unknown>
      at <unknown source file>:<unknown line>
   7: __mh_execute_header<unknown>
      at <unknown source file>:<unknown line>
   8: __mh_execute_header<unknown>
      at <unknown source file>:<unknown line>
   9: __mh_execute_header<unknown>
      at <unknown source file>:<unknown line>
  10: __mh_execute_header<unknown>
      at <unknown source file>:<unknown line>
  11: __mh_execute_header<unknown>
      at <unknown source file>:<unknown line>
  12: __mh_execute_header<unknown>
      at <unknown source file>:<unknown line>
  13: __mh_execute_header<unknown>
      at <unknown source file>:<unknown line>
  14: __mh_execute_header<unknown>
      at <unknown source file>:<unknown line>
  15: __mh_execute_header<unknown>
      at <unknown source file>:<unknown line>
  16: __mh_execute_header<unknown>
      at <unknown source file>:<unknown line>
  17: __mh_execute_header<unknown>
      at <unknown source file>:<unknown line>
  18: __mh_execute_header<unknown>
      at <unknown source file>:<unknown line>
  19: __mh_execute_header<unknown>
      at <unknown source file>:<unknown line>
  20: __mh_execute_header<unknown>
      at <unknown source file>:<unknown line>
  21: __mh_execute_header<unknown>
      at <unknown source file>:<unknown line>
  22: __mh_execute_header<unknown>
      at <unknown source file>:<unknown line>

Run with COLORBT_SHOW_HIDDEN=1 environment variable to disable frame filtering.
Run with RUST_BACKTRACE=full to include source snippets.

The "Location: crates/zksync/compiler/src/zksolc/mod.rs:136" has something to do with zk output artifacts

image

To test this I cleared the artifacts and ran the test command again - it worked without errors.

This happens for every change I make to test files. When I run forge test --zksync the compilation fails with the error. I need to rm -r zkout/ and run the test again to compile properly. Able to reproduce this consistently every time I make any change to the test file. This was not the case in the older version(don't know which version it was, around 2 months old) and makes the testing process slow and painful - compilation takes a long time.

elfedy commented 2 months ago

@Chipe1 this issue is known to happen due to compilation not being deterministic when using yul sometimes and we are still figuring out the best path forward to solve it. Can you try using --zk-force-evmla flag when compiling or adding force_evmla = true under [profile.default.zksync] on foundry.toml? That should result in deterministic builds and should work as a temporary workaround for this problem.

Chipe1 commented 2 months ago

@elfedy Thanks for the quick reply! I don't have a [profile.default.zksync], only [profile.zksync] as in the docs, so I added the force_evmla = true under it but nothing changed. Facing the same issue. Changed [profile.zksync] to [profile.default.zksync] and I started getting "Error: bytecode size exceeds the limit of 65536 instructions" error during compilation - even with fallback_oz = true

Interestingly, after removing the force_evmla = true things started working (now using profile.default.zksync instead of profile.zksync). Now it always compiles all the files for zksolc even those without code changes

[⠊] Compiling...
No files changed, compilation skipped
[⠃] Using zksolc-1.5.3
[⠊] Compiling (zksync)
[⠢] Compiling 92 files with zksolc and solc 0.8.20
[⠆] zksolc and solc 0.8.20 finished in 49.27s
Compiler run successful with warnings:

This fixed my issue 👍 But this also makes test runs painfully slow. Earlier it used to only compile the 1 or 2 changed contracts

elfedy commented 2 months ago

@Chipe1 thanks for pointing out to the docs as they seem to be outdated. Will raise this with the authors. Yes if contract is too big then you are out of luck for now as the only solutions are either making the contracts smaller so you can use force_evmla or wiping out the cache every time you modify a test. That change should not have any difference in how cache behaves so if you are getting everything recompiled consistently even though you didn't change the contracts and you can give us something to reproduce it please raise another issue.

Chipe1 commented 2 months ago

Got it. Not able to re-produce the original error I was facing any more... zksolc having to compile ALL files again is a different issue though, so closing this one. Will create a new issue once I'm able to get a minimal reproducible example. Thanks for your help!