-
Notifications
You must be signed in to change notification settings - Fork 21
feat(fraud-proofs): Implement PostCommitment #229
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
11 commits
Select commit
Hold shift + click to select a range
da1e931
feat(fraud-proofs): Implement PostCommitment
snawaz fcab707
Use fresh blockhash for duplicate post commitment test
snawaz 37818f3
Update post commitment verifier selection expectations
snawaz fb00c4a
Use StateBuffer data hash for PostCommitment
snawaz ef09752
Use StateBuffer authority in PostCommitment
snawaz f1eb4f6
Use one-byte tag offset for commitment args
snawaz 97d8db8
Decode extendable StateBuffer in PostCommitment
snawaz 3ef69eb
Drop trivial PostCommitment instruction data test
snawaz 8515df9
Rename commitment posting tests
snawaz 8f9c81a
Remove pending verifier registry revision
snawaz d2c79fc
Use operator status enum in post commitment
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,19 @@ | ||
| use wheels::variable_offset_layout; | ||
|
|
||
| use crate::compat::Pubkey; | ||
|
|
||
| #[derive(Clone, Debug, PartialEq, Eq)] | ||
| #[variable_offset_layout(buffer_offset = 1)] | ||
| pub struct PostCommitmentArgs { | ||
| pub commit_id: u64, | ||
|
|
||
| pub lamports: u64, | ||
|
|
||
| pub owner: Pubkey, | ||
|
|
||
| /// Hash of replay/data-availability pointer bytes. | ||
| pub da_pointer_hash: [u8; 32], | ||
|
|
||
| /// ER slot that produced this commitment, when available. | ||
| pub er_slot: Option<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,66 @@ | ||
| use solana_program::{ | ||
| instruction::{AccountMeta, Instruction}, | ||
| pubkey::Pubkey, | ||
| }; | ||
| use solana_sdk_ids::system_program; | ||
| use wheels::layout::Encodable; | ||
|
|
||
| use crate::{ | ||
| compat::{Compatize, Modernize}, | ||
| pda::delegation_record_pda_from_delegated_account, | ||
| v2::{ | ||
| pda::{ | ||
| operator_bond_pda, pending_commitment_pda, protocol_config_pda, | ||
| state_buffer_pda, verifier_registry_pda, | ||
| }, | ||
| DlpV2Instruction, PostCommitmentArgs, | ||
| }, | ||
| }; | ||
|
|
||
| /// Builds the instruction that posts one v2 account-state commitment. | ||
| pub fn post_commitment( | ||
| operator: Pubkey, | ||
| account: Pubkey, | ||
| args: PostCommitmentArgs, | ||
| ) -> Instruction { | ||
| Instruction { | ||
| program_id: crate::id().modernize(), | ||
| accounts: vec![ | ||
| AccountMeta::new(operator, true), | ||
| AccountMeta::new_readonly( | ||
| operator_bond_pda(&operator.compatize()).modernize(), | ||
| false, | ||
| ), | ||
| AccountMeta::new( | ||
| pending_commitment_pda(&account.compatize(), args.commit_id) | ||
| .modernize(), | ||
| false, | ||
| ), | ||
| AccountMeta::new_readonly( | ||
| state_buffer_pda( | ||
| &account.compatize(), | ||
| args.commit_id, | ||
| &operator.compatize(), | ||
| ) | ||
| .modernize(), | ||
| false, | ||
| ), | ||
| AccountMeta::new_readonly(account, false), | ||
| AccountMeta::new_readonly( | ||
| delegation_record_pda_from_delegated_account( | ||
| &account.compatize(), | ||
| ) | ||
| .modernize(), | ||
| false, | ||
| ), | ||
| AccountMeta::new_readonly(protocol_config_pda().modernize(), false), | ||
| AccountMeta::new(verifier_registry_pda().modernize(), false), | ||
| AccountMeta::new_readonly(system_program::id(), false), | ||
| ], | ||
| data: [ | ||
| DlpV2Instruction::PostCommitment.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
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,118 @@ | ||
| use wheels::fixed_offset_layout; | ||
|
|
||
| use crate::compat::Pubkey; | ||
|
|
||
| pub const PENDING_COMMITMENT_STATUS_ACTIVE: u8 = 1; | ||
| pub const PENDING_COMMITMENT_STATUS_AWAITING_OPERATOR_RESPONSE: u8 = 2; | ||
| pub const PENDING_COMMITMENT_STATUS_AWAITING_CHALLENGER_REVEAL: u8 = 3; | ||
| pub const PENDING_COMMITMENT_STATUS_AWAITING_DISPUTE_RESOLUTION: u8 = 4; | ||
| pub const PENDING_COMMITMENT_STATUS_RESOLVED_OPERATOR: u8 = 5; | ||
| pub const PENDING_COMMITMENT_STATUS_RESOLVED_CHALLENGER: u8 = 6; | ||
| pub const PENDING_COMMITMENT_STATUS_FINALIZED: u8 = 7; | ||
| pub const PENDING_COMMITMENT_STATUS_EXPIRED: u8 = 8; | ||
| pub const PENDING_COMMITMENT_STATUS_CANCELLED: u8 = 9; | ||
|
|
||
| pub const RESOLVED_STATE_SOURCE_OPERATOR_COMMITMENT: u8 = 1; | ||
| pub const RESOLVED_STATE_SOURCE_CHALLENGER_REVEAL: u8 = 2; | ||
|
|
||
| /// PDA: `["pending-commitment", account, commit_id]`. | ||
| /// Created by `PostCommitment`. | ||
| /// Closed by `CloseTerminalAccounts` after finalize, cancel, or expiry. | ||
| /// | ||
| /// One account per delegated account and commit id. | ||
| #[derive(Clone, Debug, PartialEq, Eq)] | ||
| #[fixed_offset_layout(buffer_offset = 0)] | ||
| pub struct PendingCommitment { | ||
| /// Account type marker. | ||
| pub discriminator: [u8; 8], | ||
|
|
||
| /// Current state-machine state for this commitment. | ||
| pub status: u8, | ||
|
|
||
| /// Operator identity that posted the commitment. | ||
| pub operator_identity: Pubkey, | ||
|
|
||
| /// OperatorBond checked when the commitment was posted. | ||
| pub operator_bond: Pubkey, | ||
|
|
||
| /// Delegated account whose base-layer state will be finalized. | ||
| pub account_pubkey: Pubkey, | ||
|
|
||
| /// Operator-chosen nonce for this account commitment. | ||
| pub commit_id: u64, | ||
|
|
||
| /// Delegation record tying this account to the ER context. | ||
| pub delegation_record: Pubkey, | ||
|
|
||
| /// Hash of replay/data-availability pointer bytes. | ||
| pub da_pointer_hash: [u8; 32], | ||
|
|
||
| /// Hash of lamports, owner, and data_hash. | ||
| pub account_state_hash: [u8; 32], | ||
|
|
||
| /// Hash of full account data. | ||
| pub data_hash: [u8; 32], | ||
|
|
||
| /// Lamports committed by the operator. | ||
| pub lamports: u64, | ||
|
|
||
| /// Owner committed by the operator. | ||
| pub owner: Pubkey, | ||
|
|
||
| /// Hash binding operator, account, commit id, delegation, DA, and state. | ||
| pub state_commitment_hash: [u8; 32], | ||
|
|
||
| /// Registry account used when this commitment was posted. | ||
| pub verifier_registry: Pubkey, | ||
|
|
||
| /// Monotonic id for this approval/challenge window. | ||
| pub challenge_window_id: u64, | ||
|
|
||
| /// Slot when the commitment was posted. | ||
| pub posted_slot: u64, | ||
|
|
||
| /// Slot when verifier selection and the challenge window started. | ||
| pub activation_slot: u64, | ||
|
|
||
| /// Slot when approval/challenge window closes. | ||
| pub challenge_window_end_slot: u64, | ||
|
|
||
| /// Number of unique selected verifiers that approved. | ||
| pub approval_count: u16, | ||
|
|
||
| /// Threshold copied from ProtocolConfig when the commitment is posted. | ||
| pub approval_threshold: u16, | ||
|
|
||
| /// Active Challenge account, if any. | ||
| pub active_challenge: Option<Pubkey>, | ||
|
|
||
| /// Which opened state finalization must use after dispute resolution. | ||
| pub resolved_state_source: Option<u8>, | ||
|
|
||
| /// ER slot that produced this commitment, when available. | ||
| pub er_slot: Option<u64>, | ||
|
|
||
| /// Aligns selected verifier elements after the Vec length prefix. | ||
| pub _pad_before_selected_verifiers: [u8; 7], | ||
|
|
||
| /// Verifiers selected by round-robin for this commitment. | ||
| #[extendable = 2] | ||
| pub selected_verifiers: Vec<SelectedVerifier>, | ||
| } | ||
|
|
||
| #[derive(Clone, Debug, PartialEq, Eq)] | ||
| #[fixed_offset_layout(buffer_offset = 2)] | ||
| pub struct SelectedVerifier { | ||
| /// Selected verifier identity. | ||
| pub verifier_identity: Pubkey, | ||
|
|
||
| /// Whether this verifier has approved this commitment. | ||
| pub approved: bool, | ||
|
|
||
| /// Keeps each Vec element aligned for fixed-layout decoding. | ||
| pub _pad_after_approved: [u8; 7], | ||
| } | ||
|
|
||
| impl PendingCommitment { | ||
| pub const DISCRIMINATOR: [u8; 8] = *b"v2pend00"; | ||
| } |
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 @@ | ||
| //! Processors for v2 fraud-proof instructions. | ||
|
|
||
| mod post_commitment; | ||
| mod write_state_buffer; | ||
|
|
||
| pub use post_commitment::*; | ||
| pub use write_state_buffer::*; |
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 | 🏗️ Heavy lift
🔎 Supported by static analysis
🏁 Script executed:
Repository: magicblock-labs/delegation-program
Length of output: 172
🏁 Script executed:
Repository: magicblock-labs/delegation-program
Length of output: 16039
🏁 Script executed:
Repository: magicblock-labs/delegation-program
Length of output: 13138
🏁 Script executed:
Repository: magicblock-labs/delegation-program
Length of output: 799
🌐 Web query:
magicblock-labs magicblock-wheels wheels::layout::Encodable encode Rust💡 Result:
The
wheels::layout::Encodabletrait is part of themagicblock-wheelsrepository, which serves as an internal, shared Rust codebase for MagicBlock projects [1]. This repository contains reusable building blocks, including thewheelscrate (a publicno_stdcrate) andwheels-macros(a proc-macro crate) [1]. TheEncodabletrait is typically used in conjunction with procedural macros to facilitate serialization in Rust for MagicBlock's Ephemeral Rollups environment [1]. While MagicBlock's primary user-facing SDK for program integration isephemeral-rollups-sdk[2][3], themagicblock-wheelslibrary provides lower-level utility code used internally by the organization [1]. Becausemagicblock-wheelsis explicitly designated as an internal SDK for reusable code [1], users building on MagicBlock should generally rely on the publicephemeral-rollups-sdk[2][3] or the documentation available at https://docs.magicblock.xyz/ [3][4]. If you are working directly within a repository that depends onmagicblock-wheels, you can typically implement theEncodabletrait for your types using the provided macros fromwheels-macros, which allows for automatic encoding logic necessary for on-chain program interactions [1].Citations:
🌐 Web query:
site:github.com/magicblock-labs/magicblock-wheels "trait Encodable" "fn encode"💡 Result:
The pattern trait Encodable { fn encode(...) } is not part of the Rust standard library. In the Rust ecosystem, this pattern is frequently implemented by custom crates or specific library projects—such as internal SDKs—to define how a type should be serialized into a byte representation or another specific format [1]. Because this trait name is common for serialization logic, different libraries may define their own version of an Encodable trait. If you encounter this in a specific project, you should check the project's documentation or source code to see how the trait is defined and which types implement it. In generic Rust development, serialization is typically handled by established crates like serde, which uses the Serialize trait rather than Encodable.
Citations:
🏁 Script executed:
Repository: magicblock-labs/delegation-program
Length of output: 2458
🏁 Script executed:
Repository: magicblock-labs/delegation-program
Length of output: 878
Remove the unchecked
.unwrap()onargs.encode().Return and propagate the encoding error, or document the invariant that guarantees
PostCommitmentArgsencoding cannot fail. This production.unwrap()is a major issue under the repository guidelines.🤖 Prompt for AI Agents
Source: Path instructions