Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 0 additions & 5 deletions modules/sdk-coin-avaxc/src/avaxc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1230,11 +1230,6 @@ export class AvaxC extends AbstractEthLikeNewCoins {
return hash.digest();
}

Comment thread
prithvishet2503 marked this conversation as resolved.
Resolved

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟣 pre-existing, not blocking: Pre-existing, security-relevant: AVAXC TSS wallets still accept any deposit address when the platform reply says forwarderVersion: 0. The inherited isWalletAddress returns true for forwarder v0 (abstractEthLikeNewCoins.ts:3267). That check runs before the TSS/MPC branch at line 3276. Fix: for walletVersion 3, 5 and 6 with a commonKeychain, always run MPC verification, whatever forwarderVersion the platform sends. The fix belongs in the base class or a thin AvaxC override. Users who pass forwarderVersion 0 themselves for multisig v0 wallets must keep getting true.
A small fix can ride a push you are already making; otherwise a short reply is enough.

Why this was flagged

Wallet.createAddress (sdk-core/src/bitgo/wallet/wallet.ts:1561) sets impliedForwarderVersion = forwarderVersion ?? verificationData.coinSpecific?.forwarderVersion. When the caller passes no forwarderVersion, the value comes from the platform's /wallet/:id/address reply. In AbstractEthLikeNewCoins.isWalletAddress (abstractEthLikeNewCoins.ts:3259-3269), forwarderVersion === 0 returns true before isTssWalletVersion/shouldUseTssVerification is checked at lines 3276-3294. A compromised platform or MITM, the threat model of CECHO-2723, can reply {address: <attacker 0x>, coinSpecific: {forwarderVersion: 0}} for an avaxc wallet with walletVersion 3, 5 or 6. The MPC derivation check never runs, and createAddress returns the attacker's address as verified. The PR says TSS wallets gain real verification, but this bypass leaves them exactly as exposed as under the old always-true stub. Its residual-risk note covers only multisig v0 forwarders, not this TSS bypass.

Verification: In wallet.ts:1561, verificationData.impliedForwarderVersion = forwarderVersion ?? verificationData.coinSpecific?.forwarderVersion;, so the version comes from the /wallet/:id/address reply. Then if (forwarderVersion === 0) { return true; } runs before isTssWalletVersion / shouldUseTssVerification and the verifyMPCWalletAddress call that follow.

async isWalletAddress(params: VerifyAddressOptions): Promise<boolean> {
// TODO: Fix this later
return true;
}

/**
* Ensure either enterprise or newFeeAddress is passed, to know whether to create new key or use enterprise key
* @param params
Expand Down
106 changes: 104 additions & 2 deletions modules/sdk-coin-avaxc/test/unit/avaxc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import { getBuilder } from './getBuilder';
import * as secp256k1 from 'secp256k1';
import { bip32 } from '@bitgo/secp256k1';
import * as nock from 'nock';
import { common, RecoveryProviderError, TransactionType, Wallet } from '@bitgo/sdk-core';
import { Eth, optionalDeps } from '@bitgo/sdk-coin-eth';
import { InvalidAddressError, common, RecoveryProviderError, TransactionType, Wallet } from '@bitgo/sdk-core';
import { Eth, optionalDeps, TssVerifyEthAddressOptions, VerifyEthAddressOptions } from '@bitgo/sdk-coin-eth';
import { AvaxSignTransactionOptions } from '../../src/iface';
import * as assert from 'node:assert';
import * as should from 'should';
import { EXPORT_C, IMPORT_C, endpointResponses, recoveryUsers } from '../resources/avaxc';
import { TavaxP } from '@bitgo/sdk-coin-avaxp';
Expand Down Expand Up @@ -1488,6 +1489,107 @@ describe('Avalanche C-Chain', function () {
});
});
});

describe('Address Verification', function () {
describe('isWalletAddress', function () {
// Vector shared with the AbstractEthLikeNewCoins MPC tests:
// commonKeychain @ index 0 -> 0x01153f3adfe454a72589ca9ef74f013c19e54961
// (secp256k1 + keccak derivation is chain-agnostic, so it holds for avaxc)
const commonKeychain =
'03f9c2fb2e5a8b78a44f5d1e4f906f8e3d7a0e6b5c4d3e2f1a0b9c8d7e6f5a4b3c2d1e0f9e8d7c6b5a4' +
'93827160594857463728190a0b0c0d0e0f101112131415161718191a1b1c1d1e1f';
const keychains = [
{ pub: 'user_pub', commonKeychain },
{ pub: 'backup_pub', commonKeychain },
{ pub: 'bitgo_pub', commonKeychain },
];

it('should verify an MPC (TSS v3) wallet receive address', async function () {
const params = {
address: '0x01153f3adfe454a72589ca9ef74f013c19e54961',
coinSpecific: { forwarderVersion: 3 },
keychains,
index: 0,
walletVersion: 3,
} as unknown as TssVerifyEthAddressOptions;

(await avaxCoin.isWalletAddress(params)).should.equal(true);
});

it('should reject a well-formed address derived at the wrong index (CECHO-2723)', async function () {
// Same keychain derived at index 1 (m/1 -> 0x9b017d...e374), presented as index 0:
// a legitimate-looking address that does not match the requested derivation.
const params = {
address: '0x9b017d8c641f02c68bcf22bba4d9125d2cdee374',
coinSpecific: { forwarderVersion: 3 },
keychains,
index: 0,
walletVersion: 3,
} as unknown as TssVerifyEthAddressOptions;

(await avaxCoin.isWalletAddress(params)).should.equal(false);
});

it('should throw for an invalid address format instead of returning true', async function () {
const params = {
address: '0xinvalid',
coinSpecific: { forwarderVersion: 3 },
keychains,
index: 0,
walletVersion: 3,
} as unknown as TssVerifyEthAddressOptions;

await assert.rejects(async () => avaxCoin.isWalletAddress(params), InvalidAddressError);
});

it('should reject MPC verification when commonKeychain is missing', async function () {
const invalidKeychains = [
{ pub: 'user_pub' },
{ pub: 'backup_pub', commonKeychain },
{ pub: 'bitgo_pub', commonKeychain },
];
const params = {
address: '0x01153f3adfe454a72589ca9ef74f013c19e54961',
coinSpecific: { forwarderVersion: 3 },
keychains: invalidKeychains,
index: 0,
walletVersion: 3,
} as unknown as TssVerifyEthAddressOptions;

await assert.rejects(async () => avaxCoin.isWalletAddress(params), /missing required param commonKeychain/);
});

it('should return true for forwarder version 0 addresses (unverifiable by design)', async function () {
// Production AVAXC wallets are walletVersion 0 / forwarderVersion 0 (on-chain multisig);
// the base class documents v0 as unverifiable because the deployment nonce is not stored.
const params = {
address: '0xd5f90cc9ba0109521c7c75b8713a5f308930f43e',
baseAddress: '0x4a61abc3a4315cc517efde422c3b2aa8412f27ef',
coinSpecific: { forwarderVersion: 0 },
index: 78328,
walletVersion: 0,
} as unknown as VerifyEthAddressOptions;

(await avaxCoin.isWalletAddress(params)).should.equal(true);
});

it('should fail closed for forwarder versions with no deployed factory on avaxc', async function () {
// The AvalancheC network in @bitgo/statics has no forwarder factory addresses configured,
// so a v1 forwarder deposit address cannot be recomputed and must not verify.
const params = {
address: '0x0000000000000000000000000000000000000001',
baseAddress: '0x4a61abc3a4315cc517efde422c3b2aa8412f27ef',
coinSpecific: { forwarderVersion: 1, salt: '78328' },
index: 78328,
walletVersion: 0,
} as unknown as VerifyEthAddressOptions;
await assert.rejects(
async () => avaxCoin.isWalletAddress(params),
/Forwarder factory addresses not configured for this network/
);
});
});
});
});

describe('avaxc recoveryBlockchainExplorerQuery', function () {
Expand Down
Loading