Merge PR #3449: LCD proof verification

This commit is contained in:
Christopher Goes 2019-01-30 22:48:20 +01:00 committed by GitHub
parent fd71351541
commit bc193df8e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 2 deletions

View File

@ -24,6 +24,7 @@ FEATURES
* Gaia CLI (`gaiacli`)
* [\#3429](https://github.com/cosmos/cosmos-sdk/issues/3429) Support querying
for all delegator distribution rewards.
* \#3449 Proof verification now works with absence proofs
* Gaia
- [\#3397](https://github.com/cosmos/cosmos-sdk/pull/3397) Implement genesis file sanitization to avoid failures at chain init.

View File

@ -24,7 +24,10 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)
var verifier tmlite.Verifier
var (
verifier tmlite.Verifier
verifierHome string
)
// CLIContext implements a typical CLI context created in SDK modules for
// transaction handling and queries.
@ -43,6 +46,7 @@ type CLIContext struct {
Async bool
PrintResponse bool
Verifier tmlite.Verifier
VerifierHome string
Simulate bool
GenerateOnly bool
FromAddress sdk.AccAddress
@ -68,8 +72,9 @@ func NewCLIContext() CLIContext {
}
// We need to use a single verifier for all contexts
if verifier == nil {
if verifier == nil || verifierHome != viper.GetString(cli.HomeFlag) {
verifier = createVerifier()
verifierHome = viper.GetString(cli.HomeFlag)
}
return CLIContext{

View File

@ -219,6 +219,13 @@ func (ctx CLIContext) verifyProof(queryPath string, resp abci.ResponseQuery) err
kp = kp.AppendKey([]byte(storeName), merkle.KeyEncodingURL)
kp = kp.AppendKey(resp.Key, merkle.KeyEncodingURL)
if resp.Value == nil {
err = prt.VerifyAbsence(resp.Proof, commit.Header.AppHash, kp.String())
if err != nil {
return errors.Wrap(err, "failed to prove merkle proof")
}
return nil
}
err = prt.VerifyValue(resp.Proof, commit.Header.AppHash, kp.String(), resp.Value)
if err != nil {
return errors.Wrap(err, "failed to prove merkle proof")