From f08c73db26c9e45f024f488d939851c03c93af9b Mon Sep 17 00:00:00 2001 From: weatherstar Date: Tue, 24 Dec 2024 17:40:11 +0800 Subject: [PATCH 1/3] fix: verify evm txid which return by custom rpc --- packages/kit-bg/src/services/ServiceSend.ts | 13 +++++++++++++ packages/kit-bg/src/vaults/base/VaultBase.ts | 7 +++++++ packages/kit-bg/src/vaults/impls/evm/Vault.ts | 16 ++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/packages/kit-bg/src/services/ServiceSend.ts b/packages/kit-bg/src/services/ServiceSend.ts index e16ed57eed4..b55d19df0f4 100644 --- a/packages/kit-bg/src/services/ServiceSend.ts +++ b/packages/kit-bg/src/services/ServiceSend.ts @@ -158,6 +158,19 @@ class ServiceSend extends ServiceBase { ...params, customRpcInfo, }); + + try { + const verified = await vault.verifyTxId({ + txid: result.txid, + signedTx: result, + }); + if (!verified) { + throw new Error('Invalid txid'); + } + } catch (error) { + throw new Error('Invalid txid'); + } + txid = result.txid; } diff --git a/packages/kit-bg/src/vaults/base/VaultBase.ts b/packages/kit-bg/src/vaults/base/VaultBase.ts index 3f4a74038a8..d0a53f97d99 100644 --- a/packages/kit-bg/src/vaults/base/VaultBase.ts +++ b/packages/kit-bg/src/vaults/base/VaultBase.ts @@ -1419,4 +1419,11 @@ export abstract class VaultBase extends VaultBaseChainOnly { ): Promise { throw new NotImplemented(); } + + async verifyTxId(params: { + txid: string; + signedTx: ISignedTxPro; + }): Promise { + return Promise.resolve(true); + } } diff --git a/packages/kit-bg/src/vaults/impls/evm/Vault.ts b/packages/kit-bg/src/vaults/impls/evm/Vault.ts index 70f5c30ef31..2c13ba278f2 100644 --- a/packages/kit-bg/src/vaults/impls/evm/Vault.ts +++ b/packages/kit-bg/src/vaults/impls/evm/Vault.ts @@ -1232,6 +1232,7 @@ export default class Vault extends VaultBase { } const client = new ClientEvm(rpcUrl); const txid = await client.broadcastTransaction(signedTx.rawTx); + return { ...signedTx, txid, @@ -1239,6 +1240,21 @@ export default class Vault extends VaultBase { }; } + override async verifyTxId(params: { + txid: string; + signedTx: ISignedTxPro; + }): Promise { + const { signedTx, txid } = params; + + if (typeof txid !== 'string') { + return false; + } + + const recoveredTxid = ethers.utils.keccak256(signedTx.rawTx); + + return recoveredTxid === txid; + } + // RPC Client async getRpcClient() { const rpcInfo = From d9189bb3d62539b67ef2dc87e370e91bbafd7063 Mon Sep 17 00:00:00 2001 From: weatherstar Date: Wed, 25 Dec 2024 10:40:05 +0800 Subject: [PATCH 2/3] fix: call oncancel error --- .../pages/SendConfirmFromSwap/SendConfirmFromSwap.tsx | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/kit/src/views/Send/pages/SendConfirmFromSwap/SendConfirmFromSwap.tsx b/packages/kit/src/views/Send/pages/SendConfirmFromSwap/SendConfirmFromSwap.tsx index 38888670608..b1fc0a0d283 100644 --- a/packages/kit/src/views/Send/pages/SendConfirmFromSwap/SendConfirmFromSwap.tsx +++ b/packages/kit/src/views/Send/pages/SendConfirmFromSwap/SendConfirmFromSwap.tsx @@ -70,13 +70,11 @@ function SendConfirmFromSwap() { const isLastTx = i === len - 1; const result: ISendTxOnSuccessData[] = await new Promise((resolve) => { - navigationToNext.current = true; appNavigation.push(EModalSendRoutes.SendConfirm, { ...route.params, popStack: false, unsignedTxs: [unsignedTx], onSuccess: (data: ISendTxOnSuccessData[]) => { - navigationToNext.current = false; if (isLastTx) { appNavigation.pop(); onSuccess?.(data); @@ -84,12 +82,10 @@ function SendConfirmFromSwap() { resolve(data); }, onFail: (error: Error) => { - navigationToNext.current = false; appNavigation.pop(); onFail?.(error); }, onCancel: () => { - navigationToNext.current = false; appNavigation.pop(); onCancel?.(); }, @@ -127,6 +123,7 @@ function SendConfirmFromSwap() { networkId, encodedTxs: encodedTxList, }); + navigationToNext.current = true; if (multiTxsFeeResult.txFees.length === unsignedTxs.length) { await handleConfirmMultiTxsOnHwOrExternal(multiTxsFeeResult); } else { @@ -140,8 +137,9 @@ function SendConfirmFromSwap() { } } + navigationToNext.current = true; + if (!batchEstimateButSingleConfirm) { - navigationToNext.current = true; action = StackActions.replace(EModalSendRoutes.SendConfirm, { ...route.params, // @ts-ignore From 35b400c312541690d4339bc9274d13e3477024fa Mon Sep 17 00:00:00 2001 From: weatherstar Date: Wed, 25 Dec 2024 11:05:13 +0800 Subject: [PATCH 3/3] fix: lint --- packages/kit-bg/src/vaults/impls/evm/Vault.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/kit-bg/src/vaults/impls/evm/Vault.ts b/packages/kit-bg/src/vaults/impls/evm/Vault.ts index 2c13ba278f2..7d6feb7e892 100644 --- a/packages/kit-bg/src/vaults/impls/evm/Vault.ts +++ b/packages/kit-bg/src/vaults/impls/evm/Vault.ts @@ -1252,7 +1252,7 @@ export default class Vault extends VaultBase { const recoveredTxid = ethers.utils.keccak256(signedTx.rawTx); - return recoveredTxid === txid; + return recoveredTxid.toLowerCase() === txid.toLowerCase(); } // RPC Client