-
Notifications
You must be signed in to change notification settings - Fork 21
feat(fraud-proofs): Implement RaiseChallenge #236
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
Draft
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d58c8a2
feat(fraud-proofs): Implement RaiseChallenge
snawaz 6b3a0d6
Prepare Challenge state for reveal
snawaz 6cdc6a1
Drop trivial RaiseChallenge instruction data test
snawaz 08ae804
Rename challenge tests
snawaz 2e42ebc
Remove pending revision from challenge update
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,14 @@ | ||
| use wheels::variable_offset_layout; | ||
|
|
||
| #[derive(Clone, Debug, PartialEq, Eq)] | ||
| #[variable_offset_layout(buffer_offset = 1)] | ||
| pub struct RaiseChallengeArgs { | ||
| /// State commitment hash stored in the pending commitment being challenged. | ||
| pub state_commitment_hash: [u8; 32], | ||
|
|
||
| /// Salted hash binding the challenger state to this challenge. | ||
| pub challenge_hash: [u8; 32], | ||
|
|
||
| /// Lamports locked in the challenge account until reveal or resolution. | ||
| 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
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,50 @@ | ||
| 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::{challenge_pda, pending_commitment_pda, protocol_config_pda}, | ||
| DlpV2Instruction, RaiseChallengeArgs, | ||
| }, | ||
| }; | ||
|
|
||
| /// Builds the instruction that raises a hash-only v2 challenge. | ||
| pub fn raise_challenge( | ||
| challenger: Pubkey, | ||
| account: Pubkey, | ||
| commit_id: u64, | ||
| args: RaiseChallengeArgs, | ||
| ) -> Instruction { | ||
| Instruction { | ||
| program_id: crate::id().modernize(), | ||
| accounts: vec![ | ||
| AccountMeta::new(challenger, true), | ||
| AccountMeta::new( | ||
| challenge_pda( | ||
| &account.compatize(), | ||
| commit_id, | ||
| &challenger.compatize(), | ||
| ) | ||
| .modernize(), | ||
| false, | ||
| ), | ||
| AccountMeta::new( | ||
| pending_commitment_pda(&account.compatize(), commit_id) | ||
| .modernize(), | ||
| false, | ||
| ), | ||
| AccountMeta::new_readonly(protocol_config_pda().modernize(), false), | ||
| AccountMeta::new_readonly(system_program::id(), false), | ||
| ], | ||
| data: [ | ||
| DlpV2Instruction::RaiseChallenge.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 |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| use wheels::fixed_offset_layout; | ||
|
|
||
| use crate::compat::Pubkey; | ||
|
|
||
| pub const CHALLENGE_STATUS_AWAITING_REVEAL: u8 = 1; | ||
| pub const CHALLENGE_STATUS_AWAITING_RESOLVER: u8 = 2; | ||
| pub const CHALLENGE_STATUS_TERMINAL: u8 = 3; | ||
|
|
||
| pub const CHALLENGE_OUTCOME_NONE: u8 = 0; | ||
| pub const CHALLENGE_OUTCOME_INVALID_REVEAL: u8 = 1; | ||
| pub const CHALLENGE_OUTCOME_MATCHING_STATE_CHALLENGER_PENALIZED: u8 = 2; | ||
|
|
||
| /// PDA: `["challenge", account, commit_id, challenger]`. | ||
| /// Created by `RaiseChallenge`. | ||
| /// Closed by `CloseTerminalAccounts` after terminal challenge outcome. | ||
| #[derive(Clone, Debug, PartialEq, Eq)] | ||
| #[fixed_offset_layout(buffer_offset = 0)] | ||
| pub struct Challenge { | ||
| /// Account type marker. | ||
| pub discriminator: [u8; 8], | ||
|
|
||
| /// Current challenge lifecycle state. | ||
| pub status: u8, | ||
|
|
||
| /// Terminal outcome, or `CHALLENGE_OUTCOME_NONE` before resolution. | ||
| pub outcome: u8, | ||
|
|
||
| /// Keeps the following fixed-width fields 8-byte aligned. | ||
| pub _pad_after_outcome: [u8; 6], | ||
|
|
||
| /// PendingCommitment being challenged. | ||
| pub pending_commitment: Pubkey, | ||
|
|
||
| /// Challenger that locked stake and owns the reveal. | ||
| pub challenger_identity: Pubkey, | ||
|
|
||
| /// State commitment hash copied from the pending commitment at raise time. | ||
| pub state_commitment_hash: [u8; 32], | ||
|
|
||
| /// Salted hash binding the challenger state to this challenge. | ||
| pub challenge_hash: [u8; 32], | ||
|
|
||
| /// Challenger-revealed account lamports. Zero until reveal. | ||
| pub challenger_lamports: u64, | ||
|
|
||
| /// Challenger-revealed account owner. Default pubkey until reveal. | ||
| pub challenger_owner: Pubkey, | ||
|
|
||
| /// Challenger-revealed account data hash. Zero until reveal. | ||
| pub challenger_data_hash: [u8; 32], | ||
|
|
||
| /// Challenger StateBuffer PDA used for reveal. Default pubkey until reveal. | ||
| pub challenger_state_buffer: Pubkey, | ||
|
|
||
| /// Lamports locked in this challenge account. | ||
| pub challenger_stake_lamports: u64, | ||
|
|
||
| /// Slot when the challenge was raised. | ||
| pub raised_slot: u64, | ||
|
|
||
| /// Slot after which an unrevealed challenge can be timed out. | ||
| pub reveal_deadline_slot: u64, | ||
| } | ||
|
|
||
| impl Challenge { | ||
| pub const DISCRIMINATOR: [u8; 8] = *b"v2chal00"; | ||
| } |
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
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.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: magicblock-labs/delegation-program
Length of output: 789
🏁 Script executed:
Repository: magicblock-labs/delegation-program
Length of output: 13995
🏁 Script executed:
Repository: magicblock-labs/delegation-program
Length of output: 16313
🏁 Script executed:
Repository: magicblock-labs/delegation-program
Length of output: 2712
Remove the bare
.unwrap()fromargs.encode(). This production.unwrap()violates the repository convention. Handle the encoding result explicitly or document the invariant that makes it infallible.🤖 Prompt for AI Agents
Source: Path instructions