Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relaxed address strength restrictions for legacy 20 byte addresses #772

Merged
merged 5 commits into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

## [Unreleased](https://github.com/CosmWasm/wasmd/tree/HEAD)

[Full Changelog](https://github.com/CosmWasm/wasmd/compare/v0.23.0...HEAD)
**Fixed bugs + Api Breaking:**
- Add support for old contract addresses of length 20 [\#758](https://github.com/CosmWasm/wasmd/issues/758)

[Full Changelog](https://github.com/CosmWasm/wasmd/compare/v0.23.0...HEAD)

## [v0.23.0](https://github.com/CosmWasm/wasmd/tree/v0.23.0) (2022-01-28)

Expand Down
6 changes: 4 additions & 2 deletions x/wasm/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ func GetContractStorePrefix(addr sdk.AccAddress) []byte {
func GetContractByCreatedSecondaryIndexKey(contractAddr sdk.AccAddress, c ContractCodeHistoryEntry) []byte {
prefix := GetContractByCodeIDSecondaryIndexPrefix(c.CodeID)
prefixLen := len(prefix)
r := make([]byte, prefixLen+AbsoluteTxPositionLen+ContractAddrLen)
contractAddrLen := len(contractAddr)
r := make([]byte, prefixLen+AbsoluteTxPositionLen+contractAddrLen)
copy(r[0:], prefix)
copy(r[prefixLen:], c.Updated.Bytes())
copy(r[prefixLen+AbsoluteTxPositionLen:], contractAddr)
Expand Down Expand Up @@ -87,7 +88,8 @@ func GetContractCodeHistoryElementKey(contractAddr sdk.AccAddress, pos uint64) [
// GetContractCodeHistoryElementPrefix returns the key prefix for a contract code history entry: `<prefix><contractAddr>`
func GetContractCodeHistoryElementPrefix(contractAddr sdk.AccAddress) []byte {
prefixLen := len(ContractCodeHistoryElementPrefix)
r := make([]byte, prefixLen+ContractAddrLen)
contractAddrLen := len(contractAddr)
r := make([]byte, prefixLen+contractAddrLen)
copy(r[0:], ContractCodeHistoryElementPrefix)
copy(r[prefixLen:], contractAddr)
return r
Expand Down
37 changes: 36 additions & 1 deletion x/wasm/types/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,54 @@ func TestGetContractByCodeIDSecondaryIndexPrefix(t *testing.T) {
}
}

func TestGetContractCodeHistoryElementPrefix(t *testing.T) {

// test that contract addresses of 20 length are still supported
addr := bytes.Repeat([]byte{4}, 20)
got := GetContractCodeHistoryElementPrefix(addr)
exp := []byte{5, // prefix
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, // address 20 bytes
4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
}
assert.Equal(t, exp, got)

addr = bytes.Repeat([]byte{4}, ContractAddrLen)
got = GetContractCodeHistoryElementPrefix(addr)
exp = []byte{5, // prefix
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, // address 32 bytes
4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4,
}
assert.Equal(t, exp, got)
}

func TestGetContractByCreatedSecondaryIndexKey(t *testing.T) {
e := ContractCodeHistoryEntry{
CodeID: 1,
Updated: &AbsoluteTxPosition{2 + 1<<(8*7), 3 + 1<<(8*7)},
}
addr := bytes.Repeat([]byte{4}, ContractAddrLen)

// test that contract addresses of 20 length are still supported
addr := bytes.Repeat([]byte{4}, 20)
got := GetContractByCreatedSecondaryIndexKey(addr, e)
exp := []byte{6, // prefix
0, 0, 0, 0, 0, 0, 0, 1, // codeID
1, 0, 0, 0, 0, 0, 0, 2, // height
1, 0, 0, 0, 0, 0, 0, 3, // index
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, // address 32 bytes
4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
}
assert.Equal(t, exp, got)

addr = bytes.Repeat([]byte{4}, ContractAddrLen)
got = GetContractByCreatedSecondaryIndexKey(addr, e)
exp = []byte{6, // prefix
0, 0, 0, 0, 0, 0, 0, 1, // codeID
1, 0, 0, 0, 0, 0, 0, 2, // height
1, 0, 0, 0, 0, 0, 0, 3, // index
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, // address 32 bytes
4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4,
}
Expand Down