From 255828c714072f5cc729fff423a9e9dc18ed01dc Mon Sep 17 00:00:00 2001 From: itsdevbear Date: Tue, 23 Jan 2024 14:17:55 -0500 Subject: [PATCH 1/4] push --- baseapp/abci_utils.go | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/baseapp/abci_utils.go b/baseapp/abci_utils.go index b09a22b33ecf..a1ecc36edeeb 100644 --- a/baseapp/abci_utils.go +++ b/baseapp/abci_utils.go @@ -14,17 +14,10 @@ import ( protoio "github.com/cosmos/gogoproto/io" "github.com/cosmos/gogoproto/proto" - "cosmossdk.io/math" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/mempool" ) -// VoteExtensionThreshold defines the total voting power % that must be -// submitted in order for all vote extensions to be considered valid for a -// given height. -var VoteExtensionThreshold = math.LegacyNewDecWithPrec(667, 3) - type ( // ValidatorStore defines the interface contract require for verifying vote // extension signatures. Typically, this will be implemented by the x/staking @@ -133,13 +126,10 @@ func ValidateVoteExtensions( sumVP += vote.Validator.Power } - if totalVP > 0 { - percentSubmitted := math.LegacyNewDecFromInt(math.NewInt(sumVP)).Quo(math.LegacyNewDecFromInt(math.NewInt(totalVP))) - if percentSubmitted.LT(VoteExtensionThreshold) { - return fmt.Errorf("insufficient cumulative voting power received to verify vote extensions; got: %s, expected: >=%s", percentSubmitted, VoteExtensionThreshold) - } + // If the sum of the voting power has not reached (2/3 + 1) we need to error. + if sumVP < (totalVP*2/3)+1 { + return fmt.Errorf("insufficient cumulative voting power received to verify vote extensions; got: %d, expected: >=%d", sumVP, (totalVP*2/3)+1) } - return nil } From 53390adfe06554af03302c07d75e40f08b8afb03 Mon Sep 17 00:00:00 2001 From: itsdevbear Date: Wed, 24 Jan 2024 11:38:34 -0500 Subject: [PATCH 2/4] add more safety checks --- baseapp/abci_utils.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/baseapp/abci_utils.go b/baseapp/abci_utils.go index a1ecc36edeeb..4ea310971fb1 100644 --- a/baseapp/abci_utils.go +++ b/baseapp/abci_utils.go @@ -126,9 +126,17 @@ func ValidateVoteExtensions( sumVP += vote.Validator.Power } + // This check is probably unnecessary, but better safe than sorry. + if totalVP <= 0 { + return fmt.Errorf("total voting power must be positive, got: %d", totalVP) + } + // If the sum of the voting power has not reached (2/3 + 1) we need to error. - if sumVP < (totalVP*2/3)+1 { - return fmt.Errorf("insufficient cumulative voting power received to verify vote extensions; got: %d, expected: >=%d", sumVP, (totalVP*2/3)+1) + if requiredVP := ((totalVP * 2) / 3) + 1; sumVP < requiredVP { + return fmt.Errorf( + "insufficient cumulative voting power received to verify vote extensions; got: %d, expected: >=%d", + sumVP, requiredVP, + ) } return nil } From 5f40824be52f3dadca1ce645bfdb0db6eb5bc6e6 Mon Sep 17 00:00:00 2001 From: itsdevbear Date: Thu, 25 Jan 2024 11:20:23 -0500 Subject: [PATCH 3/4] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb3d10fa6b5d..5b08b7a4fb6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -87,6 +87,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i * (simulation) [#17911](https://github.com/cosmos/cosmos-sdk/pull/17911) Fix all problems with executing command `make test-sim-custom-genesis-fast` for simulation test. * (simulation) [#18196](https://github.com/cosmos/cosmos-sdk/pull/18196) Fix the problem of `validator set is empty after InitGenesis` in simulation test. * (baseapp) [#18551](https://github.com/cosmos/cosmos-sdk/pull/18551) Fix SelectTxForProposal the calculation method of tx bytes size is inconsistent with CometBFT +* (abci): [#19200](https://github.com/cosmos/cosmos-sdk/pull/19200) Ensure that sdk side ve math matches cometbft ### API Breaking Changes From 947abdaa6194c01a7ac29d0c9d69e4327adcef5a Mon Sep 17 00:00:00 2001 From: itsdevbear Date: Thu, 25 Jan 2024 11:53:17 -0500 Subject: [PATCH 4/4] fix test --- baseapp/abci_test.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/baseapp/abci_test.go b/baseapp/abci_test.go index efca5b74079b..769349f84e20 100644 --- a/baseapp/abci_test.go +++ b/baseapp/abci_test.go @@ -2224,11 +2224,25 @@ func TestBaseApp_VoteExtensions(t *testing.T) { } require.Equal(t, 10, successful) + extVotes := []abci.ExtendedVoteInfo{} + for _, val := range vals { + extVotes = append(extVotes, abci.ExtendedVoteInfo{ + VoteExtension: allVEs[0], + BlockIdFlag: cmtproto.BlockIDFlagCommit, + ExtensionSignature: []byte{}, + Validator: abci.Validator{ + Address: val.Bytes(), + Power: 666, + }, + }, + ) + } + prepPropReq := &abci.RequestPrepareProposal{ Height: 1, LocalLastCommit: abci.ExtendedCommitInfo{ Round: 0, - Votes: []abci.ExtendedVoteInfo{}, + Votes: extVotes, }, } @@ -2287,6 +2301,7 @@ func TestBaseApp_VoteExtensions(t *testing.T) { ExtensionSignature: extSig, Validator: abci.Validator{ Address: vals[i].Bytes(), + Power: 666, }, }) }