Skip to content

feat: added a way to verify validator identity within ER#1133

Draft
taco-paco wants to merge 1 commit intomasterfrom
feat/magic-program/is-validator-check
Draft

feat: added a way to verify validator identity within ER#1133
taco-paco wants to merge 1 commit intomasterfrom
feat/magic-program/is-validator-check

Conversation

@taco-paco
Copy link
Copy Markdown
Contributor

@taco-paco taco-paco commented Apr 6, 2026

Summary

With callbacks it is importmant for developers to verify if callback was triggered by validator and not someone else. For that purpose they can now call VerifyValidatorIdentity in magicblock-program with "validator" account, magic-program will compare pubkeys and error if they do not match.

Compatibility

  • No breaking changes
  • Config change (describe):
  • Migration needed (describe):

Testing

  • tests (or explain)

Checklist

  • docs updated (if needed)
  • closes #

Summary by CodeRabbit

  • New Features
    • Added a new validator identity verification instruction to the MagicBlock program, enabling validation of validator authority accounts against expected identities.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 6, 2026

Manual Deploy Available

You can trigger a manual deploy of this PR branch to testnet:

Deploy to Testnet 🚀

Alternative: Comment /deploy on this PR to trigger deployment directly.

⚠️ Note: Manual deploy requires authorization. Only authorized users can trigger deployments.

Comment updated automatically when the PR is synchronized.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 6, 2026

📝 Walkthrough

Walkthrough

This pull request introduces a new VerifyValidatorIdentity instruction to the MagicBlock program. The instruction definition was added to the instruction set, and a corresponding handler was implemented in a new module. The handler validates that the validator authority account provided in the transaction matches the expected validator authority identifier, after confirming the MagicBlock program account exists and the magic context is correct. Unit tests cover success and failure scenarios for validator identity verification.

Suggested reviewers

  • GabrielePicco
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/magic-program/is-validator-check

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@magicblock-magic-program-api/src/instruction.rs`:
- Around line 306-310: Update the VerifyValidatorIdentity instruction docs to
match the handler in verify_validator_identity.rs: list index 0 as the Magic
Context account (MAGIC_CONTEXT_PUBKEY) and index 1 as the Validator Authority,
and ensure the account reference descriptions and ordering reflect that the
handler expects the magic context first and validator authority second (so the
documented account layout aligns with VerifyValidatorIdentity and
MAGIC_CONTEXT_PUBKEY usage).

In `@programs/magicblock/src/verify_validator_identity.rs`:
- Around line 32-35: Update the error logging string in the
VerifyValidatorIdentity handler so it correctly references the instruction name
instead of "ScheduleCommit"; locate the ic_msg! call in the
VerifyValidatorIdentity logic that currently logs "ScheduleCommit ERR: Magic
program account not found" and change it to a descriptive message like
"VerifyValidatorIdentity ERR: Magic program account not found" (or similar) so
logs correctly reflect the VerifyValidatorIdentity instruction context.
- Around line 86-101: In setup_transaction_accounts(), avoid using
HashMap::remove().unwrap() which yields an opaque panic; replace both unwrap()
calls with expect(...) that include descriptive messages referencing the keys
and the helper that should have populated them (e.g., mention
MAGIC_CONTEXT_PUBKEY and the validator returned by validator_authority_id()) so
if ensure_started_validator(...) failed to insert the entries the test failure
will report which key was missing and where (setup_transaction_accounts /
ensure_started_validator).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: ce461575-ae50-45d1-acf6-5288481e2219

📥 Commits

Reviewing files that changed from the base of the PR and between b9d2ada and c59a386.

⛔ Files ignored due to path filters (1)
  • test-integration/Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (4)
  • magicblock-magic-program-api/src/instruction.rs
  • programs/magicblock/src/lib.rs
  • programs/magicblock/src/magicblock_processor.rs
  • programs/magicblock/src/verify_validator_identity.rs

Comment on lines +306 to +310

/// Verifies if account's pubkey corresponds to current validator identity
/// # Account references
/// - **0.** `[]` Validator Authority
VerifyValidatorIdentity,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Instruction documentation does not match the handler's expected account layout.

The handler in verify_validator_identity.rs expects:

  • Index 0: Magic Context account (MAGIC_CONTEXT_PUBKEY)
  • Index 1: Validator Authority

However, the documentation only lists the Validator Authority at index 0. This mismatch could cause integration issues for developers using this instruction.

📝 Suggested documentation fix
     /// Verifies if account's pubkey corresponds to current validator identity
     /// # Account references
-    /// - **0.** `[]`  Validator Authority
+    /// - **0.** `[]`  Magic Context account
+    /// - **1.** `[]`  Validator Authority
     VerifyValidatorIdentity,
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/// Verifies if account's pubkey corresponds to current validator identity
/// # Account references
/// - **0.** `[]` Validator Authority
VerifyValidatorIdentity,
/// Verifies if account's pubkey corresponds to current validator identity
/// # Account references
/// - **0.** `[]` Magic Context account
/// - **1.** `[]` Validator Authority
VerifyValidatorIdentity,
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@magicblock-magic-program-api/src/instruction.rs` around lines 306 - 310,
Update the VerifyValidatorIdentity instruction docs to match the handler in
verify_validator_identity.rs: list index 0 as the Magic Context account
(MAGIC_CONTEXT_PUBKEY) and index 1 as the Validator Authority, and ensure the
account reference descriptions and ordering reflect that the handler expects the
magic context first and validator authority second (so the documented account
layout aligns with VerifyValidatorIdentity and MAGIC_CONTEXT_PUBKEY usage).

