From 4f04992e3a1505be01991867b002da7021808f59 Mon Sep 17 00:00:00 2001 From: Deepak Jangid Date: Thu, 19 Nov 2026 10:06:46 +0530 Subject: [PATCH 1/2] fix(abstract-eth): verify contractCall and customTx EVM TSS intents Verify contractCall, customTx, and their kebab-case aliases (contract-call, custom-tx) in AbstractEthLikeNewCoins.verifyTssTransaction instead of returning true unchecked. Require exactly one declared recipient and compare decoded to, value (default 0), and calldata against it, throwing TxIntentMismatchRecipientError on any mismatch or when zero or multiple recipients are supplied. Exempt the kebab-case aliases from the generic missing-txParams guard so they reach the same fail-closed check. Leave NO_RECIPIENT_TX_TYPES and non-EVM coins unchanged. Ticket: CECHO-2680 Co-authored-by: Ralph CLI Ralph: 18.13.2-bitgo.13 openrouter/google/gemini-4-neon@default openrouter/z-ai/glm-5.3-flash@smol:low+commit:high+memory:low openrouter/anthropic/claude-opus-5.5@slow:high+plan:xhigh openrouter/openai/gpt-6.1-terra@vision:low+advisor:medium openrouter/deepseek/deepseek-v4.1-flash-1017@task:high openrouter/inclusionai/ling-3.1-flash@tiny:low openrouter/moonshotai/kimi-k3.1-pro@designer:high openrouter/google/gemini-3-pro-image@image web/exa@web openrouter/microsoft/mai-transcribe-2@dictation openrouter/typesafe/jev-1.14@judge --- .../src/abstractEthLikeNewCoins.ts | 60 +++++++++++++++- modules/sdk-coin-eth/test/unit/eth.ts | 22 +++--- .../test/unit/tssPaymentVerification.ts | 69 +++++++++++++++++-- 3 files changed, 132 insertions(+), 19 deletions(-) diff --git a/modules/abstract-eth/src/abstractEthLikeNewCoins.ts b/modules/abstract-eth/src/abstractEthLikeNewCoins.ts index b07629af0f..71675cda85 100644 --- a/modules/abstract-eth/src/abstractEthLikeNewCoins.ts +++ b/modules/abstract-eth/src/abstractEthLikeNewCoins.ts @@ -592,6 +592,9 @@ export const optionalDeps = { /** Intent types other than payments that verifyTssTransaction already verifies. */ const TSS_DEDICATED_INTENT_TYPES = new Set(['defiApprove', 'defiDeposit', 'defiWithdraw', 'wrapApprove']); +/** Contract-call / custom-tx intent spellings verified against a single declared recipient. */ +const TSS_CONTRACT_CALL_INTENT_TYPES = new Set(['contractCall', 'contract-call', 'customTx', 'custom-tx']); + type TssDecodedArg = ReturnType[number]; const TSS_ERC20_TRANSFER_TYPES = ['address', 'uint256']; @@ -3815,6 +3818,56 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin implem } } + /** + * Verify a `contractCall` / `customTx` (including kebab-case aliases) intent against the decoded + * transaction. Fails closed unless exactly one recipient is declared and decoded `to`, `value` + * (default 0) and `data` match the declared address, amount and calldata exactly. + */ + private async verifyTssContractCall( + txType: string, + recipients: ITransactionRecipient[], + txHex: string | undefined, + throwRecipientMismatch: (message: string, mismatchedRecipients: Recipient[]) => Promise + ): Promise { + if (recipients.length === 0) { + await throwRecipientMismatch(`${txType} transaction requires a declared recipient to verify against`, []); + } + if (recipients.length > 1) { + await throwRecipientMismatch( + `${txType} transaction must declare a single recipient, got ${recipients.length}`, + [] + ); + } + if (!txHex) { + throw new Error('missing txHex in txPrebuild'); + } + + const recipient = recipients[0]; + const txBuilder = this.getTransactionBuilder(); + txBuilder.from(txHex); + const txJson = (await txBuilder.build()).toJson(); + const to = (txJson.to ?? '').toLowerCase(); + const value = txJson.value ?? '0'; + const data = (txJson.data || '0x').toLowerCase(); + const mismatch = (message: string, address = to, amount = value): Promise => + throwRecipientMismatch(message, [{ address, amount }]); + + if (!recipient.address || to !== recipient.address.toLowerCase()) { + await mismatch('destination address does not match with the recipient address'); + } + const expectedAmount = + recipient.amount === undefined || recipient.amount === null || recipient.amount === '' ? '0' : recipient.amount; + if (!tssValuesEqual(value, expectedAmount)) { + await mismatch('the transaction amount in txPrebuild does not match the value given by client'); + } + const expectedData = isEmptyTssCalldata(recipient.data) + ? '0x' + : addHexPrefix(recipient.data as string).toLowerCase(); + if (data !== expectedData) { + await mismatch('transaction calldata does not match the calldata given by client'); + } + } + /** * @param {VerifyEthTransactionOptions} params * @param {TransactionParams} params.txParams - params object passed to send @@ -3846,7 +3899,10 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin implem txPrebuild?.consolidateId || txParams.stakingRequestId || txParams.prebuildTx?.stakingRequestId || - (txParams.type && NO_RECIPIENT_TX_TYPES.has(txParams.type)) + (txParams.type && NO_RECIPIENT_TX_TYPES.has(txParams.type)) || + // The kebab-case aliases of contractCall/customTx are not in NO_RECIPIENT_TX_TYPES, but they + // are verified fail-closed below, so they must not trip this generic guard either. + (txParams.type && TSS_CONTRACT_CALL_INTENT_TYPES.has(txParams.type)) ) ) { throw new Error('missing txParams'); @@ -3871,6 +3927,8 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin implem } else { await this.verifyTssBatchPayment(txParams, recipients, txPrebuild.txHex, throwRecipientMismatch); } + } else if (txType && TSS_CONTRACT_CALL_INTENT_TYPES.has(txType)) { + await this.verifyTssContractCall(txType, txParams.recipients ?? [], txPrebuild.txHex, throwRecipientMismatch); } else if (txType && !TSS_DEDICATED_INTENT_TYPES.has(txType) && !params.verification?.consolidationToBaseAddress) { this.warnTssVerificationIncomplete( txType, diff --git a/modules/sdk-coin-eth/test/unit/eth.ts b/modules/sdk-coin-eth/test/unit/eth.ts index 9eeb9106d3..631e72ccd5 100644 --- a/modules/sdk-coin-eth/test/unit/eth.ts +++ b/modules/sdk-coin-eth/test/unit/eth.ts @@ -1626,7 +1626,7 @@ describe('ETH:', function () { }); }; - ['tokenApproval', 'customTx', 'defiApprove'].forEach((type) => { + ['tokenApproval', 'defiApprove'].forEach((type) => { it(`should reject approve(wrapper, amount) on the underlying relabelled as ${type}`, async function () { await expectDefiRejection( verifyAs(type, defiCalldata('approve(address,uint256)', [wrapper, amount])), @@ -1635,22 +1635,21 @@ describe('ETH:', function () { }); }); - it('should reject a mutated-amount wrapper approve relabelled as customTx', async function () { + it('should reject a mutated-amount wrapper approve relabelled as tokenApproval', async function () { await expectDefiRejection( - verifyAs('customTx', defiCalldata('approve(address,uint256)', [wrapper, '999999999999'])), + verifyAs('tokenApproval', defiCalldata('approve(address,uint256)', [wrapper, '999999999999'])), /must be declared as a wrapApprove intent/ ); }); it('should reject a wrapper approve with trailing bytes (an ERC-20 ignores them)', async function () { await expectDefiRejection( - verifyAs('customTx', defiCalldata('approve(address,uint256)', [wrapper, amount]) + '00'), + verifyAs('tokenApproval', defiCalldata('approve(address,uint256)', [wrapper, amount]) + '00'), /must be declared as a wrapApprove intent/ ); }); it('should not affect approvals of the underlying to other spenders', async function () { - (await verifyAs('customTx', defiCalldata('approve(address,uint256)', [address2, amount]))).should.equal(true); (await verifyAs('tokenApproval', defiCalldata('approve(address,uint256)', [address2, amount]))).should.equal( true ); @@ -1668,7 +1667,7 @@ describe('ETH:', function () { ); try { await coin.verifyTransaction({ - txParams: { type: 'customTx', wallet } as any, + txParams: { type: 'tokenApproval', wallet } as any, txPrebuild: { txHex, coin: 'hteth', walletId: 'w' } as any, wallet, verification: {}, @@ -1688,9 +1687,7 @@ describe('ETH:', function () { // Every type below skips the wrapApprove check and reaches the guard; none of these txs is an approve of a // wrapper, so all must verify exactly as they did before the guard existed. const benign: Array<[string, string, string]> = [ - ['customTx', defiCalldata('transfer(address,uint256)', [address2, amount]), underlying], - ['customTx', defiCalldata('approve(address,uint256)', [address2, amount]), underlying], - ['customTx', defiCalldata('approve(address,uint256)', [wrapper, amount]), address2], + ['tokenApproval', defiCalldata('transfer(address,uint256)', [address2, amount]), underlying], ['tokenApproval', defiCalldata('approve(address,uint256)', [address2, amount]), underlying], ['tokenApproval', defiCalldata('approve(address,uint256)', [wrapper, amount]), address2], ['acceleration', defiCalldata('transfer(address,uint256)', [address2, amount]), address2], @@ -1703,10 +1700,9 @@ describe('ETH:', function () { }); it('should not affect transfers to the underlying or approves of the wrapper on other contracts', async function () { - (await verifyAs('customTx', defiCalldata('transfer(address,uint256)', [wrapper, amount]))).should.equal(true); - ( - await verifyAs('customTx', defiCalldata('approve(address,uint256)', [wrapper, amount]), address2) - ).should.equal(true); + (await verifyAs('tokenApproval', defiCalldata('transfer(address,uint256)', [wrapper, amount]))).should.equal( + true + ); }); it('should still verify a declared wrapApprove through the full check', async function () { diff --git a/modules/sdk-coin-eth/test/unit/tssPaymentVerification.ts b/modules/sdk-coin-eth/test/unit/tssPaymentVerification.ts index 9f0c05234d..3ea29145b6 100644 --- a/modules/sdk-coin-eth/test/unit/tssPaymentVerification.ts +++ b/modules/sdk-coin-eth/test/unit/tssPaymentVerification.ts @@ -325,13 +325,72 @@ describe('TSS payment verification', function () { }); }); - describe('other intents', function () { - it('warns for contractCall instead of claiming it was verified', async function () { - const txHex = await buildTx({ to: recipient, value: '1' }); - (await verify({ type: 'contractCall', recipients: [] }, txHex)).should.be.true(); - warned(/contractCall: no verifier is implemented/).should.be.true(); + // CECHO-2680 / INFOSEC-671: contractCall and customTx (both spellings) are verified against a + // single declared recipient instead of returning true unchecked. + describe('contractCall / customTx verification', function () { + const callData = calldata('deposit', ['uint256', 'address'], ['5', baseAddress]); + + for (const type of ['contractCall', 'contract-call', 'customTx', 'custom-tx']) { + it(`verifies a matching ${type} call`, async function () { + const txHex = await buildTx({ to: otherRecipient, value: '0', data: callData }); + const txParams = { type, recipients: [{ address: otherRecipient, amount: '0', data: callData }] }; + (await verify(txParams, txHex)).should.be.true(); + warn.called.should.be.false(); + }); + + it(`rejects a ${type} call to a different destination`, async function () { + const txHex = await buildTx({ to: recipient, value: '0', data: callData }); + const txParams = { type, recipients: [{ address: otherRecipient, amount: '0', data: callData }] }; + await expectMismatch(verify(txParams, txHex), /destination address does not match/); + }); + + it(`rejects a ${type} call with a different native value`, async function () { + const txHex = await buildTx({ to: otherRecipient, value: '1', data: callData }); + const txParams = { type, recipients: [{ address: otherRecipient, amount: '0', data: callData }] }; + await expectMismatch(verify(txParams, txHex), /amount in txPrebuild does not match/); + }); + + it(`rejects a ${type} call with different calldata`, async function () { + const txHex = await buildTx({ to: otherRecipient, value: '0', data: callData }); + const declared = calldata('deposit', ['uint256', 'address'], ['6', baseAddress]); + const txParams = { type, recipients: [{ address: otherRecipient, amount: '0', data: declared }] }; + await expectMismatch(verify(txParams, txHex), /calldata does not match/); + }); + + it(`rejects a ${type} with no recipients`, async function () { + const txHex = await buildTx({ to: otherRecipient, value: '1' }); + await expectMismatch(verify({ type }, txHex), /requires a declared recipient/); + await expectMismatch(verify({ type, recipients: [] }, txHex), /requires a declared recipient/); + }); + + it(`rejects a ${type} with more than one recipient`, async function () { + const txHex = await buildTx({ to: otherRecipient, value: '0', data: callData }); + const txParams = { + type, + recipients: [ + { address: otherRecipient, amount: '0', data: callData }, + { address: recipient, amount: '0', data: callData }, + ], + }; + await expectMismatch(verify(txParams, txHex), /must declare a single recipient/); + }); + } + + it('defaults a contractCall value to 0 and empty calldata when the intent declares neither', async function () { + const txHex = await buildTx({ to: otherRecipient, value: '0' }); + (await verify({ type: 'contractCall', recipients: [{ address: otherRecipient }] }, txHex)).should.be.true(); + }); + + it('rejects a contractCall whose tx carries value the intent did not declare', async function () { + const txHex = await buildTx({ to: otherRecipient, value: '1' }); + await expectMismatch( + verify({ type: 'contractCall', recipients: [{ address: otherRecipient }] }, txHex), + /amount in txPrebuild does not match/ + ); }); + }); + describe('other intents', function () { it('warns for an intent type with no verifier', async function () { const txHex = await buildTx({ to: recipient, value: '1' }); (await verify({ type: 'acceleration' }, txHex)).should.be.true(); From c0bc68aec91ed9af3926e19224f594659978e161 Mon Sep 17 00:00:00 2001 From: Deepak Jangid Date: Fri, 20 Nov 2026 18:47:59 +0530 Subject: [PATCH 2/2] fix(abstract-eth): verify contract calls against the original tx bytes verifyTssContractCall decoded a TransactionBuilder round trip, which drops calldata shorter than a selector and trailing bytes after recognised calls, so the check could pass bytes that differ from what is signed. Decode the serialized transaction directly. Restore coverage that a wrapper approve relabelled as customTx is still rejected. Ticket: CECHO-2680 --- .../src/abstractEthLikeNewCoins.ts | 32 ++++++++++---- modules/sdk-coin-eth/test/unit/eth.ts | 44 +++++++++++++++---- .../test/unit/tssPaymentVerification.ts | 30 +++++++++++++ 3 files changed, 88 insertions(+), 18 deletions(-) diff --git a/modules/abstract-eth/src/abstractEthLikeNewCoins.ts b/modules/abstract-eth/src/abstractEthLikeNewCoins.ts index 71675cda85..58b226c17f 100644 --- a/modules/abstract-eth/src/abstractEthLikeNewCoins.ts +++ b/modules/abstract-eth/src/abstractEthLikeNewCoins.ts @@ -94,6 +94,7 @@ import { decodeUnwrapCalldata, decodeWrapCalldata, ERC1155TransferBuilder, + EthTransactionData, ERC721TransferBuilder, getBufferedByteCode, getCommon, @@ -3644,6 +3645,27 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin implem return { isToken: true, contract: contract.toLowerCase() }; } + /** + * Decode raw serialized EVM transaction bytes directly via `EthTransactionData.fromSerialized`, + * bypassing `TransactionBuilder.from()` / `.build()` reserialization so calldata bytes cannot be + * altered or normalized before verification. + */ + private decodeRawTssTxFields(txHex: string | undefined): { to: string; value: string; data: string } { + if (!txHex) { + throw new Error('missing txHex in txPrebuild'); + } + const common = AbstractEthLikeNewCoins.getCustomChainCommon(this.getChainId()); + if (!this.staticsCoin?.features.includes(CoinFeature.EIP1559)) { + common.setHardfork(optionalDeps.EthCommon.Hardfork.Petersburg); + } + const txJson = EthTransactionData.fromSerialized(txHex, common).toJson(); + return { + to: (txJson.to ?? '').toLowerCase(), + value: txJson.value ?? '0', + data: (txJson.data || '0x').toLowerCase(), + }; + } + /** * Verify a single-recipient payment: explicit calldata must match exactly; otherwise the bytes * must be a plain native send or a canonical ERC-20 transfer of the declared token. @@ -3838,17 +3860,9 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin implem [] ); } - if (!txHex) { - throw new Error('missing txHex in txPrebuild'); - } const recipient = recipients[0]; - const txBuilder = this.getTransactionBuilder(); - txBuilder.from(txHex); - const txJson = (await txBuilder.build()).toJson(); - const to = (txJson.to ?? '').toLowerCase(); - const value = txJson.value ?? '0'; - const data = (txJson.data || '0x').toLowerCase(); + const { to, value, data } = this.decodeRawTssTxFields(txHex); const mismatch = (message: string, address = to, amount = value): Promise => throwRecipientMismatch(message, [{ address, amount }]); diff --git a/modules/sdk-coin-eth/test/unit/eth.ts b/modules/sdk-coin-eth/test/unit/eth.ts index 631e72ccd5..2df905b861 100644 --- a/modules/sdk-coin-eth/test/unit/eth.ts +++ b/modules/sdk-coin-eth/test/unit/eth.ts @@ -1635,22 +1635,44 @@ describe('ETH:', function () { }); }); - it('should reject a mutated-amount wrapper approve relabelled as tokenApproval', async function () { + it('should still reject approve(wrapper, amount) relabelled as customTx, with or without a declared call', async function () { + // customTx is now verified by the contract-call handler before the wrapper guard runs; either check + // may reject, but the relabelled wrapper approve must never sign. + const data = defiCalldata('approve(address,uint256)', [wrapper, amount]); + const coin = bitgo.coin('hteth') as Hteth; + const wallet = new Wallet(bitgo, coin, { coinSpecific: { baseAddress: address1 } }); + const txHex = await buildDefiTxHex(data, underlying); + for (const recipients of [undefined, [{ address: underlying, amount: '0', data }]]) { + await expectDefiRejection( + coin.verifyTransaction({ + txParams: { type: 'customTx', recipients, wallet } as never, + txPrebuild: { txHex, coin: 'hteth', walletId: 'w' } as never, + wallet, + verification: {}, + walletType: 'tss', + }), + recipients ? /must be declared as a wrapApprove intent/ : /requires a declared recipient/ + ); + } + }); + + it('should reject a mutated-amount wrapper approve relabelled as transferToken', async function () { await expectDefiRejection( - verifyAs('tokenApproval', defiCalldata('approve(address,uint256)', [wrapper, '999999999999'])), + verifyAs('transferToken', defiCalldata('approve(address,uint256)', [wrapper, '999999999999'])), /must be declared as a wrapApprove intent/ ); }); it('should reject a wrapper approve with trailing bytes (an ERC-20 ignores them)', async function () { await expectDefiRejection( - verifyAs('tokenApproval', defiCalldata('approve(address,uint256)', [wrapper, amount]) + '00'), + verifyAs('transferToken', defiCalldata('approve(address,uint256)', [wrapper, amount]) + '00'), /must be declared as a wrapApprove intent/ ); }); it('should not affect approvals of the underlying to other spenders', async function () { - (await verifyAs('tokenApproval', defiCalldata('approve(address,uint256)', [address2, amount]))).should.equal( + // tokenApproval and customTx have their own verifiers; an intent type with no verifier still passes untouched. + (await verifyAs('transferToken', defiCalldata('approve(address,uint256)', [address2, amount]))).should.equal( true ); }); @@ -1667,7 +1689,7 @@ describe('ETH:', function () { ); try { await coin.verifyTransaction({ - txParams: { type: 'tokenApproval', wallet } as any, + txParams: { type: 'transferToken', wallet } as never, txPrebuild: { txHex, coin: 'hteth', walletId: 'w' } as any, wallet, verification: {}, @@ -1687,9 +1709,10 @@ describe('ETH:', function () { // Every type below skips the wrapApprove check and reaches the guard; none of these txs is an approve of a // wrapper, so all must verify exactly as they did before the guard existed. const benign: Array<[string, string, string]> = [ - ['tokenApproval', defiCalldata('transfer(address,uint256)', [address2, amount]), underlying], - ['tokenApproval', defiCalldata('approve(address,uint256)', [address2, amount]), underlying], - ['tokenApproval', defiCalldata('approve(address,uint256)', [wrapper, amount]), address2], + // tokenApproval and customTx are verified by their own handlers and are not part of this list. + ['transferToken', defiCalldata('transfer(address,uint256)', [address2, amount]), underlying], + ['transferToken', defiCalldata('approve(address,uint256)', [address2, amount]), underlying], + ['transferToken', defiCalldata('approve(address,uint256)', [wrapper, amount]), address2], ['acceleration', defiCalldata('transfer(address,uint256)', [address2, amount]), address2], ['fillNonce', '0x', address2], ['enabletoken', defiCalldata('transfer(address,uint256)', [address2, amount]), address2], @@ -1700,9 +1723,12 @@ describe('ETH:', function () { }); it('should not affect transfers to the underlying or approves of the wrapper on other contracts', async function () { - (await verifyAs('tokenApproval', defiCalldata('transfer(address,uint256)', [wrapper, amount]))).should.equal( + (await verifyAs('transferToken', defiCalldata('transfer(address,uint256)', [wrapper, amount]))).should.equal( true ); + ( + await verifyAs('transferToken', defiCalldata('approve(address,uint256)', [wrapper, amount]), address2) + ).should.equal(true); }); it('should still verify a declared wrapApprove through the full check', async function () { diff --git a/modules/sdk-coin-eth/test/unit/tssPaymentVerification.ts b/modules/sdk-coin-eth/test/unit/tssPaymentVerification.ts index 3ea29145b6..90c8f77458 100644 --- a/modules/sdk-coin-eth/test/unit/tssPaymentVerification.ts +++ b/modules/sdk-coin-eth/test/unit/tssPaymentVerification.ts @@ -388,6 +388,36 @@ describe('TSS payment verification', function () { /amount in txPrebuild does not match/ ); }); + + // The builder drops calldata shorter than a 4-byte selector when it reserializes, so the check + // must read the original signed bytes, not a rebuilt copy. + it('rejects a contractCall whose signed bytes carry sub-selector calldata the intent did not declare', async function () { + const common = AbstractEthLikeNewCoins.getCustomChainCommon(coin.getChainId()); + const tx = FeeMarketEIP1559Transaction.fromTxData( + { + nonce: 1, + maxPriorityFeePerGas: 10, + maxFeePerGas: 100, + gasLimit: 100000, + to: otherRecipient, + value: 0, + data: '0x01', + chainId: coin.getChainId(), + }, + { common } + ); + const txHex = '0x' + tx.serialize().toString('hex'); + await expectMismatch( + verify({ type: 'contractCall', recipients: [{ address: otherRecipient, amount: '0' }] }, txHex), + /calldata does not match/ + ); + ( + await verify( + { type: 'contractCall', recipients: [{ address: otherRecipient, amount: '0', data: '0x01' }] }, + txHex + ) + ).should.be.true(); + }); }); describe('other intents', function () {