-
Notifications
You must be signed in to change notification settings - Fork 57
fix(solana): sig verification #872
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
Changes from 3 commits
d2bbba8
66e0aa6
504d7fe
e6d497b
1630bef
9a77b71
317c2a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,16 @@ | ||
| //! Utility functions for IBC on Solana | ||
|
|
||
| use solana_ibc_constants::ANCHOR_DISCRIMINATOR_LEN; | ||
|
|
||
| /// Compute Anchor instruction discriminator | ||
| /// | ||
| /// This computes the first 8 bytes of SHA256("global:{instruction_name}") | ||
| /// following Anchor's discriminator calculation formula. | ||
| pub fn compute_discriminator(instruction_name: &str) -> [u8; 8] { | ||
| pub fn compute_discriminator(instruction_name: &str) -> [u8; ANCHOR_DISCRIMINATOR_LEN] { | ||
| let preimage = format!("global:{instruction_name}"); | ||
| let mut hash_result = [0u8; 8]; | ||
| hash_result.copy_from_slice(&solana_sha256_hasher::hash(preimage.as_bytes()).to_bytes()[..8]); | ||
| let mut hash_result = [0u8; ANCHOR_DISCRIMINATOR_LEN]; | ||
| hash_result.copy_from_slice( | ||
| &solana_sha256_hasher::hash(preimage.as_bytes()).to_bytes()[..ANCHOR_DISCRIMINATOR_LEN], | ||
| ); | ||
| hash_result | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,20 +41,26 @@ impl MisbehaviourChunk { | |
| pub const SEED: &'static [u8] = b"misbehaviour_chunk"; | ||
| } | ||
|
|
||
| /// Storage for Ed25519 signature verification results | ||
| /// Storage for Ed25519 signature verification results. | ||
| /// IMPORTANT: Field order matters: verifier reads `data[8]` for `is_valid`. | ||
| #[account] | ||
| #[derive(InitSpace)] | ||
| pub struct SignatureVerification { | ||
| /// The submitter who created this verification | ||
| pub submitter: Pubkey, | ||
| /// Whether the signature is valid | ||
| pub is_valid: bool, | ||
| /// The submitter who created this verification | ||
| pub submitter: Pubkey, | ||
| } | ||
|
|
||
| impl SignatureVerification { | ||
| pub const SEED: &'static [u8] = b"sig_verify"; | ||
| } | ||
|
|
||
| // Compile-time verification that discriminator length matches the shared constant | ||
| const _: () = assert!( | ||
| SignatureVerification::DISCRIMINATOR.len() == solana_ibc_constants::ANCHOR_DISCRIMINATOR_LEN | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the compile time check for the discriminator length. One question. When can the lengths be different?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. potentially anchor allows setting custom discriminators (non 8 bytes). |
||
| ); | ||
|
|
||
| #[cfg(test)] | ||
| mod compatibility_tests { | ||
| use super::*; | ||
|
|
||
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.
I suggest we solve this todo before merging.
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.
@vaporif you didn't make a PR to natlint?