Comment on lines +32 to +35
ic_msg!(
invoke_context,
"ScheduleCommit ERR: Magic program account not found"
);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Error message references wrong instruction.

The error message says "ScheduleCommit ERR" but this is the VerifyValidatorIdentity instruction handler. This appears to be a copy-paste artifact that could confuse debugging.

📝 Suggested fix
         .ok_or_else(|| {
             ic_msg!(
                 invoke_context,
-                "ScheduleCommit ERR: Magic program account not found"
+                "VerifyValidatorIdentity ERR: Magic program account not found"
             );
             InstructionError::UnsupportedProgramId
         })?;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
ic_msg!(
invoke_context,
"ScheduleCommit ERR: Magic program account not found"
);
.ok_or_else(|| {
ic_msg!(
invoke_context,
"VerifyValidatorIdentity ERR: Magic program account not found"
);
InstructionError::UnsupportedProgramId
})?;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@programs/magicblock/src/verify_validator_identity.rs` around lines 32 - 35,
Update the error logging string in the VerifyValidatorIdentity handler so it
correctly references the instruction name instead of "ScheduleCommit"; locate
the ic_msg! call in the VerifyValidatorIdentity logic that currently logs
"ScheduleCommit ERR: Magic program account not found" and change it to a
descriptive message like "VerifyValidatorIdentity ERR: Magic program account not
found" (or similar) so logs correctly reflect the VerifyValidatorIdentity
instruction context.

Comment on lines +86 to +101
fn setup_transaction_accounts() -> Vec<(Pubkey, AccountSharedData)> {
let mut account_data = HashMap::new();
account_data.insert(
MAGIC_CONTEXT_PUBKEY,
AccountSharedData::new(u64::MAX, MagicContext::SIZE, &crate::id()),
);
ensure_started_validator(&mut account_data, None);
let validator = validator_authority_id();
vec![
(
MAGIC_CONTEXT_PUBKEY,
account_data.remove(&MAGIC_CONTEXT_PUBKEY).unwrap(),
),
(validator, account_data.remove(&validator).unwrap()),
]
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Test helper uses .unwrap() on HashMap::remove() which could silently fail.

While .unwrap() is acceptable in test code, if ensure_started_validator doesn't populate the expected keys, the test would panic with a generic message. Consider using .expect() with a descriptive message for better debugging.

💡 Optional improvement for test debuggability
         vec![
             (
                 MAGIC_CONTEXT_PUBKEY,
-                account_data.remove(&MAGIC_CONTEXT_PUBKEY).unwrap(),
+                account_data.remove(&MAGIC_CONTEXT_PUBKEY)
+                    .expect("MAGIC_CONTEXT_PUBKEY should be in account_data"),
             ),
-            (validator, account_data.remove(&validator).unwrap()),
+            (validator, account_data.remove(&validator)
+                .expect("validator should be in account_data")),
         ]
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
fn setup_transaction_accounts() -> Vec<(Pubkey, AccountSharedData)> {
let mut account_data = HashMap::new();
account_data.insert(
MAGIC_CONTEXT_PUBKEY,
AccountSharedData::new(u64::MAX, MagicContext::SIZE, &crate::id()),
);
ensure_started_validator(&mut account_data, None);
let validator = validator_authority_id();
vec![
(
MAGIC_CONTEXT_PUBKEY,
account_data.remove(&MAGIC_CONTEXT_PUBKEY).unwrap(),
),
(validator, account_data.remove(&validator).unwrap()),
]
}
fn setup_transaction_accounts() -> Vec<(Pubkey, AccountSharedData)> {
let mut account_data = HashMap::new();
account_data.insert(
MAGIC_CONTEXT_PUBKEY,
AccountSharedData::new(u64::MAX, MagicContext::SIZE, &crate::id()),
);
ensure_started_validator(&mut account_data, None);
let validator = validator_authority_id();
vec![
(
MAGIC_CONTEXT_PUBKEY,
account_data.remove(&MAGIC_CONTEXT_PUBKEY)
.expect("MAGIC_CONTEXT_PUBKEY should be in account_data"),
),
(validator, account_data.remove(&validator)
.expect("validator should be in account_data")),
]
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@programs/magicblock/src/verify_validator_identity.rs` around lines 86 - 101,
In setup_transaction_accounts(), avoid using HashMap::remove().unwrap() which
yields an opaque panic; replace both unwrap() calls with expect(...) that
include descriptive messages referencing the keys and the helper that should
have populated them (e.g., mention MAGIC_CONTEXT_PUBKEY and the validator
returned by validator_authority_id()) so if ensure_started_validator(...) failed
to insert the entries the test failure will report which key was missing and
where (setup_transaction_accounts / ensure_started_validator).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant