Skip to content

wallet: construct_from_address_net does not validate base58 addresses against the network #242

@fpelliccioni

Description

@fpelliccioni

Problem

kth_wallet_payment_address_construct_from_address_net(address, net) takes a kth_network_t parameter, but only uses it for CashAddr disambiguation — base58 addresses pass through without any network validation.

A testnet base58 address (m... / n... with version byte 0x6f) is accepted even when net == mainnet. The function name and signature imply full network validation, but the implementation falls back to from_string(address, net) which calls decode_base58 first, and if that succeeds it returns immediately without consulting net.

Expected behavior

Either:

  • Option A (strict): Validate that the base58 version byte matches the requested network (e.g., mainnet_p2kh = 0x00 / mainnet_p2sh = 0x05 for mainnet, testnet_p2kh = 0x6f / testnet_p2sh = 0xc4 for testnet). Reject mismatches.
  • Option B (permissive + documented): Keep the current behavior but document explicitly that net only disambiguates CashAddr parsing — base58 addresses are always accepted regardless of network.

Affected code

  • C++: payment_address::from_string(string, config::network) in src/domain/src/wallet/payment_address.cpp
  • C-API: kth_wallet_payment_address_construct_from_address_net in src/c-api/src/wallet/payment_address.cpp

Context

Introduced alongside the CashAddr global removal in PR #240 / #241. The config::network parameter was added to replace the global set_cashaddr_prefix(). The base58 path was intentionally left untouched at the time, but the API name implies broader validation than it delivers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions