Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eth_estimateGas and eth_call error if a non-zero value is specified without a funded from address #2869

Closed
tkporter opened this issue Nov 29, 2023 · 5 comments · Fixed by #2856

Comments

@tkporter
Copy link

System information

zkEVM Node version: v0.0.X-RCXX - unknown, whatever https://zkevm-rpc.com is using
OS & Version: Windows/Linux/OSX - OSX
Commit hash : (if develop)
Network: Mainnet/Testnet - mainnet

Expected behaviour

I should be able to estimate gas when calling a payable function with some value. For example, making an eth_estimateGas RPC against my smart contract at 0xaad207a0Fd7a4e3C927Ccc78ac8134baF586B852 and calling the sendHelloWorld function with 0.01 ETH should give me a non-error output

However it complains presumably because the default account used for eth_estimateGas is assumed to have a balance of 0:

$ cast estimate 0xaad207a0Fd7a4e3C927Ccc78ac8134baF586B852 'sendHelloWorld(uint32,string)' 43114 'Hello!' --rpc-url https://zkevm-rpc.com --value $(cast tw 0.01)
Error:
(code: -32000, message: insufficient funds for gas * price + value, data: None)

If I explicitly specify a from address with a balance, all is fine:

$ cast estimate 0xaad207a0Fd7a4e3C927Ccc78ac8134baF586B852 'sendHelloWorld(uint32,string)' 43114 'Hello!' --rpc-url https://zkevm-rpc.com --value $(cast tw 0.01) --from 0x5fb02f40f56d15f0442a39d11a23f73747095b20
214815

This is not expected behavior - all other EVM compatible chains work when estimating gas w/ value even without specifying the from address. For example, calling my same smart contract on Ethereum:

$ cast estimate 0x7ff2bF58C38A41AD7C9CbC14e780e8a7EDBbd48D 'sendHelloWorld(uint32,string)' 43114 'Hello!' --rpc-url https://rpc.ankr.com/eth --value $(cast tw 0.01)
171203

Actual behaviour

:(

$ cast estimate 0xaad207a0Fd7a4e3C927Ccc78ac8134baF586B852 'sendHelloWorld(uint32,string)' 43114 'Hello!' --rpc-url https://zkevm-rpc.com --value $(cast tw 0.01)
Error:
(code: -32000, message: insufficient funds for gas * price + value, data: None)

Steps to reproduce the behaviour

Use cast as done above, or manually construct the eth_estimateGas using the params specified

Backtrace

n/a

When submitting logs: please submit them as text and not screenshots.

@tkporter
Copy link
Author

Similar error if you just try an eth_call :(

$ cast call 0xaad207a0Fd7a4e3C927Ccc78ac8134baF586B852 'sendHelloWorld(uint32,string)' 43114 'Hello!' --rpc-url https://zkevm-rpc.com --value $(cast tw 0.01)
Error:
(code: -32000, message: failed to execute the unsigned transaction, data: None)

@tkporter tkporter changed the title eth_estimateGas errors if value is specified without a from address eth_estimateGas and eth_call error if a non-zero value is specified without a funded from address Nov 29, 2023
@tclemos tclemos self-assigned this Nov 30, 2023
@tclemos tclemos added this to the v0.4.3 milestone Nov 30, 2023
@tclemos
Copy link
Contributor

tclemos commented Nov 30, 2023

hi @tkporter thanks for sharing this, I'll talk to the team internally and see how we can manage this.

@tclemos
Copy link
Contributor

tclemos commented Nov 30, 2023

hi @tkporter, we have discussed internally and looks like the behavior is working as expected, I'll explain:

The estimateGas call indeed checks (prior to execution) the sender balance to have enough funds to execute the transaction.

On Mainnet, when a From address is not specified while estimating gas or performing a call, the default sender address is set to 0x000..000, but if you check here you will see this address has a lot of funds: https://etherscan.io/address/0x0000000000000000000000000000000000000000

On zkEVM our default sender address is 0x111...111 and the logic is exactly the same, the difference is that this address has no funds, as you can see it here: https://zkevm.polygonscan.com/address/0x1111111111111111111111111111111111111111

As you already have mentioned, when you specify a From address that has enough balance to pay for the transfer, it works, and this is exactly what you need to do in order to perform this operation.

@tclemos tclemos closed this as completed Nov 30, 2023
@tkporter
Copy link
Author

wow that's wild! sorry for the false alarm. we run infrastructure on pretty much all the big EVM chains (mainnets & testnets) and have never ran into this before

For posterity, I tried overriding the address(0) balance on eth to be 0 just to confirm, and this is true:

$ cast rpc eth_call --raw '[{"data":"0x13b1f1ff000000000000000000000000000000000000000000000000000000000000a86a0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000648656c6c6f210000000000000000000000000000000000000000000000000000", "to": "0x7ff2bF58C38A41AD7C9CbC14e780e8a7EDBbd48D", "value": "0x2386f26fc10000" }, "latest", { "0x0000000000000000000000000000000000000000": { "balance": "0x0" } } ]' --rpc-url https://rpc.ankr.com/eth
Error:
(code: -32000, message: err: insufficient funds for gas * price + value: address 0x0000000000000000000000000000000000000000 have 0 want 10000000000000000 (supplied gas 150000000), data: None)

@tkporter
Copy link
Author

tkporter commented Nov 30, 2023

Btw, one of the more surprising things is we started running into this a couple days ago for the very first time, but previously had no issues. Unsure if a recent node upgrade could be the reason or what

Edit: figured this out, was something on our side :)

tkporter added a commit to hyperlane-xyz/hyperlane-monorepo that referenced this issue Dec 1, 2023
…hains to match addresses in MultiProtocolApp (#3001)

### Description

Fixes 2 issues:
1. Estimates gas in Kathy by explicitly specifying the `from` address
due to this bug with PolygonZkEvm when using a non-zero value
0xPolygonHermez/zkevm-node#2869
2. Now that we've added neutron & mantapacific as mainnet chains but we
don't have helloworld deployments on these chains, Kathy was trying to
send to & from these chains. To fix, I changed the constructor of
`MultiProtocolApp` to intersect the multiProvider to only work with the
chains specified in `addresses`

### Drive-by changes

n/a

### Related issues

n/a

### Backward compatibility

ye

### Testing

Ran kathy locally successfully & sent from polygonzkevm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants