fix(contracts-bedrock): MerkleTrie process tail small node #114
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
MPT Storage
Ethereum Yellow Paper:
For an MPT node, as described in the yellow paper,
When the RLP encoded size of an MPT node exceeds 32, store the hash of the RLP encoded value of the node in the slot corresponding to its parent node, and then use the hash value to read the specific content of the node;
When the RLP encoded size of the node is less than 32, its content is stored directly in the parent's corresponding slot.
Description
The error "'MerkleTrie: ran out of proof elements'" is reported from 'MerkleTrie.get()' when the provided storage proofs contain small nodes(RLP encoded size is less than 32).
Here is an on-chain example: https://testnet.bscscan.com/tx/0xa5f9d2f9c5804391ee695e0b0c71df17e1dd4333691fb714924ff2470320dadf
There are 8 proof elements (returned via Geth's
curl https://opbnb-testnet-rpc.bnbchain.org -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_getProof","id": 15198, "params": ["0x4200000000000000000000000000000000000016", ["0x5cd60ecef836e75dd12539abe8ad5f4ba0dc4fcaae2c45024c69bd9e20746eba"], "0x1115ac0" ]}' | jq '.result.storageProof'
):Although the above proofs list only has 8 elements, it actually represents 9 MPT nodes.
Due to the fact that proofs[7] is a fullNode that contains a child shortNode whose RLP encoded size is less than 32, the last MPT node is included in the child-slot of proofs[7].
The L1 contract fails to process the last MPT shortnode correctly when it verifies the proofs provided by the exchange via MerkleTrie.get(). The error MerkleTrie: ran out of proof elements is reported.
See Also