`rebate_info` and `rebate_manager` are unable to sign the CPI call due to an incorrect implementation of the `seeds` function
The `seeds` functions for `rebate_manager` and `rebate_info` omit the bump seed, so the program cannot sign CPI calls for these accounts. This prevents `claim_rebate_fee` and `withdraw` from executing, locking tokens in the contract.
Source: https://github.com/sherlock-audit/2024-08-woofi-solana-deployment-judging/issues/29
Found by
g, shaflow01
Summary
rebate_info and rebate_manager will not be able to sign the CPI message because their seeds function has been implemented incorrectly.
Root Cause
The implementation of the seeds function is incorrect because the correct seed needs to include the full seed phrase and the bump, but the seeds function does not include the bump.
pub fn seeds(&self) -> [&[u8]; 2] {
[
REBATEMANAGER_SEED.as_bytes(),
self.quote_token_mint.as_ref(),
]
}
pub fn seeds(&self) -> [&[u8]; 3] {
[
REBATEINFO_SEED.as_bytes(),
self.rebate_manager.as_ref(),
self.rebate_authority.as_ref(),
]
}
Internal pre-conditions
None
External pre-conditions
None
Attack Path
None
Impact
It will prevent the claim_rebate_fee and withdraw operations from executing, resulting in tokens being permanently locked in the contract.
PoC
No response
Mitigation
Here is an example of fixing rebate_manager:
#[account]
#[derive(InitSpace)]
pub struct RebateManager {
pub authority: Pubkey, // 32
#[max_len(ADMIN_AUTH_MAX_LEN)]
pub admin_authority: Vec<Pubkey>,
pub quote_token_mint: Pubkey, // 32
pub token_vault: Pubkey, // 32
+ pub rebate_manager_bump: [u8; 1],
}
pub fn seeds(&self) -> [&[u8]; 2] {
[
REBATEMANAGER_SEED.as_bytes(),
self.quote_token_mint.as_ref(),
+ self.rebate_manager_bump.as_ref(),
]
}
pub fn initialize(
&mut self,
authority: Pubkey,
quote_token_mint: Pubkey,
token_vault: Pubkey,
+ bump: u8.
) -> Result<()> {
self.authority = authority;
self.quote_token_mint = quote_token_mint;
self.token_vault = token_vault;
+ self.rebate_manager_bump = [bump];
Ok(())
}
pub fn handler(ctx: Context<CreateRebateManager>) -> Result<()> {
let authority = ctx.accounts.authority.key();
let quote_token_mint = ctx.accounts.quote_token_mint.key();
let token_vault = ctx.accounts.token_vault.key();
+ let bump = ctx.bumps.rebate_manager;
let rebate_manager = &mut ctx.accounts.rebate_manager;
- rebate_manager.initialize(authority, quote_token_mint, token_vault);
+ rebate_manager.initialize(authority, quote_token_mint, token_vault, bump);
}
The fix for rebate_info is the same as described above.
Discussion
toprince
Valid. same with https://github.com/sherlock-audit/2024-08-woofi-solana-deployment-judging/issues/18
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/woonetwork/WOOFi_Solana/pull/32
gjaldon
The rebate_manager's bump is now stored in the account and included in its seeds(). The issue is fixed and transfers from the rebate_manager will succeed.
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 `seeds` functions for `rebate_manager` and `rebate_info` do not include the bump seed, so the derived program address does not match the actual account address and CPI signing fails.
What the attacker needed
None
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.
In Solana programs, accounts can be controlled by the program itself using a set of seeds and a bump value. If the bump is left out when the program tries to sign for the account, the signature is invalid. Here, the bump was missing, so the program could not move tokens out of the rebate accounts.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.