keep the encrypted master secret of imported slip39 shares, so that the wallet decrypts it with any passphrase as the shares do
What changed, and why it matters
This commit fixes how Sparrow Wallet stores the backup/recovery seed when a user imports a wallet using SLIP39 shares (a type of multi-share mnemonic backup). Previously, the wallet decrypted the shares with the passphrase entered at import time and stored the resulting master secret. That meant if the user later opened the wallet with a different passphrase, the wallet would derive the wrong keys. The change keeps the master secret in its encrypted form, so any passphrase works the same way the original SLIP39 shares do. This is a correctness fix for passphrase handling in SLIP39 wallets.
Treat this as a bug-fix patch that corrects key derivation for SLIP39 wallets imported with a passphrase. Users who imported SLIP39 shares with a non-empty passphrase before this fix should verify that their wallet derives the expected addresses; if not, they may need to re-import. No immediate exploit path is evident from the diff alone, but incorrect key derivation can lead to funds appearing inaccessible or backups not matching wallet state.
Security signals we found
SLIP39 passphrase handling changed from one-time decryption to persistent encrypted master secret
Stored seed now derives correct keys regardless of which passphrase is later used
New unit test explicitly checks passphrase-variant key derivation parity
Submodule bump suggests related crypto library changes
Evidence from the diff
The patch changes Slip39.java so that instead of recovering the raw secret with the supplied passphrase and creating a DeterministicSeed from the raw bytes, it recovers the encrypted master secret (EMS) and converts it to a single-share mnemonic. That mnemonic is then stored in the DeterministicSeed. The wallet later decrypts it with whatever passphrase the user provides, matching SLIP39 semantics where the passphrase is part of the recovery input rather than a one-time decryption key. A unit test verifies that the stored seed produces the same master secret for passphrases ‘TREZOR’, ‘’, and ‘another’. The drongo submodule is also bumped, presumably to add the EMS/recovery APIs.
Changed components
src/main/java/com/sparrowwallet/sparrow/io/Slip39.javadrongo submoduleSLIP39 wallet import/keystore generationInspect captured patch +47 / −4
### drongo
@@ -1 +1 @@
-Subproject commit 2cf12e7917ca8c0261c9b7629e241bd14ac99f9d
+Subproject commit 1337b24641de1950c1544174a9587ed9a410315a
### src/main/java/com/sparrowwallet/sparrow/io/Slip39.java
@@ -4,9 +4,9 @@
import com.sparrowwallet.drongo.policy.PolicyType;
import com.sparrowwallet.drongo.wallet.*;
import com.sparrowwallet.drongo.wallet.slip39.RecoveryState;
+import com.sparrowwallet.drongo.wallet.slip39.Slip39MnemonicCode;
import com.sparrowwallet.drongo.wallet.slip39.Share;
-import java.nio.charset.StandardCharsets;
import java.util.List;
public class Slip39 implements KeystoreMnemonicShareImport {
@@ -35,8 +35,9 @@ public Keystore getKeystore(PolicyType policyType, List<ChildNumber> derivation,
}
if(recoveryState.isComplete()) {
- byte[] secret = recoveryState.recover(passphrase.getBytes(StandardCharsets.UTF_8));
- DeterministicSeed seed = new DeterministicSeed(secret, passphrase, System.currentTimeMillis(), DeterministicSeed.Type.SLIP39);
+ //The secret is kept encrypted as it was created, so that the wallet decrypts it with any passphrase as the shares do
+ List<String> singleShare = Slip39MnemonicCode.INSTANCE.toSingleShareMnemonic(recoveryState.recoverEms());
+ DeterministicSeed seed = new DeterministicSeed(singleShare, passphrase, System.currentTimeMillis(), DeterministicSeed.Type.SLIP39);
return Keystore.fromSeed(seed, policyType, derivation);
} else {
throw new Slip39ProgressException(recoveryState.getShortStatus(), recoveryState.getStatus());
### src/test/java/com/sparrowwallet/sparrow/io/Slip39Test.java
@@ -0,0 +1,42 @@
+package com.sparrowwallet.sparrow.io;
+
+import com.sparrowwallet.drongo.Network;
+import com.sparrowwallet.drongo.policy.PolicyType;
+import com.sparrowwallet.drongo.protocol.ScriptType;
+import com.sparrowwallet.drongo.wallet.Keystore;
+import com.sparrowwallet.drongo.wallet.slip39.Shamir;
+import com.sparrowwallet.drongo.wallet.slip39.Slip39MnemonicCode;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.List;
+
+public class Slip39Test {
+ private static final List<String> MNEMONICS = List.of(
+ "budget surprise agency romp clay quiet spew favorite purchase thumb observe sympathy acrobat presence unfold focus already tricycle diagnose muscle",
+ "budget surprise birthday romp breathe scroll intend humidity aspect plains isolate crystal blimp dragon garbage both kind dance human craft",
+ "budget surprise cleanup romp early remove uncover hearing lamp firefly ounce species submit snake phrase genuine tactics mustang desire artist",
+ "budget surprise desert romp deny easy senior arena smirk average single smart fatal lecture threaten eyebrow lunar carve indicate romantic",
+ "budget surprise email romp academic anxiety sister nylon fake makeup spine breathe window true recall desktop shelter divorce luck screw");
+
+ @AfterEach
+ public void tearDown() {
+ Network.set(null);
+ }
+
+ @Test
+ public void importedSeedDecryptsAsTheSharesWithAnyPassphrase() throws Exception {
+ Network.set(Network.MAINNET);
+ List<List<String>> shares = MNEMONICS.stream().map(mnemonic -> Arrays.asList(mnemonic.split(" "))).toList();
+ Keystore keystore = new Slip39().getKeystore(PolicyType.SINGLE_HD, ScriptType.P2WPKH.getDefaultDerivation(), shares, "TREZOR");
+
+ List<String> storedMnemonic = keystore.getSeed().getMnemonicCode();
+ for(String passphrase : List.of("TREZOR", "", "another")) {
+ byte[] expected = Shamir.combineMnemonics(MNEMONICS, passphrase.getBytes(StandardCharsets.US_ASCII));
+ Assertions.assertArrayEquals(expected, Slip39MnemonicCode.INSTANCE.toSeed(storedMnemonic, passphrase), passphrase);
+ }
+ }
+}Why this scored 58/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.