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

Incorrect behavior of fakeBlockChain.prototype.getBlock #446

Closed
alcuadrado opened this issue Feb 21, 2019 · 10 comments
Closed

Incorrect behavior of fakeBlockChain.prototype.getBlock #446

alcuadrado opened this issue Feb 21, 2019 · 10 comments

Comments

@alcuadrado
Copy link
Member

alcuadrado commented Feb 21, 2019

Hi,

I'm pretty sure there's a bug here: https://github.com/ethereumjs/ethereumjs-vm/blob/master/lib/fakeBlockChain.js#L10

In my experience, using a VM instance without skipping validation will call this function with block hashes, so it's hashing the hash. hash should be blockTag.

Of course, the validation process fails anyway, but that incorrect implementation of getBlock is confusing, especially when debugging and seeing strange block hashes.

@alcuadrado
Copy link
Member Author

@s1na
Copy link
Contributor

s1na commented Feb 22, 2019

Haven't looked deeply, but generally fakeBlockchain should be avoided apart from unit testing or something. Would you maybe like to submit a PR if you think there's a bug?

@holgerd77
Copy link
Member

@s1na Hmm, fakeBlockchain is currently used as the default blockchain if no blockchain is passed, so I think it's problematic if we advice to avoid since this is not really transparent from the outside.

I am actually not really aware why fakeBlockchain was introduced in the first place and what is the main purpose? Was this rather functionality or performance-guided? Couldn't this behavior taken from the blockchain class directly? This would probably also avoid compatibility problems if blockchain and fakeBlockchain behavior diverge.

@alcuadrado
Copy link
Member Author

@s1na Hmm, fakeBlockchain is currently used as the default blockchain if no blockchain is passed, so I think it's problematic if we advice to avoid since this is not really transparent from the outside.

That's how I found this issue. I wasn't passing any blockchain to the VM, and running a block without skipping validations. That resulted in a crash, and when trying to debug it, the block hashes that the VM saw were completely different from the ones of the blocks I was creating.

@s1na
Copy link
Contributor

s1na commented Feb 22, 2019

@holgerd77 What do you think about removing it? or moving it to the tests/ dir, where it can be used as a mock object?

@holgerd77
Copy link
Member

What would you do on VM instantiation? Create a normal blockchain object as default?

@holgerd77
Copy link
Member

Again: are you aware why this was introduced compared to using blockchain?

@s1na
Copy link
Contributor

s1na commented Feb 22, 2019

No, I'm also not sure why it was introduced. Git history shows this commit to have added fakeBlockchain as a default.

Yeah, if no blockchain was provided, create a new normal instance. If however blockchain has to be provided by the user, we could alternatively throw an error if none was provided (but what you suggested is probably the better approach).

@holgerd77
Copy link
Member

Ok, then let's remove but also let's be a bit cautious here.

Circling @vpulim and @axic, your guys comments would be helpful for some confirmation.

@holgerd77
Copy link
Member

Fixed by #466, will close.

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.

4 participants