-
Notifications
You must be signed in to change notification settings - Fork 21
feat(fraud-proofs): Implement RegisterVerifier #198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1685d16
feat(fraud-proofs): Implement RegisterVerifier
snawaz 63f065c
Use layout views for RegisterVerifier
snawaz d8d66c1
Dispatch RegisterVerifier without program id
snawaz 0879223
Use fresh blockhash for duplicate verifier test
snawaz 4f2314c
Use one-byte tag offset for verifier args
snawaz 7fee91e
Drop trivial RegisterVerifier instruction data test
snawaz ea178a1
Rename register verifier tests
snawaz d1cb4aa
dev review
snawaz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| use wheels::variable_offset_layout; | ||
|
|
||
| #[derive(Clone, Debug, PartialEq, Eq)] | ||
| #[variable_offset_layout(buffer_offset = 1)] | ||
| pub struct RegisterVerifierArgs { | ||
| pub stake_lamports: u64, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| mod init_protocol_config; | ||
| mod register_operator; | ||
| mod register_verifier; | ||
|
|
||
| pub use init_protocol_config::*; | ||
| pub use register_operator::*; | ||
| pub use register_verifier::*; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| use solana_program::{ | ||
| instruction::{AccountMeta, Instruction}, | ||
| pubkey::Pubkey, | ||
| }; | ||
| use solana_sdk_ids::system_program; | ||
| use wheels::layout::Encodable; | ||
|
|
||
| use crate::{ | ||
| compat::{Compatize, Modernize}, | ||
| v2::{ | ||
| pda::{protocol_config_pda, verifier_bond_pda}, | ||
| DlpV2Instruction, RegisterVerifierArgs, | ||
| }, | ||
| }; | ||
|
|
||
| /// Builds the instruction that registers one verifier for v2 approvals. | ||
| pub fn register_verifier( | ||
| verifier: Pubkey, | ||
| authority: Pubkey, | ||
| args: RegisterVerifierArgs, | ||
| ) -> Instruction { | ||
| Instruction { | ||
| program_id: crate::id().modernize(), | ||
| accounts: vec![ | ||
| AccountMeta::new(verifier, true), | ||
| AccountMeta::new_readonly(authority, true), | ||
| AccountMeta::new( | ||
| verifier_bond_pda(&verifier.compatize()).modernize(), | ||
| false, | ||
| ), | ||
| AccountMeta::new_readonly(protocol_config_pda().modernize(), false), | ||
| AccountMeta::new_readonly(system_program::id(), false), | ||
| ], | ||
| data: [ | ||
| DlpV2Instruction::RegisterVerifier.to_vec(), | ||
| args.encode().unwrap(), | ||
| ] | ||
| .concat(), | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| mod operator_bond; | ||
| mod protocol_config; | ||
| mod verifier_bond; | ||
| mod verifier_registry; | ||
|
|
||
| pub use operator_bond::*; | ||
| pub use protocol_config::*; | ||
| pub use verifier_bond::*; | ||
| pub use verifier_registry::*; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| use wheels::fixed_offset_layout; | ||
|
|
||
| use crate::compat::Pubkey; | ||
|
|
||
| #[derive(Clone, Debug, PartialEq, Eq)] | ||
| #[fixed_offset_layout(buffer_offset = 0)] | ||
| pub struct VerifierBond { | ||
| /// Account type marker. | ||
| pub discriminator: [u8; 8], | ||
|
|
||
| /// Canonical PDA bump for this account. | ||
| pub bump: u8, | ||
|
|
||
| /// Verifier identity allowed to approve commitments through this bond. | ||
| pub verifier_identity: Pubkey, | ||
|
|
||
| /// Slashable verifier stake held in this account. | ||
| /// CHECKPOINT: the staking asset is SOL or BLOCK? | ||
| /// If this changes to BLOCK, this field will need to point at token-account | ||
| /// accounting instead of native lamports. | ||
| pub stake_lamports: u64, | ||
|
|
||
| /// Current verifier lifecycle state, stored as `VerifierStatus::value()`. | ||
| pub status: u8, | ||
|
|
||
| /// Slot when the verifier registered. | ||
| /// CHECKPOINT: keep this only if future verifier eligibility rules compare | ||
| /// the current slot with this registration slot, such as requiring a newly | ||
| /// registered verifier to wait before it can be selected or approve. | ||
| pub registered_slot: u64, | ||
|
|
||
| /// Slot when withdrawal was requested, if the verifier is exiting. | ||
| pub withdraw_requested_slot: Option<u64>, | ||
| } | ||
|
|
||
| impl VerifierBond { | ||
| pub const DISCRIMINATOR: [u8; 8] = *b"v2vrbond"; | ||
| } | ||
|
|
||
| #[repr(u8)] | ||
| #[derive(Clone, Copy, Debug, PartialEq, Eq)] | ||
| pub enum VerifierStatus { | ||
| Active = 1, | ||
| Exiting = 2, | ||
| Slashed = 3, | ||
| Jailed = 4, | ||
| } | ||
|
|
||
| impl VerifierStatus { | ||
| pub const fn value(self) -> u8 { | ||
| self as u8 | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| mod init_protocol_config; | ||
| mod register_operator; | ||
| mod register_verifier; | ||
|
|
||
| pub use init_protocol_config::*; | ||
| pub use register_operator::*; | ||
| pub use register_verifier::*; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| use dlp_api::{ | ||
| error::DlpError, | ||
| v2::{ | ||
| pda::{PROTOCOL_CONFIG_SEED, VERIFIER_BOND_SEED}, | ||
| ProtocolConfig, RegisterVerifierArgs, VerifierBond, VerifierStatus, | ||
| }, | ||
| }; | ||
| use pinocchio::{ | ||
| cpi::{Seed, Signer}, | ||
| error::ProgramError, | ||
| sysvars::{clock::Clock, Sysvar}, | ||
| AccountView, ProgramResult, | ||
| }; | ||
| use pinocchio_system::instructions as system; | ||
| use wheels::{ | ||
| layout::{Decodable, Encodable}, | ||
| require, require_eq_keys, require_ge, require_n_accounts, require_signer, | ||
| }; | ||
|
|
||
| use crate::{ | ||
| processor::fast::utils::pda::create_pda, | ||
| requires::{ | ||
| require_initialized_pda, require_uninitialized_pda, StandardCtx, | ||
| }, | ||
| }; | ||
|
|
||
| /// Register one verifier for v2 approvals. | ||
| /// | ||
| /// Accounts: | ||
| /// 0: `[signer, writable]` verifier identity and stake payer | ||
| /// 1: `[signer]` protocol authority that admits the verifier | ||
| /// 2: `[writable]` VerifierBond PDA | ||
| /// 3: `[]` ProtocolConfig PDA | ||
| /// 4: `[]` system program, required by system CPI | ||
| #[inline(never)] | ||
| pub fn process_register_verifier( | ||
| accounts: &[AccountView], | ||
| data: &[u8], | ||
| ) -> ProgramResult { | ||
| let [ | ||
| verifier, // force multi-line | ||
| authority, | ||
| verifier_bond, | ||
| protocol_config, | ||
| _system_program, | ||
| ] = require_n_accounts!(accounts, 5); | ||
|
|
||
| require_signer!(verifier); | ||
| require_signer!(authority); | ||
|
|
||
| let args = RegisterVerifierArgs::decode(data)?; | ||
|
|
||
| require_initialized_pda( | ||
| protocol_config, | ||
| &[PROTOCOL_CONFIG_SEED], | ||
| &crate::fast::ID, | ||
| false, | ||
| "protocol config", | ||
| )?; | ||
| let protocol_config_data = protocol_config.try_borrow()?; | ||
| let protocol_config_state = | ||
| ProtocolConfig::decode(protocol_config_data.as_ref())?; | ||
| require!( | ||
| protocol_config_state.discriminator() == ProtocolConfig::DISCRIMINATOR, | ||
| ProgramError::InvalidAccountData | ||
| ); | ||
|
|
||
| require_eq_keys!( | ||
| protocol_config_state.authority(), | ||
| authority.address(), | ||
| DlpError::InvalidAuthority | ||
| ); | ||
| require_ge!( | ||
| args.stake_lamports(), | ||
| protocol_config_state.min_verifier_bond(), | ||
| ProgramError::InvalidInstructionData | ||
| ); | ||
|
|
||
| drop(protocol_config_data); | ||
|
|
||
| let verifier_bond_bump = require_uninitialized_pda( | ||
| verifier_bond, | ||
| &[VERIFIER_BOND_SEED, verifier.address().as_ref()], | ||
| &crate::fast::ID, | ||
| true, | ||
| StandardCtx::new("verifier bond"), | ||
| )?; | ||
|
|
||
| create_pda( | ||
| verifier_bond, | ||
| &crate::fast::ID, | ||
| VerifierBond::DATA_LEN, | ||
| &[Signer::from(&[ | ||
| Seed::from(VERIFIER_BOND_SEED), | ||
| Seed::from(verifier.address().as_ref()), | ||
| Seed::from(&[verifier_bond_bump]), | ||
| ])], | ||
| verifier, | ||
| )?; | ||
|
|
||
| system::Transfer { | ||
| from: verifier, | ||
| to: verifier_bond, | ||
| lamports: args.stake_lamports(), | ||
| } | ||
| .invoke()?; | ||
|
|
||
| VerifierBond { | ||
| discriminator: VerifierBond::DISCRIMINATOR, | ||
| bump: verifier_bond_bump, | ||
| verifier_identity: verifier.address().to_bytes().into(), | ||
| stake_lamports: args.stake_lamports(), | ||
| status: VerifierStatus::Active.value(), | ||
| registered_slot: Clock::get()?.slot, | ||
| withdraw_requested_slot: None, | ||
| } | ||
| .encode_to(verifier_bond.try_borrow_mut()?.as_mut())?; | ||
|
|
||
| Ok(()) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift
🧩 Analysis chain
🏁 Script executed:
Repository: magicblock-labs/delegation-program
Length of output: 3460
🏁 Script executed:
Repository: magicblock-labs/delegation-program
Length of output: 18393
🏁 Script executed:
Repository: magicblock-labs/delegation-program
Length of output: 14224
🌐 Web query:
magicblock-labs magicblock-wheels wheels layout Encodable encode variable_offset_layout source💡 Result:
MagicBlock Labs maintains a repository named magicblock-wheels, which serves as a shared, internal SDK and repository for reusable code building blocks, including Rust crates (
rust/wheels) and TypeScript packages [1][2]. The codebase is designed for internal use by MagicBlock projects rather than as a public-facing SDK [1]. Regarding the specific technical terms mentioned: 1. Encodable and variable_offset_layout: These terms are associated with data serialization and layout management within MagicBlock's infrastructure. For instance, the use of Encodable traits (e.g., inwith(Encodable)) has been utilized in MagicBlock repositories like ephemeral-spl-token to replace direct byte-slice manipulation (with_data(&[u8])) for more structured instruction or data encoding [3]. 2. Source and Layout: The magicblock-wheels repository itself is organized into arust/workspace and ats/directory to manage these shared utilities [1]. MagicBlock's broader technology stack, including its ephemeral rollups and high-performance execution environments, relies on such shared serialization and layout primitives to manage efficient state transitions and on-chain program interactions [4][5]. For official documentation and up-to-date integration details, developers are directed to the ephemeral-rollups-sdk [1][6].Citations:
🏁 Script executed:
Repository: magicblock-labs/delegation-program
Length of output: 221
🏁 Script executed:
Repository: magicblock-labs/delegation-program
Length of output: 285
🏁 Script executed:
Repository: magicblock-labs/delegation-program
Length of output: 428
🏁 Script executed:
Repository: magicblock-labs/delegation-program
Length of output: 14787
🏁 Script executed:
Repository: magicblock-labs/delegation-program
Length of output: 282
🏁 Script executed:
Repository: magicblock-labs/delegation-program
Length of output: 4204
🏁 Script executed:
Repository: magicblock-labs/delegation-program
Length of output: 24084
Remove
unwrap()from the production instruction builder.Encodable::encode()returnsResult<Vec<u8>, DataLayoutError>. Handle this error inregister_verifierinstead of panicking. If an invariant guarantees successful encoding forRegisterVerifierArgs, document the invariant explicitly.🤖 Prompt for AI Agents
Source: Path instructions