From c1a7e6ed7bfc8ced9a873ddf6a7aec2216a16ae6 Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Thu, 30 May 2024 11:43:05 +0200 Subject: [PATCH 1/4] Fix gas_used deserialization (cherry picked from commit 9bdf442ae31c9f9b44c8e41d8744805f32762468) --- packages/std/src/results/submessages.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/std/src/results/submessages.rs b/packages/std/src/results/submessages.rs index 84ab978535..d21fa01c56 100644 --- a/packages/std/src/results/submessages.rs +++ b/packages/std/src/results/submessages.rs @@ -181,6 +181,10 @@ pub struct Reply { pub payload: Binary, /// The amount of gas used by the submessage, /// measured in [Cosmos SDK gas](https://github.com/CosmWasm/cosmwasm/blob/main/docs/GAS.md). + /// + /// This only contains a useful value on chains running CosmWasm 2.0 or higher. + /// On older chains, this field is always 0. + #[serde(default)] pub gas_used: u64, pub result: SubMsgResult, } From 23876e1943fe02001beb7b2c9f17dab3b73f3f5f Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Thu, 30 May 2024 11:51:16 +0200 Subject: [PATCH 2/4] Add test for old reply serialization (cherry picked from commit 806ee186d21391fbb2b89f69487cbd6b13680cd6) --- packages/std/src/results/submessages.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/packages/std/src/results/submessages.rs b/packages/std/src/results/submessages.rs index d21fa01c56..ac36fd0f7c 100644 --- a/packages/std/src/results/submessages.rs +++ b/packages/std/src/results/submessages.rs @@ -616,4 +616,29 @@ mod tests { } ); } + + #[test] + fn reply_serialization_cosmwasm_1() { + // json coming from wasmvm 1.5.0 + let json = r#"{"id":1234,"result":{"ok":{"events":[{"type":"message","attributes":[{"key":"signer","value":"caller-addr"}]}],"data":"Zm9vYmFy"}}}"#; + + let reply: Reply = from_json(json).unwrap(); + assert_eq!(reply.id, 1234); + assert_eq!(reply.payload, Binary::default()); + assert_eq!( + reply.result, + SubMsgResult::Ok(SubMsgResponse { + data: Some(Binary::from_base64("Zm9vYmFy").unwrap()), + events: vec![Event { + ty: "message".to_string(), + attributes: vec![Attribute { + key: "signer".to_string(), + value: "caller-addr".to_string() + }] + }], + msg_responses: vec![] + }) + ); + assert_eq!(reply.gas_used, 0); + } } From 13ca51ddd6b14153bf021170adcf4153fcd2bd29 Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Thu, 30 May 2024 12:43:12 +0200 Subject: [PATCH 3/4] Regenerate schemas (cherry picked from commit aa1a7f2b5151412f111056bd62871bae9d8e48a5) --- contracts/reflect/schema/raw/response_to_sub_msg_result.json | 4 ++-- contracts/reflect/schema/reflect.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/contracts/reflect/schema/raw/response_to_sub_msg_result.json b/contracts/reflect/schema/raw/response_to_sub_msg_result.json index f6c05147e3..e6ba23339b 100644 --- a/contracts/reflect/schema/raw/response_to_sub_msg_result.json +++ b/contracts/reflect/schema/raw/response_to_sub_msg_result.json @@ -4,13 +4,13 @@ "description": "The result object returned to `reply`. We always get the ID from the submessage back and then must handle success and error cases ourselves.", "type": "object", "required": [ - "gas_used", "id", "result" ], "properties": { "gas_used": { - "description": "The amount of gas used by the submessage, measured in [Cosmos SDK gas](https://github.com/CosmWasm/cosmwasm/blob/main/docs/GAS.md).", + "description": "The amount of gas used by the submessage, measured in [Cosmos SDK gas](https://github.com/CosmWasm/cosmwasm/blob/main/docs/GAS.md).\n\nThis only contains a useful value on chains running CosmWasm 2.0 or higher. On older chains, this field is always 0.", + "default": 0, "type": "integer", "format": "uint64", "minimum": 0.0 diff --git a/contracts/reflect/schema/reflect.json b/contracts/reflect/schema/reflect.json index ccbaedab95..6227f412be 100644 --- a/contracts/reflect/schema/reflect.json +++ b/contracts/reflect/schema/reflect.json @@ -2006,13 +2006,13 @@ "description": "The result object returned to `reply`. We always get the ID from the submessage back and then must handle success and error cases ourselves.", "type": "object", "required": [ - "gas_used", "id", "result" ], "properties": { "gas_used": { - "description": "The amount of gas used by the submessage, measured in [Cosmos SDK gas](https://github.com/CosmWasm/cosmwasm/blob/main/docs/GAS.md).", + "description": "The amount of gas used by the submessage, measured in [Cosmos SDK gas](https://github.com/CosmWasm/cosmwasm/blob/main/docs/GAS.md).\n\nThis only contains a useful value on chains running CosmWasm 2.0 or higher. On older chains, this field is always 0.", + "default": 0, "type": "integer", "format": "uint64", "minimum": 0.0 From fc0148cbefeb08dc0a1653dde4ab4e966267a192 Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Thu, 30 May 2024 12:45:51 +0200 Subject: [PATCH 4/4] Add changelog entry (cherry picked from commit 6e891634bbb64a2b58aea61be475a3e7468be02f) # Conflicts: # CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bc946061db..3569348833 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,9 @@ and this project adheres to ### Fixed - cosmwasm-std: Fix CWA-2024-002 +- cosmwasm-std: Fix `Reply` deserialization on CosmWasm 1.x chains ([#2159]) + +[#2159]: https://github.com/CosmWasm/cosmwasm/pull/2159 ### Added