matter-labs / foundry-zksync

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

call may fail or behave unexpectedly due to empty code target #720

Open L0GYKAL opened 1 week ago

L0GYKAL commented 1 week 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 (d053ecd 2024-11-10T00:27:05.976102717Z)

What command(s) is the bug in?

forge script

Operating System

Linux

Describe the bug

On a previously compiling & deployed forge project, I now have errors about cheatcodes when trying to deploy again. I made no changes to the contract or to the script since last deployment.


2024-11-10T09:49:48.856085Z ERROR foundry_zksync_core::vm::tracers::cheatcode: call may fail or behave unexpectedly due to empty code target=0x9f7cf1d1f558e57ef88a59ac3d47214ef25b6a06 calldata="c0406226"
Traces:
  [204154] MockMerkleScript::setUp()
    └─ ← [Return] 

  [204154] MockMerkleScript::run()
    └─ ← [Return] 

Script ran successfully.```

It says that the script runs successfully but no transaction is sent (with the ```-broadcast``` flag in the command).
Here is the script command: ```forge script MockMerkleScript --zksync --slow --chain-id 324 --build-info --build-info-path deployment --rpc-url https://mainnet.era.zksync.io -vvvvv --account XXX --password XXX --broadcast```
I tried with a dedicated RPC, but it changed nothing.
L0GYKAL commented 1 week ago

I tried to deploy another project and it failed with the exact same errors

nbaztec commented 6 days ago

Could you share the source repository or the reproducible example please.

L0GYKAL commented 6 days ago

Hey, yes here is an example: https://github.com/L0GYKAL/zk-forge_example

I executed the foundryup-zksync command again and now my forge version is : forge 0.0.2 (d053ecd 2024-11-11T00:25:54.225428781Z) Now I have another issue when compiling:


