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

Commit

Permalink
Construct placeholder leaf for wrong extension node case
Browse files Browse the repository at this point in the history
  • Loading branch information
miha-stopar committed Feb 27, 2024
1 parent bd82e59 commit a90ae32
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions geth-utils/gethutil/mpt/witness/prepare_witness.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,12 +554,42 @@ func convertProofToWitness(statedb *state.StateDB, addr common.Address, addrh []
branchRlp := proof[len(proof)-2] // the last element has to be a leaf
isExtension := true

extNode := proof2[len(proof2)-1]
extNode := proof2[len(proof2)-1] // Let's name it E1
bNode := prepareBranchNode(branchRlp, branchRlp, extNode, extNode, extListRlpBytes, extValues,
key[keyIndex], key[keyIndex], false, false, isExtension)
nodes = append(nodes, bNode)

node := prepareStorageLeafNode(proof[len(proof)-1], proof[len(proof)-1], nil, storage_key, key, nonExistingStorageProof, false, false, false, false)
/*
Let's say we have an extension node E1 at the following path [3, 5, 8].
Let's say E1 has nibbles [1, 2, 3]. Let's say we want to prove there does not exist
a leaf at [3, 5, 8, 1, 2] (because there is E1 there).
We need to construct a leaf L1 that will have the key equal to the queried key.
This means the nibbles are the same as in the path to E1 (without extension nibbles).
In the circuit, the leaf L1 will have the same key as the queried key once
the KeyData will be queried with offset 1 (to get the accumulated key RLC up until E1).
The nibbles stored in L1 will be added to the RLC and compared with the queried
key (has to be the same).
*/

l := keyIndex - len(nibbles)
path := make([]byte, l) // Up to the E1 nibbles (without them)
copy(path, key[:l])
// The remaining `key` nibbles are to be stored in the constructed leaf.

compact := trie.HexToCompact(key[l:])
// Add RLP:
compactLen := byte(len(compact))
rlp2 := 128 + compactLen
rlp1 := 192 + compactLen + 1
// Constructed leaf L1:
constructedLeaf := append([]byte{rlp1, rlp2}, compact...)

// Add dummy value:
constructedLeaf = append(constructedLeaf, 1)

node := prepareStorageLeafNode(proof[len(proof)-1], constructedLeaf, nil, storage_key, key, nonExistingStorageProof, false, false, false, false)
nodes = append(nodes, node)
}
}
Expand Down

0 comments on commit a90ae32

Please sign in to comment.