-
Notifications
You must be signed in to change notification settings - Fork 42
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
Bug: Proofs of Absence can be Forged #86
Comments
Regarding the root cause, mentioned above, I think changing that if condition to this should fix it: if len(data) == 0 && isEmptyRange && len(proof.nodes) == 0 {
// empty range, proof, and data and nID < min or nID > max: always checks out
if nID.Less(min) || max.Less(nID) {
return true
}
return false
} This would ensure that an empty range is only valid if nID < min or nID > max in the root. Need to think a bit further about the empty-tree case though. Note that an empty tree is defined as this (or base-case here) but I think that would also work with the above. |
I think this change is good. I would just add a special case for the empty root since its purported min and max namespaces aren't accurate.
The extra check is necessary - otherwise, it's impossible to verify a proof of absence for namespace 0 in the empty tree
|
- Reject empty "proofs" of absence, except in the special case where the root doesn't cover the namespace being proved - Add test case to catch regression - Add test case to ensure that the absence of the zero namespace can be proved against the empty tree
- Reject empty "proofs" of absence, except in the special case where the root doesn't cover the namespace being proved - Add test case to catch regression - Add test case to ensure that the absence of the zero namespace can be proved against the empty tree
- Reject empty "proofs" of absence, except in the special case where the root doesn't cover the namespace being proved - Add test case to catch regression - Add test case to ensure that the absence of the zero namespace can be proved against the empty tree <!-- Please read and fill out this form before submitting your PR. Please make sure you have reviewed our contributors guide before submitting your first PR. --> closes #86 ## Overview <!-- Please provide an explanation of the PR, including the appropriate context, background, goal, and rationale. If there is an issue with this information, please provide a tl;dr and link the issue. --> ## Checklist <!-- Please complete the checklist to ensure that the PR is ready to be reviewed. IMPORTANT: PRs should be left in Draft until the below checklist is completed. --> - [x] New and updated code has appropriate documentation - [x] New and updated code has new and/or updated testing - [x] Required CI checks are passing - [x] Visual proof for any user facing features like CLI or documentation updates - [x] Linked issues closed with keywords Co-authored-by: Ismail Khoffi <[email protected]>
Bug: Proofs of Absence can be Forged
Problem
The namespaced merkle tree exposes a
VerifyNamespace
method whose documentation states that it "verifies that the namespace is complete and no leaf of that namespace was left out in the proof."This API allow consumers to write code like the following:
Unfortunately, this code is vulnerable. A malicious prover can falsely claim that the namespace is empty, and, as long as he also provides an empty proof, the claim will be accepted.
Test Case
A simple test case which reproduces the issue is as follows:
Root Cause
This behavior is introduced by the following condition here:
Suggested Solution
Currently, the handling of empty range proofs is not well defined. I propose to reject all proofs that do not contain at least one node in either the
proof.nodes
ordata
arguments, unless the tree is the empty. (Without this special case, it's impossible to check range proofs against the empty tree). This will change the semantics of the NMT, causing some existing test cases to fail.The text was updated successfully, but these errors were encountered: