Skip to content

Commit

Permalink
Prevent Oracle from approving lifecycle events (#98)
Browse files Browse the repository at this point in the history
* Prevent Oracle from approving lifecycle events

* Regenerate IDL and clients

* Change error to be Oracle specific and prevent Oracle from listening
  • Loading branch information
danenbm authored May 2, 2024
1 parent 718b12a commit 20d7c4f
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 2 deletions.
16 changes: 16 additions & 0 deletions clients/js/src/generated/errors/mplCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,22 @@ export class MissingExternalAccountError extends ProgramError {
codeToErrorMap.set(0x22, MissingExternalAccountError);
nameToErrorMap.set('MissingExternalAccount', MissingExternalAccountError);

/** InvalidExternalPluginSetting: Invalid setting for external plugin */
export class InvalidExternalPluginSettingError extends ProgramError {
override readonly name: string = 'InvalidExternalPluginSetting';

readonly code: number = 0x23; // 35

constructor(program: Program, cause?: Error) {
super('Invalid setting for external plugin', program, cause);
}
}
codeToErrorMap.set(0x23, InvalidExternalPluginSettingError);
nameToErrorMap.set(
'InvalidExternalPluginSetting',
InvalidExternalPluginSettingError
);

/**
* Attempts to resolve a custom program error from the provided error code.
* @category Errors
Expand Down
3 changes: 3 additions & 0 deletions clients/rust/src/generated/errors/mpl_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ pub enum MplCoreError {
/// 34 (0x22) - Missing account needed for external plugin
#[error("Missing account needed for external plugin")]
MissingExternalAccount,
/// 35 (0x23) - Invalid setting for external plugin
#[error("Invalid setting for external plugin")]
InvalidExternalPluginSetting,
}

impl solana_program::program_error::PrintProgramError for MplCoreError {
Expand Down
5 changes: 5 additions & 0 deletions idls/mpl_core.json
Original file line number Diff line number Diff line change
Expand Up @@ -4163,6 +4163,11 @@
"code": 34,
"name": "MissingExternalAccount",
"msg": "Missing account needed for external plugin"
},
{
"code": 35,
"name": "InvalidExternalPluginSetting",
"msg": "Invalid setting for external plugin"
}
],
"metadata": {
Expand Down
4 changes: 4 additions & 0 deletions programs/mpl-core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ pub enum MplCoreError {
/// 34 - Missing account needed for external plugin
#[error("Missing account needed for external plugin")]
MissingExternalAccount,

/// 35 - Oracle external plugin can only be configured to deny
#[error("Oracle external plugin can only be configured to deny")]
OracleCanDenyOnly,
}

impl PrintProgramError for MplCoreError {
Expand Down
15 changes: 13 additions & 2 deletions programs/mpl-core/src/plugins/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ use crate::{
};

use super::{
ExternalPlugin, ExternalPluginInitInfo, ExternalPluginKey, ExternalPluginType,
ExternalRegistryRecord, Plugin, PluginHeaderV1, PluginRegistryV1, PluginType, RegistryRecord,
ExternalCheckResultBits, ExternalPlugin, ExternalPluginInitInfo, ExternalPluginKey,
ExternalPluginType, ExternalRegistryRecord, Plugin, PluginHeaderV1, PluginRegistryV1,
PluginType, RegistryRecord,
};

/// Create plugin header and registry if it doesn't exist
Expand Down Expand Up @@ -330,6 +331,16 @@ pub fn initialize_external_plugin<'a, T: DataBlob + SolanaAccount>(
(init_info.init_plugin_authority, &init_info.lifecycle_checks)
}
ExternalPluginInitInfo::Oracle(init_info) => {
// You cannot configure an Oracle plugin to approve lifecycle events.
if let Some(lifecycle_checks) = &init_info.lifecycle_checks {
for (_, result) in lifecycle_checks {
let result_bits = ExternalCheckResultBits::from(*result);
if result_bits.can_listen() || result_bits.can_approve() {
return Err(MplCoreError::OracleCanDenyOnly.into());
}
}
}

(init_info.init_plugin_authority, &init_info.lifecycle_checks)
}
ExternalPluginInitInfo::DataStore(init_info) => (init_info.init_plugin_authority, &None),
Expand Down

0 comments on commit 20d7c4f

Please sign in to comment.