Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: verify evm txid return by custom rpc #6408

Merged
merged 3 commits into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: verify evm txid which return by custom rpc
  • Loading branch information
weatherstar committed Dec 24, 2024
commit f08c73db26c9e45f024f488d939851c03c93af9b
13 changes: 13 additions & 0 deletions packages/kit-bg/src/services/ServiceSend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

weatherstar marked this conversation as resolved.
Show resolved Hide resolved
txid = result.txid;
}

Expand Down
7 changes: 7 additions & 0 deletions packages/kit-bg/src/vaults/base/VaultBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1419,4 +1419,11 @@ export abstract class VaultBase extends VaultBaseChainOnly {
): Promise<IEncodedTx> {
throw new NotImplemented();
}

async verifyTxId(params: {
txid: string;
signedTx: ISignedTxPro;
}): Promise<boolean> {
return Promise.resolve(true);
}
}
16 changes: 16 additions & 0 deletions packages/kit-bg/src/vaults/impls/evm/Vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1232,13 +1232,29 @@ export default class Vault extends VaultBase {
}
const client = new ClientEvm(rpcUrl);
const txid = await client.broadcastTransaction(signedTx.rawTx);

return {
...signedTx,
txid,
encodedTx: signedTx.encodedTx,
};
}

override async verifyTxId(params: {
txid: string;
signedTx: ISignedTxPro;
}): Promise<boolean> {
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 =
Expand Down