Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

MPT StorageDoesNotExist #1699

Merged
merged 19 commits into from
Feb 2, 2024
Merged

MPT StorageDoesNotExist #1699

merged 19 commits into from
Feb 2, 2024

Conversation

miha-stopar
Copy link
Collaborator

Description

A couple of StorageDoesNotExist issues to be addressed:

  1. Witness generation fails for getProof proofs of length 0.

  2. For StorageDoesNotExist, when the trie is empty, the key
    occupies 33 (33 = 161 - 128) bytes, as in the example below:

[227 161 32 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]

Currently, the length for the RLP items is set valueLen = 34, so we don't have space for all 33 bytes.

  1. It seems that some constraints of the StorageDoesNotExist proof were lost on the way - currently there are only constraints for the wrong leaf, but the constraints for the case when the node in branch is nil are missing.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

TestStorageDoesNotExistOnlySProof in mpt-witness-generator/witness/gen_witness_from_infura_blockchain_test.go.

@github-actions github-actions bot added the crate-zkevm-circuits Issues related to the zkevm-circuits workspace member label Dec 5, 2023
@ed255 ed255 linked an issue Dec 14, 2023 that may be closed by this pull request
@miha-stopar miha-stopar mentioned this pull request Jan 9, 2024
1 task
@miha-stopar miha-stopar marked this pull request as ready for review January 24, 2024 10:03
Copy link
Contributor

@rrtoledo rrtoledo left a comment

Choose a reason for hiding this comment

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

First pass

mpt-witness-generator/witness/prepare_witness.go Outdated Show resolved Hide resolved
mpt-witness-generator/witness/prepare_witness.go Outdated Show resolved Hide resolved
mpt-witness-generator/witness/leaf.go Outdated Show resolved Hide resolved
mpt-witness-generator/witness/prepare_witness.go Outdated Show resolved Hide resolved
@ed255 ed255 linked an issue Jan 25, 2024 that may be closed by this pull request
Comment on lines +385 to 387
if (i != upTo-1) || (areThereNibbles && isNonExistingProof) { // extension node
var numberOfNibbles byte
isExtension = true
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you confirm if we can set isExtension like the following?

let isExtension = (i != upTo-1) || (areThereNibbles && isNonExistingProof);

If that is the case, we can set isExtension at the earliest possible line. We don't have to mutate it in multiple places.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We need to know whether in the previous iteration of the loop there was an extension node - see:

} else {
	var extNode1 []byte = nil
	var extNode2 []byte = nil
	if isExtension {
		extNode1 = proof1[i-1]
		extNode2 = proof2[i-1]
	}

	bNode := prepareBranchNode(proof1[i], proof2[i], extNode1, extNode2, extListRlpBytes, extValues,
		key[keyIndex], key[keyIndex], false, false, isExtension)
	nodes = append(nodes, bNode)

	keyIndex += 1

	isExtension = false
}

This is why isExtension is set to false only here (after one iteration). Does it make sense?

However, when inspecting this I realized there were some leftovers from before refactoring, I removed them in the last commit: cc98424

Copy link
Collaborator

Choose a reason for hiding this comment

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

That makes sense to me; thanks for elaborating on this.

@@ -142,9 +142,10 @@ impl<F: Field> AccountLeafConfig<F> {
config.is_mod_extension[is_s.idx()] = cb.query_bool();
}

// Constraint 1
Copy link
Collaborator

Choose a reason for hiding this comment

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

What does the constraint number refer to?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

My intention is to name the constraints so that reading the MPT specs will be easier (the names will be used there), however, I just started with that, but I plan to equip all the constraints with such names.

Copy link
Member

Choose a reason for hiding this comment

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

This is a fantastic idea @miha-stopar !

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually coming from you @adria0 :)

Copy link
Member

Choose a reason for hiding this comment

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

😅

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see the reasoning now. It's a good idea to add anchors to better reference the spec.
It would be great to add a one-sentence description of the constraint.

github-merge-queue bot pushed a commit that referenced this pull request Jan 31, 2024
### Description

While reviewing #1699, I noticed some room to improve the ergonomics of
the words.

### Issue Link


### Type of change

New feature (non-breaking change which adds functionality)

### Contents

- Replaced the `address_word_to_expr` function with the `compress`
method so that we can compress a word directly without finding that
function to use.
- introduced `zero_f` and `one_f` to create zero and one for `Word<F>`.

### Rationale

I noticed that it is hard to create a `one()` and `zero()` method for
both `Word<Expression<F>>` and `Word<F>`. The compiler complains about
implementing duplicated methods. Since we already use `one()` and
`zero()` in many places for `Word<Expression<F>>`, I named `zero_f` and
`one_f` for the methods for `Word<F>`.
Copy link
Collaborator

@ChihChengLiang ChihChengLiang left a comment

Choose a reason for hiding this comment

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

LGTM.
I added more nitpicks.

Comment on lines +385 to 387
if (i != upTo-1) || (areThereNibbles && isNonExistingProof) { // extension node
var numberOfNibbles byte
isExtension = true
Copy link
Collaborator

Choose a reason for hiding this comment

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

That makes sense to me; thanks for elaborating on this.

@@ -142,9 +142,10 @@ impl<F: Field> AccountLeafConfig<F> {
config.is_mod_extension[is_s.idx()] = cb.query_bool();
}

// Constraint 1
Copy link
Collaborator

Choose a reason for hiding this comment

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

I see the reasoning now. It's a good idea to add anchors to better reference the spec.
It would be great to add a one-sentence description of the constraint.

&mut cb.base,
address.clone(),
proof_type.clone(),
Word::<Expression<F>>::new([0.expr(), 0.expr()]),
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can now use Word::zero() here now

Suggested change
Word::<Expression<F>>::new([0.expr(), 0.expr()]),
Word::zero(),

Copy link
Contributor

@rrtoledo rrtoledo left a comment

Choose a reason for hiding this comment

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

LGTM!
Thanks for the great work and commenting! :)

@miha-stopar miha-stopar added this pull request to the merge queue Feb 2, 2024
Merged via the queue into main with commit 81e715a Feb 2, 2024
15 checks passed
@miha-stopar miha-stopar deleted the mpt-storage-not-exist branch February 2, 2024 17:01
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
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 StorageDoesNotExist
4 participants