Recovery can be done without Guardians’ approvals by looking at initial account update tx data
The initial account registration creates a social recovery backup with a threshold of zero and no guardians, so its encryption keys can be derived from the RIK alone. Anyone who knows the RIK can decrypt the social secret from the on-chain initial account update and recover the account's master key without guardian approval.
Originally disclosed on Code4rena
Submitted by montecristo
lib/src/account/v0.rs #L436
In general, recovery can only be done with Guardians’ approvals, since we need to recover secret from guardians’ shares and use secret + msk_ss_rik to calculate key_data, which will then be used to decrypt the original data (in social recovery, data is msk_ss_social).
However, when an account is initially registered, AccountUpdate struct’s social recovery information is unsafely generated with weak parameters (threshold = 0). This allows derivation of key_data and key_meta without relying on guardian shares.
AccountUpdate of initial account registration is registered on chain and publicly available. So anyone with msk_ss_rik can look up transaction history and can decrypt original data (msk_ss_social) without possession of guardian shares, because key_data and key_meta of the initial social recovery can be calculated deterministically.
With msk_ss_rik and msk_ss_social, one can derive msk_decryption_key and recover account’s msk from AccountState.rec.enc_msk
This is a violation of one of the main invariants:
Recovery of a backup only occurs when more than the specified threshold of Guardians has approved the request.
Finding description and impact
The root cause stems from the following facts:
-
When account secret is generated,
recovery.socialis created with default parameters(guardians = [], threshold = 0)trace1, trace2File: lib/src/account/v0.rs
409: let social = create_recovery( 410: rng, // 411: acc, 412: &msk_ss_rik, 413: &msk_ss_social, 414:@> &[], 415:@> 0, 416: )?; -
This allows deterministic derivation of
key_metaandkey_datawithout relying on guardians’ shares-
sss::sharewill return(Fr::ZERO, [])for threshold 0 trace1, trace2File: lib/src/backup/v0.rs
// @audit threshold = 0, guardians = [] 380: let (secret, shares) = sss::share(rng, threshold, guardians.len());File: lib/src/crypto/sss.rs
32: pub(crate) fn share<R: RngCore + CryptoRng>( 33: rng: &mut R, 34: t: usize, 35: n: usize, 36: ) -> (Secret, Vec<Share>) { 37: // a threshold 0 sharing is just a constant 38: if t == 0 { 39:@> return (Secret(pp::Fr::ZERO), vec![]); 40: } -
As a result,
key_metaandkey_datacan be directly calculated frommsk_ss_rik-
key_meta = kdfn(msk_ss_rik, "KDFMetakey" || [])// @audit comms = [] 404: let key_meta: [u8; sym::SIZE_KEY] = kdfn(sym_key, &KDFMetakey { comms: &comms }); -
key_data = kdfn("BackupKDFInput" || msk_ss_rik || Fr::ZERO, "EmptyInfo")409: let key_data: [u8; sym::SIZE_KEY] = kdfn( 410: &BackupKDFInput { 411: key: sym_key, 412: secret, // @audit secret = 0 413: }, 414: &EmptyInfo, 415: );
-
-
-
This
recovery.socialinformation is available on chain because it’s included in initial account update transaction trace1, trace2File: lib/src/account/v0.rs
635: pub fn update<R: Rng + CryptoRng>(&self, rng: &mut R) -> Result<AccountUpdate> { ... 703: let st = AccountStateV0 { ... 710: rec: RecoveryStateV0 { 711: pke: None, 712: assoc, 713: // TODO: unfortunately we cannot generate this anew every time 714:@> social: self.recovery.social.clone(), 715: enc_msk, 716: }, 717: }; 718: 719: let sig = self.old_sig.sign(rng, &st); 720: Ok(AccountUpdate::V0(AccountUpdateV0 { 721: acc: self.acc, 722:@> msg: AccountMessageV0::Update(AccountUpdateFullV0 { sig, state: st }), 723: }))This means anyone with the knowledge of
msk_ss_rikcan recovermsk_ss_socialbecause: -
Since initial
account_update.rec.socialis visible on chain, social recoveryBackupCipherTextis known -
This initial recovery is generated with known parameters i.e. threshold = 0, guardians = []
-
BackupCipherTextis comprised of the following values ref:data = Sym.Seal(key_meta, BackupMetadata(Sym.Seal(key_data, msk_ss_social)))refencap = []because threshold = 0comms = []due to the same reason
-
Since
key_dataandkey_metacan be calculated frommsk_ss_rik,msk_ss_socialcan be decrypted fromBackupCipherText
With msk_ss_rik and msk_ss_social, one can derive msk_decryption_key and recover account’s msk.
Impact
This is a violation of one of the main invariants in the README:
- Recovery of a backup only occurs when more than the specified threshold of Guardians has approved the request.
FAQ
Q: This attack requires the knowledge of msk_ss_rik, which is a significant restriction.
A: Correct, however I believe this report is worth Medium severity because it violates the main invariant. Without the invariant, I wouldn’t have submitted this issue. Moreover, key_data and key_meta should be only retrieved from guardians’ approval, even for the party that knows msk_ss_rik. That’s because guardians “guard” secret, from which key_data is derived. However, the protocol publicly shares unsafe encryption of msk_ss_social by mistake.
Q: How do you know initial account update will always contain unsafe social recovery?
A: Because AccountUpdate.msg.state.rec.social property is mandatory and will be very likely to be filled with the explained library logic
AccountUpdate -> AccountUpdateV0 -> AccountMessageV0 -> AccountUpdateFullV0 -> AccountStateV0 -> RecoveryStateV0 -> social: BackupCipherText
File: lib/src/account/v0.rs
101: pub(crate) struct RecoveryStateV0 {
102: pub pke: Option<pke::EncryptionKey>, // this is set iff. recovery has been started
103: pub(crate) assoc: Vec<AssociationsV0>, // encryption of the recovery authorization key
104:@> pub(crate) social: BackupCiphertext, // social backup ciphertext
105: pub(crate) enc_msk: sym::AEADCiphertext, // encrypted MSK (encrypted with key derived from RIK and social shares)
106: }
Q: This only happens for account that did not initiate social recovery. If the account initiates a social recovery, rec.social will be updated with BackupCipherText generated with non-zero threshold and guardians.
A: Wrong. Accounts that initiated social recovery are also affected by this issue. Although new rec.social will be much more secure with non-zero threshold, initial account update transaction and account_update information is still visible on chain. Anyone with msk_ss_rik can recover initial msk_ss_social by looking at initial account update string. And with msk_ss_rik and the initial msk_ss_social, they can recover account’s msk. This breaks the main invariant.
Q: This report is wrong because msk_ss_social is rotated on recovery initiation. So even if you decrypted old mks_ss_social, it’s outdated and useless.
A: Nope, the main impact of this issue is msk recover without guardians’ approval, and we can decrypt msk from old msk_ss_social and old enc_msk, recorded on initial account update. More specifically, during account initialization, AccountUpdate contains msg.state.rec.enc_msk, which is generated as Sym.Seal(kdfn(msk_ss_rik, msk_ss_social_old), msk) ref. Since msk_ss_rik does not change, we can decrypt msk from enc_msk_old with msk_ss_rik and msk_ss_social_old.
Recommended mitigation steps
Don’t generate initial social recovery with trivial parameters.
Make social property optional and fill it only when recovery is initiated.
- Set threshold=1 in
gen()so initial recovery backup is unrecoverable (0 shares < threshold 1)- Move
guardians.len() < thresholdcheck fromBackupCiphertextV0::newto publicbackup()API, allowing internalcreate_recovery()to produce intentionally unrecoverable backups
Status: Mitigation confirmed. Full details in reports from montecristo, niffylord, and DCENT09.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The initial social recovery backup is generated with a threshold of zero and an empty guardian list, which makes its key material deterministically derivable from the RIK instead of requiring guardian shares.
Impact
An attacker who already knows the RIK could recover the account's master key without any guardian approval, breaking the stated invariant that recovery requires more than the threshold of guardians to approve.
What the attacker needed
Knowledge of the account's RIK secret; access to on-chain transaction history
The fix
The project mitigated it by setting the initial threshold to one so the initial backup is unrecoverable, and by moving the guardian-count check so internal recovery creation can produce intentionally unrecoverable backups.
How it was found
- Obtain the account's RIK secret.
- Look up the initial account update transaction on chain, which contains the social recovery ciphertext.
- Derive the metadata and data keys from the RIK because the threshold is zero.
- Decrypt the social secret from the ciphertext.
- Combine the RIK and social secret to derive the decryption key and recover the master key from the encrypted MSK.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A backup is normally locked so that several trusted friends (guardians) must agree before it can be opened. Here the very first backup was created with a rule that needs zero friends, so its lock can be opened by anyone who already holds one other piece of the account's key material. That lets such a person read the backup and recover the account's main secret without asking any guardian.
What is Crypto?
Encryption, signatures, randomness or certificate checks that do not protect what they claim to.