From fe5e82ae25f0e19f5f674764459d36b26bcc5db3 Mon Sep 17 00:00:00 2001 From: Assaf Morami Date: Thu, 20 Apr 2023 16:33:43 +0300 Subject: [PATCH 01/11] Add the memo field in IbcMsg::Transfer --- contracts/ibc-reflect-send/src/contract.rs | 1 + contracts/ibc-reflect-send/src/ibc.rs | 1 + contracts/ibc-reflect-send/tests/integration.rs | 1 + packages/std/src/ibc.rs | 6 ++++++ 4 files changed, 9 insertions(+) diff --git a/contracts/ibc-reflect-send/src/contract.rs b/contracts/ibc-reflect-send/src/contract.rs index 3784fc57cd..243b0c4014 100644 --- a/contracts/ibc-reflect-send/src/contract.rs +++ b/contracts/ibc-reflect-send/src/contract.rs @@ -157,6 +157,7 @@ pub fn handle_send_funds( to_address: remote_addr, amount, timeout: env.block.time.plus_seconds(PACKET_LIFETIME).into(), + memo: None, }; let res = Response::new() diff --git a/contracts/ibc-reflect-send/src/ibc.rs b/contracts/ibc-reflect-send/src/ibc.rs index dca8cbf78c..1982f20987 100644 --- a/contracts/ibc-reflect-send/src/ibc.rs +++ b/contracts/ibc-reflect-send/src/ibc.rs @@ -414,6 +414,7 @@ mod tests { to_address, amount, timeout, + memo, }) => { assert_eq!(transfer_channel_id, channel_id.as_str()); assert_eq!(remote_addr, to_address.as_str()); diff --git a/contracts/ibc-reflect-send/tests/integration.rs b/contracts/ibc-reflect-send/tests/integration.rs index c0c2977b83..261909eae7 100644 --- a/contracts/ibc-reflect-send/tests/integration.rs +++ b/contracts/ibc-reflect-send/tests/integration.rs @@ -234,6 +234,7 @@ fn send_remote_funds() { to_address, amount, timeout, + memo, }) => { assert_eq!(transfer_channel_id, channel_id.as_str()); assert_eq!(remote_addr, to_address.as_str()); diff --git a/packages/std/src/ibc.rs b/packages/std/src/ibc.rs index 8f2505a4ec..d148f4e7e8 100644 --- a/packages/std/src/ibc.rs +++ b/packages/std/src/ibc.rs @@ -36,6 +36,11 @@ pub enum IbcMsg { amount: Coin, /// when packet times out, measured on remote chain timeout: IbcTimeout, + /// optional memo + /// can put here `{"ibc_callback":"secret1contractAddr"}` to get a callback on ack/timeout + /// see this for more info: + /// https://github.com/scrtlabs/SecretNetwork/blob/78a5f82a4/x/ibc-hooks/README.md?plain=1#L144-L188 + memo: Option, }, /// Sends an IBC packet with given data over the existing channel. /// Data should be encoded in a format defined by the channel version, @@ -786,6 +791,7 @@ mod tests { to_address: "my-special-addr".into(), amount: Coin::new(12345678, "uatom"), timeout: IbcTimeout::with_timestamp(Timestamp::from_nanos(1234567890)), + memo: None, }; let encoded = to_string(&msg).unwrap(); let expected = r#"{"transfer":{"channel_id":"channel-123","to_address":"my-special-addr","amount":{"denom":"uatom","amount":"12345678"},"timeout":{"block":null,"timestamp":"1234567890"}}}"#; From 7752a20849f292733ce67f2509fde6c58909bb73 Mon Sep 17 00:00:00 2001 From: Assaf Morami Date: Thu, 20 Apr 2023 19:56:00 +0300 Subject: [PATCH 02/11] memo Option -> String --- contracts/ibc-reflect-send/src/contract.rs | 2 +- packages/std/src/ibc.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/contracts/ibc-reflect-send/src/contract.rs b/contracts/ibc-reflect-send/src/contract.rs index 243b0c4014..be5fdd10c3 100644 --- a/contracts/ibc-reflect-send/src/contract.rs +++ b/contracts/ibc-reflect-send/src/contract.rs @@ -157,7 +157,7 @@ pub fn handle_send_funds( to_address: remote_addr, amount, timeout: env.block.time.plus_seconds(PACKET_LIFETIME).into(), - memo: None, + memo: "", }; let res = Response::new() diff --git a/packages/std/src/ibc.rs b/packages/std/src/ibc.rs index d148f4e7e8..b516e9d688 100644 --- a/packages/std/src/ibc.rs +++ b/packages/std/src/ibc.rs @@ -40,7 +40,7 @@ pub enum IbcMsg { /// can put here `{"ibc_callback":"secret1contractAddr"}` to get a callback on ack/timeout /// see this for more info: /// https://github.com/scrtlabs/SecretNetwork/blob/78a5f82a4/x/ibc-hooks/README.md?plain=1#L144-L188 - memo: Option, + memo: String, }, /// Sends an IBC packet with given data over the existing channel. /// Data should be encoded in a format defined by the channel version, @@ -791,10 +791,10 @@ mod tests { to_address: "my-special-addr".into(), amount: Coin::new(12345678, "uatom"), timeout: IbcTimeout::with_timestamp(Timestamp::from_nanos(1234567890)), - memo: None, + memo: "", }; let encoded = to_string(&msg).unwrap(); - let expected = r#"{"transfer":{"channel_id":"channel-123","to_address":"my-special-addr","amount":{"denom":"uatom","amount":"12345678"},"timeout":{"block":null,"timestamp":"1234567890"}}}"#; + let expected = r#"{"transfer":{"channel_id":"channel-123","to_address":"my-special-addr","amount":{"denom":"uatom","amount":"12345678"},"timeout":{"block":null,"timestamp":"1234567890"},"memo":""}}"#; assert_eq!(encoded.as_str(), expected); } From 0aee15eb64e3200027b252b9be12d92353e097fb Mon Sep 17 00:00:00 2001 From: Assaf Morami Date: Wed, 28 Jun 2023 10:21:42 +0300 Subject: [PATCH 03/11] Add WasmMsg::{Migrate,UpdateAdmin,ClearAdmin} --- packages/std/src/results/cosmos_msg.rs | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/packages/std/src/results/cosmos_msg.rs b/packages/std/src/results/cosmos_msg.rs index 8d214a2615..fa5bf2a8d8 100644 --- a/packages/std/src/results/cosmos_msg.rs +++ b/packages/std/src/results/cosmos_msg.rs @@ -150,6 +150,33 @@ pub enum WasmMsg { /// A human-readbale label for the contract, must be unique across all contracts label: String, }, + /// Migrates a given contracts to use new wasm code. Passes a MigrateMsg to allow us to + /// customize behavior. + /// + /// Only the contract admin (as defined in wasmd), if any, is able to make this call. + /// + /// This is translated to a [MsgMigrateContract](https://github.com/CosmWasm/wasmd/blob/v0.14.0/x/wasm/internal/types/tx.proto#L86-L96). + /// `sender` is automatically filled with the current contract's address. + Migrate { + contract_addr: String, + /// new_code_hash is the hex encoded hash of the new code. This is used by Secret Network to harden against replaying the contract + /// It is used to bind the request to a destination contract in a stronger way than just the contract address which can be faked + new_code_hash: String, + /// the code_id of the new logic to place in the given contract + new_code_id: u64, + /// msg is the json-encoded MigrateMsg struct that will be passed to the new code + #[derivative(Debug(format_with = "binary_to_string"))] + msg: Binary, + }, + /// Sets a new admin (for migrate) on the given contract. + /// Fails if this contract is not currently admin of the target contract. + UpdateAdmin { + contract_addr: String, + admin: String, + }, + /// Clears the admin on the given contract, so no more migration possible. + /// Fails if this contract is not currently admin of the target contract. + ClearAdmin { contract_addr: String }, } #[cfg(feature = "stargate")] From c6c5ee775f7656d12196bd1acfb7cb9e26aa75d6 Mon Sep 17 00:00:00 2001 From: Assaf Morami Date: Wed, 5 Jul 2023 21:39:12 +0300 Subject: [PATCH 04/11] Update WasmMsg::Migrate to have more consistent field names --- packages/std/src/results/cosmos_msg.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/std/src/results/cosmos_msg.rs b/packages/std/src/results/cosmos_msg.rs index 9e65fb15fd..ee104fb2b9 100644 --- a/packages/std/src/results/cosmos_msg.rs +++ b/packages/std/src/results/cosmos_msg.rs @@ -177,11 +177,11 @@ pub enum WasmMsg { /// `sender` is automatically filled with the current contract's address. Migrate { contract_addr: String, - /// new_code_hash is the hex encoded hash of the new code. This is used by Secret Network to harden against replaying the contract + /// code_hash is the hex encoded hash of the **new** code. This is used by Secret Network to harden against replaying the contract /// It is used to bind the request to a destination contract in a stronger way than just the contract address which can be faked - new_code_hash: String, - /// the code_id of the new logic to place in the given contract - new_code_id: u64, + code_hash: String, + /// the code_id of the **new** logic to place in the given contract + code_id: u64, /// msg is the json-encoded MigrateMsg struct that will be passed to the new code #[derivative(Debug(format_with = "binary_to_string"))] msg: Binary, From b46529a2a7e4b595b39722e09ef5cd8b5a60443f Mon Sep 17 00:00:00 2001 From: Assaf Morami Date: Thu, 3 Aug 2023 14:50:39 +0300 Subject: [PATCH 05/11] Add env.transaction.hash --- packages/std/src/types.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/std/src/types.rs b/packages/std/src/types.rs index 5d3b91633c..e1c99c65d0 100644 --- a/packages/std/src/types.rs +++ b/packages/std/src/types.rs @@ -27,6 +27,11 @@ pub struct TransactionInfo { /// using the pair (`env.block.height`, `env.transaction.index`). /// pub index: u32, + #[serde(default)] + /// The hash of the current transaction bytes. + /// aka txhash or transaction_id + /// hash = sha256(tx_bytes) + pub hash: String, } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] From 84e47738906bece138850f579457cc211494492b Mon Sep 17 00:00:00 2001 From: Assaf Morami Date: Fri, 4 Aug 2023 00:29:40 +0300 Subject: [PATCH 06/11] Add env.transaction.hash to mock_env() --- packages/std/src/testing/mock.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/std/src/testing/mock.rs b/packages/std/src/testing/mock.rs index 9931259995..e8561e0953 100644 --- a/packages/std/src/testing/mock.rs +++ b/packages/std/src/testing/mock.rs @@ -253,7 +253,7 @@ pub fn mock_env() -> Env { Binary::from_base64("wLsKdf/sYqvSMI0G0aWRjob25mrIB0VQVjTjDXnDafk=").unwrap(), ), }, - transaction: Some(TransactionInfo { index: 3 }), + transaction: Some(TransactionInfo { index: 3, hash: "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" }), contract: ContractInfo { address: Addr::unchecked(MOCK_CONTRACT_ADDR), code_hash: "".to_string(), From 6b8a328bd430a5025266c0daf84192261ba393d6 Mon Sep 17 00:00:00 2001 From: Luca Spinazzola Date: Tue, 26 Sep 2023 00:26:26 -0400 Subject: [PATCH 07/11] add admin to WasmMsg::Instantiate --- packages/std/src/results/cosmos_msg.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/std/src/results/cosmos_msg.rs b/packages/std/src/results/cosmos_msg.rs index ee104fb2b9..5a238fcf99 100644 --- a/packages/std/src/results/cosmos_msg.rs +++ b/packages/std/src/results/cosmos_msg.rs @@ -156,6 +156,7 @@ pub enum WasmMsg { /// This is translated to a [MsgInstantiateContract](https://github.com/CosmWasm/wasmd/blob/v0.16.0-alpha1/x/wasm/internal/types/tx.proto#L47-L61). /// `sender` is automatically filled with the current contract's address. Instantiate { + admin: Option, code_id: u64, /// code_hash is the hex encoded hash of the code. This is used by Secret Network to harden against replaying the contract /// It is used to bind the request to a destination contract in a stronger way than just the contract address which can be faked @@ -215,7 +216,10 @@ pub enum VoteOption { NoWithVeto, } + /// Shortcut helper as the construction of WasmMsg::Instantiate can be quite verbose in contract code. +/// +/// When using this, `admin` is always unset. If you need more flexibility, create the message directly. pub fn wasm_instantiate( code_id: u64, code_hash: impl Into, @@ -225,6 +229,7 @@ pub fn wasm_instantiate( ) -> StdResult { let payload = to_binary(msg)?; Ok(WasmMsg::Instantiate { + admin: None, code_id, code_hash: code_hash.into(), msg: payload, From dcca91a3c20dca1f21ed64b5e01ff1add3ccd7a8 Mon Sep 17 00:00:00 2001 From: Luca Spinazzola Date: Tue, 26 Sep 2023 00:36:48 -0400 Subject: [PATCH 08/11] fix setting mock_env hash hash is a String not &str --- packages/std/src/testing/mock.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/std/src/testing/mock.rs b/packages/std/src/testing/mock.rs index e8561e0953..595341f714 100644 --- a/packages/std/src/testing/mock.rs +++ b/packages/std/src/testing/mock.rs @@ -253,7 +253,7 @@ pub fn mock_env() -> Env { Binary::from_base64("wLsKdf/sYqvSMI0G0aWRjob25mrIB0VQVjTjDXnDafk=").unwrap(), ), }, - transaction: Some(TransactionInfo { index: 3, hash: "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" }), + transaction: Some(TransactionInfo { index: 3, hash: "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855".to_string() }), contract: ContractInfo { address: Addr::unchecked(MOCK_CONTRACT_ADDR), code_hash: "".to_string(), From dcdf314ddc964f4f929ff9d6c876b4b965ecdeeb Mon Sep 17 00:00:00 2001 From: Assaf Morami Date: Tue, 26 Sep 2023 19:12:29 +0300 Subject: [PATCH 09/11] Fix mock hash --- packages/std/src/testing/mock.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/std/src/testing/mock.rs b/packages/std/src/testing/mock.rs index e8561e0953..595341f714 100644 --- a/packages/std/src/testing/mock.rs +++ b/packages/std/src/testing/mock.rs @@ -253,7 +253,7 @@ pub fn mock_env() -> Env { Binary::from_base64("wLsKdf/sYqvSMI0G0aWRjob25mrIB0VQVjTjDXnDafk=").unwrap(), ), }, - transaction: Some(TransactionInfo { index: 3, hash: "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" }), + transaction: Some(TransactionInfo { index: 3, hash: "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855".to_string() }), contract: ContractInfo { address: Addr::unchecked(MOCK_CONTRACT_ADDR), code_hash: "".to_string(), From 25c8651b7574c7b81cbacb1cf05feefe64890998 Mon Sep 17 00:00:00 2001 From: toml01 Date: Wed, 27 Sep 2023 18:29:16 +0200 Subject: [PATCH 10/11] try to fix CI --- .github/workflows/lint.yml | 2 +- rust-toolchain | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 749ba88e02..aae4afd0a7 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -27,7 +27,7 @@ jobs: toolchain: ${{ matrix.rust }} - name: Add wasm toolchain run: | - rustup target add wasm32-unknown-unknown + rustup target add --toolchain ${{ matrix.rust }} wasm32-unknown-unknown - name: Install Clippy if: matrix.make.name == 'Clippy' diff --git a/rust-toolchain b/rust-toolchain index 07ade694b1..870bbe4e50 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly \ No newline at end of file +stable \ No newline at end of file From 81ba47bf110b5bdd154cd13a8f275a2517f8f3d3 Mon Sep 17 00:00:00 2001 From: toml01 Date: Wed, 27 Sep 2023 18:44:19 +0200 Subject: [PATCH 11/11] fix docstring --- packages/std/src/types.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/std/src/types.rs b/packages/std/src/types.rs index e1c99c65d0..55e992ec5b 100644 --- a/packages/std/src/types.rs +++ b/packages/std/src/types.rs @@ -55,7 +55,7 @@ pub struct BlockInfo { /// # time: Timestamp::from_nanos(1_571_797_419_879_305_533), /// # chain_id: "cosmos-testnet-14002".to_string(), /// # }, - /// # transaction: Some(TransactionInfo { index: 3 }), + /// # transaction: Some(TransactionInfo { index: 3, hash: "".to_string() }), /// # contract: ContractInfo { /// # address: Addr::unchecked("contract"), /// # code_hash: "".to_string() @@ -80,7 +80,7 @@ pub struct BlockInfo { /// # time: Timestamp::from_nanos(1_571_797_419_879_305_533), /// # chain_id: "cosmos-testnet-14002".to_string(), /// # }, - /// # transaction: Some(TransactionInfo { index: 3 }), + /// # transaction: Some(TransactionInfo { index: 3, hash: "".to_string() }), /// # contract: ContractInfo { /// # address: Addr::unchecked("contract"), /// # code_hash: "".to_string()