Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-gray committed Feb 12, 2024
1 parent 36b1890 commit 0d095f0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
5 changes: 1 addition & 4 deletions programs/example-queries-solana-verify/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ pub mod example_queries_solana_verify {
processor::verify_signatures(ctx, signer_indices)
}

pub fn verify_query(
ctx: Context<VerifyQuery>,
bytes: Vec<u8>,
) -> Result<()> {
pub fn verify_query(ctx: Context<VerifyQuery>, bytes: Vec<u8>) -> Result<()> {
processor::verify_query(ctx, bytes)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{
error::ExampleQueriesSolanaVerifyError,
state::{QuerySignatureSet, WormholeGuardianSet}, MESSAGE_PREFIX, QUERY_MESSAGE_LEN,
state::{QuerySignatureSet, WormholeGuardianSet},
MESSAGE_PREFIX, QUERY_MESSAGE_LEN,
};
use anchor_lang::{
prelude::*,
Expand Down Expand Up @@ -36,7 +37,10 @@ impl<'info> VerifyQuery<'info> {
let guardian_set = ctx.accounts.guardian_set.clone().into_inner();

// Check that the guardian set is still active.
let timestamp = Clock::get()?.unix_timestamp.try_into().expect("timestamp overflow");
let timestamp = Clock::get()?
.unix_timestamp
.try_into()
.expect("timestamp overflow");
require!(
guardian_set.is_active(&timestamp),
ExampleQueriesSolanaVerifyError::GuardianSetExpired
Expand All @@ -52,12 +56,19 @@ impl<'info> VerifyQuery<'info> {
);

// Recompute the message hash and compare it to the one in the signature set account.
let recomputed = [MESSAGE_PREFIX, &solana_program::keccak::hashv(&[&bytes]).to_bytes()].concat();
let recomputed = [
MESSAGE_PREFIX,
&solana_program::keccak::hashv(&[&bytes]).to_bytes(),
]
.concat();

// And verify that the message hash is the same as the one already encoded in the signature
// set.
require!(recomputed == signature_set.message, ExampleQueriesSolanaVerifyError::InvalidMessageHash);

require!(
recomputed == signature_set.message,
ExampleQueriesSolanaVerifyError::InvalidMessageHash
);

// SECURITY: defense-in-depth, check again that these are the expected length
require_eq!(
recomputed.len(),
Expand All @@ -72,7 +83,6 @@ impl<'info> VerifyQuery<'info> {

#[access_control(VerifyQuery::constraints(&ctx, &bytes))]
pub fn verify_query(ctx: Context<VerifyQuery>, bytes: Vec<u8>) -> Result<()> {

// Done.
Ok(())
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{
error::ExampleQueriesSolanaVerifyError,
state::{QuerySignatureSet, WormholeGuardianSet}, QUERY_MESSAGE_LEN,
state::{QuerySignatureSet, WormholeGuardianSet},
QUERY_MESSAGE_LEN,
};
use anchor_lang::{
prelude::*,
Expand Down Expand Up @@ -65,7 +66,7 @@ pub fn verify_signatures(ctx: Context<VerifySignatures>, signer_indices: [i8; 19
// is no data from the instruction sysvar loaded by that point. We have to load it and perform
// the safety checks in this instruction handler.
let instructions_sysvar = &ctx.accounts.instructions;

// We grab the index of the instruction before this instruction, which should be the sig verify
// program.
let sig_verify_index = u16::checked_sub(
Expand Down Expand Up @@ -116,7 +117,10 @@ pub fn verify_signatures(ctx: Context<VerifySignatures>, signer_indices: [i8; 19

// And verify that the message hash is the same as the one already encoded in the signature
// set.
require!(message == signature_set.message, ExampleQueriesSolanaVerifyError::MessageMismatch);
require!(
message == signature_set.message,
ExampleQueriesSolanaVerifyError::MessageMismatch
);
} else {
// We are assuming that the signature set has not been "initialized" if there is no
// indication of verified signatures (via `sig_verify_successes`) written to this account
Expand Down

0 comments on commit 0d095f0

Please sign in to comment.