matter-labs / foundry-zksync

Fork of Foundry tailored for zkSync environment

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cannot deploy with `forge create`

PatrickAlphaC opened this issue · comments

Component

Forge

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

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.0.2 (0989cdc 2024-06-20T00:23:19.835658000Z)

What command(s) is the bug in?

forge create

Operating System

macOS (Intel)

Describe the bug

Historically, I was able to deploy to zksync by using:

forge create src/MyContract.sol:MyContract --rpc-url $(ZKSYNC_SEPOLIA_RPC_URL) --account $(ACCOUNT) --legacy --zksync

However, now I'm getting this error:

failed rpc call for estimating fee: JsonRpcClientError(JsonRpcError(JsonRpcError { code: 3, message: "execution reverted", data: Some(String("0x")) }))

What's going on?

We did introduce a change to create with #421, but in our testing (both manual and CI) we didn't have such issue.
Could you share more information? Is MyContract an example contract you can share?

I'd like to see more output, both from the foundry logs and from the backtrace, could you provide those if you can't share something more reproducible?

I have indeed confirmed that PR to not be the cause of the issue, having reproduced it (from internal conversation) using the CrowdfundingCampaign contract from the zksync 101 tutorial both with sepolia and era-test-node.

Unfortunately, I also found (at least in that case) that the error is due to not having specified the --constructor-args (or equivalent) parameter, explaining also why deploying via the script is still successful.

Does that fix your issue @PatrickAlphaC ?

The contract is a basic ERC20. You can see it here:

// contracts/MyContract.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract MyContract is ERC20 {
    constructor(uint256 initialSupply) ERC20("OurToken", "OT") {
        _mint(msg.sender, initialSupply);
    }
}

Here is my full debug output:

