-
Notifications
You must be signed in to change notification settings - Fork 71
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
fix: prevent out of bounds on lookup inners access #365
Closed
crodriguezvega
wants to merge
12
commits into
master
from
carlos/prevent-out-of-bounds-lookup-inners
Closed
Changes from 7 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
2c08967
fix: prevent out of bounds on lookup inners access
crodriguezvega 93df82c
Merge branch 'master' into carlos/prevent-out-of-bounds-lookup-inners
crodriguezvega 4634232
Merge branch 'master' of github.com:cosmos/ics23 into carlos/prevent-…
colin-axner e08b568
refactor: return error instead of panic when decompressing proof
colin-axner 1c9d758
test: add additional test case
colin-axner c33dd0d
chore: changelog entry
colin-axner 284999c
chore: changelog wording
colin-axner 365ec7a
lint
colin-axner 891d26e
lint spacing
colin-axner d7055a0
chore: add comment
colin-axner bc9a525
Merge branch 'master' into carlos/prevent-out-of-bounds-lookup-inners
colin-axner fdcee81
Merge branch 'master' into carlos/prevent-out-of-bounds-lookup-inners
colin-axner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package ics23 | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestDecompressExist(t *testing.T) { | ||
leafOp := &LeafOp{ | ||
Hash: HashOp_SHA256, | ||
PrehashKey: HashOp_NO_HASH, | ||
PrehashValue: HashOp_NO_HASH, | ||
Length: LengthOp_NO_PREFIX, | ||
Prefix: []byte{}, | ||
} | ||
innerOps := []*InnerOp{ | ||
&InnerOp{ | ||
Hash: HashOp_SHA256, | ||
Prefix: generateInnerOpPrefix(), | ||
}, | ||
&InnerOp{ | ||
Hash: HashOp_SHA256, | ||
Prefix: generateInnerOpPrefix(), | ||
Suffix: []byte{1}, | ||
}, | ||
&InnerOp{ | ||
Hash: HashOp_SHA256, | ||
Prefix: generateInnerOpPrefix(), | ||
Suffix: []byte{2}, | ||
}, | ||
} | ||
|
||
var ( | ||
compressedExistProof *CompressedExistenceProof | ||
lookup []*InnerOp | ||
) | ||
|
||
cases := []struct { | ||
name string | ||
malleate func() | ||
expProof *ExistenceProof | ||
expError error | ||
}{ | ||
{ | ||
"success: single lookup", | ||
func() { | ||
compressedExistProof.Path = []int32{0} | ||
}, | ||
&ExistenceProof{ | ||
Key: []byte{0}, | ||
Value: []byte{0}, | ||
Leaf: leafOp, | ||
Path: []*InnerOp{innerOps[0]}, | ||
}, | ||
nil, | ||
}, | ||
{ | ||
"success: multiple lookups", | ||
func() { | ||
compressedExistProof.Path = []int32{0, 1, 0, 2} | ||
}, | ||
&ExistenceProof{ | ||
Key: []byte{0}, | ||
Value: []byte{0}, | ||
Leaf: leafOp, | ||
Path: []*InnerOp{innerOps[0], innerOps[1], innerOps[0], innerOps[2]}, | ||
}, | ||
nil, | ||
}, | ||
{ | ||
"success: empty exist proof", | ||
func() { | ||
compressedExistProof = nil | ||
}, | ||
nil, | ||
nil, | ||
}, | ||
{ | ||
"failure: path index out of bounds", | ||
func() { | ||
compressedExistProof.Path = []int32{0} | ||
lookup = nil | ||
}, | ||
nil, | ||
fmt.Errorf("compressed existence proof at index %d has lookup index out of bounds", 0), | ||
}, | ||
} | ||
|
||
for _, tc := range cases { | ||
tc := tc | ||
|
||
t.Run(tc.name, func(t *testing.T) { | ||
// reset default values for compressedExistProof and lookup | ||
compressedExistProof = &CompressedExistenceProof{ | ||
Key: []byte{0}, | ||
Value: []byte{0}, | ||
Leaf: leafOp, | ||
} | ||
|
||
lookup = innerOps[:] | ||
|
||
tc.malleate() | ||
|
||
proof, err := decompressExist(compressedExistProof, lookup) | ||
if !reflect.DeepEqual(tc.expProof, proof) { | ||
t.Fatalf("expexted proof: %v, got: %v", tc.expProof, proof) | ||
} | ||
|
||
if tc.expError == nil && err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if tc.expError != nil && err.Error() != tc.expError.Error() { | ||
t.Fatalf("expected: %v, got: %v", tc.expError, err) | ||
} | ||
|
||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
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.
tests broke with an error return here. I don't have a great understanding of when this case arises? Is there a comment we can add to elaborate on it? @AdityaSripal
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.
If a nonexistence proof is proving the leftmost key wouldn't the leftExist be nil? So decompressExist returns nil and we don't error out on line 149
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.
ah yes, thank you! That makes sense to me, added a comment