Error: Compiler run failed:
Error
Internal exception in StandardCompiler::compile: /solidity/libsolidity/interface/Natspec.cpp(89): Throw in function static Json::Value solidity::frontend::Natspec::userDocumentation(const ContractDefinition &)
Dynamic exception type: boost::wrapexcept<solidity::langutil::InternalCompilerError>
std::exception::what: Solidity assertion failed
[solidity::util::tag_comment*] = Solidity assertion failed```
But my collegue doesn't get this error (he still gets the error related to this issue though)
nbaztec commented 6 days ago

Try running forge clean for the compiler error, else it should be something with the installed solc binary.

I tried running your example with

ADMIN_ADDRESS=0xd0A5a140F12cE611845e707c3C674b8C0d1a2C07 forge script RandomTokenScript --zksync --broadcast --slow --private-key <snip> --rpc-url <mainnet>

and it worked for me, is there something additional that you might have different in your setup?

L0GYKAL commented 6 days ago

My colleague and I executed the command forge clean but it changed nothing

L0GYKAL commented 5 days ago

The 2 calldata are "setUp" and "run" so it means zk-forge doesn't find the script contract (in the EVM emulation: not deployed or deployed in an unexpected address) so when it calls the functions of the script the contract is empty so nothing runs

L0GYKAL commented 5 days ago

I also tried on a new computer to simulate the script and it had the same error, so I don't understand how it is not reproducible on your side PS, I tried to install a previous version of zk-forge but after the compilation of an old commit, the --zksync flag wasn't available so I can't roll back version

elfedy commented 5 days ago

I was able to run the example against era_test_node node (had to do forge install before). Does it work there? Here are the full logs for ADMIN_ADDRESS=0xc981b213603171963F81C687B9fC880d33CaeD16 forge script RandomTokenScript --slow --broadcast --rpc-url http://localhost:8011 --private-key <any_of_era_test_node_keys> --zksync:

⠊] Compiling...
[⠒] Compiling 57 files with Solc 0.8.27
[⠆] Solc 0.8.27 finished in 1.06s
Compiler run successful!
[⠃] Using zksolc-1.5.4
[⠊] Compiling (zksync)
[⠘] Compiling 57 files with zksolc and solc 0.8.27
[⠃] zksolc and solc 0.8.27 finished in 4.69s
Compiler run successful!
Script ran successfully.

== Logs ==
  Token address is:
  0xb03b0432524bF54dDefBC38033eEe3D8b6b154C4

## Setting up 1 EVM.

==========================

Chain 260

Estimated gas price: 0.050000001 gwei

Estimated total gas used for script: 634497495

Estimated amount required: 0.031724875384497495 ETH

==========================

##### 260
✅  [Success]Hash: 0xe15a201b3c1116dadaf7a42b426bcd460e1b7eb68df516f564652caf710c6cca
Contract Address: 0x915148c3a7d97ecF4F741FfaaB8263F9D66F2d0c
Block: 1
Paid: 0.028610261 ETH (1144410440 gas * 0.025 gwei)

##### 260
✅  [Success]Hash: 0x07f82b1bbe1bdb2c6c45625f903319ebc4740358df4007ea1c8ed8f934dfc7f0
Contract Address: 0xb03b0432524bF54dDefBC38033eEe3D8b6b154C4
Block: 3
Paid: 0.0056943908 ETH (227775632 gas * 0.025 gwei)

✅ Sequence #1 on 260 | Total Paid: 0.0343046518 ETH (1372186072 gas * avg 0.025 gwei)

==========================

ONCHAIN EXECUTION COMPLETE & SUCCESSFUL.

Transactions saved to: /home/elfedy/msl/issues/zk-forge_example/broadcast/RandomToken.s.sol/260/run-latest.json

Sensitive values saved to: /home/elfedy/msl/issues/zk-forge_example/cache/RandomToken.s.sol/260/run-latest.json

Maybe paste the full logs and the command you are using in the latest example so we can troubleshoot what's different in your environment?

L0GYKAL commented 5 days ago

forge script RandomTokenScript --zksync --slow --broadcast --chain-id 324 --build-info --build-info-path deployment --rpc-url -vvvvv --account XXX --password XXX

elfedy commented 5 days ago

Could you paste the full logs as well?

L0GYKAL commented 5 days ago

image (8)

No files changed, compilation skipped
[⠃] Using zksolc-1.5.4
[⠊] Compiling (zksync)
No files changed, compilation skipped
2024-11-12T17:19:36.977019Z ERROR foundry_zksync_core::vm::tracers::cheatcode: call may fail or behave unexpectedly due to empty code target=0x9f7cf1d1f558e57ef88a59ac3d47214ef25b6a06 calldata="0a9254e4"
2024-11-12T17:19:43.742296Z ERROR foundry_zksync_core::vm::tracers::cheatcode: call may fail or behave unexpectedly due to empty code target=0x9f7cf1d1f558e57ef88a59ac3d47214ef25b6a06 calldata="c0406226"
Traces:
  [204154] RandomTokenScript::setUp()
    └─ ← [Return] 

  [204154] RandomTokenScript::run()
    └─ ← [Return] 

Script ran successfully.
elfedy commented 5 days ago
2024-11-12T17:19:36.977019Z ERROR foundry_zksync_core::vm::tracers::cheatcode: call may fail or behave unexpectedly due to empty code target=0x9f7cf1d1f558e57ef88a59ac3d47214ef25b6a06 calldata="0a9254e4"
2024-11-12T17:19:43.742296Z ERROR foundry_zksync_core::vm::tracers::cheatcode: call may fail or behave unexpectedly due to empty code target=0x9f7cf1d1f558e57ef88a59ac3d47214ef25b6a06 calldata="c0406226"

This error is triggered when there is a call to an address with no associated code stored on EraVM which I do not see how could it come from the script (this mostly happens when there are mock calls to an incorrect address for example). Can you identify where this address comes from 0x9f7cf1d1f558e57ef88a59ac3d47214ef25b6a06? Also maybe double check how you are feeding ADMIN_ADDRESS to the environment and make sure no other variable that may affect execution is there, If that address is in fact the script this means it is is trying to be executed on EraVM vs the EVM which should not happen with normal script invocation (in fact it does not when I run it).

elfedy commented 5 days ago

Can you run your command appending RUST_LOG=debug and post the whole output here?

L0GYKAL commented 4 days ago

I just replace my alchemy API-Key by \<API-KEY> in the file. I pass the ADMIN_ADDRESS value through a .env file (PS, when it isn't available the script outputs the same error, so it doesn't check/ exec the script). debug_log.txt I ctrl+shift+f the address and it shows nowhere beside the debug_log file I created

L0GYKAL commented 4 days ago

On my 2nd computer, I installed the zk forge branch: 'v0.0.2-alpha.aave-2' and managed to make it work without any problem So it comes from the new version of zk forge