Skip to content

Commit

Permalink
fix bech32 prefix in evidence (#8461)
Browse files Browse the repository at this point in the history
Co-authored-by: Tomas Tauber <2410580+tomtau@users.noreply.github.com>

Co-authored-by: Tomas Tauber <2410580+tomtau@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored and clevinson committed Mar 4, 2021
1 parent 3aaf1bc commit 6e6288d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,15 @@ Ref: https://keepachangelog.com/en/1.0.0/

# Changelog

## [v0.41.4](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.41.3) - 2021-03-02
## [v0.42.0](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.42.0) - 2021-03-03

**IMPORTANT**: This release contains an important security fix for all non Cosmos Hub chains running Stargate version of the Cosmos SDK (>0.40). Non-hub chains should not be using any version of the SDK in the v0.40.x or v0.41.x release series. See [#8461](https://github.com/cosmos/cosmos-sdk/pull/8461) for more details.

### Bug fixes

* (x/evidence) [#8461](https://github.com/cosmos/cosmos-sdk/pull/8461) Fix bech32 prefix in evidence validator address conversion

**IMPORTANT**: Due to a bug in the v0.41.x series with how evidence handles validator consensus addresses #8461, SDK based chains that are not using the default bech32 prefix (cosmos, aka all chains except for the Cosmos Hub) should not use this release or any release in the v0.41.x series. Please see #8668 for tracking & timeline for the v0.42.0 release, which will include a fix for this issue.
## [v0.41.4](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.41.3) - 2021-03-02

### Features

Expand Down
3 changes: 2 additions & 1 deletion x/evidence/types/evidence.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ func (e Equivocation) GetTotalPower() int64 { return 0 }
// FromABCIEvidence converts a Tendermint concrete Evidence type to
// SDK Evidence using Equivocation as the concrete type.
func FromABCIEvidence(e abci.Evidence) exported.Evidence {
consAddr, err := sdk.Bech32ifyAddressBytes(sdk.Bech32PrefixConsAddr, e.Validator.Address)
bech32PrefixConsAddr := sdk.GetConfig().GetBech32ConsensusAddrPrefix()
consAddr, err := sdk.Bech32ifyAddressBytes(bech32PrefixConsAddr, e.Validator.Address)
if err != nil {
panic(err)
}
Expand Down
20 changes: 20 additions & 0 deletions x/evidence/types/evidence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"time"

"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/evidence/types"
Expand Down Expand Up @@ -57,3 +58,22 @@ func TestEquivocationValidateBasic(t *testing.T) {
})
}
}

func TestEvidenceAddressConversion(t *testing.T) {
sdk.GetConfig().SetBech32PrefixForConsensusNode("testcnclcons", "testcnclconspub")
tmEvidence := abci.Evidence{
Type: abci.EvidenceType_DUPLICATE_VOTE,
Validator: abci.Validator{
Address: []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
Power: 100,
},
Height: 1,
Time: time.Now(),
TotalVotingPower: 100,
}
evidence := types.FromABCIEvidence(tmEvidence).(*types.Equivocation)
consAddr := evidence.GetConsensusAddress()
// Check the address is the same after conversion
require.Equal(t, tmEvidence.Validator.Address, consAddr.Bytes())
sdk.GetConfig().SetBech32PrefixForConsensusNode(sdk.Bech32PrefixConsAddr, sdk.Bech32PrefixConsPub)
}

0 comments on commit 6e6288d

Please sign in to comment.