2024-06-20T17:31:45.475905Z DEBUG zksync_compile_with: foundry_common::compile: compiling project
[⠃] Compiling (zksync)...2024-06-20T17:31:45.478052Z DEBUG zksync_compile_with:version: foundry_compilers::compile: getting Solc version cmd="/Users/patrick/.svm/0.8.24/solc-0.8.24" "--version"
2024-06-20T17:31:45.513465Z DEBUG zksync_compile_with:version: foundry_compilers::compile: version=0.8.24+commit.e11b9ed9.Darwin.appleclang
[⠢] Compiling (zksync)...2024-06-20T17:31:45.856389Z DEBUG zksync_compile_with:version: foundry_compilers::compile: getting Solc version cmd="/Users/patrick/.svm/0.8.24/solc-0.8.24" "--version"
2024-06-20T17:31:45.864634Z DEBUG zksync_compile_with:version: foundry_compilers::compile: version=0.8.24+commit.e11b9ed9.Darwin.appleclang
2024-06-20T17:31:45.871720Z DEBUG zksync_compile_with:version: foundry_compilers::compile: getting Solc version cmd="/Users/patrick/.svm/0.8.24/solc-0.8.24" "--version"
2024-06-20T17:31:45.882462Z DEBUG zksync_compile_with:version: foundry_compilers::compile: version=0.8.24+commit.e11b9ed9.Darwin.appleclang
2024-06-20T17:31:45.883412Z DEBUG zksync_compile_with:compile: foundry_compilers::zksync::compile: compiling cmd=cd "/Users/patrick/code/foundry-full-course-f23/foundry-erc20-f23" && "/Users/patrick/.zksync/zksolc-macosx-amd64-v1.4.1" "--base-path" "/Users/patrick/code/foundry-full-course-f23/foundry-erc20-f23" "--solc" "/Users/patrick/.zksync/solc-macosx-amd64-0.8.24-1.0.1" "--allow-paths" "/Users/patrick/code/foundry-full-course-f23/foundry-erc20-f23,/Users/patrick/code/foundry-full-course-f23/foundry-erc20-f23/lib" "--standard-json"
2024-06-20T17:31:45.884922Z DEBUG zksync_compile_with:compile: foundry_compilers::zksync::compile: spawned
[⠆] Compiling (zksync)...2024-06-20T17:31:45.886306Z DEBUG zksync_compile_with:compile: foundry_compilers::zksync::compile: wrote JSON input to stdin
[⠔] Compiling (zksync)...2024-06-20T17:31:47.192284Z DEBUG zksync_compile_with:compile: foundry_compilers::zksync::compile: finished output.status=exit status: 0 output.stderr=""
2024-06-20T17:31:47.204451Z DEBUG zksync_compile_with: foundry_common::compile: finished compiling in 1.729s
[⠒] Compiling (zksync)...
Compiler run successful!
2024-06-20T17:31:47.228753Z DEBUG reqwest::connect: starting new connection: https://zksync-sepolia.g.alchemy.com/    
2024-06-20T17:31:47.228851Z DEBUG hyper::client::connect::dns: resolving host="zksync-sepolia.g.alchemy.com"
2024-06-20T17:31:47.231758Z DEBUG hyper::client::connect::http: connecting to 104.16.224.156:443
2024-06-20T17:31:47.250135Z DEBUG hyper::client::connect::http: connected to 104.16.224.156:443
2024-06-20T17:31:47.292129Z DEBUG hyper::proto::h1::io: flushed 202 bytes
2024-06-20T17:31:47.359920Z DEBUG hyper::proto::h1::io: parsed 11 headers
2024-06-20T17:31:47.359952Z DEBUG hyper::proto::h1::conn: incoming body is content-length (41 bytes)
2024-06-20T17:31:47.359998Z DEBUG hyper::proto::h1::conn: incoming body completed
2024-06-20T17:31:47.360064Z DEBUG hyper::client::pool: pooling idle connection for ("https", zksync-sepolia.g.alchemy.com)
Enter keystore password:
Enter keystore password:
2024-06-20T17:31:51.896458Z DEBUG hyper::client::pool: reuse idle connection for ("https", zksync-sepolia.g.alchemy.com)
2024-06-20T17:31:51.896570Z DEBUG hyper::proto::h1::io: flushed 202 bytes
2024-06-20T17:31:51.971325Z DEBUG hyper::proto::h1::io: parsed 11 headers
2024-06-20T17:31:51.971355Z DEBUG hyper::proto::h1::conn: incoming body is content-length (41 bytes)
2024-06-20T17:31:51.971378Z DEBUG hyper::proto::h1::conn: incoming body completed
2024-06-20T17:31:51.971413Z DEBUG hyper::client::pool: pooling idle connection for ("https", zksync-sepolia.g.alchemy.com)
2024-06-20T17:31:51.971627Z DEBUG hyper::client::pool: reuse idle connection for ("https", zksync-sepolia.g.alchemy.com)
2024-06-20T17:31:51.971717Z DEBUG hyper::proto::h1::io: flushed 202 bytes
2024-06-20T17:31:52.045407Z DEBUG hyper::proto::h1::io: parsed 11 headers
2024-06-20T17:31:52.045426Z DEBUG hyper::proto::h1::conn: incoming body is content-length (41 bytes)
2024-06-20T17:31:52.045442Z DEBUG hyper::proto::h1::conn: incoming body completed
2024-06-20T17:31:52.045489Z DEBUG hyper::client::pool: pooling idle connection for ("https", zksync-sepolia.g.alchemy.com)
2024-06-20T17:31:52.045567Z DEBUG hyper::client::pool: reuse idle connection for ("https", zksync-sepolia.g.alchemy.com)
2024-06-20T17:31:52.045643Z DEBUG hyper::proto::h1::io: flushed 203 bytes
2024-06-20T17:31:52.166619Z DEBUG hyper::proto::h1::io: parsed 11 headers
2024-06-20T17:31:52.166651Z DEBUG hyper::proto::h1::conn: incoming body is content-length (45 bytes)
2024-06-20T17:31:52.166673Z DEBUG hyper::proto::h1::conn: incoming body completed
2024-06-20T17:31:52.166703Z DEBUG hyper::client::pool: pooling idle connection for ("https", zksync-sepolia.g.alchemy.com)
2024-06-20T17:31:52.166848Z DEBUG hyper::client::pool: reuse idle connection for ("https", zksync-sepolia.g.alchemy.com)
2024-06-20T17:31:52.166933Z DEBUG hyper::proto::h1::io: flushed 280 bytes
2024-06-20T17:31:52.310789Z DEBUG hyper::proto::h1::io: parsed 11 headers
2024-06-20T17:31:52.310807Z DEBUG hyper::proto::h1::conn: incoming body is content-length (40 bytes)
2024-06-20T17:31:52.310821Z DEBUG hyper::proto::h1::conn: incoming body completed
2024-06-20T17:31:52.310850Z DEBUG hyper::client::pool: pooling idle connection for ("https", zksync-sepolia.g.alchemy.com)
2024-06-20T17:31:52.310969Z DEBUG hyper::client::pool: reuse idle connection for ("https", zksync-sepolia.g.alchemy.com)
2024-06-20T17:31:52.311050Z DEBUG hyper::proto::h1::io: flushed 203 bytes
2024-06-20T17:31:52.449988Z DEBUG hyper::proto::h1::io: parsed 11 headers
2024-06-20T17:31:52.450007Z DEBUG hyper::proto::h1::conn: incoming body is content-length (45 bytes)
2024-06-20T17:31:52.450024Z DEBUG hyper::proto::h1::conn: incoming body completed
2024-06-20T17:31:52.450056Z DEBUG hyper::client::pool: pooling idle connection for ("https", zksync-sepolia.g.alchemy.com)
2024-06-20T17:31:52.451266Z DEBUG hyper::client::pool: reuse idle connection for ("https", zksync-sepolia.g.alchemy.com)
2024-06-20T17:31:52.451364Z DEBUG hyper::proto::h1::io: flushed 22350 bytes
2024-06-20T17:31:52.744441Z DEBUG hyper::proto::h1::io: parsed 11 headers
2024-06-20T17:31:52.744457Z DEBUG hyper::proto::h1::conn: incoming body is content-length (86 bytes)
2024-06-20T17:31:52.744470Z DEBUG hyper::proto::h1::conn: incoming body completed
2024-06-20T17:31:52.744500Z DEBUG hyper::client::pool: pooling idle connection for ("https", zksync-sepolia.g.alchemy.com)
Error: 
failed rpc call for estimating fee: JsonRpcClientError(JsonRpcError(JsonRpcError { code: 3, message: "execution reverted", data: Some(String("0x")) }))

