From 93978d7424311b5f4bebd97ca2da7d99cf4d5b39 Mon Sep 17 00:00:00 2001 From: Evan Gray Date: Mon, 12 Feb 2024 15:05:26 -0500 Subject: [PATCH] cargo fmt --- .../example-queries-solana-verify/src/lib.rs | 5 +---- .../src/processor/verify_query.rs | 22 ++++++++++++++----- .../src/processor/verify_signatures.rs | 10 ++++++--- tests/example-queries-solana-verify.ts | 6 ++--- 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/programs/example-queries-solana-verify/src/lib.rs b/programs/example-queries-solana-verify/src/lib.rs index b50861a..c3d9415 100644 --- a/programs/example-queries-solana-verify/src/lib.rs +++ b/programs/example-queries-solana-verify/src/lib.rs @@ -28,10 +28,7 @@ pub mod example_queries_solana_verify { processor::verify_signatures(ctx, signer_indices) } - pub fn verify_query( - ctx: Context, - bytes: Vec, - ) -> Result<()> { + pub fn verify_query(ctx: Context, bytes: Vec) -> Result<()> { processor::verify_query(ctx, bytes) } } diff --git a/programs/example-queries-solana-verify/src/processor/verify_query.rs b/programs/example-queries-solana-verify/src/processor/verify_query.rs index e93ede3..4a96655 100644 --- a/programs/example-queries-solana-verify/src/processor/verify_query.rs +++ b/programs/example-queries-solana-verify/src/processor/verify_query.rs @@ -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::*, @@ -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(×tamp), ExampleQueriesSolanaVerifyError::GuardianSetExpired @@ -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(), @@ -72,7 +83,6 @@ impl<'info> VerifyQuery<'info> { #[access_control(VerifyQuery::constraints(&ctx, &bytes))] pub fn verify_query(ctx: Context, bytes: Vec) -> Result<()> { - // Done. Ok(()) } diff --git a/programs/example-queries-solana-verify/src/processor/verify_signatures.rs b/programs/example-queries-solana-verify/src/processor/verify_signatures.rs index 1df2c64..0d1c49e 100644 --- a/programs/example-queries-solana-verify/src/processor/verify_signatures.rs +++ b/programs/example-queries-solana-verify/src/processor/verify_signatures.rs @@ -1,6 +1,7 @@ use crate::{ error::ExampleQueriesSolanaVerifyError, - state::{QuerySignatureSet, WormholeGuardianSet}, QUERY_MESSAGE_LEN, + state::{QuerySignatureSet, WormholeGuardianSet}, + QUERY_MESSAGE_LEN, }; use anchor_lang::{ prelude::*, @@ -65,7 +66,7 @@ pub fn verify_signatures(ctx: Context, 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( @@ -116,7 +117,10 @@ pub fn verify_signatures(ctx: Context, 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 diff --git a/tests/example-queries-solana-verify.ts b/tests/example-queries-solana-verify.ts index d751586..4233c97 100644 --- a/tests/example-queries-solana-verify.ts +++ b/tests/example-queries-solana-verify.ts @@ -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 () => { @@ -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 () => { @@ -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 () => {