mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 23:26:44 +00:00
fix: validate empty receipts
This commit is contained in:
parent
23104b78ec
commit
e52ff169cf
3 changed files with 17 additions and 3 deletions
|
|
@ -9,7 +9,6 @@ import (
|
|||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
"io"
|
||||
"math/big"
|
||||
"math/rand"
|
||||
|
|
@ -17,6 +16,8 @@ import (
|
|||
"sort"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
|
||||
"github.com/VictoriaMetrics/fastcache"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/p2p/discover/portalwire"
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
|
|
@ -34,6 +35,8 @@ var (
|
|||
ErrInvalidBlockHash = errors.New("invalid block hash")
|
||||
)
|
||||
|
||||
var emptyReceiptHash = hexutil.MustDecode("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")
|
||||
|
||||
type ContentKey struct {
|
||||
selector ContentType
|
||||
data []byte
|
||||
|
|
@ -525,6 +528,12 @@ func (h *HistoryNetwork) validateContent(contentKey []byte, content []byte) erro
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if bytes.Equal(header.ReceiptHash.Bytes(), emptyReceiptHash) {
|
||||
if len(content) > 0 {
|
||||
return fmt.Errorf("content should be empty, but received %v", content)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
_, err = ValidatePortalReceiptsBytes(content, header.ReceiptHash.Bytes())
|
||||
return err
|
||||
case EpochAccumulatorType:
|
||||
|
|
@ -556,7 +565,7 @@ func (h *HistoryNetwork) validateContents(contentKeys [][]byte, contents [][]byt
|
|||
err := h.validateContent(contentKey, content)
|
||||
if err != nil {
|
||||
h.log.Error("content validate failed", "contentKey", hexutil.Encode(contentKey), "content", hexutil.Encode(content), "err", err)
|
||||
return fmt.Errorf("content validate failed with content key %v", hexutil.Encode(contentKey))
|
||||
return fmt.Errorf("content validate failed with content key %x and content %x", contentKey, content)
|
||||
}
|
||||
contentId := h.portalProtocol.ToContentId(contentKey)
|
||||
_ = h.portalProtocol.Put(contentId, content)
|
||||
|
|
|
|||
|
|
@ -1,17 +1,21 @@
|
|||
# Test data for Portal Hive
|
||||
# Data is formatted by comment of block height, header, block body, and receipt, expect for blocks 1 and 100 which don't have receipts
|
||||
# Data is formatted by comment of block height, header, block body, and receipt
|
||||
|
||||
# Block number: 1
|
||||
- content_key: "0x0088e96d4537bea4d9c05d12549907b32561d3bf31f45aae734cdc119f13406cb6"
|
||||
content_value: "0x080000001c020000f90211a0d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d493479405a56e2d52c817161883f50c441c3228cfe54d9fa0d67e4d450343046425ae4271474353857ab860dbc0a1dde64b41b5cd3a532bf3a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008503ff80000001821388808455ba422499476574682f76312e302e302f6c696e75782f676f312e342e32a0969b900de27b6ac6a67742365dd65f55a0526c41fd18e1b16f1a1215c2e66f5988539bd4979fef1ec401000080ff0700000000000000000000000000000000000000000000000000000023d6398abe4eba641e97a075b30780c12ebe18b24e83a9a9c7bdd94a910cf749bb6bb61aeab6bc5786067f7432bad790642b578881460279ad773a8191596c3087811c70634dbf2ea3abb7199cb5638713844db315d63467f40b5d38eeb884ddcb57866840a050f634417365e9515cd5e6826038ceb45659d85365cfcfceb7a6e9886aaff50b16b6af2bc3bde8b7e701b2cb5022ba49cac9d6c456834e692772b12acf7af78a8375b80ef177c9ad743a14ff0d4935f9ac105444fd57f802fed32495bab257b9585a149a7de4ac53eda7b6df7b9dac7f92325ba05eb1e6b588202048719c250620f4bfa71307470d6c835156db527294c6e6004f9de0c3595a7f1df43427c770506e7e3ca5d021f065544c6ba191d8ffc5fc0805b805d301c926c183ed9ec7e467b962e2304fa7945b6b18042dc2a53cb62b27b28af50fc06db5da2f83bd479f3719b9972fc723c69e4cd13877dcf7cc2a919a95cdf5d7805d9bd9a9f1fbf7a880d82ba9d7af9ed554ce01ea778db5d93d0665ca4fee11f4f873b0b1b58ff1337769b6ee458316030aeac65a5aab68d60fbf214bd44455f892260020000000000000000000000000000000000000000000000000000000000000"
|
||||
- content_key: "0x0188e96d4537bea4d9c05d12549907b32561d3bf31f45aae734cdc119f13406cb6"
|
||||
content_value: "0x0800000008000000c0"
|
||||
- content_key: "0x0288e96d4537bea4d9c05d12549907b32561d3bf31f45aae734cdc119f13406cb6"
|
||||
content_value: "0x"
|
||||
|
||||
# Block number: 100
|
||||
- content_key: "0x00dfe2e70d6c116a541101cecbb256d7402d62125f6ddc9b607d49edc989825c64"
|
||||
content_value: "0x0800000021020000f90216a0db10afd3efa45327eb284c83cc925bd9bd7966aea53067c1eebe0724d124ec1ea01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794bb7b8287f3f0a933474a79eae42cbca977791171a090c25f6d7fddeb31a6cc5668a6bba77adbadec705eb7aa5a51265c2d1e3bb7aca056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000085042be722b664821388808455ba43eb9e476574682f4c5649562f76312e302e302f6c696e75782f676f312e342e32a05bb43c0772e58084b221c8e0c859a45950c103c712c5b8f11d9566ee078a45018837129c7f29a9364b0186c4fd5a9b0100000000000000000000000000000000000000000000000000005abe24fddf787826108ee6aa6eb22e8f7ab8e1f2fc3e595a7a8b2f3a27a317a1d7e84db77d1b8a63c32551cbd3c2d3dcfc4f187cfe26db5f9322cd38361fea4e6ebce4de13d97c3eb90bf675f243e527b25db30e3c44dd5375ed9db875685fc96665a9508b9ac80d80bffd490c133dafa57bc23b8affd58fefb3bcfbdc0f6159438704ba2c1ca1178b7ed919eb4802061b025078525e1257b076c00cad6797e16afef5c85d945c0dd70daf201917eb815efdaebf6996e6c51da7c981fb126690d23bd9e36890a948c0c69d4081964b32b73144c4a67296f1d26fdca398f8730a2048719c250620f4bfa71307470d6c835156db527294c6e6004f9de0c3595a7f1df43427c770506e7e3ca5d021f065544c6ba191d8ffc5fc0805b805d301c926c183ed9ec7e467b962e2304fa7945b6b18042dc2a53cb62b27b28af50fc06db5da2f83bd479f3719b9972fc723c69e4cd13877dcf7cc2a919a95cdf5d7805d9bd9a9f1fbf7a880d82ba9d7af9ed554ce01ea778db5d93d0665ca4fee11f4f873b0b1b58ff1337769b6ee458316030aeac65a5aab68d60fbf214bd44455f892260020000000000000000000000000000000000000000000000000000000000000"
|
||||
- content_key: "0x01dfe2e70d6c116a541101cecbb256d7402d62125f6ddc9b607d49edc989825c64"
|
||||
content_value: "0x0800000008000000c0"
|
||||
- content_key: "0x02dfe2e70d6c116a541101cecbb256d7402d62125f6ddc9b607d49edc989825c64"
|
||||
content_value: "0x"
|
||||
|
||||
# Block number: 7000000
|
||||
- content_key: "0x0017aa411843cb100e57126e911f51f295f5ddb7e9a3bd25e708990534a828c4b7"
|
||||
|
|
|
|||
Loading…
Reference in a new issue