Skip to content

Commit

Permalink
🐛 Enforce systems approval in macro expansion
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielePicco committed Oct 30, 2024
1 parent 3fc9ab9 commit 20f7ffa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
10 changes: 10 additions & 0 deletions crates/bolt-helpers/attribute/world-apply/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ pub fn apply_system(attr: TokenStream, item: TokenStream) -> TokenStream {
if !ctx.accounts.authority.is_signer && ctx.accounts.authority.key != &ID {
return Err(WorldError::InvalidAuthority.into());
}
if !ctx.accounts.world.permissionless
&& !ctx
.accounts
.world
.systems()
.approved_systems
.contains(&ctx.accounts.bolt_system.key())
{
return Err(WorldError::SystemNotApproved.into());
}
let remaining_accounts: Vec<AccountInfo<'info>> = ctx.remaining_accounts.to_vec();
let res = bolt_system::cpi::#execute_func_name(
ctx.accounts
Expand Down
5 changes: 3 additions & 2 deletions examples/system-apply-velocity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ pub mod system_apply_velocity {
ctx.accounts.position.x += 10 * (ctx.accounts.velocity.x + 2) + 3;
msg!("last applied: {}", ctx.accounts.velocity.last_applied);
msg!("Position: {}", ctx.accounts.position.x);
msg!("Remaining accounts: {}", ctx.remaining_accounts.len());
msg!("Remaining accounts len: {}", ctx.remaining_accounts.len());
msg!("Remaining accounts: {:?}", ctx.remaining_accounts);
msg!("Authority: {}", ctx.accounts.authority.key);
Ok(ctx.accounts)
}
Expand All @@ -34,7 +35,7 @@ pub mod system_apply_velocity {
pub struct ExtraAccounts {
#[account(address = bolt_lang::solana_program::sysvar::clock::id())]
pub sysvar_clock: AccountInfo,
#[account(address = pubkey!("6LHhFVwif6N9Po3jHtSmMVtPjF6zRfL3xMosSzcrQAS8"))]
#[account(address = pubkey!("tEsT3eV6RFCWs1BZ7AXTzasHqTtMnMLCB2tjQ42TDXD"))]
pub some_extra_account: AccountInfo,
#[account(address = Metadata::id())]
pub program_metadata: Program<Metadata>,
Expand Down

0 comments on commit 20f7ffa

Please sign in to comment.