From 26821053e90f9a38a372d4ae6ab71e246213fa70 Mon Sep 17 00:00:00 2001 From: Rakesh Reddy Date: Wed, 18 Nov 2026 20:48:08 +0530 Subject: [PATCH] fix(sdk-coin-eth): strictly verify the multisig enable-token sendMultiSig operation (CECHO-2815) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The multisig branch of Erc7984Token.verifyEnableTokenTransaction compared only txPrebuild.buildParams.recipients — client-attached echo data built by Wallet.buildTokenEnablements from the caller's own enableTokens — so the operation the user actually signs was never inspected. Onchain-multisig users sign the sendMultiSig operation hash over txPrebuild.recipients[0] (address, amount, data), never over txHex, and the MultiSigV3 contract enforces at execution that the broadcast args hash to that op: a compromised platform could serve any recipient (attacker contract with native value, ERC-20 approve theft, or a delegate substitution) and the user would first-sign it. Strict flow (default): bind the signed recipient in full — 1. sendMultiSig native value must be 0; 2. the recipient data must decode fail-closed as a delegation calldata (rejects approve/transfer and smuggled inner calls); 3. aclMulticall shape must target the ACL contract (the forwarder shape is bound on-chain by onlyParent plus the enforced callFromParent target/value); 4. verifyStrictEnableTokenCalldata binds delegate == pinned enterprise viewing key, future expiry, and an exact deduplicated match against the requested tokens (CECHO-2720 helper, unchanged); 5. when the prebuild carries a txHex, its sendMultiSig args must mirror the recipient — a diverging (decoy) txHex is rejected. Revert path: gated by the Flipt flag cecho-2815-multisig-enable-token-strict- verification delivered on the prebuild as featureFlags. DEFAULT TRUE — the flag absent, unreadable, or true runs strict verification; only an explicit false reverts to the legacy flow, byte-for-byte, per request, with no SDK redeploy. abstract-eth: TransactionPrebuild.featureFlags carries server-evaluated (Flipt) flags with the prebuild; the flag constant lives in zamaUtils so consumers can import it without pulling the sdk-coin-eth module graph (its value import would otherwise enter the eth/erc20Token require cycle first and crash module init). Tests: 13 new multisig strict-path cases — benign both delegation shapes, txHex mirror pass, value theft, approve theft, delegate substitution, smuggled inner call, wrong ACL target, callFromParent theft shape, decoy txHex, non-sendMultiSig txHex, missing recipient, and explicit flag=false reverting to the legacy flow. sdk-coin-eth 591 passing, abstract-eth 188 passing. --- .../src/abstractEthLikeNewCoins.ts | 6 + modules/abstract-eth/src/lib/zamaUtils.ts | 13 ++ modules/sdk-coin-eth/src/erc7984Token.ts | 217 +++++++++++++++--- .../sdk-coin-eth/test/unit/erc7984Token.ts | 170 +++++++++++++- 4 files changed, 374 insertions(+), 32 deletions(-) diff --git a/modules/abstract-eth/src/abstractEthLikeNewCoins.ts b/modules/abstract-eth/src/abstractEthLikeNewCoins.ts index b07629af0f..a039eb6ff6 100644 --- a/modules/abstract-eth/src/abstractEthLikeNewCoins.ts +++ b/modules/abstract-eth/src/abstractEthLikeNewCoins.ts @@ -166,6 +166,12 @@ export interface TransactionPrebuild extends BaseTransactionPrebuild { eip1559?: EIP1559; isBatch?: boolean; }; + /** + * Feature flags evaluated server-side (e.g. Flipt) and delivered with the prebuild. + * A flag key absent from the map means that flag is at its default value; consumers + * must treat absence as the default, never as an error. + */ + featureFlags?: Record; } export interface SignFinalOptions { diff --git a/modules/abstract-eth/src/lib/zamaUtils.ts b/modules/abstract-eth/src/lib/zamaUtils.ts index 7110dcabd9..3c1adb9bc9 100644 --- a/modules/abstract-eth/src/lib/zamaUtils.ts +++ b/modules/abstract-eth/src/lib/zamaUtils.ts @@ -73,6 +73,19 @@ export const finalizeUnwrapMethodId = addHexPrefix( EthereumAbi.methodID('finalizeUnwrap', [...finalizeUnwrapTypes]).toString('hex') ); +/** + * Flipt feature flag (evaluated by the platform, delivered on the prebuild as + * `txPrebuild.featureFlags`) gating the strict multisig enable-token verification + * (CECHO-2815). DEFAULT TRUE: when the flag is absent, unreadable, or true, the strict + * verification runs; only an explicit `false` reverts to the legacy flow. The strict + * path is therefore the default behavior while the flag keeps a full, per-request + * revert path to the pre-CECHO-2815 flow with no SDK redeploy. + * + * Lives here (not in sdk-coin-eth) so consumers can import it without pulling the + * sdk-coin-eth module graph. + */ +export const STRICT_MULTISIG_ENABLE_TOKEN_VERIFICATION_FLAG = 'cecho-2815-multisig-enable-token-strict-verification'; + // --------------------------------------------------------------------------- // Encoding functions // --------------------------------------------------------------------------- diff --git a/modules/sdk-coin-eth/src/erc7984Token.ts b/modules/sdk-coin-eth/src/erc7984Token.ts index 499a10482e..91e43aabb2 100644 --- a/modules/sdk-coin-eth/src/erc7984Token.ts +++ b/modules/sdk-coin-eth/src/erc7984Token.ts @@ -40,9 +40,11 @@ import { finalizeUnwrapMethodId, UINT64_MAX, decodeTransferData, + STRICT_MULTISIG_ENABLE_TOKEN_VERIFICATION_FLAG, } from '@bitgo/abstract-eth'; import { bip32 } from '@bitgo/secp256k1'; import * as _ from 'lodash'; +import { BigNumber } from 'bignumber.js'; import { Eth } from './eth'; import { TransactionBuilder } from './lib'; @@ -826,48 +828,201 @@ export class Erc7984Token extends Eth { return true; } else { - // Multisig path: buildParams-level check - const recipients = txPrebuild.buildParams?.recipients as - | Array<{ tokenName?: string; amount?: string }> - | undefined; - if (!recipients || recipients.length === 0) { - throw new Error('verifyEnableTokenTransaction: missing buildParams.recipients for multisig path'); + // Multisig path (CECHO-2815). Onchain-multisig users sign the sendMultiSig operation + // hash over txPrebuild.recipients[0] (address, amount, data) — never over txHex — + // and the MultiSigV3 contract enforces at execution that the broadcast args hash to + // that op (Eth.signTransaction → getOperationSha3ForExecuteAndConfirm). recipients[0] + // is therefore the authoritative binding, and the strict flow verifies it in full. + // + // Flipt kill switch: the flag defaults to TRUE, so strict verification is the + // default behavior; the platform delivers an explicit false on the prebuild to + // revert to the legacy flow — a per-request revert path with no SDK redeploy. + if (txPrebuild.featureFlags?.[STRICT_MULTISIG_ENABLE_TOKEN_VERIFICATION_FLAG] === false) { + return this.verifyEnableTokenTransactionLegacyMultisig(params); } + return this.verifyEnableTokenTransactionStrictMultisig(params); + } + } + + /** + * Legacy multisig enable-token verification (pre-CECHO-2815), kept verbatim as the + * Flipt revert path. Checks only txPrebuild.buildParams.recipients, which + * Wallet.buildTokenEnablements attaches client-side from the caller's own + * enableTokens — it validates the client's own request, not the prebuild the + * platform returned, and so provides no protection against a compromised platform. + * Do not extend this path; new checks belong in the strict flow. + */ + private verifyEnableTokenTransactionLegacyMultisig(params: VerifyEthTransactionOptions): boolean { + const { txParams, txPrebuild } = params; + const recipients = txPrebuild.buildParams?.recipients as Array<{ tokenName?: string; amount?: string }> | undefined; + if (!recipients || recipients.length === 0) { + throw new Error('verifyEnableTokenTransaction: missing buildParams.recipients for multisig path'); + } + + // Determine requested token names from txParams + const requestedTokenNames: string[] = []; + if (txParams.enableTokens && txParams.enableTokens.length > 0) { + requestedTokenNames.push(...txParams.enableTokens.map((t) => t.name)); + } else if (txParams.recipients && txParams.recipients.length > 0) { + requestedTokenNames.push( + ...txParams.recipients.map((r) => r.tokenName).filter((name): name is string => Boolean(name)) + ); + } - // Determine requested token names from txParams - const requestedTokenNames: string[] = []; - if (txParams.enableTokens && txParams.enableTokens.length > 0) { - requestedTokenNames.push(...txParams.enableTokens.map((t) => t.name)); - } else if (txParams.recipients && txParams.recipients.length > 0) { - requestedTokenNames.push(...txParams.recipients.map((r: any) => r.tokenName).filter(Boolean)); + // Verify all recipients have tokenName and amount = '0' + for (const recipient of recipients) { + if (!recipient.tokenName) { + throw new Error('verifyEnableTokenTransaction: recipient is missing tokenName in buildParams'); + } + if (recipient.amount !== '0') { + throw new Error( + `verifyEnableTokenTransaction: expected amount 0 for token enablement but got ${recipient.amount}` + ); } + } - // Verify all recipients have tokenName and amount = '0' - for (const recipient of recipients) { - if (!recipient.tokenName) { - throw new Error('verifyEnableTokenTransaction: recipient is missing tokenName in buildParams'); - } - if (recipient.amount !== '0') { + // Verify requested token names are present in recipients + if (requestedTokenNames.length > 0) { + const recipientTokenNames = recipients.map((r) => r.tokenName); + for (const requested of requestedTokenNames) { + if (!recipientTokenNames.includes(requested)) { throw new Error( - `verifyEnableTokenTransaction: expected amount 0 for token enablement but got ${recipient.amount}` + `verifyEnableTokenTransaction: requested token ${requested} not found in buildParams recipients` ); } } + } - // Verify requested token names are present in recipients - if (requestedTokenNames.length > 0) { - const recipientTokenNames = recipients.map((r) => r.tokenName); - for (const requested of requestedTokenNames) { - if (!recipientTokenNames.includes(requested)) { - throw new Error( - `verifyEnableTokenTransaction: requested token ${requested} not found in buildParams recipients` - ); - } - } - } + return true; + } - return true; + /** + * Strict multisig enable-token verification (CECHO-2815) — the default flow. + * + * Onchain-multisig users sign the sendMultiSig operation hash over + * txPrebuild.recipients[0] = (address, amount, data): Eth.signTransaction resolves the + * recipients from the prebuild (never from client params) and hashes the data verbatim, + * halfSigned carries no txHex, and the MultiSigV3 contract enforces at execution that + * the broadcast args hash to the op the user signed. recipients[0] is therefore the + * single authoritative binding, and it is verified here in full: + * 1. amount == 0 — a non-zero sendMultiSig value moves native funds directly. + * 2. the data decodes fail-closed as a delegation calldata — rejects any other + * selector (e.g. an ERC-20 approve theft prebuild) and smuggled inner calls. + * 3. aclMulticall shape: the target must be the ACL contract (root wallet). + * callFromParent shape: the forwarder address is wallet-specific and not + * statically verifiable (same decision as the TSS path); the on-chain + * onlyParent modifier plus the enforced callFromParent target/value close + * the fund-theft vector regardless of which forwarder is targeted. + * 4. verifyStrictEnableTokenCalldata binds the delegate to the pinned enterprise + * viewing key (fail closed when unpinned), a future expiry, an exact + * deduplicated match against the requested tokens, and — for the + * callFromParent shape — target == ACL contract with zero native value. + * 5. When the prebuild carries a txHex, its sendMultiSig args must mirror + * recipients[0] exactly: a diverging txHex (e.g. a decoy that passes + * verification while different args get signed) is rejected. + */ + private async verifyEnableTokenTransactionStrictMultisig(params: VerifyEthTransactionOptions): Promise { + const { txParams, txPrebuild } = params; + + // Requested tokens: enableTokens when present (prebuildAndSignTransaction merges the + // original params over the buildParams), else the client-built recipients' tokenNames. + const requestedTokenNames: string[] = []; + if (txParams.enableTokens && txParams.enableTokens.length > 0) { + requestedTokenNames.push(...txParams.enableTokens.map((t) => t.name)); + } else if (txParams.recipients && txParams.recipients.length > 0) { + requestedTokenNames.push( + ...txParams.recipients.map((r) => r.tokenName).filter((name): name is string => Boolean(name)) + ); + } + if (requestedTokenNames.length === 0) { + throw new Error('verifyEnableTokenTransaction: requested tokens must be non-empty for the multisig strict path'); + } + const requestedAddresses = requestedTokenNames.map((name) => { + const tokenCoin = this.bitgo.coin(name) as Erc7984Token; + return tokenCoin.tokenContractAddress.toLowerCase(); + }); + + const network = this.getNetwork() as EthereumNetwork; + const aclContractAddress = network?.zamaAclContractAddress; + if (!aclContractAddress) { + throw new Error('verifyEnableTokenTransaction: zamaAclContractAddress not configured for this network'); } + + // The operation that gets signed. Mirror the signer's resolution exactly + // (Eth.signTransaction: txPrebuild.recipients || txPrebuild.txInfo?.recipients). + const recipients = txPrebuild.recipients || txPrebuild.txInfo?.recipients; + if (!Array.isArray(recipients) || recipients.length !== 1) { + throw new Error( + 'verifyEnableTokenTransaction: multisig prebuild must carry exactly one recipient — the sendMultiSig operation that gets signed' + ); + } + const recipient = recipients[0] as { address?: string; amount?: string | number; data?: string }; + if (!recipient.address) { + throw new Error('verifyEnableTokenTransaction: multisig prebuild recipient is missing an address'); + } + + // 1. The signed sendMultiSig native value must be 0. + if (new BigNumber(recipient.amount ?? 0).comparedTo(0) !== 0) { + throw new Error(`verifyEnableTokenTransaction: expected sendMultiSig value 0 but got ${recipient.amount}`); + } + + // 2. Fail-closed delegation decode of the signed data. + const data = recipient.data; + if (!data || data === '0x') { + throw new Error('verifyEnableTokenTransaction: multisig prebuild recipient is missing delegation calldata'); + } + const delegation = decodeDelegationCallsFromCalldata(data); + + // 3. Shape → target binding (see the callFromParent note above). + if (delegation.shape === 'aclMulticall' && recipient.address.toLowerCase() !== aclContractAddress.toLowerCase()) { + throw new Error( + `verifyEnableTokenTransaction: sendMultiSig target ${recipient.address} does not match ACL contract ${aclContractAddress}` + ); + } + + // 4. Strict delegation content (delegate pin, expiry, exact deduplicated token set, + // callFromParent target == ACL with zero native value). + this.verifyStrictEnableTokenCalldata( + { to: recipient.address, data, value: '0' }, + aclContractAddress, + requestedAddresses + ); + + // 5. txHex mirror, defense in depth: when the prebuild carries a txHex, its + // sendMultiSig envelope must encode the same operation that will be signed. + if (txPrebuild.txHex) { + const txBuilder = this.getTransactionBuilder(); + txBuilder.from(txPrebuild.txHex); + const txJson = (await txBuilder.build()).toJson(); + const txData = txJson.data || ''; + if (!txData.toLowerCase().startsWith(sendMultisigMethodId.toLowerCase())) { + throw new Error( + 'verifyEnableTokenTransaction: multisig prebuild txHex must be a sendMultiSig call to the wallet contract' + ); + } + const decoded = decodeTransferData(txData); + if (decoded.to.toLowerCase() !== recipient.address.toLowerCase()) { + throw new Error( + `verifyEnableTokenTransaction: txHex sendMultiSig target ${decoded.to} does not match the recipient ${recipient.address} that will be signed` + ); + } + if (!new BigNumber(decoded.amount).isEqualTo(recipient.amount ?? 0)) { + throw new Error( + `verifyEnableTokenTransaction: txHex sendMultiSig value ${decoded.amount} does not match the recipient amount ${recipient.amount} that will be signed` + ); + } + // TransferData.data is typed loosely (bytes); for a sendMultiSig envelope it is the + // hex-encoded calldata, matching the decode in verifyWrapTransaction. + const txHexCalldata = (decoded.data as string).replace(/^0x/, '').toLowerCase(); + const signedCalldata = data.replace(/^0x/, '').toLowerCase(); + if (txHexCalldata !== signedCalldata) { + throw new Error( + 'verifyEnableTokenTransaction: txHex sendMultiSig calldata does not match the recipient calldata that will be signed' + ); + } + } + + return true; } /** diff --git a/modules/sdk-coin-eth/test/unit/erc7984Token.ts b/modules/sdk-coin-eth/test/unit/erc7984Token.ts index 5b6c9516ed..a4bcca381e 100644 --- a/modules/sdk-coin-eth/test/unit/erc7984Token.ts +++ b/modules/sdk-coin-eth/test/unit/erc7984Token.ts @@ -29,6 +29,8 @@ import { TransferBuilderERC7984, confidentialTransferNoProofMethodId, approveMethodId, + STRICT_MULTISIG_ENABLE_TOKEN_VERIFICATION_FLAG, + TransactionPrebuild, } from '@bitgo/abstract-eth'; import EthereumAbi from 'ethereumjs-abi'; import { addHexPrefix } from 'ethereumjs-util'; @@ -711,7 +713,9 @@ describe('Erc7984Token', function () { }); // ------------------------------------------------------------------------- - describe('verifyTransaction – multisig path', function () { + describe('verifyTransaction – multisig path (legacy flow, Flipt flag off)', function () { + const FLAG_OFF = { [STRICT_MULTISIG_ENABLE_TOKEN_VERIFICATION_FLAG]: false }; + it('should verify valid buildParams recipients', async function () { const result = await coin.verifyTransaction({ txParams: { @@ -719,6 +723,7 @@ describe('Erc7984Token', function () { recipients: [{ tokenName: 'hteth:ctest1', address: '0xabc', amount: '0' }] as any, }, txPrebuild: { + featureFlags: FLAG_OFF, buildParams: { type: 'enabletoken', recipients: [{ tokenName: 'hteth:ctest1', address: '0xabc', amount: '0' }], @@ -740,6 +745,7 @@ describe('Erc7984Token', function () { ] as any, }, txPrebuild: { + featureFlags: FLAG_OFF, buildParams: { type: 'enabletoken', recipients: [ @@ -762,6 +768,7 @@ describe('Erc7984Token', function () { recipients: [{ tokenName: 'hteth:ctest1', address: '0xabc', amount: '0' }] as any, }, txPrebuild: { + featureFlags: FLAG_OFF, buildParams: { type: 'enabletoken', recipients: [{ tokenName: 'hteth:wrongtoken', address: '0xabc', amount: '0' }], @@ -781,6 +788,7 @@ describe('Erc7984Token', function () { recipients: [{ tokenName: 'hteth:ctest1', address: '0xabc', amount: '0' }] as any, }, txPrebuild: { + featureFlags: FLAG_OFF, buildParams: { type: 'enabletoken', recipients: [{ tokenName: 'hteth:ctest1', address: '0xabc', amount: '100' }], @@ -799,6 +807,7 @@ describe('Erc7984Token', function () { type: 'enabletoken', }, txPrebuild: { + featureFlags: FLAG_OFF, buildParams: {}, } as any, wallet: {} as any, @@ -807,6 +816,165 @@ describe('Erc7984Token', function () { .should.be.rejectedWith(/missing buildParams.recipients/); }); }); + + // ------------------------------------------------------------------------- + describe('verifyTransaction – multisig strict path (CECHO-2815, Flipt flag default true)', function () { + // Client-built recipients echo, as attached by Wallet.buildTokenEnablements. + const clientRecipients = [{ tokenName: 'hteth:ctest1', address: '0xabc', amount: '0' }]; + const enableTokenParams = { type: 'enabletoken', enableTokens: [{ name: 'hteth:ctest1' }] }; + const delegationData = buildMulticallDelegationCalldata(DELEGATE_ADDRESS, [CTEST1_TOKEN_ADDRESS], EXPIRY); + const forwarderDelegationData = wrapInCallFromParent(ZAMA_ACL_ADDRESS, delegationData); + // ERC-20 approve theft calldata: the wallet contract would call token.approve(attacker, 1). + const approveTheftCalldata = + approveMethodId + EthereumAbi.rawEncode(['address', 'uint256'], [ATTACKER_CONTRACT_ADDRESS, 1]).toString('hex'); + const smuggledDelegationData = encodeRawMulticall([ + buildDelegationCalldata(DELEGATE_ADDRESS, CTEST1_TOKEN_ADDRESS, EXPIRY), + approveTheftCalldata, + ]); + const forwarderTheftData = encodeRawCallFromParent( + ATTACKER_CONTRACT_ADDRESS, + '1000000000000000000', + delegationData + ); + const walletContract = '0x8f977e912ef500548a0c3be6ddde9899f1199b81'; + const expireTime = Math.floor(Date.now() / 1000) + 3600; + + /** + * A realistic onchain-multisig enable-token prebuild: recipients[0] is the sendMultiSig + * operation that Eth.signTransaction hashes into the user's operation signature, and + * featureFlags carry the server-evaluated Flipt state. One unchecked cast: the wire + * recipient carries a `data` field the TransactionRecipient type does not model. + */ + function buildStrictPrebuild(opts: { + recipient?: { address: string; amount: string; data: string }; + featureFlags?: Record; + txHex?: string; + }): TransactionPrebuild { + return { + buildParams: { type: 'enabletoken', recipients: clientRecipients }, + ...(opts.recipient ? { recipients: [opts.recipient] } : {}), + coin: 'hteth', + gasPrice: 1, + gasLimit: 1, + isBatch: false, + nextContractSequenceId: 1, + ...(opts.featureFlags ? { featureFlags: opts.featureFlags } : {}), + ...(opts.txHex ? { txHex: opts.txHex } : {}), + } as unknown as TransactionPrebuild; + } + + async function verifyMultisigEnable(prebuild: TransactionPrebuild): Promise { + // Test seam: the multisig strict path never reads the wallet object. + return coin.verifyTransaction({ + txParams: enableTokenParams, + txPrebuild: prebuild, + wallet: {} as unknown as Wallet, + walletType: 'onchain', + }); + } + + it('should verify a benign base-wallet enable (aclMulticall shape) with the flag absent — default true', async function () { + const result = await verifyMultisigEnable( + buildStrictPrebuild({ recipient: { address: ZAMA_ACL_ADDRESS, amount: '0', data: delegationData } }) + ); + result.should.equal(true); + }); + + it('should verify a benign forwarder enable (callFromParent shape)', async function () { + const result = await verifyMultisigEnable( + buildStrictPrebuild({ + recipient: { address: FORWARDER_ADDRESS, amount: '0', data: forwarderDelegationData }, + }) + ); + result.should.equal(true); + }); + + it('should verify a benign enable when the txHex sendMultiSig envelope mirrors the signed recipient', async function () { + const txHex = await buildRawContractCallTxHex( + walletContract, + sendMultiSigData(ZAMA_ACL_ADDRESS, '0', delegationData, expireTime, 1, '0x' + '00'.repeat(65)) + ); + const result = await verifyMultisigEnable( + buildStrictPrebuild({ recipient: { address: ZAMA_ACL_ADDRESS, amount: '0', data: delegationData }, txHex }) + ); + result.should.equal(true); + }); + + it('should reject a non-zero sendMultiSig value (native fund theft)', async function () { + await verifyMultisigEnable( + buildStrictPrebuild({ recipient: { address: ZAMA_ACL_ADDRESS, amount: '12345', data: delegationData } }) + ).should.be.rejectedWith(/expected sendMultiSig value 0/); + }); + + it('should reject an ERC-20 approve theft prebuild (non-delegation calldata)', async function () { + await verifyMultisigEnable( + buildStrictPrebuild({ + recipient: { address: ATTACKER_CONTRACT_ADDRESS, amount: '0', data: approveTheftCalldata }, + }) + ).should.be.rejectedWith(/Not a valid delegation calldata/); + }); + + it('should reject delegate substitution to an attacker viewing key', async function () { + await verifyMultisigEnable( + buildStrictPrebuild({ + recipient: { + address: ZAMA_ACL_ADDRESS, + amount: '0', + data: buildMulticallDelegationCalldata(ATTACKER_DELEGATE_ADDRESS, [CTEST1_TOKEN_ADDRESS], EXPIRY), + }, + }) + ).should.be.rejectedWith(/does not match the expected enterprise viewing key/); + }); + + it('should reject a smuggled non-delegation inner call', async function () { + await verifyMultisigEnable( + buildStrictPrebuild({ recipient: { address: ZAMA_ACL_ADDRESS, amount: '0', data: smuggledDelegationData } }) + ).should.be.rejectedWith(/unrecognised method ID/); + }); + + it('should reject an aclMulticall-shaped op targeted away from the ACL contract', async function () { + await verifyMultisigEnable( + buildStrictPrebuild({ recipient: { address: WRONG_ACL_ADDRESS, amount: '0', data: delegationData } }) + ).should.be.rejectedWith(/does not match ACL contract/); + }); + + it('should reject the callFromParent theft shape (forwarder calling an attacker contract with funds)', async function () { + await verifyMultisigEnable( + buildStrictPrebuild({ recipient: { address: FORWARDER_ADDRESS, amount: '0', data: forwarderTheftData } }) + ).should.be.rejectedWith(/callFromParent target .* does not match ACL contract/); + }); + + it('should reject a decoy txHex whose sendMultiSig args differ from the signed recipient', async function () { + const txHex = await buildRawContractCallTxHex( + walletContract, + sendMultiSigData(ATTACKER_CONTRACT_ADDRESS, '12345', delegationData, expireTime, 1, '0x' + '00'.repeat(65)) + ); + await verifyMultisigEnable( + buildStrictPrebuild({ recipient: { address: ZAMA_ACL_ADDRESS, amount: '0', data: delegationData }, txHex }) + ).should.be.rejectedWith(/txHex sendMultiSig target .* does not match the recipient/); + }); + + it('should reject a txHex that is not a sendMultiSig envelope', async function () { + const txHex = await buildRawContractCallTxHex(walletContract, approveTheftCalldata); + await verifyMultisigEnable( + buildStrictPrebuild({ recipient: { address: ZAMA_ACL_ADDRESS, amount: '0', data: delegationData }, txHex }) + ).should.be.rejectedWith(/must be a sendMultiSig call/); + }); + + it('should reject a prebuild with no recipient to bind the signature to', async function () { + await verifyMultisigEnable(buildStrictPrebuild({})).should.be.rejectedWith(/exactly one recipient/); + }); + + it('should revert to the legacy flow on an explicit flag false (kill-switch proof)', async function () { + const result = await verifyMultisigEnable( + buildStrictPrebuild({ + recipient: { address: ATTACKER_CONTRACT_ADDRESS, amount: '12345', data: approveTheftCalldata }, + featureFlags: { [STRICT_MULTISIG_ENABLE_TOKEN_VERIFICATION_FLAG]: false }, + }) + ); + result.should.equal(true); + }); + }); }); // ---------------------------------------------------------------------------