diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index 56efd763b..0e8458078 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -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) diff --git a/light/rpc/client.go b/light/rpc/client.go index 9101de28b..5e70dd5fd 100644 --- a/light/rpc/client.go +++ b/light/rpc/client.go @@ -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) }