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
3 changed files with 15 additions and 2 deletions
+7 -2
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{
+7
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")