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

Fix rinkeby consensus bug #1094

Closed
wants to merge 5 commits into from
Closed

Conversation

jochem-brouwer
Copy link
Member

Related: #1090

Pretty dirty PR, but setups a test which setups the right context. What is very strange is that, when comparing traces, the gas used and the stack operations are all good. Except the state root is not correct in the end..?

The only thing I can think of is either (1) the miner is paid an incorrect amount or (2) the deposited code is not right (so there's an issue in memory).

@jochem-brouwer
Copy link
Member Author

CC @holgerd77

@codecov
Copy link

codecov bot commented Feb 11, 2021

Codecov Report

Merging #1094 (9fac0e2) into master (7c4c5b9) will increase coverage by 0.38%.
The diff coverage is 89.62%.

Impacted file tree graph

Flag Coverage Δ
block 81.22% <100.00%> (ø)
blockchain 83.44% <ø> (ø)
client 86.88% <88.33%> (-0.13%) ⬇️
common 86.34% <ø> (ø)
devp2p 84.56% <100.00%> (+0.55%) ⬆️
ethash 82.08% <ø> (ø)
tx 91.93% <100.00%> (+1.93%) ⬆️
vm ?

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

@jochem-brouwer
Copy link
Member Author

Just checked, return value is also right. I have no idea what is going on here. Are we sure that we are on the right hard fork in this block?

@jochem-brouwer
Copy link
Member Author

Will stop here. This is a very weird situation. I have no idea what's going on 🤔

@jochem-brouwer
Copy link
Member Author

Ah, I think I see the problem! The created address as reported by our VM is 0xe962... but the actual created address is 0xa5b2...

Does clique have a different way to calculate contract addresses? @holgerd77

@holgerd77
Copy link
Member

@jochem-brouwer no. The only changed thing in respective to addresses is the COINBASE opcode returning the active signer for clique.

@jochem-brouwer
Copy link
Member Author

Where does this state root come from? 135fae6d4909a072d77707a797769afc72f6239a72173e0f411c7700af66ac26

Account has nonce 1 when we do the transaction (should be 0) (on above's state root). How come VM does not throw when we run this block? It should see that it cannot execute the transaction; transaction in the block has nonce 0, but the DB has nonce 1, so VM should not execute the transaction, otherwise we can replay transaction on the VM?

const trie = new Trie(stateDB)
const stateManager = new DefaultStateManager({ trie, common })
// Ensure we run on the right root
stateManager.setStateRoot(Buffer.from('135fae6d4909a072d77707a797769afc72f6239a72173e0f411c7700af66ac26', 'hex'))
Copy link
Member Author

Choose a reason for hiding this comment

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

If I change this to:

        // Ensure we run on the right root
        stateManager.setStateRoot(Buffer.from('0c8c521bd9c5272533db5ec1c9f73a6c727e343005f8a5c61e197d2953c0e165', 'hex'))

(This is the state root of block 14181). Then the test passes... (Valid receipt trie, valid root, etc.) There seems to be something going wrong with setting the state root somewhere? It seems to set the state root wrong at some point? My gut says that this might have to do with a bug in clique somewhere? @holgerd77

Copy link
Member

Choose a reason for hiding this comment

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

I can't follow the argumentation, if you set the state root to the wrong state root (or am I missing something here?) then the test passes, does this say anything (except that it is really the state root that is wrong?)? 🤔 This can still be anything leading to a state root failure.

Please correct me if I am missing the point.

Copy link
Member Author

Choose a reason for hiding this comment

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

This 0x0c8c... is the state root of block 14181. I don't know where this original 0x135f... root comes from? I also forgot if I copied some of your code since I cannot find the original (😅 )

Copy link
Member

Choose a reason for hiding this comment

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

Update: ah, sorry, this is the pre-state root, right? Is this ensured that this is the correct one?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it should be; it is the state root of the previous block (which is the state root after processing the block). I took the state root from #1091.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I think my state root request for the script from here is likely wrong? But with the corrected state root the tests pass? Why this? 😄 Shouldn't they fail?

Copy link
Member

Choose a reason for hiding this comment

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

Lunch time 🍜

Copy link
Member

Choose a reason for hiding this comment

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

(or is it? I am getting confused, too hungry. 😛 )

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes good point - it should fail, since it fails in client. So that implies that client or clique is somehow messing up the state root.

Copy link
Member Author

Choose a reason for hiding this comment

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

Also put a comment on your code above.

client: ensure we update VM opcodes when switching
@jochem-brouwer
Copy link
Member Author

Closing here, this one is fixed in #1101. I messed up the rebase - I first rebased on master, then wanted to remove these debug tools commits, but then I'd have to search through a lot of commits. Better to just open a new branch.

@ryanio ryanio deleted the fix-rinkeby-consensus-bug 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.

2 participants