Skip to content

fix: correct testnet P2SH address classification bug in bitcoin provider#44

Open
Tmalone1250 wants to merge 15 commits intoentrius:mainfrom
Tmalone1250:fix/issue-33-p2sh-classification
Open

fix: correct testnet P2SH address classification bug in bitcoin provider#44
Tmalone1250 wants to merge 15 commits intoentrius:mainfrom
Tmalone1250:fix/issue-33-p2sh-classification

Conversation

@Tmalone1250
Copy link
Copy Markdown

Description

Corrected the Bitcoin address classification logic in detect_address_type to properly handle Testnet P2SH addresses.

Technical Details

  • Identified that addresses starting with prefix '2' (Testnet P2SH) were previously misclassified as ADDR_TYPE_P2PKH because they were grouped with 'm' and 'n' prefixes.
  • Split the condition to explicitly return ADDR_TYPE_P2SH_P2WPKH for addresses starting with '2'.
  • Verified the fix with a standalone logic test script across multiple address types (Mainnet P2PKH/P2SH, Testnet P2PKH/P2SH).

Fixes #33
Reference: Sovereign Protocol local-first workflow.

LandynDev and others added 15 commits March 25, 2026 20:59
…rius#3)

Previously fee_divisor minimum was 2 (allowing up to 50% fee on miner
collateral per swap). Now enforced at minimum 20 (max 5%) in both the
contract and CLI.
…ation (entrius#8)

The halt flag previously only blocked vote_reserve. Now it also blocks
post_collateral and vote_activate, while all swap resolution paths
(fulfill, confirm, timeout, extend, claim) remain allowed so in-flight
swaps can safely unwind and users can always withdraw.
)

A miner could claim a third-party tx to the user's dest address as their
own fulfillment. Store miner_dest_address on the swap struct at initiation
and validate tx_info.sender against it during dest-side verification.
* Verify dest transaction sender matches miner's posted address

A miner could claim a third-party tx to the user's dest address as their
own fulfillment. Store miner_dest_address on the swap struct at initiation
and validate tx_info.sender against it during dest-side verification.

* Support direction-specific rates for miner pair posting

Miners can now post separate rates for each swap direction (e.g., 340 TAO/BTC
for BTC->TAO, 350 TAO/BTC for TAO->BTC) to capture tx fee asymmetry. Commitment
format bumped to v3 with two rate fields. Backend unchanged — each swap still
stores one rate, selected by direction at initiation time.

* Make rate logic chain-agnostic and rename rate_reverse to counter_rate

Replace TAO-centric assumptions with canonical chain ordering so
any pair (including non-TAO pairs like BTC-ETH) works correctly.
TAO is preferred as the rate denomination when present, otherwise
alphabetical ordering is used as a deterministic fallback.

- Add canonical_pair() to chains.py with TAO-preference ordering
- Rename rate_reverse → counter_rate across all files
- Change get_rate_for_direction(source_is_tao) to accept chain name
- Rename rate.py params: source_is_tao → is_reverse, tao_decimals/asset_decimals → dest_decimals/source_decimals
- Filter miners with rate=0 for the desired direction (CLI + validator)
- Fix test_scale.py swap encoding (missing miner_source_address, miner_dest_address, rate)
- Fix float comparison for rate display → use string comparison
- Add 5 unit tests: canonical_pair, direction after normalization, direction-specific rate calc

* Fix CLI to support single-direction rate posting

- Allow counter_rate=0 (miner only supports one direction)
- Auto-select destination chain when only one option remains
- Add context to chain prompts (you receive/send on this chain)
- Display "not supported" for disabled directions in status/summary
- Add 2 unit tests for single-direction parsing and normalization

* Improve rate display clarity across CLI

- Use "send X, get Y" format for rate confirmation and swap summary
- Split miners table into explicit BTC→TAO / TAO→BTC columns
- Show "—" for disabled directions (rate=0) in tables
- Use "not supported" label for disabled directions in status

* Add canonical_pair TAO preference test

Verify that chains sorting after "tao" alphabetically (e.g. "thor")
still get TAO as dest, not alphabetical ordering.

* Add test for disabled direction guard chain (rate=0 → dest_amount=0)

Verifies the full defense-in-depth: get_rate_for_direction returns 0 for
disabled direction, validator guard catches it, and calculate_dest_amount
produces 0 as a fallback (contract rejects InvalidAmount).

* Fix rate swap on non-canonical CLI input and display edge cases

- Swap rates during normalization when positional args used in
  non-canonical order (e.g. alw miner post tao ... btc ... 340 360)
- Fix display showing "get 0" in green when forward rate is disabled
- Consistent — in view_rates for rate=0 (matches view_miners)

* Fix status.py to show directional rates instead of single rate

---------

Co-authored-by: Ander <61125407+anderdc@users.noreply.github.com>
* Persist pending confirms in SQLite

* Address feedback
…found from provider-unreachable (entrius#10)

* Prevent miner slashing when chain provider is unreachable during verification

* Condense docstrings to single sentences

* feat: Extend reservation on provider-unreachable path to protect user funds during chain outages

* fix: remove unused test scripts
* Remove unused treasury_hotkey and netuid from contract storage

Neither field was read after construction — dead storage that inflated
the ABI and constructor parameter list without serving any purpose.

* Unify address types from Vec<u8> to String in contract and client

The same user source address was typed as Vec<u8> in reservation/strike
storage but String in SwapData. Strike clearing in confirm_swap relied
on an implicit UTF-8 roundtrip (as_bytes().to_vec()). Using String
everywhere makes the types consistent and removes the fragile assumption.

* Reset commitment version to v1

No production release has happened — v3 was accumulated from internal
iterations. Reset to v1 so the first release starts clean.

* Deduplicate miner matching logic in swap command

swap.py reimplemented the exact filtering + reverse-direction MinerPair
construction that already exists in helpers.find_matching_miners().
Replace with a single call to the shared helper.

* Fix scoring window never populated for resolved swaps

The contract removes swap data from storage atomically when
confirm/timeout quorum is reached, so get_swap() always returns
None for resolved swaps. The tracker's monitoring phase could never
observe a terminal status, leaving the scoring window permanently
empty.

Add resolve() to capture terminal state when the validator's own
vote succeeds, and infer terminal state when another validator
reaches quorum (swap disappears between polls).
* Allow zero rate for either swap direction in miner post

The forward rate was forced > 0, preventing miners from zeroing out
whichever direction canonical ordering put first. Now either rate
accepts 0 (not offered), with at least one required positive.

Also cleans up the interactive UX:
- Drop source/destination language from prompts (just "Chain" + addresses)
- Silently auto-select the second chain when only one option
- Rate header explains denomination once, prompts are just "BTC -> TAO:"
- Confirmation shows chain names instead of Source/Destination labels
- Rate display uses "1 BTC = 220 TAO" format

* Handle missing contract registration gracefully in view commands

view miners: catch ContractError per-miner and show dashes for
collateral/active instead of aborting the entire table.

view rates: silently skip miners without contract registration
instead of showing a misleading "contract read error" warning.
…n handlers (entrius#18)

* Extract helper methods from Bitcoin and Subtensor verify_transaction for readability

* Extract helper methods from send_amount_lightweight and axon handlers for readability
@Tmalone1250 Tmalone1250 reopened this Apr 14, 2026
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.

6 participants