Prove pda system account storage lamports really secure. Some people concern about pda account, that assigned for system program rather than itself program id is not secure. This 's a piece of code that prove that pda account assigned for system program always secure.
TODO
Program init pda account
#[program]
pub mod pda {
use super::*;
pub fn initialize(ctx: Context<Initialize>) -> Result<()> {
let bump = *ctx.bumps.get("escrow_account").unwrap();
ctx.accounts.create_native_account_vault(bump)?;
Ok(())
}
}
Program init hack pda account
#[program]
pub mod hacker {
use super::*;
pub fn drain(ctx: Context<Drain>) -> Result<()> {
let bump = *ctx.bumps.get("escrow_account").unwrap();
ctx.accounts.drain_sol(bump)?;
Ok(())
}
}
-
Deploy program: deploy pda:
cd programs/pda anchor build && anchor deploy
-
Deploy hacker:
cd prgrams/hacker anchor build && anchor deploy
Notes: Update program in declare id in all program
declare_id!("FcBBAczSDVtSwJ55RWfbGAwEQTyQ3Urh29UHi3qrFPJf");
-
Run client
cd client && cargo build
run test:
/target/debug/client --pda-program-id programId --hacker-program-id programId
Example:
./target/debug/client --pda-program-id DzSN8ZCEURUe3nXtUi23L4N6jCQT16B8GjfZQ1CkoQEh --hacker-program-id FcBBAczSDVtSwJ55RWfbGAwEQTyQ3Urh29UHi3qrFPJf