Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Unwrap DelegatingBytes32 and prevent Hash from wrapping other Hash instances #1423

Merged
merged 2 commits into from
May 9, 2019

Conversation

ajsutton
Copy link
Contributor

@ajsutton ajsutton commented May 9, 2019

PR description

When blocks are generated without any change to the world state (only possible with empty blocks in Clique or IBFT where there's no block reward), the world state root hash was being repeatedly wrapped in a new Hash instance until eventually it triggered a stack overflow. The same Hash instance survives because the actual BlockHeader instance is cached by the blockchain and the state root hash round trips through the block creator, world state Merkle trie entirely unchanged except for being wrapped an additional time.

Fix is to apply the same unwrap process to DelegatingBytes32 as already existed in DelegatingBytesValue. To save creating a new object at all a check has also been added to Hash.wrap so that it just casts the existing value if it's already a Hash.

Bytes32 wrapped = v;

if (wrapped instanceof DelegatingBytes32) {
wrapped = ((DelegatingBytes32) wrapped).wrapped;
Copy link
Contributor

Choose a reason for hiding this comment

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

just return the thing - then at the bottom return v.

@ajsutton ajsutton merged commit 0fdacbd into PegaSysEng:master May 9, 2019
@ajsutton ajsutton deleted the unwrap branch May 9, 2019 04:46
notlesh pushed a commit to notlesh/pantheon that referenced this pull request May 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants