-
Notifications
You must be signed in to change notification settings - Fork 791
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
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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') |
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
BinaryTree methods
.fromProof
andverifyBinaryProof
can exist as independent functions and do not need to be called from aBinaryTree
instance.This PR creates
proof.ts
to export two functions:binaryTreeFromProof
andverifyBinaryProof
and modifies the class methods to call these functions.