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

runBlock gives less gasUsed than runTx #64

Closed
asinyagin opened this issue May 20, 2016 · 16 comments
Closed

runBlock gives less gasUsed than runTx #64

asinyagin opened this issue May 20, 2016 · 16 comments

Comments

@asinyagin
Copy link
Contributor

Hi,

As I see, runBlock() gives wrong gasUsed while runTx() uses correct number of gas. Here's how to reproduce it: https://github.com/asinyagin/ethereumjs-test/blob/master/app.js . The app prints:

root@982421ef3b07:~/ethereumjs-test# node app.js 
tx: 5a24e
block: 05254e
@axic
Copy link
Member

axic commented May 20, 2016

Does runTx gives the correct number compared to geth/ethereumj? And do you see a consistent difference between the two when running with other examples or is random?

@asinyagin
Copy link
Contributor Author

yeah, the live network uses the same number of gas as runTx

@axic
Copy link
Member

axic commented May 20, 2016

The difference seems to be 32000 which is the cost of CREATE. There might be something off in block vs. tx regarding deploying a contract. Are you calling CREATE from your code?

cc @wanderer

@wanderer
Copy link
Member

so to recap I bet this is also the creation cost of a precompiled. @axic added an option to active the precompiles @asinyagin can you give that a try?

@asinyagin
Copy link
Contributor Author

asinyagin commented May 23, 2016

@axic I'm not sure. That's Ballot contract from https://ethereum.github.io/browser-solidity/#version=soljson-latest.js compiled with solc 0.3.0 with constructor parameter 10.

@asinyagin
Copy link
Contributor Author

asinyagin commented May 23, 2016

@wanderer it gives the same gasUsed (the wrong one) with the key. Is the code correct? https://github.com/asinyagin/ethereumjs-test/blob/master/app.js#L37

@danfinlay
Copy link

I'm also experiencing out of gas errors, I think it may be related to this. Particularly, I'm getting OOG errors on transactions estimated by testrpc (which relies on ethereumjs-vm).

The bug is documented on the testrpc github here and includes a test case.

kumavis referenced this issue in MetaMask/web3-provider-engine May 30, 2016
@danfinlay
Copy link

Even better and more specific reproduction steps in this testrpc issue, #96.

@kumavis
Copy link
Member

kumavis commented Jun 2, 2016

playing out the repro here with some deeper logging trufflesuite/ganache-cli-archive#96
while the trace is exactly the same, the gas calc divergence can be seen near the end https://www.diffchecker.com/7w3djc6a
the logging is a little confusing... +3 is gas used, resulting number is remaining gas (limit - used)

some how 4683971-3 = 4663968 (off by 20000) but only in runBlock and not in estimateGas

wat

@wanderer
Copy link
Member

wanderer commented Jun 2, 2016

@kumavis so its messing up on the SSTORE on line 148

@kumavis
Copy link
Member

kumavis commented Jun 2, 2016

ah ok
somehow the dynamic cost is calc'd wrong

@kumavis
Copy link
Member

kumavis commented Jun 2, 2016

© 2015 DiffChecker, Inc.

lel

@kumavis
Copy link
Member

kumavis commented Jun 2, 2016

turns out my issue was unrelated -- was an issues in testrpc's provider-engine trufflesuite/ganache-cli-archive#96

@wanderer
Copy link
Member

wanderer commented Jun 2, 2016

@asinyagin The problem is here https://github.com/asinyagin/ethereumjs-test/blob/master/app.js#L75 There is a cost difference between homestead and pre-homestead to create an account. By default tx's are homestead, but by setting the block number to 0 you force it to run as pre-homestead.

I added a check in 475143f that should fix teh problem if you give the VM the option opts:{enableHomestead: true}

@wanderer
Copy link
Member

wanderer commented Jun 4, 2016

@asinyagin please reopen if this if its still an issue

@wanderer wanderer closed this as completed Jun 4, 2016
@asinyagin
Copy link
Contributor Author

@wanderer thanks! it works great

evertonfraga added a commit to evertonfraga/ethereumjs-vm that referenced this issue Feb 25, 2020
holgerd77 added a commit to holgerd77/ethereumjs-vm that referenced this issue Nov 30, 2020
holgerd77 pushed a commit that referenced this issue Dec 1, 2020
holgerd77 pushed a commit that referenced this issue Mar 11, 2021
ryanio pushed a commit that referenced this issue Jan 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants