Skip to content

Commit

Permalink
Merge PR #3449: LCD proof verification
Browse files Browse the repository at this point in the history
  • Loading branch information
cwgoes authored Jan 30, 2019
1 parent fd71351 commit bc193df
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 7 additions & 2 deletions client/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -43,6 +46,7 @@ type CLIContext struct {
Async bool
PrintResponse bool
Verifier tmlite.Verifier
VerifierHome string
Simulate bool
GenerateOnly bool
FromAddress sdk.AccAddress
Expand All @@ -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{
Expand Down
7 changes: 7 additions & 0 deletions client/context/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit bc193df

Please sign in to comment.