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

Add specs for MPTs #1383

Merged
merged 11 commits into from
Nov 27, 2023
Merged

Add specs for MPTs #1383

merged 11 commits into from
Nov 27, 2023

Conversation

4l0n50
Copy link
Contributor

@4l0n50 4l0n50 commented Nov 24, 2023

No description provided.

@4l0n50 4l0n50 added the documentation Improvements or additions to documentation label Nov 24, 2023
@pgebheim
Copy link
Collaborator

Amazing @wborgeaud can we get this merged before Monday?

evm/spec/mpts.tex Outdated Show resolved Hide resolved
evm/spec/mpts.tex Outdated Show resolved Hide resolved
evm/spec/mpts.tex Outdated Show resolved Hide resolved
evm/spec/mpts.tex Outdated Show resolved Hide resolved
evm/spec/mpts.tex Show resolved Hide resolved
evm/spec/mpts.tex Outdated Show resolved Hide resolved
evm/spec/mpts.tex Show resolved Hide resolved
evm/spec/mpts.tex Show resolved Hide resolved
evm/spec/mpts.tex Show resolved Hide resolved
evm/spec/mpts.tex Outdated Show resolved Hide resolved
Copy link
Contributor

@wborgeaud wborgeaud 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!

evm/spec/mpts.tex Outdated Show resolved Hide resolved
evm/spec/mpts.tex Show resolved Hide resolved
\item the nonce,
\item the balance,
\item a pointer to the account's storage trie,
\item a hash of the account's code.
Copy link
Contributor

Choose a reason for hiding this comment

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

It's the hash of the empty byte sequence keccak(b'') = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470.

\item a pointer to the account's storage trie,
\item a hash of the account's code.
\end{enumerate}
The storage trie payload in turn is a single word.
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, Ethereum storage slots hold one 256-bit integer.

evm/spec/mpts.tex Outdated Show resolved Hide resolved
\item[State Trie:] Encoded as a list containing nonce, balance, storage trie hash and code hash.
\item[Storage Trie:] The RLP encoding of the value (thus the double RLP encoding)
\item[Transaction Trie:] The RLP encoded transaction.
\item[Receipt Trie:] Depending on the transaction type it's encoded as ${\sf RLP}({\sf RLP}({\tt receipt}))$ for Legacy transactions or ${\sf RLP}({\tt txn\_type}||{\sf RLP}({\tt receipt}))$ for transactions of type 1 or 2. Each receipt is encoded as a list containing:
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't it be just {\tt txn\_type}||{\sf RLP}({\tt receipt}) for type 1 or 2 txns?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmmm, at least the comment on the code explicitly says
// There is a double encoding! What we compute is: // either RLP(RLP(receipt)) for Legacy transactions or RLP(txn_type||RLP(receipt)) for transactions of type 1 or 2
@LindaGuiga or @hratoanina?

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed, we are doubly encoding (it didn't work with a simple encoding). I believe the value is the simple RLP encoding, and the actual node encoding is then the RLP encoding of the value (and therefore the double encoding). @hratoanina?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hm this is confusing. When running the ERC20 test, the receipt trie root is gotten with

Hashing [249, 1, 176, 130, 32, 128, 185, 1, 170, 2, 249, 1, 166, 1, 130, 220, 179, 185, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 66, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 248, 157, 248, 155, 148, 95, 189, 178, 49, 86, 120, 175, 236, 179, 103, 240, 50, 217, 63, 100, 47, 100, 24, 10, 163, 248, 99, 160, 221, 242, 82, 173, 27, 226, 200, 155, 105, 194, 176, 104, 252, 55, 141, 170, 149, 43, 167, 241, 99, 196, 161, 22, 40, 245, 90, 77, 245, 35, 179, 239, 160, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 231, 241, 114, 94, 119, 52, 206, 40, 143, 131, 103, 225, 187, 20, 62, 144, 187, 63, 5, 18, 160, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 31, 144, 144, 170, 226, 139, 138, 61, 206, 173, 242, 129, 176, 241, 40, 40, 230, 118, 195, 38, 160, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 107, 199, 94, 45, 99, 16, 0, 0]

which is the RLP encoding of [0x2080, 0x2 + RLP(receipt)], the leaf node at 0 with payload tx_type + RLP(receipt). So there doesn't seem to be a double RLP encoding here, unless I'm missing something.

Copy link
Contributor

@LindaGuiga LindaGuiga Nov 27, 2023

Choose a reason for hiding this comment

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

Doesn't the 185 indicate the start of an RLP encoding for (0x2 || RLP(receipt)) here? (with 249 starting the RLP encoding of the receipt)?

Copy link
Contributor

Choose a reason for hiding this comment

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

But actually, I think we should also change that for transactions: when calling the encode method on a transaction node, we also RLP encode the RLP encoding

Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't the 185 indicate the start of an RLP encoding for (0x2 || RLP(receipt)) here? (with 249 starting the RLP encoding of the receipt)?

Sure, but that's just because the RLP of a list is the concatenation of the RLP of the items of the list (prefixed by the length).

Copy link

sonarcloud bot commented Nov 27, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@4l0n50 4l0n50 merged commit acd3b1a into 0xPolygonZero:main Nov 27, 2023
5 checks passed
@Nashtare Nashtare deleted the mpt_specs branch November 27, 2023 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants