Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: wallet client recovery privacy improvements #5697

Merged

Conversation

dpc
Copy link
Contributor

@dpc dpc commented Jul 19, 2024

See comments in the code.

Fix #5584

@dpc dpc requested a review from a team as a code owner July 19, 2024 07:13
@dpc
Copy link
Contributor Author

dpc commented Jul 19, 2024

ATM. This needs another round of self-review, but is probably in reviewable state.

@@ -64,24 +61,16 @@ static BITCOIN_RPC_REGISTRY: Lazy<Mutex<BTreeMap<String, DynBitcoindRpcFactory>>
pub fn create_bitcoind(config: &BitcoinRpcConfig, handle: TaskHandle) -> Result<DynBitcoindRpc> {
let registry = BITCOIN_RPC_REGISTRY.lock().expect("lock poisoned");

let kind = env::var(FM_FORCE_BITCOIN_RPC_KIND_ENV)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ooops. I didn"t want to make this change.

@dpc dpc force-pushed the 24-07-15-wallet-module-recovery-privacy branch 4 times, most recently from 58c3d8d to 87ba9eb Compare July 19, 2024 16:43
@dpc dpc requested a review from elsirion July 27, 2024 03:18
Copy link
Contributor

@elsirion elsirion left a comment

Choose a reason for hiding this comment

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

The algorithm likely skips scripts that could have received money

Comment on lines +29 to +40
// To avoid updating `decoys` for the whole recovery, which might be a lot of extra updates
// most of which will be thrown away, ignore script pubkeys from before this `session_idx`
decoy_session_threshold: u64,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: is writing to a vector really that expensive? The complexity doesn"t feel worth it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The cost of a cloning is more of a problem, potentially. Also, we really only want some recently used addresses as a decoy, as we are going to check only few (potentially) last used addresses. An attacker might see through things if we query some much older addresses.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since I might need to query old addresses anyway, maybe I"ll just replace it with some probabilistic thing to potentially keep some older addresses around...

modules/fedimint-wallet-client/src/backup.rs Show resolved Hide resolved
@dpc dpc force-pushed the 24-07-15-wallet-module-recovery-privacy branch 2 times, most recently from 6a7f406 to bd66153 Compare August 9, 2024 19:10
Comment on lines 415 to 426
if used_tweak_idxes.contains(&cur_tweak_idx) {
debug!(target: LOG_CLIENT_MODULE_WALLET,
tweak_idx=%cur_tweak_idx,
"Skipping checking history of an address, as it was previously used");
last_used_idx = Some(cur_tweak_idx);
tweak_idxes_with_pegins.insert(cur_tweak_idx);
} else {
let history = check_addr_history(cur_tweak_idx).await?;

if !history.is_empty() {
last_used_idx = Some(cur_tweak_idx);
tweak_idxes_with_pegins.insert(cur_tweak_idx);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The amount of mutability here makes it quite hard to review, I was procrastinating on reviewing this PR for way too long due to it. Let"s discuss during review club, I think there is a beautiful, small algorithm hidden in here that wants to get implemented with some iterator chaining 😆

Copy link
Contributor

Choose a reason for hiding this comment

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

call: could loop over a range

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@elsirion Hmm... now that I"m looking at it ... if I do while or for, I can"t use break value; which will introduce a different mutable value.

Comment on lines 270 to 272
= recover_scan_idxes_for_activity(
self.state.next_unused_idx_from_backup,
self.state.tracker.used_tweak_idxes(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Eventually we should scan from index zero to not miss anything, but we need the already claimed list in the backup to do so privately.

@elsirion elsirion dismissed their stale review August 20, 2024 16:41

main point addressed

@dpc
Copy link
Contributor Author

dpc commented Aug 21, 2024

@elsirion @bradleystachurski Just went ahead and implemented the better backup for wallet as we"ve discussed during the review.

@dpc dpc requested a review from elsirion August 21, 2024 19:15
elsirion
elsirion previously approved these changes Aug 22, 2024
Copy link
Contributor

@elsirion elsirion left a comment

Choose a reason for hiding this comment

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

I think the final version we settled on is good, I"m trying to simplify that one fn nonetheless, see my take here: https://github.com/fedimint/fedimint/pull/5903/files/30ccddc406fe318d941d39350a7cd77d21414c8e..3bd09478781a718bf051c74d9725bd585d8fd4d3

last_used_idx = Some(cur_tweak_idx);
tweak_idxes_with_pegins.insert(cur_tweak_idx);
} else {
let history = check_addr_history(cur_tweak_idx).await?;
Copy link
Contributor

Choose a reason for hiding this comment

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

While rewriting this fn I noticed that we might be losing a lot of progress here depending on the retry behavior of check_addr_history. We are very dependent on it never failing here.

@dpc dpc force-pushed the 24-07-15-wallet-module-recovery-privacy branch from 30ccddc to 674409a Compare August 22, 2024 18:16
@dpc
Copy link
Contributor Author

dpc commented Aug 22, 2024

@elsirion I took most of #5903 and altered it to make it work. I will squash after you review approve.

elsirion
elsirion previously approved these changes Aug 23, 2024
@elsirion elsirion added this pull request to the merge queue Aug 23, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Aug 23, 2024
@dpc
Copy link
Contributor Author

dpc commented Aug 23, 2024

Seems like a legitimate flake https://github.com/fedimint/fedimint/actions/runs/10528393578/job/29173781412 , will try to repro locally.

@dpc dpc added this pull request to the merge queue Aug 23, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Aug 23, 2024
@dpc
Copy link
Contributor Author

dpc commented Aug 23, 2024

@elsirion CI flakiness exposed a place I"ve missed. See commit.

@dpc dpc requested a review from elsirion August 23, 2024 21:19
@@ -794,10 +793,7 @@ impl FedimintCli {
// TODO: until we implement recovery for other modules we can't really wait
Copy link
Member

Choose a reason for hiding this comment

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

[nit] Can also remove this TODO

@bradleystachurski bradleystachurski added this pull request to the merge queue Aug 23, 2024
Merged via the queue into fedimint:master with commit 5a34061 Aug 23, 2024
23 checks passed
@dpc dpc deleted the 24-07-15-wallet-module-recovery-privacy branch November 12, 2024 04:25
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.

Wallet recovery: sync federation history to preserve privacy
3 participants