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

sendTransaction throws too much gas on contract to contract transactions. #316

Closed
kyriediculous opened this issue Oct 17, 2018 · 5 comments
Assignees

Comments

@kyriediculous
Copy link

Hi , It's me again possibly with a real issue this time. 😄

In my contract I have functions that call external contracts, these should work fine. I don't have any issues with ethers v3 using these contracts in my client app.

My deploy script (from my previous issue) uses ethers v4, and whenever I call such a function I get an error from estimateGas inside sendTransaction:

responseText:
   '{"jsonrpc":"2.0","id":42,"error":{"code":-32000,"message":"gas required exceeds allowance or always failing transaction"}}\n' }

If I then add a gasLimit it works, so my guess is estimateGas is calculating the transaction to use inifinite gas:
//This works! await controller.setOrganisationController(ethers.utils.formatBytes32String('DiD'), '0x'+controllerProfile, {gasPrice: '0x0', gasLimit: ethers.utils.hexlify(8000000)})

Additionally on calls to constant functions that work the same way I'm getting call exceptions:


{ Error: call exception (address="0x4f54Cad459F3B3e198b9de49edA33511513e1dFc", method="getUser(address)", args=["0x4f54Cad459F3B3e198b9de49edA33511513e1dFc"], version=4.0.7)
    at Object.throwError (/home/nico/Documents/knuckles-app/contracts/node_modules/ethers/errors.js:76:17)
    at /home/nico/Documents/knuckles-app/contracts/node_modules/ethers/contract.js:184:36
    at process._tickCallback (internal/process/next_tick.js:68:7)
  reason: 'call exception',
  code: 'CALL_EXCEPTION',
  address: '0x4f54Cad459F3B3e198b9de49edA33511513e1dFc',
  method: 'getUser(address)',
  args: [ '0x4f54Cad459F3B3e198b9de49edA33511513e1dFc' ] }

Here I can not add a gasLimit, because I can't override the gasLimit for calls.

Error: call cannot override gasLimit
    at /home/nico/Documents/knuckles-app/contracts/node_modules/ethers/contract.js:156:31
    at Array.forEach (<anonymous>)
    at /home/nico/Documents/knuckles-app/contracts/node_modules/ethers/contract.js:154:51
    at process._tickCallback (internal/process/next_tick.js:68:7)

This getter for example works perfect

console.log(await controller.admins(wallet.address))

I haven't had this issue with these contracts with ethers 3.0.0 before.

I want to check if it is perhaps my blockchain config (which I doubt , because it works with truffle migrations thought) but when trying to use ganache with my ethersjs deploy script I'm getting:

Error: Error: Transaction hash mismatch from Provider.sendTransaction. (expectedHash="0x355c8da2822e2d69c0d95ba2a25a6cc79d71608a46ca112476ea2025ec645a1d", returnedHash="0xe1f40a4dbf302d22355881c287b5c13f2b4094a9f7fbaf6cb188eee701bd80fe", version=4.0.7)
    at deploy (/home/nico/Documents/knuckles-app/contracts/migrations/2_deploy.js:31:11)
    at process._tickCallback (internal/process/next_tick.js:68:7)
@ricmoo
Copy link
Member

ricmoo commented Oct 17, 2018

I do indeed block gasLimit on constant calls, but you are right, perhaps I shouldn’t? Although it really shouldn’t be necessary. Maybe I’ll pull the gasEstimate for constant calls.

The reason this never happened on v3 though, is because v3 always hard-coded the gasLimit to 1.5 million, which led to lots of other issues (e.g “insufficient funds”, if you had enough for 1.3 million gas, and were calling a contract that would only require 34,000).

Your problem is certainly caused by estimateGas returning too high a value; for some reason it has guessed your tax will fail. Is there any reason the function might throw? Maybe the from or value is not being forwarded properly? Can you post the function code? Also, which provider is it using?

@ricmoo ricmoo added the investigate Under investigation and may be a bug. label Oct 17, 2018
@ricmoo ricmoo self-assigned this Oct 17, 2018
@kyriediculous
Copy link
Author

kyriediculous commented Oct 17, 2018

I think the true problem lies with geth, that it calculates more gas than actually needed.

That being said perhaps if estimateGas errors it should let gas use the default which would be the block gas limit of the pending block. In reference to the JSON-RPC documentation:

eth_estimateGas

Generates and returns an estimate of how much gas is necessary to allow the transaction to complete. The transaction will not be added to the blockchain. Note that the estimate may be significantly more than the amount of gas actually used by the transaction, for a variety of reasons including EVM mechanics and node performance.
Parameters

See eth_call parameters, expect that all properties are optional. If no gas limit is specified geth uses the block gas limit from the pending block as an upper bound. As a result the returned estimate might not be enough to executed the call/transaction when the amount of gas is higher than the pending block gas limit.

I'm sure the calls don't exceed the block gas limit.

I'm using the jsonRpcProvider with our own clique POA chain. The genesis is configured to have a block gas limit of 16 million even.

  function setOrganisationController(bytes32 _name, bytes32 _profile) external isAdmin {
    Users(ContractProvider(CMC).contracts("users")).register(_name, _profile, address(this));
  }

which calls (I've even commented the require statement to make sure)

  function register(bytes32 _name, bytes32 _profile, address _sender) isEnabled("controller") external {
    //require(users[_sender] == bytes32(0) );
    users[_sender] = _profile;
    ens[_name] = _sender;
    emit logRegister(_name, _sender, _profile);
  }

@eduardonunesp
Copy link

Here on my project, sometimes the transaction works and sometimes the transaction fail with actions.js?03bd:71 Error: JsonRpcEngine - response has no error or result for request: { "method": "eth_estimateGas", "params": [ { "gasPrice": "0x3b9aca00", "from": "0xC3dFc9282BF68DFAd041a04a0c09bE927b093992", "to": "0xd028e13a0b17E4B758B003a793cb6F0F6531Ba75", "data": "0x392d661c000000000000000000000000000000000000000000000000016345785d8a00000000000000000000000000009682fdfa17003f9126d70294ea9e90e76ba113b7" } ], "id": 1219216365, "jsonrpc": "2.0" }

@RyRy79261
Copy link

Experiencing the same issue, sending a TX that usually sets 85548 and uses 42774 yet I'm getting an estimation error of over 7 mil

@ricmoo
Copy link
Member

ricmoo commented Jun 3, 2020

I think this issue is stale, and has been addressed in v5 by allowing the gasLimit to be overridden. If not though, please re-open.

Thanks! :)

@ricmoo ricmoo closed this as completed Jun 3, 2020
@ricmoo ricmoo removed the investigate Under investigation and may be a bug. label Oct 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants