-
Notifications
You must be signed in to change notification settings - Fork 264
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
Fallback function reverts without an apparent reason #487
Comments
Here is one workaround that I just found: Update - I have confirmed the above by running:
And then:
The first one gives 1973, while the second one gives 2000, which means that the first one has consumed 27 gas units more than the second one. I am guessing that the transaction was just on the brinks of exceeding the gas stipend provided to the fallback, and with SC's additional events, it has exceeded that point. |
Thanks for reporting and for describing the work-around. testrpc-sc sets an |
@cgewecke :
|
Oh yes, agree. Something's not working as expected in that version of testrpc-sc. |
Any chance it could be fixed on 0.6.x, or am I the only one left using it? |
Actually, @barakman on second glance - I'm not sure you'd be better off with 0.7.x or that much can be done with testrpc-sc. You're very close to the wire there - basically 327 gas? I think you're getting free events but might be incurring opcode charges for setting them up or something. A single LOG is 375 plus topics at 375 each and SC is injecting 5 in that function which should take you way over 2300. 0.7.x would likely still fail here - its instrumentation statements cost ~114 gas each. Very sorry about this. There are things about the way SC works which are fundamentally not great, esp in tight gas conditions. |
@cgewecke : Thanks. As I wrote above - "I am guessing that the transaction was just on the brinks of exceeding the gas stipend provided to the fallback, and with SC's additional events, it has exceeded that point". That said, I think your interpretation of me being "very close to the wire there - basically 327 gas" actually implies that I'm not that close to the wire, since I spend only 327 out of 2300 available. In addition to that, you're also suggesting that the 5 events injected by SC consume an additional amount larger than 1973, leading the function to exceed the stipend. However, 5 events times 375 per event equals 1900, so that doesn't quite explain it (since 327 + 1900 < 2300). I believe that the actual formula for the gas consumption of an event is:
In which case, the function should have reverted even after applying my workaround. So while your analysis fails to explain why the original transaction reverts, my analysis fails to explain why the workaround allows the transaction to complete successfully. I guess I might be missing something here (or perhaps the formula above is incorrect). In any case, to my understand, there is not much that you can do about it... is that correct? |
@barakman I've misunderstood what's in the original fallback. I thought you had an event in there and the code below costs 1973 on ganache-cli, so you'd only have a few hundred gas left.
Let me investigate what it would take to get an 0.7.x script working on your repo sometime in the next few days. I think that's probably the best option for the long term since you will be able to use any ganache-cli with it and be synced with updates etc. Is the repo/branch you're working on https://github.com/bancorprotocol/contracts at |
@cgewecke : It's actually in this ongoing branch, so there could be some changes ahead, but most likely not around the related area. Running SC on it may take about an hour if not more, so you may want to delete all tests except for the one relevant to this issue (as well as the two folders under the same path). Moreover, this test scans through many use-cases before finally reaching the one which would cause a problem without my workaround. So you may want to "strip them out" by changing this line to:
Then, in order to actually make the transaction revert, you'll need to undo my workaround, by replacing the current I recommend that you add a message in the (new) Thank you for helping out :) |
I am trying to execute a transaction in which a contract function transfers ether to another contract, thus invoking the other contract's fallback function:
When running
truffle test
, the transaction completes successfully.When running
solidity-coverage
, the transaction reverts at the fallback function.As you can imagine, it took me a very long time to formulate this conclusion.
And how did I formulate that conclusion?
First, I changed the fallback function to this:
Where the transaction has reverted with a
revert 7777777
message in both Truffle and SC.Then, I changed it to this:
Where the transaction has reverted with a
revert
message only in SC.Finally, I changed it to this:
Where the transaction has completed successfully in both Truffle and SC.
My guess is that it exceeds the gas stipend (2300) because of the event-emitting that SC injects to it:
I am using:
Any thoughts or ideas how to workaround this?
Thanks
The text was updated successfully, but these errors were encountered: