-
Notifications
You must be signed in to change notification settings - Fork 43
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
feat: verify the range of the namespace IDs of the children in the HashNode #102
Conversation
Codecov Report
@@ Coverage Diff @@
## master #102 +/- ##
==========================================
+ Coverage 96.21% 96.27% +0.05%
==========================================
Files 6 6
Lines 423 429 +6
==========================================
+ Hits 407 413 +6
Misses 10 10
Partials 6 6
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
children{[]byte{0, 0, 1, 1}, []byte{0, 0, 0, 1}}, | ||
append( | ||
[]byte{0, 0, 1, 1}, | ||
sum(crypto.SHA256, []byte{NodePrefix}, []byte{0, 0, 1, 1}, []byte{0, 0, 0, 1})..., |
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.
This test case is deleted as this represents an invalid state given the newly added logic i.e., the max namespace of the right child cannot be greater than the min namespace of the right child.
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.
one question, otherwise LGTM!
rightMinNID := namespace.ID(rightMinNs) | ||
leftMaxNID := namespace.ID(leftMaxNs) | ||
if rightMinNID.Less(leftMaxNID) { | ||
panic("nodes are out of order: the maximum namespace of the left child is greater than the min namespace of the right child") |
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 panicking here mean that someone could send a light node an invalid proof or sample and their node would crash?
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.
As you mentioned, the HashNode
method may only fail in the event of an attack on the system. However, it is important to note that the method was previously susceptible to panic, even prior to this pull request. For example, panic can occur while extracting the namespace identifier of the left or right children if they are not namespaced (i.e., if their length is less than NamespaceLen). It is not possible to return an error from this method without violating the interfaces it is intended to fulfill, namely NodeHasher
and hash
.
At this time, it may be better to allow the light client to crash rather than enter an invalid state.
I will investigate the implementation of proper error handling in the HashNode
method, including handling other potential errors beyond just the namespace ID range, in a follow-up pull request. As this has a broad scope, it requires careful attention and consideration during implementation.
Tracking issue #109
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.
Hmm, I think when this was implemented, we might have panic'ed bc it was supposed to be impossible to construct an invalid tree. But it is good thinking that someone might do so to crash light nodes and I do think we should error instead.
edit: I see. The Hash interface was another reason. Either we make it impossible client side that this panics (e.g. by doing some verification before calling this; then this should be very explicitly documented) or we have to break with the iface.
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.
For the sake of getting this PR merged: can we add this property/panic to the godoc? So the caller has a hint that verification has to happen before to not cause unexpected panics?
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.
For the sake of getting this PR merged: can we add this property/panic to the godoc? So the caller has a hint that verification has to happen before to not cause unexpected panics?
Sure! please check the following commit e7415b7
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.
Specifically, it does not treat leftMaxNs = rightMinNs as a violation of leaf ordering. The reason for this is that a namespace may span across multiple subtrees.
I see. That makes sense. Maybe @musalbas wants to update that case in the paper too.
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 might also want to handle #109 before we cut a new release to avoid any unintentional panics
Sure @evan-forbes, I am on it! |
@liamsi I'd appreciate if you could please take another look and let me know if further updates are required on the PR before merging. Thanks! |
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.
🙏🏼
Overview
This PR closes #95.
Inline with celestiaorg/celestia-app#1296.
The implementation of this pull request does not exactly follow the original suggestion in the LazyLedge paper. Specifically, it does not treat
leftMaxNs = rightMinNs
as a violation of leaf ordering. The reason for this is that a namespace may span across multiple subtrees.cc: @liamsi
Quoting from the article:
Checklist