light: Fix absence proof verification by light client (backport #7639) (#7716)

- use the full key path to pass to the VerifyAbsence function
This commit is contained in:
mergify[bot]
2022-01-27 22:53:47 +01:00
committed by GitHub
parent c152462f42
commit 28285e1d6a
2 changed files with 16 additions and 12 deletions

View File

@@ -25,3 +25,6 @@ Special thanks to external contributors on this release:
### IMPROVEMENTS
### BUG FIXES
- [light] \#7640 Light Client: fix absence proof verification (@ashcherbakov)
- [light] \#7641 Light Client: fix querying against the latest height (@ashcherbakov)

View File

@@ -162,24 +162,25 @@ func (c *Client) ABCIQueryWithOptions(ctx context.Context, path string, data tmb
}
// Validate the value proof against the trusted header.
// build a Merkle key path from path and resp.Key
if c.keyPathFn == nil {
return nil, errors.New("please configure Client with KeyPathFn option")
}
kp, err := c.keyPathFn(path, resp.Key)
if err != nil {
return nil, fmt.Errorf("can't build merkle key path: %w", err)
}
// verify value
if resp.Value != nil {
// 1) build a Merkle key path from path and resp.Key
if c.keyPathFn == nil {
return nil, errors.New("please configure Client with KeyPathFn option")
}
kp, err := c.keyPathFn(path, resp.Key)
if err != nil {
return nil, fmt.Errorf("can't build merkle key path: %w", err)
}
// 2) verify value
err = c.prt.VerifyValue(resp.ProofOps, l.AppHash, kp.String(), resp.Value)
if err != nil {
return nil, fmt.Errorf("verify value proof: %w", err)
}
} else { // OR validate the absence proof against the trusted header.
err = c.prt.VerifyAbsence(resp.ProofOps, l.AppHash, string(resp.Key))
err = c.prt.VerifyAbsence(resp.ProofOps, l.AppHash, kp.String())
if err != nil {
return nil, fmt.Errorf("verify absence proof: %w", err)
}