From cdd74ea084e941101b2de32bcd32ab8ad4c23c6c Mon Sep 17 00:00:00 2001 From: Jaco Date: Fri, 26 May 2023 08:02:18 +0300 Subject: [PATCH] .paymentInfo never mutates the existing signature (#5659) --- CHANGELOG.md | 7 +++++++ packages/api/src/submittable/createClass.ts | 8 +++++--- packages/types/src/extrinsic/v4/Extrinsic.ts | 4 ++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 249c810a73..3fbf7ce374 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # CHANGELOG +## master + +Changes: + +- Ensure that `.paymentInfo` never mutates the underlying/existing signature + + ## 10.7.2 May 21, 2023 Contributed: diff --git a/packages/api/src/submittable/createClass.ts b/packages/api/src/submittable/createClass.ts index bf6579f465..a439410c30 100644 --- a/packages/api/src/submittable/createClass.ts +++ b/packages/api/src/submittable/createClass.ts @@ -160,9 +160,11 @@ export function createClass ({ api, apiType, blockHas // setup our options (same way as in signAndSend) const eraOptions = makeEraOptions(api, this.registry, allOptions, signingInfo); const signOptions = makeSignOptions(api, eraOptions, {}); - const u8a = this.isSigned - ? api.tx(this).signFake(address, signOptions).toU8a() - : this.signFake(address, signOptions).toU8a(); + + // 1. Don't use the internal objects inside the new tx (hence toU8a) + // 2. Don't override the data from existing signed extrinsics + // 3. Ensure that this object stays intact, with no new sign after operation + const u8a = api.tx(this.toU8a()).signFake(address, signOptions).toU8a(); return api.call.transactionPaymentApi.queryInfo(u8a, u8a.length); }) diff --git a/packages/types/src/extrinsic/v4/Extrinsic.ts b/packages/types/src/extrinsic/v4/Extrinsic.ts index 24884a9841..7921919773 100644 --- a/packages/types/src/extrinsic/v4/Extrinsic.ts +++ b/packages/types/src/extrinsic/v4/Extrinsic.ts @@ -35,8 +35,8 @@ export class GenericExtrinsicV4 extends Struct implements IExtrinsicImpl { public static decodeExtrinsic (registry: Registry, value?: Call | Uint8Array | ExtrinsicValueV4, isSigned = false): ExtrinsicValueV4 { if (value instanceof GenericExtrinsicV4) { return value; - } else if (value instanceof registry.createClassUnsafe('Call')) { - return { method: value as Call }; + } else if (value instanceof registry.createClassUnsafe('Call')) { + return { method: value }; } else if (isU8a(value)) { // here we decode manually since we need to pull through the version information const signature = registry.createTypeUnsafe('ExtrinsicSignatureV4', [value, { isSigned }]);