Browse Source

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

- use the full key path to pass to the VerifyAbsence function
pull/7715/head
Alexander Shcherbakov 3 years ago
committed by GitHub
parent
commit
9b32346ebd
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 11 deletions
  1. +2
    -0
      CHANGELOG_PENDING.md
  2. +12
    -11
      light/rpc/client.go

+ 2
- 0
CHANGELOG_PENDING.md View File

@ -70,3 +70,5 @@ Special thanks to external contributors on this release:
### BUG FIXES
- fix: assignment copies lock value in `BitArray.UnmarshalJSON()` (@lklimek)
- [light] \#7640 Light Client: fix absence proof verification (@ashcherbakov)
- [light] \#7641 Light Client: fix querying against the latest height (@ashcherbakov)

+ 12
- 11
light/rpc/client.go View File

@ -196,24 +196,25 @@ func (c *Client) ABCIQueryWithOptions(ctx context.Context, path string, data tmb
}
// Validate the value proof against the trusted header.
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)
}
// build a Merkle key path from path and resp.Key
if c.keyPathFn == nil {
return nil, errors.New("please configure Client with KeyPathFn option")
}
// 2) verify value
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 {
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)
}


Loading…
Cancel
Save