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

VM: address consensus issue: tx goes OOG but refunds get applied anyways #1603

Merged
merged 9 commits into from
Dec 11, 2021

Conversation

jochem-brouwer
Copy link
Member

@jochem-brouwer jochem-brouwer commented Dec 10, 2021

Closes #1601, closes #1604

@codecov
Copy link

codecov bot commented Dec 10, 2021

Codecov Report

Merging #1603 (8147f25) into master (bffbc03) will increase coverage by 0.04%.
The diff coverage is 100.00%.

Impacted file tree graph

Flag Coverage Δ
block 84.96% <ø> (ø)
blockchain 85.08% <ø> (ø)
client 70.89% <ø> (ø)
common 100.00% <ø> (ø)
devp2p 83.17% <ø> (+0.13%) ⬆️
ethash ∅ <ø> (∅)
trie 86.09% <ø> (ø)
tx 88.62% <ø> (ø)
util 91.81% <ø> (ø)
vm 79.79% <100.00%> (+0.08%) ⬆️

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

@jochem-brouwer jochem-brouwer added the type: test all hardforks This special label enables VM state and blockchain tests for all hardforks on the respective PR. label Dec 10, 2021
@jochem-brouwer
Copy link
Member Author

This doesn't work, will stop here for now. The problem seems to be that we revert to old refund here, but this does not catch all errors which are not caught in this scope; if anything happens which makes a message scope revert then the entire refund should be forfeited.

@jochem-brouwer
Copy link
Member Author

CC @winsvega we have encountered an consensus bug in this PR which is not covered in ethereum/tests. I will write up a more detailed explanation later on, if I forget please remind me.

@winsvega
Copy link

Hm, should be covered, lets check

@jochem-brouwer
Copy link
Member Author

Here's the problem.

We check if there's an execution error in runInterpreter and if thats the case we reset the refund counter to the previous refund counter here.

This is all fine if we don't do additional error checks afterwards. For call frames, we dont do this, however, for create frames we do this and here lies the problem. In case that we throw an error over there, then we don't reset the refunds. Note that any error down the runInterpreter should be caught.

NOTE: there might be an uncovered edge case as well, in run interpreter in case of an error we also reset;

      // Clear the result on error
      result = {
        ...result,
        logs: [],
        selfdestruct: {},
      }

We might have to check what happens in case that in case we dont have enough gas to pay for code deposit, if we also revert the selfdestruct / logs correctly.

acolytec3
acolytec3 previously approved these changes Dec 10, 2021
Copy link
Contributor

@acolytec3 acolytec3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. One nigly change in the wording for the test to clarify what's happening that you can take or leave but awesome work getting a fix so quickly!

packages/vm/tests/api/runTx.spec.ts Outdated Show resolved Hide resolved
gabrocheleau
gabrocheleau previously approved these changes Dec 10, 2021
Copy link
Contributor

@gabrocheleau gabrocheleau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

Co-authored-by: acolytec3 <17355484+acolytec3@users.noreply.github.com>
@jochem-brouwer
Copy link
Member Author

ethereum/tests#1003 has found that the possible selfdestruct bug as described in #1605 is also present, will fix here. We probably also have the issue in #1605 with logs.

…pcoming ethereum/tests CreateOOGFromEOARefunds_d13g0v0)
@acolytec3
Copy link
Contributor

@jochem-brouwer So do we need to add some additional tests for these other cases regard logs/self-destruct?

@jochem-brouwer
Copy link
Member Author

I could add tests, but since these test cases which I want are covered in the ethereum-tests PR linked above, I'd say that I run that branch locally, verify that the relevant tests pass, and then once there's a new ethereum-tests release we integrate it, which then implicitly means that the relevant tests which were failing before this PR then pass. The relevant selfdestruct test passes.

@jochem-brouwer
Copy link
Member Author

Okay, ethereum/tests#1003 now has tests for both selfdestructs and logs into the contract creation context for cases where (0) contract gets deployed succesfully, (1) contract goes OOG due to invalid opcode, and (2) contract goes OOG because execution finishes but there is not enough gas left to deploy the code.

Tests now pass after 2f33d13. We had the selfdestruct vulnerability, we did not have the log vulnerability.

@jochem-brouwer jochem-brouwer marked this pull request as ready for review December 10, 2021 21:56
Copy link
Contributor

@ryanio ryanio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

amazing speed and execution on this, thank you everyone! lgtm

@ryanio ryanio merged commit 22bc187 into master Dec 11, 2021
@ryanio ryanio deleted the check-refund branch December 11, 2021 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: vm PR state: needs review type: bug type: test all hardforks This special label enables VM state and blockchain tests for all hardforks on the respective PR.
Projects
None yet
5 participants