Skip to content

Commit

Permalink
fix: Use fixed length hex for pointer at FwdCapabilityKey (backport c…
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuang committed Aug 4, 2022
1 parent e23386b commit 69597f5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/mint) [#12384](https://github.com/cosmos/cosmos-sdk/pull/12384) Ensure `GoalBonded` must be positive when performing `x/mint` parameter validation.
* (simapp) [#12437](https://github.com/cosmos/cosmos-sdk/pull/12437) fix the non-determinstic behavior in simulations caused by `GenTx` and check
empty coins slice before it is used to create `banktype.MsgSend`.
* (x/capability) []() Use fixed length hex for pointer at FwdCapabilityKey.

## [v0.45.6](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.45.6) - 2022-06-28

Expand Down
7 changes: 6 additions & 1 deletion x/capability/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ func RevCapabilityKey(module, name string) []byte {
// FwdCapabilityKey returns a forward lookup key for a given module and capability
// reference.
func FwdCapabilityKey(module string, cap *Capability) []byte {
return []byte(fmt.Sprintf("%s/fwd/%p", module, cap))
// truncate the key to fixed length, keep backward compatible on common architectures.
key := fmt.Sprintf("%#010p", cap)
if len(key) > 10 {
key = key[len(key)-10:]
}
return []byte(fmt.Sprintf("%s/fwd/0x%s", module, key))
}

// IndexToKey returns bytes to be used as a key for a given capability index.
Expand Down
7 changes: 6 additions & 1 deletion x/capability/types/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ func TestRevCapabilityKey(t *testing.T) {

func TestFwdCapabilityKey(t *testing.T) {
cap := types.NewCapability(23)
expected := []byte(fmt.Sprintf("bank/fwd/%p", cap))
key := fmt.Sprintf("%#010p", cap)
if len(key) > 10 {
key = key[len(key)-10:]
}
require.Equal(t, 10, len(key))
expected := []byte(fmt.Sprintf("bank/fwd/0x%s", key))
require.Equal(t, expected, types.FwdCapabilityKey("bank", cap))
}

Expand Down

0 comments on commit 69597f5

Please sign in to comment.