hyperledger / besu

An enterprise-grade Java-based, Apache 2.0 licensed Ethereum client https://wiki.hyperledger.org/display/besu
https://www.hyperledger.org/projects/besu
Apache License 2.0
1.51k stars 828 forks source link

Free gas network: upfront cost exceeds account balance #5813

Closed gomezgoiri closed 1 year ago

gomezgoiri commented 1 year ago

Description

I want to deploy a smart contract in a free gas private network with Besu's latest stable version (23.7.1). Besu answers Upfront cost exceeds account balance error.

Acceptance Criteria

Steps to Reproduce (Bug)

I've found this error with many configurations (IBFT2, QBFT, different Besu versions), but here I'll describe the simplest way to reproduce it:

  1. Create a free gas network using Quorum-dev-quickstart: npx quorum-dev-quickstart@latest --clientType besu --orchestrate false --quorumKeyManager false --privacy false --monitoring none --blockscout false
  2. Edit .env file to use BESU_VERSION=23.7.1.
  3. (Optional, doesn't make a difference) Adjust the block size and contract size in the genesis file.
  4. Run the network: docker compose up -d
  5. Deploy a smart contract. To test it, you can use a sample Truffle project as suggested in the SC info section.

Expected behavior: Get information about the deployed contracts and their addresses.

Actual behavior: Truffle returns the following error: Upfront cost exceeds account balance.

Frequency: Always

Logs (if a bug)

I haven't identify any relevant logs in Besu.

In the current quorum-dev-quickstart Besu version (23.4.1) I saw this error, but it is apparently fixed.

Versions

Smart contract information

I've seen the error deploying many different smart contracts, but you could use this one to test it:

Configuration:

  1. Install dotenv and HDWalletProvider.
  2. Uncomment the two related lines in truffle-config.js
  3. Create a .env file with a property called DEPLOYER_MNEMONIC and a random mnemonic.
  4. Add the following network to truffle-config.js (with the recommended configuration guidelines or not, it doesn't make a difference).
  5. Run npx truffle migrate --network local
    local: {
      provider: () =>
        new HDWalletProvider({
          mnemonic: process.env.DEPLOYER_MNEMONIC,
          providerOrUrl: "http://localhost:8545", // "https://node1.ethereum.bclab.dev"
        }),
      network_id: "*",
    },
siladu commented 1 year ago

@gomezgoiri Can you share the actual genesis file that is being used please?

I suspect it's not got the "zeroBaseFee": true config, see https://besu.hyperledger.org/stable/private-networks/how-to/configure/free-gas#4-enable-zero-base-fee-if-using-london-fork-or-later

Note, the latest version of quickstart should have it already: https://github.com/Consensys/quorum-dev-quickstart/blob/master/files/besu/config/besu/QBFTgenesis.json#L14-L17

gomezgoiri commented 1 year ago

I haven't changed the genesis file.

By default, it takes the default genesis file you commented.

Anyway, if you change BESU_CONS_ALGO to IBFT it will use this one instead, with the same result.

So I'd say that either default genesis files in quorum-dev-quickstart are not ok, or the problem lies somewhere else.

joshuafernandes commented 1 year ago

Hi @gomezgoiri I've got an example of doing this as well as extending the contract for use in a DApp.

On version 0.2.3 of the quickstart look up the dapps/quorumToken folder. Docs here https://besu.hyperledger.org/development/private-networks/tutorials/quickstart#smart-contract-and-dapp-usage

Also would recommend using hardhat instead of truffle. I've used the genesis file as is with out mods

gomezgoiri commented 1 year ago

Hi @joshuafernandes , thanks for the reference.

So far I've been using Truffle without problems with other versions of Besu (actually, even with the current one if london fork is not added to the genesis file), but I'll consider to migrate to hardhat if it is the only way to avoid issue I described above.

siladu commented 1 year ago

So far I've been using Truffle without problems with other versions of Besu (actually, even with the current one if london fork is not added to the genesis file), but I'll consider to migrate to hardhat if it is the only way to avoid issue I described above.

@gomezgoiri Could you share the exact scripts/commands that are failing with truffle please so we can try to recreate? I believe the only issues we've seen so far have been with quickstart config/docs or the smart contract scripts. It is not clear there is an issue with Besu itself yet.

siladu commented 1 year ago

Could you share the exact scripts/commands that are failing with truffle please so we can try to recreate?

Maybe you already did in the description, in which case ignore this :)

@joshuafernandes can confirm but there might be an issue with the quickstart scripts when using solc 0.8+

gomezgoiri commented 1 year ago

@gomezgoiri Could you share the exact scripts/commands that are failing with truffle please so we can try to recreate?

As you said, I'd already shared the steps to reproduce it.

Anyway, I've recreated and uploaded the sample Truffle project for your convenience here.

For comparison, I've also added the Hardhat configuration to the project. Hardhat does allow to deploy the contract.

gomezgoiri commented 1 year ago

BTW, I'm also experimenting with Polygon Supernet over the same Besu gas zero network and I've experienced this Upfront cost exceeds account balance error too.

I was trying to send a transaction signed by an account with zero balance (note that rootchain fund sends a custom ERC20 token, not the native coin):

polygon-edge rootchain fund --private-key [priv-key-account-with-zero-balance]
99 --json-rpc http://10.0.0.11:8545 --addresses 0x77C1eedFf656477462ce16084fE5Dc7F8a2507B9 --amounts 1000 --
stake-token 0x67311C86194748CBb1F4f0d69E684Ab7FeE9C62E --mint

This new scenario is more complex for me to explain, but what I want to suggest is that this error might be affecting more tools than Truffle (in this case, polygon-edge).

joshuafernandes commented 1 year ago

Hi @gomezgoiri

Thanks for this, this is a really good data point to start off with. Could you confirm that you can deploy, read & write with hardhat? Also looks like you're using the latest solc 0.8.20 and hardhat is fine - this is consistent with what I've been seeing as well.

With truffle & web3 deploys appear to be on quite working right at the moment and we'll use your repo to look into things.

Cheers Josh

siladu commented 1 year ago

Anyway, I've recreated and uploaded the sample Truffle project for your convenience here.

@gomezgoiri Thanks for this, very helpful! I was able to recreate, think I know what's going on...

Attaching a couple of logs showing the RPC requests that are sent to besu by truffle and hardhat respectively.

besu-with-truffle.log besu-with-hardhat.log

Both call eth_estimateGas which I would expect to be non-zero since free gas networks still use gas, it's just the price is 0.

Hardhat calls eth_feeHistory before calling eth_sendRawTransaction with 0 set in the max/priority gas price params (I decoded the raw RLP using https://toolkit.abdk.consulting/ethereum#transaction)

whereas Truffle calls eth_gasPrice before eth_sendRawTransaction with non-zero set in the gas price params.

Besu allows zero-priced transactions through but will still attempt to spend ETH is the incoming transaction tells it to, hence the truffle error.

Now what's interesting is that for my quickstart network, both eth_gasPrice and eth_feeHistory return 0 for the price...

➜  quorum-test-network curl -X POST --data '{"jsonrpc":"2.0","method":"eth_gasPrice","params":[],"id":53}' http://127.0.0.1:8545
{
  "jsonrpc" : "2.0",
  "id" : 53,
  "result" : "0x0"
}

➜  quorum-test-network curl -X POST --data '{"jsonrpc":"2.0","method":"eth_feeHistory","params": ["0x5", "latest", [20,30]],"id":1}' http://127.0.0.1:8545
{
  "jsonrpc" : "2.0",
  "id" : 1,
  "result" : {
    "oldestBlock" : "0x3",
    "baseFeePerGas" : [ "0x0", "0x0", "0x0", "0x0", "0x0", "0x0", "0x0", "0x0", "0x0", "0x0", "0x0", "0x0", "0x0" ],
    "gasUsedRatio" : [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]
  }
}

Assuming that truffle is using eth_gasPrice to inform the transaction's price params, then it suggests to me that there's a bug in truffle because it's not respecting the "0x0" price response to eth_gasPrice and setting the gas price params to non-zero anyway.

siladu commented 1 year ago

Hi @gomezgoiri, does my previous comment answer your question and are you happy to close this issue?

gomezgoiri commented 1 year ago

Yes, @joshuafernandes I was able to deploy the project with Hardhat.

Thanks @siladu, I'll assume that it is a bug in Truffle (and possibly in polygon-edge) then. I'll check their issues and open a new one there if nobody has raised the flag yet. It is ok for me if you close this one.