diff --git a/PENDING.md b/PENDING.md index d84b7ddb9f4f..fe0d438fabbf 100644 --- a/PENDING.md +++ b/PENDING.md @@ -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. diff --git a/client/context/context.go b/client/context/context.go index a253a88fae55..a9744408d7d4 100644 --- a/client/context/context.go +++ b/client/context/context.go @@ -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{ diff --git a/client/context/query.go b/client/context/query.go index cf70b3cea35f..9a7dea39ad19 100644 --- a/client/context/query.go +++ b/client/context/query.go @@ -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")