mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-20 06:54:41 +00:00
block: fix max commit sig size (#5567)
This commit is contained in:
@@ -30,3 +30,4 @@ Friendly reminder, we have a [bug bounty program](https://hackerone.com/tendermi
|
|||||||
- [abci/grpc] \#5520 Return async responses in order, to avoid mempool panics. (@erikgrinaker)
|
- [abci/grpc] \#5520 Return async responses in order, to avoid mempool panics. (@erikgrinaker)
|
||||||
- [blockchain/v2] \#5530 Fix "processed height 4541 but expected height 4540" panic (@melekes)
|
- [blockchain/v2] \#5530 Fix "processed height 4541 but expected height 4540" panic (@melekes)
|
||||||
- [consensus/wal] Fix WAL autorepair by opening target WAL in read/write mode (@erikgrinaker)
|
- [consensus/wal] Fix WAL autorepair by opening target WAL in read/write mode (@erikgrinaker)
|
||||||
|
- [block] \#5567 Fix MaxCommitSigBytes (@cmwaters)
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ func TestTxFilter(t *testing.T) {
|
|||||||
tx types.Tx
|
tx types.Tx
|
||||||
isErr bool
|
isErr bool
|
||||||
}{
|
}{
|
||||||
{types.Tx(tmrand.Bytes(2187)), false},
|
{types.Tx(tmrand.Bytes(2155)), false},
|
||||||
{types.Tx(tmrand.Bytes(2188)), true},
|
{types.Tx(tmrand.Bytes(2156)), true},
|
||||||
{types.Tx(tmrand.Bytes(3000)), true},
|
{types.Tx(tmrand.Bytes(3000)), true},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-2
@@ -24,6 +24,8 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
// MaxHeaderBytes is a maximum header size.
|
// MaxHeaderBytes is a maximum header size.
|
||||||
|
// NOTE: Because app hash can be of arbitrary size, the header is therefore not
|
||||||
|
// capped in size and thus this number should be seen as a soft max
|
||||||
MaxHeaderBytes int64 = 626
|
MaxHeaderBytes int64 = 626
|
||||||
|
|
||||||
// MaxOverheadForBlock - maximum overhead to encode a block (up to
|
// MaxOverheadForBlock - maximum overhead to encode a block (up to
|
||||||
@@ -583,9 +585,9 @@ const (
|
|||||||
const (
|
const (
|
||||||
// Max size of commit without any commitSigs -> 82 for BlockID, 8 for Height, 4 for Round.
|
// Max size of commit without any commitSigs -> 82 for BlockID, 8 for Height, 4 for Round.
|
||||||
MaxCommitOverheadBytes int64 = 94
|
MaxCommitOverheadBytes int64 = 94
|
||||||
// Commit sig size is made up of 32 bytes for the signature, 20 bytes for the address,
|
// Commit sig size is made up of 64 bytes for the signature, 20 bytes for the address,
|
||||||
// 1 byte for the flag and 14 bytes for the timestamp
|
// 1 byte for the flag and 14 bytes for the timestamp
|
||||||
MaxCommitSigBytes int64 = 77
|
MaxCommitSigBytes int64 = 109
|
||||||
)
|
)
|
||||||
|
|
||||||
// CommitSig is a part of the Vote included in a Commit.
|
// CommitSig is a part of the Vote included in a Commit.
|
||||||
|
|||||||
+14
-23
@@ -257,33 +257,22 @@ func TestCommitValidateBasic(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMaxCommitSigBytes(t *testing.T) {
|
func TestMaxCommitBytes(t *testing.T) {
|
||||||
// time is varint encoded so need to pick the max.
|
// time is varint encoded so need to pick the max.
|
||||||
// year int, month Month, day, hour, min, sec, nsec int, loc *Location
|
// year int, month Month, day, hour, min, sec, nsec int, loc *Location
|
||||||
timestamp := time.Date(math.MaxInt64, 0, 0, 0, 0, 0, math.MaxInt64, time.UTC)
|
timestamp := time.Date(math.MaxInt64, 0, 0, 0, 0, 0, math.MaxInt64, time.UTC)
|
||||||
|
|
||||||
cs := &CommitSig{
|
|
||||||
BlockIDFlag: BlockIDFlagNil,
|
|
||||||
ValidatorAddress: crypto.AddressHash([]byte("validator_address")),
|
|
||||||
Timestamp: timestamp,
|
|
||||||
Signature: tmhash.Sum([]byte("signature")),
|
|
||||||
}
|
|
||||||
|
|
||||||
pb := cs.ToProto()
|
|
||||||
|
|
||||||
assert.EqualValues(t, MaxCommitSigBytes, pb.Size())
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestMaxCommitBytes(t *testing.T) {
|
|
||||||
timestamp := time.Date(math.MaxInt64, 0, 0, 0, 0, 0, math.MaxInt64, time.UTC)
|
|
||||||
|
|
||||||
cs := CommitSig{
|
cs := CommitSig{
|
||||||
BlockIDFlag: BlockIDFlagNil,
|
BlockIDFlag: BlockIDFlagNil,
|
||||||
ValidatorAddress: crypto.AddressHash([]byte("validator_address")),
|
ValidatorAddress: crypto.AddressHash([]byte("validator_address")),
|
||||||
Timestamp: timestamp,
|
Timestamp: timestamp,
|
||||||
Signature: tmhash.Sum([]byte("signature")),
|
Signature: crypto.CRandBytes(MaxSignatureSize),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pbSig := cs.ToProto()
|
||||||
|
// test that a single commit sig doesn't exceed max commit sig bytes
|
||||||
|
assert.EqualValues(t, MaxCommitSigBytes, pbSig.Size())
|
||||||
|
|
||||||
// check size with a single commit
|
// check size with a single commit
|
||||||
commit := &Commit{
|
commit := &Commit{
|
||||||
Height: math.MaxInt64,
|
Height: math.MaxInt64,
|
||||||
@@ -463,9 +452,11 @@ func TestBlockMaxDataBytes(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
0: {-10, 1, 0, true, 0},
|
0: {-10, 1, 0, true, 0},
|
||||||
1: {10, 1, 0, true, 0},
|
1: {10, 1, 0, true, 0},
|
||||||
2: {809, 1, 0, true, 0},
|
2: {841, 1, 0, true, 0},
|
||||||
3: {810, 1, 0, false, 0},
|
3: {842, 1, 0, false, 0},
|
||||||
4: {811, 1, 0, false, 1},
|
4: {843, 1, 0, false, 1},
|
||||||
|
5: {954, 2, 0, false, 1},
|
||||||
|
6: {1053, 2, 100, false, 0},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, tc := range testCases {
|
for i, tc := range testCases {
|
||||||
@@ -492,9 +483,9 @@ func TestBlockMaxDataBytesNoEvidence(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
0: {-10, 1, true, 0},
|
0: {-10, 1, true, 0},
|
||||||
1: {10, 1, true, 0},
|
1: {10, 1, true, 0},
|
||||||
2: {809, 1, true, 0},
|
2: {841, 1, true, 0},
|
||||||
3: {810, 1, false, 0},
|
3: {842, 1, false, 0},
|
||||||
4: {811, 1, false, 1},
|
4: {843, 1, false, 1},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, tc := range testCases {
|
for i, tc := range testCases {
|
||||||
|
|||||||
Reference in New Issue
Block a user