Seems like the error code is wrong. It should say like "forgot constructor arguments."

But trying to redeploy (without constructor parameters), I run into other issues. Using --account it just stalls:

forge create src/OurToken.sol:OurToken --rpc-url $(ZKSYNC_SEPOLIA_RPC_URL) --account $(ACCOUNT) --legacy --zksync

Then, using a classic --private-key it is reverting with this:

(code: 3, message: ErrorObject { code: ServerError(3), message: "known transaction. transaction with hash 0xf6d5…61ca is already in the system", data: Some(RawValue("0x")) }, data: Some(String("0x")))

I think it's referring to 0x6dc3885772544909678fa470231d4a5b032d75742ca952eef3b537f6555954b7 which won't process. If I change the nonce with:

forge create src/OurToken.sol:OurToken --rpc-url $(ZKSYNC_SEPOLIA_RPC_URL) --account $(PRIVATE_KEY) --legacy --zksync --nonce 49

It just freezes again. Not sure if it's a sepolia issue.

Seems like the error code is wrong. It should say like "forgot constructor arguments."

It comes from the RPC node, and our implementation doesn't seem to differ much from original foundry when it comes to this. Perhaps we can add this improvement in the future :)


I think it's referring to 0x6dc3885772544909678fa470231d4a5b032d75742ca952eef3b537f6555954b7 which won't process.

Indeed I wasn't able to find that tx hash on the explorer, but on the output you gave the error seems to indicate a different hash? From the output above: transaction with hash 0xf6d5…61ca is already in the system . Do you still have that hash available for us to look at?

I was able to deploy a contract without params using --private-key, both on era-test-node and sepolia.
I did the same but with the --legacy cli argument just in case since I noticed you were using it.

I also tried with --account (imported with the same key I was using before), with and without --legacy.

Maybe I'm getting issues with the RPC again :/

Hey @PatrickAlphaC are you still encountering the issue?

I'm not. I will close.

I think the hard part is it's hard to tell when the RPC is having an issue vs when foundry-zksync is having an issue. Perhaps we just need to have a quick chat with quicknode/alchemy on why the endpoints are spotty.