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

0rpse - reset instructions will not work #160

Open
sherlock-admin2 opened this issue Oct 27, 2024 · 0 comments
Open

0rpse - reset instructions will not work #160

sherlock-admin2 opened this issue Oct 27, 2024 · 0 comments
Labels
Sponsor Disputed The sponsor disputed this issue's validity

Comments

@sherlock-admin2
Copy link
Contributor

sherlock-admin2 commented Oct 27, 2024

0rpse

Medium

reset instructions will not work

Summary

The reset instruction first assigns the ownership of the PDA to System and then tries to realloc its size to zero. This is not possible as after assigning ownership to System, only System will have the rights to do this.

Root Cause

After the ownership of PDA is assigned to System, no account other than System can change its size.
This issue exists in both reset_oapp.rs and reset_vault.rs:
https://github.com/sherlock-audit/2024-09-orderly-network-solana-contract/blob/main/solana-vault/packages/solana/contracts/programs/solana-vault/src/instructions/oapp_instr/reset_oapp.rs#L7-L28
https://github.com/sherlock-audit/2024-09-orderly-network-solana-contract/blob/main/solana-vault/packages/solana/contracts/programs/solana-vault/src/instructions/vault_instr/reset_vault.rs#L7-L29

Internal pre-conditions

No response

External pre-conditions

No response

Attack Path

No response

Impact

reset+reinit flow is not possible to use.

PoC

No response

Mitigation

Here is a recommended way to close accounts:

#[program]
pub mod closing_accounts_recommended {
    use super::*;

    pub fn close(ctx: Context<Close>) -> ProgramResult {
        Ok(())
    }
}

#[derive(Accounts)]
pub struct Close<'info> {
    #[account(mut, close = destination)]
    account: Account<'info, Data>,
    #[account(mut)]
    destination: AccountInfo<'info>,
}

#[account]
pub struct Data {
    data: u64,
}

close constraint will make it so that the account is deleted and remaining SOL is sent to destination, after this you can initialize PDA as usual.

@sherlock-admin3 sherlock-admin3 added the Sponsor Disputed The sponsor disputed this issue's validity label Nov 3, 2024
@sherlock-admin4 sherlock-admin4 changed the title Dandy Lavender Terrier - reset instructions will not work 0rpse - reset instructions will not work Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Sponsor Disputed The sponsor disputed this issue's validity
Projects
None yet
Development

No branches or pull requests

2 participants