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

Generate receipt roots in runBlock #1037

Closed
wants to merge 1 commit into from
Closed

Conversation

alcuadrado
Copy link
Member

Hey guys,

We found a bug in Hardhat network yesterday, that IMO is a bug in ethereumjs-vm, so I fixed it :)

I think that if a user calls vm.runBlock with the generate: true, is because they don't want to validate the block but to modify the state and update (generate) the fields of the block header that can only be computed after executing the txs. If this is the actual intention, then block.header.receiptTrie was missing.

This PR just updates that header field, and adds a test for it.

Also, as you can see in the test, using runBlock with generate: true is really really inconvenient. I don't get why the new Block wasn't added to RunBlockResult. You can only access it with an event listener. The good news is that adding it is a backwards compatible change. Should I create a PR doing it?

@codecov
Copy link

codecov bot commented Jan 9, 2021

Codecov Report

Merging #1037 (8916a0c) into master (b1bcb03) will increase coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

Flag Coverage Δ
block 77.65% <ø> (ø)
blockchain 77.92% <ø> (ø)
client 88.27% <ø> (-0.10%) ⬇️
common 91.87% <ø> (ø)
devp2p 82.77% <ø> (+0.16%) ⬆️
ethash 82.08% <ø> (ø)
tx 86.25% <ø> (ø)
vm 83.05% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

@alcuadrado
Copy link
Member Author

btw, I loved these lines updating the block @ryanio https://github.com/ethereumjs/ethereumjs-vm/pull/1037/files#diff-31eaac2b514be99694029f78d9049fe0c99a28d5bb01060644fee69fbe203926R172-R175

@holgerd77
Copy link
Member

@alcuadrado thanks for the PR, did you guys update to VM v5 and so will you get the update on a normal release? If so, how were your update experiences?

@alcuadrado
Copy link
Member Author

Not yet, I also fixed it in a v4 fork. We are currently on holiday seasons, so won't be able to migrate this month. I'll report our experience doing it.

@jochem-brouwer
Copy link
Member

jochem-brouwer commented Jan 9, 2021

Great find - you are indeed right that the receiptsRoot should also be generated, but also the field gasUsed and logsBloom should be generated - right?

You are also right that runBlock is very annoying for this use case. However, we have an issue (#1018) which proposes a new static method which actually handles this generating stuff. I think I'm in favor of that - it makes more sense to call some method like generateBlock (I don't think this is the best name for the method though, maybe something like generateBlockFields?) which handles setting these 4 vars (stateRoot, gasUsed, logsBloom and receiptsRoot) and returns the actual "verified" block.

Also this PR #974 is relevant.

@oozan
Copy link

oozan commented Mar 24, 2021

@ryanio ryanio deleted the generate-receipt-roots branch October 28, 2021 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants