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

R4R: Bugfix for multistoreproof building #2474

Closed
wants to merge 5 commits into from
Closed

R4R: Bugfix for multistoreproof building #2474

wants to merge 5 commits into from

Conversation

abelliumnt
Copy link

Suppose a IAVL store has no value, then the proof field and value field of query response will be nil. As a result, panic error will arise in multistoreproof building. We did encountered the panic error in our own application.

@abelliumnt abelliumnt changed the title Bugfix for multistoreproof building [R4R]: Bugfix for multistoreproof building Oct 11, 2018
@@ -295,6 +295,14 @@ func (rs *rootMultiStore) Query(req abci.RequestQuery) abci.ResponseQuery {
return res
}

if len(res.Proof) == 0 {
if len(res.Value) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm do we want to require proof of exclusion here?

@codecov
Copy link

codecov bot commented Oct 12, 2018

Codecov Report

Merging #2474 into develop will increase coverage by 1.79%.
The diff coverage is 0%.

@@             Coverage Diff             @@
##           develop    #2474      +/-   ##
===========================================
+ Coverage    60.07%   61.87%   +1.79%     
===========================================
  Files          150      149       -1     
  Lines         8702     9535     +833     
===========================================
+ Hits          5228     5900     +672     
- Misses        3117     3217     +100     
- Partials       357      418      +61

@abelliumnt
Copy link
Author

abelliumnt commented Oct 14, 2018

@cwgoes
Previously my change was thoughtless. We should not just leave out proof when the substore is nil.
I think the current change is a better approch to handle empty IAVL proof. Please help take a look at this again.

Besides, if the bug is very significant. If we query a empty store from a full node, the full node will encounter a panic error. For instance, now the initial fee store is empty, you can reproduce this issue by query any key on it. It would be wondoerfull if this PR could be merge into v0.25.0.

Copy link
Contributor

@cwgoes cwgoes left a comment

Choose a reason for hiding this comment

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

See comments.

@@ -56,6 +61,10 @@ func VerifyMultiStoreCommitInfo(storeName string, storeInfos []storeInfo, appHas

// VerifyRangeProof verify iavl RangeProof
func VerifyRangeProof(key, value []byte, substoreCommitHash []byte, rangeProof *iavl.RangeProof) error {
// Both rangeProof and substoreCommitHash are nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm when do we expect this? What if just one is nil?

Copy link
Author

Choose a reason for hiding this comment

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

When the query store is empty, both rangeProof and substoreCommitHash will be nil.
If only rangeProof is nil, an invalid proof error will be returned.
If only substoreCommitHash, the proof verification will report error about root hash mismatching.

@@ -295,6 +295,11 @@ func (rs *rootMultiStore) Query(req abci.RequestQuery) abci.ResponseQuery {
return res
}

if len(res.Proof) == 0 && len(res.Value) != 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

For nil values, should we require a proof that the value is nil?

Copy link
Author

Choose a reason for hiding this comment

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

Normally, if value is nil, we should return absence proof. But if the store is empty, both proof and value will be nil. In this case, we should return a multiStoreProof to demonstrage the store is empty.

var rangeProof iavl.RangeProof
cdc.MustUnmarshalBinary(iavlProof, &rangeProof)
var rangeProof *iavl.RangeProof
if iavlProof != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

When will this be nil?

Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

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

Changes look reasonable to me 👍

@jackzampolin jackzampolin changed the title [R4R]: Bugfix for multistoreproof building R4R: Bugfix for multistoreproof building Oct 25, 2018
@abelliumnt
Copy link
Author

@jackzampolin @alexanderbez @cwgoes
Do you have any further comment about this PR?

@alexanderbez
Copy link
Contributor

I do not have any :-)

@cwgoes
Copy link
Contributor

cwgoes commented Oct 26, 2018

I thought it might be wise for @jaekwon to review w.r.t the upstream lite client proof functionality.

@jaekwon
Copy link
Contributor

jaekwon commented Nov 5, 2018

Hi @HaoyangLiu, general merkle logic is merged in Tendermint and the SDK. I've updated the develop branch with a PR that takes this concern into account: #2685

@jaekwon jaekwon closed this Nov 5, 2018
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.

4 participants