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

MPT extension node turns into branch issue detected by light client #1738

Open
miha-stopar opened this issue Jan 19, 2024 · 1 comment · May be fixed by #1756
Open

MPT extension node turns into branch issue detected by light client #1738

miha-stopar opened this issue Jan 19, 2024 · 1 comment · May be fixed by #1756
Assignees
Labels
T-bug Type: bug
Milestone

Comments

@miha-stopar
Copy link
Collaborator

miha-stopar commented Jan 19, 2024

What command(s) is the bug in?

No response

Describe the bug

Mainnet test with block 18363441 fails with

panic: runtime error: index out of range [35] with length 35

goroutine 17 [running, locked to thread]:
github.com/privacy-scaling-explorations/mpt-witness-generator/witness.getDriftedPosition({0x14005112ed0, 0x23, 0x2?}, 0x0)

The issue is there is an extension node
[226 29 160 217 96 198 67 216 20 103 173 8 242 218 197 154 41 240 104 151 164 226 76 167 89 156 221 241 114 184 233 63 208 17 10]
in the S proof, which gets replaced by a branch
[248 81 128 128 128 128 128 128 128 128 128 128 128 128 128 160 217 96 198 67 216 20 103 173 8 242 218 197 154 41 240 104 151 164 226 76 167 89 156 221 241 114 184 233 63 208 17 10 160 141 70 158 90 135 150 17 215 30 146 98 157 197 214 148 52 70 144 37 56 64 111 28 57 252 62 114 96 129 79 37 127 128 128]. This branch contains the above mentioned extension node and a leaf. The issue appears when getDriftedPosition tries to compute the drifted position out of the extension node.

@miha-stopar miha-stopar added the T-bug Type: bug label Jan 19, 2024
@miha-stopar miha-stopar linked a pull request Feb 5, 2024 that will close this issue
4 tasks
@ed255 ed255 added this to the MPT milestone Feb 8, 2024
@ed255 ed255 linked a pull request Feb 8, 2024 that will close this issue
4 tasks
@miha-stopar
Copy link
Collaborator Author

Once getDriftedPosition issue was resolved, a further one appeared with a "wrong" extension node.

The problem with the wrong extension node is that in this case we don’t get the underlying branch and leaf with GetProof/GetStorageProof. If we could get the underlying branch and any of its leaves, we could (with some slight additions) reuse the WrongGadget. However, to obtain one of the underlying leaves we would need to call PrefetchAccount/PrefetchStorage to get this leaf - but we don’t know its preimage (when we are querying for the key that does not exist, we get the extension node, to get the underlying nodes we need to modify the querying key accordingly, but this is not possible because we cannot know the hash preimage).

That means we cannot an underlying branch and a leaf in the proof. An alternative is check that the key RLC up until the end of the extension node is different from the RLC of the first num_nibbles key nibbles. For example:

Wrong extension node E is at path 2 2 2 and it has three nibbles 3 4 5 (in this case num_nibbles = 6).
We are querying the key 2 2 2 5 7 7 …. Such a leaf doesn’t exist, because at path 2 2 2 5 nothing exists and the extension node E is returned (found at 2 2 2).

The problem with comparing the RLC of 2 2 2 3 4 5 and 2 2 2 5 7 7 is that num_nibbles is dynamic (different from case to case). The solution might be to add split the querying key into two rows in the witness generator (two additional rows) - one row containing 2 2 2 3 4 5, the other row the remaining nibbles (compressed into bytes, which brings another problems though - even/oddness of nibbles).

In that case we can compute the RLC of the first num_nibbles using the first row and compare it to be different of E key_data RLC. And we need to ensure that the RLC of the both two rows is the same as the querying key RLC. Note that the “dynamic” problem of num_nibbles is solved this way, because using the RLP bytes (specifying the length) we can check that after some position there are only zeros in the row (using a fixed table and is_two_byte_lookup_enabled in mpt_circuit.rs).

We also need to ensure there RLP bytes correspond to the num_nibbles.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-bug Type: bug
Projects
Status: 🏗 In progress
Development

Successfully merging a pull request may close this issue.

2 participants