Skip to content
Business logic Audit finding Intermediate

Unable to upload guardian shares on social backup

The upload-share endpoint only searches AccountState.backups for a backup ciphertext, but social backups are stored in AccountState.rec.social, so it returns 'Backup not found'. This prevents guardians from uploading their shares, making social recovery impossible.

montecristo Follow with 0xvd, ChainSentry and 12 others

Originally disclosed on Code4rena

Submitted by montecristo, also found by 0xvd, ChainSentry, count-sum, Egbe, eightzerofour, Goodman, JuggerNaut63, niffylord, RotiTelur, SanketKogekar, ScientificKatie420, ShredSecurity, Spektor, and touristS

contracts/src/http/endpoints/reconstruction/upload_share.rs #L48-L50

The upload-share endpoint fails to locate social backup ciphertexts because it only searches the AccountState.backups field while social backups are stored separately in AccountState.rec.social. This prevents guardians from uploading their shares, making social recovery impossible.

Finding description and impact

Social backup is a special recovery backup that stores the social recovery key ($\mathsf{msk\_ss\_social}$) and distributes its encryption to guardians.

The whole integration flow is demonstrated in SwafeContractTest::testNewRecoveryFlow, and is summarized as the following:

  1. Owner and guardian accounts are allocated

  2. Recovery setup

    1. Account update string will apply the following changes trace1, trace2, trace3

      1. AccountSecrets.recovery.social is set to $\mathsf{BackupCipherText.Gen}(\mathsf{msk = msk\_ss\_rik}, \mathsf{data = msk\_ss\_social})$ trace1, trace2, trace3
      2. $\mathsf{rik}$ is generated and pushed to AccountSecrets.recovery.assoc
  3. Account is updated on chain using the above account update string

    At this point, $\mathsf{BackupCipherText}$ is stored in AccountState.rec.social, as we can confirm in the below code:

    File: lib/src/account/v0.rs

    635:     pub fn update<R: Rng + CryptoRng>(&self, rng: &mut R) -> Result<AccountUpdate> {
    ...
    703:         let st = AccountStateV0 {
    704:             cnt,
    705:             backups: self.backups.clone(),
    706:             recover: self.recover.clone(),
    707:             pke: self.pke.encryption_key(),
    708:             sig: self.sig.verification_key(),
    709:             act,
    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:         };
    
  4. Recovery initiation

    1. This step generates an encryption key pair (pke, dke) and generates AccountUpdateRecovery request trace1, trace2, trace3
  5. Submits AccountUpdateRecovery request to the contract

    1. By this update, AccountState.rec.pke will be set trace1, trace2, trace3
  6. Generate guardian shares

  7. Verify guardian shares

The test ends here, but we’ll have to upload guardian share to guardian nodes for guardian distribution. Otherwise, guardian shares are not available on nodes when recovery request is received.

If we take a look at upload-share handler:

File: contracts/src/http/endpoints/reconstruction/upload_share.rs

33: pub fn handler(
34:     mut ctx: OffChainContext,
35:     state: ContractState,
36:     request: HttpRequestData,
37:     _params: Params,
38: ) -> Result<HttpResponseData, ContractError> {
39:     let request: Request = deserialize_request_body(&request)?;
40:
41:     let backup_id = request.backup_id.0;
42:     let account_id = request.account_id.0;
43:
44:     let account = state
45:         .get_account(account_id)
46:         .ok_or_else(|| ServerError::NotFound("Account not found".to_string()))?;
47:
48:@>   let backup: &BackupCiphertext = account.recover_id(backup_id).ok_or_else(|| {
49:         ServerError::NotFound(format!("Backup not found for backup_id: {}", backup_id))
50:     })?;

We need to provide account_id, backup_id to identify $\mathsf{BackupCipherText}$ stored in step 3, and later match it to our guardian share.

However, since account.recover_id finds backups only from AccountState.backups(trace1, trace2, trace3), upload-share endpoint will revert with “Backup not found” error.

Impact

  • Unable to upload guardian shares generated for social backup
  • Guardians cannot recover $\mathsf{msk\_ss\_social}$ because they do not have corresponding guardian shares in their nodes

Recommended mitigation steps

Look backup in AccountState.backups and AccountState.rec.social.

Swafe mitigated:

self.backups.iter().collect() → self.recover.iter().chain(once(&self.rec.social)).collect()

Status: Mitigation confirmed. Full details in reports from montecristo, niffylord, and DCENT09.


The original report as published on Code4rena, by montecristo. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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 upload-share handler uses a lookup function that only checks AccountState.backups, while social backup ciphertexts are stored in AccountState.rec.social.

Impact

Guardians cannot upload their shares, so they cannot recover the social master key and social recovery is impossible.

What the attacker needed

A social backup configured; guardian shares generated; recovery initiated

The fix

The lookup should search both AccountState.backups and AccountState.rec.social; the project mitigated it accordingly and the mitigation was confirmed.

How it was found

  1. Set up a social backup so that the backup ciphertext is stored in AccountState.rec.social.
  2. Initiate recovery and generate guardian shares.
  3. Call the upload-share endpoint with the account_id and backup_id.
  4. The endpoint fails to find the backup and returns 'Backup not found'.

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 social backup lets a group of trusted people (guardians) help recover an account. Each guardian must upload a piece of the recovery key to their node, but the upload endpoint looks in the wrong place for the backup data, so it always says 'not found'. As a result, the recovery pieces never reach the nodes and the account cannot be recovered.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by montecristo

View all

10 more disclosed reports, best first.

More from Swafe

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.