Skip to content

Commit e52ff16

Browse files
fearlessfeGrapeBaBa
authored andcommitted
fix: validate empty receipts
1 parent 23104b7 commit e52ff16

3 files changed

Lines changed: 17 additions & 3 deletions

File tree

p2p/discover/portal_protocol.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ import (
99
"encoding/binary"
1010
"errors"
1111
"fmt"
12-
"github.com/ethereum/go-ethereum/common/hexutil"
1312
"io"
1413
"math/big"
1514
"math/rand"
1615
"net"
1716
"sort"
1817
"time"
1918

19+
"github.com/ethereum/go-ethereum/common/hexutil"
20+
2021
"github.com/VictoriaMetrics/fastcache"
2122
"github.com/ethereum/go-ethereum/log"
2223
"github.com/ethereum/go-ethereum/p2p/discover/portalwire"

portalnetwork/history/history_network.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"context"
66
"errors"
77
"fmt"
8+
89
"github.com/ethereum/go-ethereum/common/hexutil"
910

1011
"github.com/ethereum/go-ethereum/core/types"
@@ -34,6 +35,8 @@ var (
3435
ErrInvalidBlockHash = errors.New("invalid block hash")
3536
)
3637

38+
var emptyReceiptHash = hexutil.MustDecode("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")
39+
3740
type ContentKey struct {
3841
selector ContentType
3942
data []byte
@@ -525,6 +528,12 @@ func (h *HistoryNetwork) validateContent(contentKey []byte, content []byte) erro
525528
if err != nil {
526529
return err
527530
}
531+
if bytes.Equal(header.ReceiptHash.Bytes(), emptyReceiptHash) {
532+
if len(content) > 0 {
533+
return fmt.Errorf("content should be empty, but received %v", content)
534+
}
535+
return nil
536+
}
528537
_, err = ValidatePortalReceiptsBytes(content, header.ReceiptHash.Bytes())
529538
return err
530539
case EpochAccumulatorType:
@@ -556,7 +565,7 @@ func (h *HistoryNetwork) validateContents(contentKeys [][]byte, contents [][]byt
556565
err := h.validateContent(contentKey, content)
557566
if err != nil {
558567
h.log.Error("content validate failed", "contentKey", hexutil.Encode(contentKey), "content", hexutil.Encode(content), "err", err)
559-
return fmt.Errorf("content validate failed with content key %v", hexutil.Encode(contentKey))
568+
return fmt.Errorf("content validate failed with content key %x and content %x", contentKey, content)
560569
}
561570
contentId := h.portalProtocol.ToContentId(contentKey)
562571
_ = h.portalProtocol.Put(contentId, content)

portalnetwork/history/testdata/hive_gossip.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
# Test data for Portal Hive
2-
# Data is formatted by comment of block height, header, block body, and receipt, expect for blocks 1 and 100 which don't have receipts
2+
# Data is formatted by comment of block height, header, block body, and receipt
33

44
# Block number: 1
55
- content_key: "0x0088e96d4537bea4d9c05d12549907b32561d3bf31f45aae734cdc119f13406cb6"
66
content_value: "0x080000001c020000f90211a0d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d493479405a56e2d52c817161883f50c441c3228cfe54d9fa0d67e4d450343046425ae4271474353857ab860dbc0a1dde64b41b5cd3a532bf3a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008503ff80000001821388808455ba422499476574682f76312e302e302f6c696e75782f676f312e342e32a0969b900de27b6ac6a67742365dd65f55a0526c41fd18e1b16f1a1215c2e66f5988539bd4979fef1ec401000080ff0700000000000000000000000000000000000000000000000000000023d6398abe4eba641e97a075b30780c12ebe18b24e83a9a9c7bdd94a910cf749bb6bb61aeab6bc5786067f7432bad790642b578881460279ad773a8191596c3087811c70634dbf2ea3abb7199cb5638713844db315d63467f40b5d38eeb884ddcb57866840a050f634417365e9515cd5e6826038ceb45659d85365cfcfceb7a6e9886aaff50b16b6af2bc3bde8b7e701b2cb5022ba49cac9d6c456834e692772b12acf7af78a8375b80ef177c9ad743a14ff0d4935f9ac105444fd57f802fed32495bab257b9585a149a7de4ac53eda7b6df7b9dac7f92325ba05eb1e6b588202048719c250620f4bfa71307470d6c835156db527294c6e6004f9de0c3595a7f1df43427c770506e7e3ca5d021f065544c6ba191d8ffc5fc0805b805d301c926c183ed9ec7e467b962e2304fa7945b6b18042dc2a53cb62b27b28af50fc06db5da2f83bd479f3719b9972fc723c69e4cd13877dcf7cc2a919a95cdf5d7805d9bd9a9f1fbf7a880d82ba9d7af9ed554ce01ea778db5d93d0665ca4fee11f4f873b0b1b58ff1337769b6ee458316030aeac65a5aab68d60fbf214bd44455f892260020000000000000000000000000000000000000000000000000000000000000"
77
- content_key: "0x0188e96d4537bea4d9c05d12549907b32561d3bf31f45aae734cdc119f13406cb6"
88
content_value: "0x0800000008000000c0"
9+
- content_key: "0x0288e96d4537bea4d9c05d12549907b32561d3bf31f45aae734cdc119f13406cb6"
10+
content_value: "0x"
911

1012
# Block number: 100
1113
- content_key: "0x00dfe2e70d6c116a541101cecbb256d7402d62125f6ddc9b607d49edc989825c64"
1214
content_value: "0x0800000021020000f90216a0db10afd3efa45327eb284c83cc925bd9bd7966aea53067c1eebe0724d124ec1ea01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794bb7b8287f3f0a933474a79eae42cbca977791171a090c25f6d7fddeb31a6cc5668a6bba77adbadec705eb7aa5a51265c2d1e3bb7aca056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000085042be722b664821388808455ba43eb9e476574682f4c5649562f76312e302e302f6c696e75782f676f312e342e32a05bb43c0772e58084b221c8e0c859a45950c103c712c5b8f11d9566ee078a45018837129c7f29a9364b0186c4fd5a9b0100000000000000000000000000000000000000000000000000005abe24fddf787826108ee6aa6eb22e8f7ab8e1f2fc3e595a7a8b2f3a27a317a1d7e84db77d1b8a63c32551cbd3c2d3dcfc4f187cfe26db5f9322cd38361fea4e6ebce4de13d97c3eb90bf675f243e527b25db30e3c44dd5375ed9db875685fc96665a9508b9ac80d80bffd490c133dafa57bc23b8affd58fefb3bcfbdc0f6159438704ba2c1ca1178b7ed919eb4802061b025078525e1257b076c00cad6797e16afef5c85d945c0dd70daf201917eb815efdaebf6996e6c51da7c981fb126690d23bd9e36890a948c0c69d4081964b32b73144c4a67296f1d26fdca398f8730a2048719c250620f4bfa71307470d6c835156db527294c6e6004f9de0c3595a7f1df43427c770506e7e3ca5d021f065544c6ba191d8ffc5fc0805b805d301c926c183ed9ec7e467b962e2304fa7945b6b18042dc2a53cb62b27b28af50fc06db5da2f83bd479f3719b9972fc723c69e4cd13877dcf7cc2a919a95cdf5d7805d9bd9a9f1fbf7a880d82ba9d7af9ed554ce01ea778db5d93d0665ca4fee11f4f873b0b1b58ff1337769b6ee458316030aeac65a5aab68d60fbf214bd44455f892260020000000000000000000000000000000000000000000000000000000000000"
1315
- content_key: "0x01dfe2e70d6c116a541101cecbb256d7402d62125f6ddc9b607d49edc989825c64"
1416
content_value: "0x0800000008000000c0"
17+
- content_key: "0x02dfe2e70d6c116a541101cecbb256d7402d62125f6ddc9b607d49edc989825c64"
18+
content_value: "0x"
1519

1620
# Block number: 7000000
1721
- content_key: "0x0017aa411843cb100e57126e911f51f295f5ddb7e9a3bd25e708990534a828c4b7"

0 commit comments

Comments
 (0)