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

[2.0] Privatize CanonicalAddr, Binary and Size inner values #1876

Merged
merged 5 commits into from
Nov 6, 2023
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: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ and this project adheres to
`ConversionOverflowError` and `DivideByZeroError`. ([#1896])
- cosmwasm-std: Add `SubMsg:reply_never` constructor ([#1929])
- cosmwasm-std: Add optional memo field to `IbcMsg::Transfer`. ([#1878])
- cosmwasm-std: Make inner values of `CanonicalAddr` and `Binary` private and
add constructor for `Binary`. ([#1876])
- cosmwasm-vm: Make inner value of `Size` private and add constructor. ([#1876])

[#1874]: https://github.com/CosmWasm/cosmwasm/pull/1874
[#1876]: https://github.com/CosmWasm/cosmwasm/pull/1876
[#1878]: https://github.com/CosmWasm/cosmwasm/pull/1878
[#1879]: https://github.com/CosmWasm/cosmwasm/pull/1879
[#1890]: https://github.com/CosmWasm/cosmwasm/pull/1890
Expand Down
16 changes: 16 additions & 0 deletions MIGRATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,22 @@ major releases of `cosmwasm`. Note that you can also view the
+Coin::new(1234u128, "uatom")
```

- When creating a `Binary` or `Size` instance from an inner value, you now have
to explicitly call `new`:

```diff
-Binary(vec![1u8])
+Binary::new(vec![1u8])
```

- When accessing the inner value of a `CanonicalAddr` or `Binary`, use
`as_slice` instead:

```diff
-&canonical_addr.0
+canonical_addr.as_slice()
```

## 1.4.x -> 1.5.0

- Update `cosmwasm-*` dependencies in Cargo.toml (skip the ones you don't use):
Expand Down
82 changes: 42 additions & 40 deletions contracts/crypto-verify/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<QueryResponse> {
public_key,
} => to_json_binary(&query_verify_cosmos(
deps,
&message.0,
&signature.0,
&public_key.0,
message.as_slice(),
signature.as_slice(),
public_key.as_slice(),
)?),
QueryMsg::VerifyEthereumText {
message,
Expand Down Expand Up @@ -69,9 +69,9 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<QueryResponse> {
public_key,
} => to_json_binary(&query_verify_tendermint(
deps,
&message.0,
&signature.0,
&public_key.0,
message.as_slice(),
signature.as_slice(),
public_key.as_slice(),
)?),
QueryMsg::VerifyTendermintBatch {
messages,
Expand Down Expand Up @@ -268,9 +268,9 @@ mod tests {
let public_key = hex::decode(SECP256K1_PUBLIC_KEY_HEX).unwrap();

let verify_msg = QueryMsg::VerifyCosmosSignature {
message: Binary(message),
signature: Binary(signature),
public_key: Binary(public_key),
message: Binary::new(message),
signature: Binary::new(signature),
public_key: Binary::new(public_key),
};

let raw = query(deps.as_ref(), mock_env(), verify_msg).unwrap();
Expand All @@ -290,9 +290,9 @@ mod tests {
let public_key = hex::decode(SECP256K1_PUBLIC_KEY_HEX).unwrap();

let verify_msg = QueryMsg::VerifyCosmosSignature {
message: Binary(message),
signature: Binary(signature),
public_key: Binary(public_key),
message: Binary::new(message),
signature: Binary::new(signature),
public_key: Binary::new(public_key),
};

let raw = query(deps.as_ref(), mock_env(), verify_msg).unwrap();
Expand All @@ -310,9 +310,9 @@ mod tests {
let public_key = vec![];

let verify_msg = QueryMsg::VerifyCosmosSignature {
message: Binary(message),
signature: Binary(signature),
public_key: Binary(public_key),
message: Binary::new(message),
signature: Binary::new(signature),
public_key: Binary::new(public_key),
};

let res = query(deps.as_ref(), mock_env(), verify_msg);
Expand Down Expand Up @@ -457,15 +457,15 @@ mod tests {

let messages = [ED25519_MESSAGE_HEX, ED25519_MESSAGE2_HEX]
.iter()
.map(|m| Binary(hex::decode(m).unwrap()))
.map(|m| Binary::new(hex::decode(m).unwrap()))
.collect();
let signatures = [ED25519_SIGNATURE_HEX, ED25519_SIGNATURE2_HEX]
.iter()
.map(|m| Binary(hex::decode(m).unwrap()))
.map(|m| Binary::new(hex::decode(m).unwrap()))
.collect();
let public_keys = [ED25519_PUBLIC_KEY_HEX, ED25519_PUBLIC_KEY2_HEX]
.iter()
.map(|m| Binary(hex::decode(m).unwrap()))
.map(|m| Binary::new(hex::decode(m).unwrap()))
.collect();

let verify_msg = QueryMsg::VerifyTendermintBatch {
Expand All @@ -487,18 +487,18 @@ mod tests {
// One message
let messages = [ED25519_MESSAGE_HEX]
.iter()
.map(|m| Binary(hex::decode(m).unwrap()))
.map(|m| Binary::new(hex::decode(m).unwrap()))
.collect();
// Multiple signatures
//FIXME: Use different signatures / pubkeys
let signatures = [ED25519_SIGNATURE_HEX, ED25519_SIGNATURE_HEX]
.iter()
.map(|m| Binary(hex::decode(m).unwrap()))
.map(|m| Binary::new(hex::decode(m).unwrap()))
.collect();
// Multiple pubkeys
let public_keys = [ED25519_PUBLIC_KEY_HEX, ED25519_PUBLIC_KEY_HEX]
.iter()
.map(|m| Binary(hex::decode(m).unwrap()))
.map(|m| Binary::new(hex::decode(m).unwrap()))
.collect();

let verify_msg = QueryMsg::VerifyTendermintBatch {
Expand All @@ -521,18 +521,18 @@ mod tests {
//FIXME: Use different messages
let messages = [ED25519_MESSAGE_HEX, ED25519_MESSAGE_HEX]
.iter()
.map(|m| Binary(hex::decode(m).unwrap()))
.map(|m| Binary::new(hex::decode(m).unwrap()))
.collect();
// Multiple signatures
//FIXME: Use different signatures
let signatures = [ED25519_SIGNATURE_HEX, ED25519_SIGNATURE_HEX]
.iter()
.map(|m| Binary(hex::decode(m).unwrap()))
.map(|m| Binary::new(hex::decode(m).unwrap()))
.collect();
// One pubkey
let public_keys = [ED25519_PUBLIC_KEY_HEX]
.iter()
.map(|m| Binary(hex::decode(m).unwrap()))
.map(|m| Binary::new(hex::decode(m).unwrap()))
.collect();

let verify_msg = QueryMsg::VerifyTendermintBatch {
Expand All @@ -553,17 +553,19 @@ mod tests {

let mut messages: Vec<Binary> = [ED25519_MESSAGE_HEX, ED25519_MESSAGE2_HEX]
.iter()
.map(|m| Binary(hex::decode(m).unwrap()))
.map(|m| Binary::new(hex::decode(m).unwrap()))
.collect();
// Alter one of the messages
messages[0].0[0] ^= 0x01;
let mut b: Vec<_> = messages.pop().unwrap().into();
b[0] ^= 0x01;
messages.push(Binary::new(b));
chipshort marked this conversation as resolved.
Show resolved Hide resolved
let signatures = [ED25519_SIGNATURE_HEX, ED25519_SIGNATURE2_HEX]
.iter()
.map(|m| Binary(hex::decode(m).unwrap()))
.map(|m| Binary::new(hex::decode(m).unwrap()))
.collect();
let public_keys = [ED25519_PUBLIC_KEY_HEX, ED25519_PUBLIC_KEY2_HEX]
.iter()
.map(|m| Binary(hex::decode(m).unwrap()))
.map(|m| Binary::new(hex::decode(m).unwrap()))
.collect();

let verify_msg = QueryMsg::VerifyTendermintBatch {
Expand All @@ -584,16 +586,16 @@ mod tests {

let messages = [ED25519_MESSAGE_HEX, ED25519_MESSAGE2_HEX]
.iter()
.map(|m| Binary(hex::decode(m).unwrap()))
.map(|m| Binary::new(hex::decode(m).unwrap()))
.collect();
let signatures = [ED25519_SIGNATURE_HEX, ED25519_SIGNATURE2_HEX]
.iter()
.map(|m| Binary(hex::decode(m).unwrap()))
.map(|m| Binary::new(hex::decode(m).unwrap()))
.collect();
// One of the public keys is empty
let public_keys = ["", ED25519_PUBLIC_KEY_HEX]
.iter()
.map(|m| Binary(hex::decode(m).unwrap()))
.map(|m| Binary::new(hex::decode(m).unwrap()))
.collect();

let verify_msg = QueryMsg::VerifyTendermintBatch {
Expand All @@ -620,9 +622,9 @@ mod tests {
let public_key = hex::decode(ED25519_PUBLIC_KEY_HEX).unwrap();

let verify_msg = QueryMsg::VerifyTendermintSignature {
message: Binary(message),
signature: Binary(signature),
public_key: Binary(public_key),
message: Binary::new(message),
signature: Binary::new(signature),
public_key: Binary::new(public_key),
};

let raw = query(deps.as_ref(), mock_env(), verify_msg).unwrap();
Expand All @@ -642,9 +644,9 @@ mod tests {
let public_key = hex::decode(ED25519_PUBLIC_KEY_HEX).unwrap();

let verify_msg = QueryMsg::VerifyTendermintSignature {
message: Binary(message),
signature: Binary(signature),
public_key: Binary(public_key),
message: Binary::new(message),
signature: Binary::new(signature),
public_key: Binary::new(public_key),
};

let raw = query(deps.as_ref(), mock_env(), verify_msg).unwrap();
Expand All @@ -662,9 +664,9 @@ mod tests {
let public_key = vec![];

let verify_msg = QueryMsg::VerifyTendermintSignature {
message: Binary(message),
signature: Binary(signature),
public_key: Binary(public_key),
message: Binary::new(message),
signature: Binary::new(signature),
public_key: Binary::new(public_key),
};
let res = query(deps.as_ref(), mock_env(), verify_msg);
assert!(res.is_err());
Expand Down
Loading
Loading