From ff7e22ff496ec7390d9934bd977514cd7f56af81 Mon Sep 17 00:00:00 2001 From: doom Date: Thu, 13 Jun 2024 17:34:16 +0200 Subject: [PATCH 1/2] Update Polkadot extrinsic encoding to support spec 1002005 --- src/Polkadot/Extrinsic.cpp | 18 +++++++++++++++ tests/chains/Polkadot/ExtrinsicTests.cpp | 29 ++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/src/Polkadot/Extrinsic.cpp b/src/Polkadot/Extrinsic.cpp index ebfbe67d2b0..8ec0b509c6e 100644 --- a/src/Polkadot/Extrinsic.cpp +++ b/src/Polkadot/Extrinsic.cpp @@ -388,8 +388,15 @@ Data Extrinsic::encodeIdentityAddAuthorization(const Proto::Identity::AddAuthori return data; } +static bool requires_new_spec_compatbility(uint32_t network, uint32_t specVersion) noexcept { + // version 1002005 introduces a breaking change for Polkadot and Kusama + return ((network == 0 || network == 2) && specVersion >= 1002005); +} + Data Extrinsic::encodePayload() const { Data data; + auto use_new_spec = requires_new_spec_compatbility(network, specVersion); + // call append(data, call); // era / nonce / tip @@ -398,6 +405,12 @@ Data Extrinsic::encodePayload() const { if (!feeAssetId.empty()) { append(data, feeAssetId); } + + if (use_new_spec) { + // mode (currently always 0) + data.push_back(0x00); + } + // specVersion encode32LE(specVersion, data); // transactionVersion @@ -406,6 +419,11 @@ Data Extrinsic::encodePayload() const { append(data, genesisHash); // block hash append(data, blockHash); + + if (use_new_spec) { + // empty metadata hash + data.push_back(0x00); + } return data; } diff --git a/tests/chains/Polkadot/ExtrinsicTests.cpp b/tests/chains/Polkadot/ExtrinsicTests.cpp index dd921a64343..4f5c969722a 100644 --- a/tests/chains/Polkadot/ExtrinsicTests.cpp +++ b/tests/chains/Polkadot/ExtrinsicTests.cpp @@ -159,4 +159,33 @@ TEST(PolkadotExtrinsic, Kusama_encodeAssetTransferNoCallIndices) { EXPECT_THROW(Polkadot::Extrinsic(input).encodeCall(input), std::invalid_argument); } +TEST(PolkadotExtrinsic, Polkadot_EncodePayloadWithNewSpec) { + Polkadot::Proto::SigningInput input; + input.set_network(0); + input.set_multi_address(true); + + auto* transfer = input.mutable_balance_call()->mutable_asset_transfer(); + transfer->set_to_address("14ixj163bkk2UEKLEXsEWosuFNuijpqEWZbX5JzN4yMHbUVD"); + auto* callIndices = transfer->mutable_call_indices()->mutable_custom(); + callIndices->set_module_index(0x32); + callIndices->set_method_index(0x05); + + auto value = store(999500000); + transfer->set_value(std::string(value.begin(), value.end())); + transfer->set_asset_id(1984); + + input.set_spec_version(1002000); // breaking change happens at version 1002005 + auto result = Polkadot::Extrinsic(input).encodePayload(); + EXPECT_EQ(hex(result), "3205011f00a4b558a0342ae6e379a7ed00d23ff505f1101646cb279844496ad608943eda0d82a34cee00000000104a0f0000000000"); + + input.set_spec_version(1002005); // >= 1002005 + result = Polkadot::Extrinsic(input).encodePayload(); + EXPECT_EQ(hex(result), "3205011f00a4b558a0342ae6e379a7ed00d23ff505f1101646cb279844496ad608943eda0d82a34cee0000000000154a0f000000000000"); + + input.set_spec_version(1002006); // >= 1002005 + result = Polkadot::Extrinsic(input).encodePayload(); + EXPECT_EQ(hex(result), "3205011f00a4b558a0342ae6e379a7ed00d23ff505f1101646cb279844496ad608943eda0d82a34cee0000000000164a0f000000000000"); +} + + } // namespace TW::Polkadot::tests From bf693766e614d1d10fa19c0a9f468c3fe86613ff Mon Sep 17 00:00:00 2001 From: doom Date: Thu, 13 Jun 2024 17:49:44 +0200 Subject: [PATCH 2/2] Update LIBC_PACKAGE_VERSION for Linux CI --- tools/install-sys-dependencies-linux | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/install-sys-dependencies-linux b/tools/install-sys-dependencies-linux index eec6524cd06..2f1e7db8e44 100755 --- a/tools/install-sys-dependencies-linux +++ b/tools/install-sys-dependencies-linux @@ -6,7 +6,7 @@ set -e if [[ "$1" == "ci" ]]; then LIBSTD_PACKAGE_VERSION="12.3.0-1ubuntu1~22.04" # Bump this version if the CI has been broken due to the packages update. - LIBC_PACKAGE_VERSION="2.35-0ubuntu3.7" + LIBC_PACKAGE_VERSION="2.35-0ubuntu3.8" echo "Remove GCC 13 from runner image - runner-images/8659 workaround" echo "NOTE: Bump $LIBC_PACKAGE_VERSION version if the CI has been broken due to the packages update"