Skip to content

Conversation

@SheldonZhong
Copy link
Contributor

The account state root will never be crypto.Keccak256Hash(nil). Since the empty tire root would be an empty hash (an all zero 32-byte array), an array is initialized to all zero array in stead of nil as the case in slice. The empty account root will only be crypto.Keccak256Hash(Hash{}), which is equal to 0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421. So essentially, the root of a trie will never be nil, but it would be all zero hash before commit and emptyRoot after commit an empty trie.

I think is mistake was introduced unintentionally by the author, the object was to filter out empty accounts and never reference to them. Because it does not incur fatal error but a slight performance degrade for reference to empty trie, this problem is not unveiled before careful inspection.

@karalabe
Copy link
Member

Yes, I've also seen this issue a few times. Not sure why it wasn't fixed yet. I guess it was always in some larger PR that was not yet merged. LGTM.

Btw, there's no real performance issue because the trie.Reference explicitly checks for the emptyRoot anyway. The single fault could be if someone creates a storage trie which hashes to Keccak256(nil), but that would be equivalent to a hash collision.

All in all good change, correct code, no security or perf implication :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants