Skip to content

fix restore_promises derivation-path mismatch on subset restores#901

Open
b-l-u-e wants to merge 3 commits intocashubtc:mainfrom
b-l-u-e:fix-restore-promises-derivation-path-subset
Open

fix restore_promises derivation-path mismatch on subset restores#901
b-l-u-e wants to merge 3 commits intocashubtc:mainfrom
b-l-u-e:fix-restore-promises-derivation-path-subset

Conversation

@b-l-u-e
Copy link
Contributor

@b-l-u-e b-l-u-e commented Feb 22, 2026

This PR fixes a wallet restore issue where restored proofs could receive the wrong derivation_path when the mint returns only a subset of requested outputs (or returns them in a non-zero index range/order).
It also adds a regression test to ensure this mismatch cannot reoccur.

so here in restore_promises:

  • secrets and rs were filtered using matching_indices
  • but derivation_paths was not filtered before calling _construct_proofs(...)

1) Wallet fix

In cashu/wallet/wallet.py:

  • filtered derivation_paths using the same matching_indices used for secrets/rs before _construct_proofs(...).
     secrets = [secrets[i] for i in matching_indices]
         rs = [rs[i] for i in matching_indices]
+        derivation_paths = [derivation_paths[i] for i in matching_indices]
         logger.debug(
             f"Restored {len(restored_promises)} promises. Constructing proofs."
         )

This restores 1:1 alignment among:

  • restored_promises
  • filtered secrets
  • filtered rs
  • filtered derivation_paths

2) Regression test

In tests/wallet/test_wallet_restore.py:

  • added test_restore_promises_derivation_paths_subset
  • test verifies each restored proof’s derivation_path matches the path expected for that proof’s secret
  • catches subset/non-zero-index restore mismatch scenarios.

Test Plan

  • poetry run pytest tests/wallet/test_wallet_restore.py::test_restore_promises_derivation_paths_subset -v

Note: While preparing this PR I hit a local pre-commit mypy error:
tests/conftest.py:119: Argument "seed" to "Ledger" has incompatible type "str | None"; expected "str"

not sure of the cause but maybe comes from here or rather maybe i am missing somethin???

git add tests/wallet/test_wallet_restore.py
git commit -s -m "test(wallet): add regression test for restore derivation-path mismatch"
trim trailing whitespace.................................................Passed
fix end of files.........................................................Passed
check yaml...........................................(no files to check)Skipped
check for added large files..............................................Passed
check docstring is first.................................................Passed
check json...........................................(no files to check)Skipped
debug statements (python)................................................Passed
mixed line ending........................................................Passed
check for case conflicts.................................................Passed
ruff.....................................................................Passed
ruff-format..............................................................Passed
mypy.....................................................................Failed
- hook id: mypy
- exit code: 1

tests/conftest.py:119: error: Argument "seed" to "Ledger" has incompatible type "str | None"; expected "str"  [arg-type]
Found 1 error in 1 file (checked 1 source file)

so i had to add an explicit guard in tests/conftest.py before constructing Ledger:

--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -114,6 +114,7 @@ async def ledger():
             Unit.usd: lightning_backend_usd,
         },
     }
+    assert settings.mint_private_key is not None
     ledger = Ledger(
         db=Database("mint", settings.mint_database),
         seed=settings.mint_private_key,

also i struggled with ruff-format for the cashu/wallet/wallet.py and ended up making changes in other part of the code file which is unrelated to the issue solved

@github-project-automation github-project-automation bot moved this to Backlog in nutshell Feb 22, 2026
@b-l-u-e b-l-u-e changed the title Fix restore_promises derivation-path mismatch on subset restores [WIP] Fix restore_promises derivation-path mismatch on subset restores Feb 22, 2026
Signed-off-by: b-l-u-e <winnie.gitau282@gmail.com>
Signed-off-by: b-l-u-e <winnie.gitau282@gmail.com>
Signed-off-by: b-l-u-e <winnie.gitau282@gmail.com>
@b-l-u-e b-l-u-e force-pushed the fix-restore-promises-derivation-path-subset branch from e1802af to b70bbbe Compare February 23, 2026 13:13
@b-l-u-e b-l-u-e changed the title [WIP] Fix restore_promises derivation-path mismatch on subset restores fix restore_promises derivation-path mismatch on subset restores Feb 23, 2026
@b-l-u-e b-l-u-e marked this pull request as ready for review February 23, 2026 15:34
@mercie-ux
Copy link

Ran this locally and verified that the regression test fails without filtering derivation_paths and passes with the fix. The alignment fix looks correct.

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

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

2 participants