Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

I "succeeded" to hang Ganache #647

Closed
vporton opened this issue Oct 7, 2020 · 4 comments
Closed

I "succeeded" to hang Ganache #647

vporton opened this issue Oct 7, 2020 · 4 comments

Comments

@vporton
Copy link

vporton commented Oct 7, 2020

Bug description

The software at https://github.com/vporton/eth-tokens-sum/tree/hangs-ganache consistently hangs Ganache.

Notes

I start Ganache with npx ganache-cli -d, then run npx buidler test --network ganache.

Then after a few hundereds or so iterations of my software's loop Ganache hangs (no more reacts to queries, cannot be exited with Ctrl+C, only with Ctrl+Z and kill).

Note that my software uses a random number generator. To make the test fully repriseable, need to seed it with a fixed value. However, every time I ran this test, Ganache hanged.

Also note that Buidler instead produces a weird out-of-gas error. (I suspect it has a common codebase with Ganache and this is essentially the same bug.)

Your Environment

  • Version used: Ganache CLI v6.11.0 (ganache-core: 2.12.1)
  • Operating System and version: Ubuntu 20.04.1
@davidmurdoch
Copy link
Member

My hunch is that the _balanceOf function in SumOfTokens.sol is getting stuck in an infinite loop (well... until it runs out of gas).

Ganache's default gasLimit for calls is 0x1fffffffffffff (Number.MAX_SAFE_INTEGER). (I know it is weird to have an limit for eth_call, but this upper bound allows for easy prevention of a class of DoS attacks on real nodes.) Buidler's upper bound is probably much lower than ganache's, which is why it fails with OOG. My hunch is either a) ethereumjs-vm can't perform the arithmetic on Number.MAX_SAFE_INTEGER, so it just isn't decreasing as it should, or b) you just haven't waited long enough for it to run out of gas :-).

If you pass a gasLimit to your eth_calls, (e.g., const result = await sumOfTokens.balanceOf(to.address, t, { gasLimit: 85000});) you'll get OOG errors with ganache, too.

I've run the transfer.js tests against my development ganache-cli and logged the gas usage, and it is decreasing, it just takes a very long time to go from 9007199254740991 to 0...in my testing (with logging and with a debugger attached ... which does make things much slower) gasLeft decreases 1,000,000 gas every ~10 seconds, which means it will take about 3,000 years to run out of gas... if I did the math correctly, of course :-).

@vporton vporton closed this as completed Oct 7, 2020
@davidmurdoch
Copy link
Member

@vporton did you figure out the issue?

@davidmurdoch davidmurdoch transferred this issue from trufflesuite/ganache-ui Oct 7, 2020
@vporton
Copy link
Author

vporton commented Oct 7, 2020

@vporton did you figure out the issue?

First you were right, there was an infinite loop in my contract. Second after much debugging (just two minutes ago), my test now runs without errors.

@davidmurdoch
Copy link
Member

Good to hear! Good luck on the bounty!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants