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

Extension into branch #1756

Open
wants to merge 45 commits into
base: main
Choose a base branch
from
Open

Extension into branch #1756

wants to merge 45 commits into from

Conversation

miha-stopar
Copy link
Collaborator

@miha-stopar miha-stopar commented Feb 5, 2024

Description

Light client mainnet test with block 18363441 revealed some issues:

  • getDriftedPosition in branch.go issue
  • Calling getProof/getStorageProof in modified_extension_node.go when the short extension node is a branch and there is no trie node at this address/key
  • Wrongly prepared storage leaf

Furthermore, the test revealed a case which was not envisioned before - when proving that the leaf doesn't exist one might get a "wrong" extension node (so there are three scenarios for does-not-exist proofs: nil object in a branch, wrong leaf, wrong extension node), so WrongGadget needs to be extended to cover this case.

Issue Link

#1738

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Test

TestExtensionIntoBranch, TestAccountWrongExtensionNode in gen_witness_from_local_blockchain_test.go.
TestStorageWrongExtensionNode, TestStorageWrongExtensionNode1 in gen_witness_from_infura_blockchain_test.go.

@ed255 ed255 linked an issue Feb 8, 2024 that may be closed by this pull request
@github-actions github-actions bot added the crate-geth-utils Issues related to the geth-utils workspace member label Feb 9, 2024
@github-actions github-actions bot added the crate-zkevm-circuits Issues related to the zkevm-circuits workspace member label Feb 28, 2024
nibbles = append(nibbles, leafKeyRow[2]-48)
var keyLen int
if leafKeyRow[1] > 128 {
keyLen = int(leafKeyRow[1] - 128)
Copy link
Contributor

@KimiWu123 KimiWu123 Apr 15, 2024

Choose a reason for hiding this comment

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

A question about the keyLen.
In this if condition, leafKeyRow is not 248, let's say it's 249, then the length of the payload should be leafKeyRow[1]*256 + leafKeyRow[2]. I don't get why the keyLen here is int(leafKeyRow[1] - 128). Besides, leafKeyRow[2] in below (L160) should be also part of the length.

I also found that the keyLen in the else case in L178 is using leafKeyRow[2] instead of leafKeyRow[1]. I guess the implementation in if and else should be swithced?


I made this fix in my PR bcs the drifted position is incorrect in my case.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The reason this might seem confusing is because for the account and storage leaves I think the length is never big enough for the first byte to be 249, it's at most 248.

It would be more clear if the first condition would say leafKeyRow[0] < 248 instead of leafKeyRow[0] != 248 (and the second block would need to say leafKeyRow[0] == 248).

The first if block handles the cases when leafKeyRow[0] < 248, the second block handles the cases for leafKeyRow[0] == 248. It works ok for account and storage leaves, but not for the transaction leaves which can be very long and can have the first byte 249. Another block is needed for these cases.

@miha-stopar miha-stopar marked this pull request as ready for review April 18, 2024 09:54
Copy link
Contributor

@KimiWu123 KimiWu123 left a comment

Choose a reason for hiding this comment

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

First round (witness generation) pass, only left some minor suggestions.

geth-utils/gethutil/mpt/witness/branch.go Outdated Show resolved Hide resolved
geth-utils/gethutil/mpt/witness/leaf.go Outdated Show resolved Hide resolved
geth-utils/gethutil/mpt/witness/leaf.go Outdated Show resolved Hide resolved
geth-utils/gethutil/mpt/witness/leaf.go Outdated Show resolved Hide resolved
geth-utils/gethutil/mpt/witness/leaf.go Outdated Show resolved Hide resolved
geth-utils/gethutil/mpt/witness/leaf.go Show resolved Hide resolved
Copy link
Contributor

@KimiWu123 KimiWu123 left a comment

Choose a reason for hiding this comment

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

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crate-geth-utils Issues related to the geth-utils workspace member crate-zkevm-circuits Issues related to the zkevm-circuits workspace member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MPT extension node turns into branch issue detected by light client
2 participants