Skip to content

fix(address-codec-ergo): reject testnet and non-P2PK addresses that cannot round-trip - #14

Open
Kshot3000 wants to merge 1 commit into
rosen-bridge:devfrom
Kshot3000:fix/ergo-codec-mainnet-p2pk
Open

Kshot3000 wants to merge 1 commit into
rosen-bridge:devfrom
Kshot3000:fix/ergo-codec-mainnet-p2pk

Conversation

@Kshot3000

Copy link
Copy Markdown

Summary

Fixes #9 for the codec layer: encodeErgoAddress stored only the content bytes of any address that passed from_base58, and decodeErgoAddress always rebuilds a mainnet P2PK address from those bytes. Two kinds of input therefore passed validation and encoding, then produced a stuck or silently rerouted transfer:

  • Testnet P2PK — encodes to the same bytes as the mainnet address of the same key; a target entered on an encoded chain is silently paid on mainnet, and a target entered from Cardano passes the extractor's validation but can never match the guard-built output address, so every guard rejects every payment and the event loops until it times out.
  • Short P2S — encodes to the script bytes, which either throw inside parseRosenData when decoded (the extractor then returns nothing and the locked funds sit with no event) or are misread as a public key.

Change

encodeErgoAddress and validateErgoAddress now share one parse step that refuses addresses the stored format cannot represent, throwing the existing UnsupportedAddressError (with a reason) for:

  • non-mainnet addresses (checked with Address.from_mainnet_str), and
  • non-P2PK addresses (address_type_prefix() !== P2Pk).

The stored format and decodeErgoAddress are unchanged: every mainnet P2PK address encodes byte-for-byte as before, and all previously stored values decode exactly as before. Watchers and extractors using validateAddress/encodeAddress now fail at admission — with an error a user can act on — instead of accepting a target the bridge cannot pay.

Deliberate scope limits, flagged for maintainers:

  • Actually supporting testnet or P2S targets would require changing the stored format (e.g. storing the prefix byte along with the content bytes, as the Cardano codec in this repo does with its full address bytes). That is a wire-format decision I did not want to bundle into a bug fix; this PR only stops the silent corruption.
  • The bridge form in rosen-bridge/ui (networks/base/src/validateAddress.ts, linked from Ergo Address Codec Accepts Testnet and P2S, Then Decodes as Mainnet P2PK #9) has its own copy of the permissive validation and should get the same restriction; it does not consume this package's validator.

Verification

  • Tests first: 4 new tests (encode/validate × testnet/P2S) all fail on pristine dev, pass with the fix. Package suite 10/10.
  • Dependents rebuilt and green: @rosen-bridge/address-codec 3/3, @rosen-bridge/address-manager 4/4, @rosen-bridge/rosen-extractor 228/228 — no existing test anywhere in this repo used a testnet or non-P2PK Ergo target.
  • tsc --noEmit, eslint, and prettier clean on the changed files.

Changeset included (@rosen-bridge/address-codec-ergo: patch).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ergo Address Codec Accepts Testnet and P2S, Then Decodes as Mainnet P2PK

1 participant