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

BinaryTree: extract proof methods #3889

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

ScottyPoi
Copy link
Contributor

BinaryTree methods .fromProof and verifyBinaryProof can exist as independent functions and do not need to be called from a BinaryTree instance.

This PR creates proof.ts to export two functions: binaryTreeFromProof and verifyBinaryProof and modifies the class methods to call these functions.

Copy link

codecov bot commented Feb 27, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 75.86%. Comparing base (c3301a4) to head (b58299b).

Additional details and impacted files

Impacted file tree graph

Flag Coverage Δ
block 76.87% <ø> (ø)
blockchain 85.69% <ø> (ø)
client 66.27% <ø> (ø)
common 90.73% <ø> (ø)
devp2p 76.27% <ø> (ø)
ethash 81.04% <ø> (ø)
evm 71.06% <ø> (+0.01%) ⬆️
genesis 99.84% <ø> (ø)
mpt 59.48% <ø> (-0.24%) ⬇️
rlp 69.70% <ø> (ø)
statemanager 70.47% <ø> (ø)
tx 80.96% <ø> (ø)
util 85.54% <ø> (ø)
vm 57.81% <ø> (ø)
wallet 83.78% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

const root = putStack[0][0]
proofTrie.root(root)
return proofTrie
return binaryTreeFromProof(_proof)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we even need these class methods anymore? I'd be inclined to just remove them from the class entirely. @gabrocheleau what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They don't make much sense to use. But maybe they satisfy the expectations of a trie interface?

* @returns The value from the key, or null if valid proof of non-existence.
*/
export async function verifyBinaryProof(
_rootHash: Uint8Array,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are there _ before these variable names? It looks like they are all used in the code so assuming we don't need this for linting, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably put there to satisfy the linter when the method was not yet implemented. can delete the _ now

const expectedValue = valueNode.values[_key[31]]
if (!expectedValue) {
if (value) {
throw new Error('Proof is invalid')
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to give more detailed error messaging since we have different possible outcomes (i.e. proof witness does not reach key and proof witness leads to different value or something to that effect)?

_rootHash: Uint8Array,
_key: Uint8Array,
_proof: Uint8Array[],
): Promise<Uint8Array | null> {
Copy link
Contributor

Choose a reason for hiding this comment

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

I know we've had similar discussions in the past and can't remember, don't we have a stylistic preference for using undefined instead of null within the monorepo? I have no opinion in this case but just want to make sure we're consistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We should clarify what a null return means -- is it possible the key exists with null as the value? or does returning null mean there is no entry at that key?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants