Skip to content

Commit

Permalink
Fixing freeze plugin update permissions.
Browse files Browse the repository at this point in the history
  • Loading branch information
blockiosaurus committed Mar 1, 2024
1 parent 430aa3e commit 4e23642
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions clients/js/test/plugins/asset/delegate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ test('a delegate can freeze the token', async (t) => {
__kind: 'Freeze',
fields: [{ frozen: true }],
},
authority: delegateAddress,
}).sendAndConfirm(umi);

const asset = await fetchAssetWithPlugins(umi, assetAddress.publicKey);
Expand Down
18 changes: 11 additions & 7 deletions programs/mpl-core/src/plugins/freeze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,17 @@ impl PluginValidation for Freeze {
_args: &crate::processor::UpdatePluginArgs,
authorities: &[Authority],
) -> Result<ValidationResult, solana_program::program_error::ProgramError> {
if !self.frozen
&& ((ctx.authority.key == &asset.owner && authorities.contains(&Authority::Owner))
|| (ctx.authority.key == &asset.update_authority.key()
&& authorities.contains(&Authority::UpdateAuthority))
|| authorities.contains(&Authority::Pubkey {
address: *ctx.authority.key,
}))
// The owner can't update the freeze status.
if (ctx.authority.key != &asset.owner
&& (ctx.authority.key == &asset.update_authority.key()
&& authorities.contains(&Authority::UpdateAuthority))
|| authorities.contains(&Authority::Pubkey {
address: *ctx.authority.key,
}))
// Unless the owner is the only authority.
|| (ctx.authority.key == &asset.owner
&& authorities.contains(&Authority::Owner)
&& authorities.len() == 1)
{
Ok(ValidationResult::Approved)
} else {
Expand Down
2 changes: 2 additions & 0 deletions programs/mpl-core/src/processor/update_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ pub(crate) fn update_plugin<'a>(
//TODO: Handle plugins that are dynamically sized.
args.plugin
.save(ctx.accounts.asset_address, registry_record.offset)?;
} else {
return Err(MplCoreError::InvalidAuthority.into());
}

Ok(())
Expand Down

0 comments on commit 4e23642

Please sign in to comment.