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 93978d7
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 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
6 changes: 3 additions & 3 deletions tests/example-queries-solana-verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ describe("example-queries-solana-verify", () => {
})
.rpc()
).to.be.rejectedWith(
"AnchorError thrown in programs/example-queries-solana-verify/src/processor/verify_query.rs:40. Error Code: GuardianSetExpired. Error Number: 7798. Error Message: GuardianSetExpired."
"AnchorError thrown in programs/example-queries-solana-verify/src/processor/verify_query.rs:44. Error Code: GuardianSetExpired. Error Number: 7798. Error Message: GuardianSetExpired."
);
});
it("Rejects an invalid guardian set!", async () => {
Expand Down Expand Up @@ -360,7 +360,7 @@ describe("example-queries-solana-verify", () => {
})
.rpc()
).to.be.rejectedWith(
"AnchorError thrown in programs/example-queries-solana-verify/src/processor/verify_query.rs:59. Error Code: InvalidMessageHash. Error Number: 6514. Error Message: InvalidMessageHash."
"AnchorError thrown in programs/example-queries-solana-verify/src/processor/verify_query.rs:67. Error Code: InvalidMessageHash. Error Number: 6514. Error Message: InvalidMessageHash."
);
});
it("Rejects a no quorum signature set!", async () => {
Expand Down Expand Up @@ -408,7 +408,7 @@ describe("example-queries-solana-verify", () => {
})
.rpc()
).to.be.rejectedWith(
"AnchorError thrown in programs/example-queries-solana-verify/src/processor/verify_query.rs:49. Error Code: NoQuorum. Error Number: 6515. Error Message: NoQuorum."
"AnchorError thrown in programs/example-queries-solana-verify/src/processor/verify_query.rs:53. Error Code: NoQuorum. Error Number: 6515. Error Message: NoQuorum."
);
});
it("Rejects a valid signature on the wrong guardian index!", async () => {
Expand Down

0 comments on commit 93978d7

Please sign in to comment.