From ee1cb0cba075530a6364f80bfe5d534aa2409c21 Mon Sep 17 00:00:00 2001 From: Zsolt Felfoldi Date: Wed, 8 May 2019 16:11:21 +0200 Subject: [PATCH] light: add canonical header verification to GetTransaction --- light/odr_util.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/light/odr_util.go b/light/odr_util.go index 197fd032da..100bd58428 100644 --- a/light/odr_util.go +++ b/light/odr_util.go @@ -236,6 +236,11 @@ func GetTransaction(ctx context.Context, odr OdrBackend, txHash common.Hash) (*t return nil, common.Hash{}, 0, 0, err } else { pos := r.Status[0].Lookup + // first ensure that we have the header, otherwise block body retrieval will fail + // also verify if this is a canonical block by getting the header by number and checking its hash + if header, err := GetHeaderByNumber(ctx, odr, pos.BlockIndex); err != nil || header.Hash() != pos.BlockHash { + return nil, common.Hash{}, 0, 0, err + } if body, err := GetBody(ctx, odr, pos.BlockHash, pos.BlockIndex); err != nil || uint64(len(body.Transactions)) <= pos.Index || body.Transactions[pos.Index].Hash() != txHash { return nil, common.Hash{}, 0, 0, err } else {