From 387fcc48c0b65ed088734302359afff6e807c00a Mon Sep 17 00:00:00 2001 From: Reisen Date: Tue, 6 Jul 2021 12:03:43 +0000 Subject: [PATCH] Add Mut layer to accounts in bridge program. Change-Id: I78dfb4568eaec4f597a6d0e1ac10a0f698bb5a61 --- solana/bridge/program/src/api/governance.rs | 16 +++++++-------- solana/bridge/program/src/api/initialize.rs | 15 ++++++++++---- solana/bridge/program/src/api/post_message.rs | 11 +++++----- solana/bridge/program/src/api/post_vaa.rs | 4 ++-- .../program/src/api/verify_signature.rs | 4 ++-- solana/bridge/program/src/instructions.rs | 20 +++++++++---------- solana/bridge/program/src/vaa.rs | 2 +- .../solitaire/program/src/processors/peel.rs | 2 +- 8 files changed, 41 insertions(+), 33 deletions(-) diff --git a/solana/bridge/program/src/api/governance.rs b/solana/bridge/program/src/api/governance.rs index fffea82d..fa3ad5fd 100644 --- a/solana/bridge/program/src/api/governance.rs +++ b/solana/bridge/program/src/api/governance.rs @@ -74,10 +74,10 @@ pub fn upgrade_contract( #[derive(FromAccounts)] pub struct UpgradeGuardianSet<'b> { /// Payer for account creation (vaa-claim) - pub payer: Signer>, + pub payer: Mut>>, /// Bridge config - pub bridge: Bridge<'b, { AccountState::Initialized }>, + pub bridge: Mut>, /// GuardianSet change VAA pub vaa: ClaimableVAA<'b, GovernancePayloadGuardianSetChange>, @@ -86,7 +86,7 @@ pub struct UpgradeGuardianSet<'b> { pub guardian_set_old: GuardianSet<'b, { AccountState::Initialized }>, /// New guardian set - pub guardian_set_new: GuardianSet<'b, { AccountState::Uninitialized }>, + pub guardian_set_new: Mut>, } impl<'b> InstructionContext<'b> for UpgradeGuardianSet<'b> { @@ -152,10 +152,10 @@ pub fn upgrade_guardian_set( #[derive(FromAccounts)] pub struct SetFees<'b> { /// Payer for account creation (vaa-claim) - pub payer: Signer>, + pub payer: Mut>>, /// Bridge config - pub bridge: Bridge<'b, { AccountState::Initialized }>, + pub bridge: Mut>, /// Governance VAA pub vaa: ClaimableVAA<'b, GovernancePayloadSetMessageFee>, @@ -179,7 +179,7 @@ pub fn set_fees(ctx: &ExecutionContext, accs: &mut SetFees, _data: SetFeesData) #[derive(FromAccounts)] pub struct TransferFees<'b> { /// Payer for account creation (vaa-claim) - pub payer: Signer>, + pub payer: Mut>>, /// Bridge config pub bridge: Bridge<'b, { AccountState::Initialized }>, @@ -188,10 +188,10 @@ pub struct TransferFees<'b> { pub vaa: ClaimableVAA<'b, GovernancePayloadTransferFees>, /// Account collecting tx fees - pub fee_collector: Derive, "fee_collector">, + pub fee_collector: Mut, "fee_collector">>, /// Fee recipient - pub recipient: Info<'b>, + pub recipient: Mut>, } impl<'b> InstructionContext<'b> for TransferFees<'b> { diff --git a/solana/bridge/program/src/api/initialize.rs b/solana/bridge/program/src/api/initialize.rs index ab749c71..9671d29e 100644 --- a/solana/bridge/program/src/api/initialize.rs +++ b/solana/bridge/program/src/api/initialize.rs @@ -18,10 +18,17 @@ type Payer<'a> = Signer>; #[derive(FromAccounts, ToInstruction)] pub struct Initialize<'b> { - pub bridge: Bridge<'b, { AccountState::Uninitialized }>, - pub guardian_set: GuardianSet<'b, { AccountState::Uninitialized }>, - pub fee_collector: FeeCollector<'b>, - pub payer: Payer<'b>, + /// Bridge config. + pub bridge: Mut>, + + /// Location the new guardian set will be allocated at. + pub guardian_set: Mut>, + + /// Location of the fee collector that users will need to pay. + pub fee_collector: Mut>, + + /// Payer for account creation. + pub payer: Mut>, } impl<'b> InstructionContext<'b> for Initialize<'b> { diff --git a/solana/bridge/program/src/api/post_message.rs b/solana/bridge/program/src/api/post_message.rs index b90f4f1e..e2e855af 100644 --- a/solana/bridge/program/src/api/post_message.rs +++ b/solana/bridge/program/src/api/post_message.rs @@ -37,22 +37,23 @@ impl<'a> From<&PostMessage<'a>> for SequenceDerivationData<'a> { #[derive(FromAccounts)] pub struct PostMessage<'b> { - pub bridge: Bridge<'b, { AccountState::Initialized }>, + /// Bridge config needed for fee calculation. + pub bridge: Mut>, /// Account to store the posted message - pub message: UninitializedMessage<'b>, + pub message: Mut>, /// Emitter of the VAA pub emitter: Signer>, /// Tracker for the emitter sequence - pub sequence: Sequence<'b>, + pub sequence: Mut>, /// Payer for account creation - pub payer: Signer>, + pub payer: Mut>>, /// Account to collect tx fee - pub fee_collector: FeeCollector<'b>, + pub fee_collector: Mut>, pub clock: Sysvar<'b, Clock>, } diff --git a/solana/bridge/program/src/api/post_vaa.rs b/solana/bridge/program/src/api/post_vaa.rs index 3409d759..feaa6bbc 100644 --- a/solana/bridge/program/src/api/post_vaa.rs +++ b/solana/bridge/program/src/api/post_vaa.rs @@ -70,10 +70,10 @@ pub struct PostVAA<'b> { pub signature_set: SignatureSet<'b, { AccountState::Initialized }>, /// Message the VAA is associated with. - pub message: Message<'b, { AccountState::MaybeInitialized }>, + pub message: Mut>, /// Account used to pay for auxillary instructions. - pub payer: Info<'b>, + pub payer: Mut>>, /// Clock used for timestamping. pub clock: Sysvar<'b, Clock>, diff --git a/solana/bridge/program/src/api/verify_signature.rs b/solana/bridge/program/src/api/verify_signature.rs index 4944b3c1..e153ab49 100644 --- a/solana/bridge/program/src/api/verify_signature.rs +++ b/solana/bridge/program/src/api/verify_signature.rs @@ -27,13 +27,13 @@ use std::io::Write; #[derive(FromAccounts)] pub struct VerifySignatures<'b> { /// Payer for account creation - pub payer: Signer>, + pub payer: Mut>>, /// Guardian set of the signatures pub guardian_set: GuardianSet<'b, { AccountState::Initialized }>, /// Signature Account - pub signature_set: SignatureSet<'b, { AccountState::MaybeInitialized }>, + pub signature_set: Mut>, /// Instruction reflection account (special sysvar) pub instruction_acc: Info<'b>, diff --git a/solana/bridge/program/src/instructions.rs b/solana/bridge/program/src/instructions.rs index 2ef7e63b..2d077528 100644 --- a/solana/bridge/program/src/instructions.rs +++ b/solana/bridge/program/src/instructions.rs @@ -110,7 +110,7 @@ pub fn post_message( accounts: vec![ AccountMeta::new(bridge, false), AccountMeta::new(message, false), - AccountMeta::new(emitter, true), + AccountMeta::new_readonly(emitter, true), AccountMeta::new(sequence, false), AccountMeta::new(payer, true), AccountMeta::new(fee_collector, false), @@ -152,7 +152,7 @@ pub fn verify_signatures( accounts: vec![ AccountMeta::new(payer, true), - AccountMeta::new(guardian_set, false), + AccountMeta::new_readonly(guardian_set, false), AccountMeta::new(signature_set, false), AccountMeta::new_readonly(sysvar::instructions::id(), false), AccountMeta::new_readonly(sysvar::rent::id(), false), @@ -197,9 +197,9 @@ pub fn post_vaa(program_id: Pubkey, payer: Pubkey, vaa: PostVAAData) -> Instruct program_id, accounts: vec![ - AccountMeta::new(guardian_set, false), - AccountMeta::new(bridge, false), - AccountMeta::new(signature_set, false), + AccountMeta::new_readonly(guardian_set, false), + AccountMeta::new_readonly(bridge, false), + AccountMeta::new_readonly(signature_set, false), AccountMeta::new(message, false), AccountMeta::new(payer, true), AccountMeta::new_readonly(sysvar::clock::id(), false), @@ -283,9 +283,9 @@ pub fn upgrade_guardian_set( accounts: vec![ AccountMeta::new(payer, true), AccountMeta::new(bridge, false), - AccountMeta::new(payload_message, false), + AccountMeta::new_readonly(payload_message, false), AccountMeta::new(claim, false), - AccountMeta::new(guardian_set_old, false), + AccountMeta::new_readonly(guardian_set_old, false), AccountMeta::new(guardian_set_new, false), AccountMeta::new_readonly(solana_program::system_program::id(), false), ], @@ -319,7 +319,7 @@ pub fn set_fees( accounts: vec![ AccountMeta::new(payer, true), AccountMeta::new(bridge, false), - AccountMeta::new(message, false), + AccountMeta::new_readonly(message, false), AccountMeta::new(claim, false), AccountMeta::new_readonly(solana_program::system_program::id(), false), ], @@ -355,8 +355,8 @@ pub fn transfer_fees( accounts: vec![ AccountMeta::new(payer, true), - AccountMeta::new(bridge, false), - AccountMeta::new(message, false), + AccountMeta::new_readonly(bridge, false), + AccountMeta::new_readonly(message, false), AccountMeta::new(claim, false), AccountMeta::new(fee_collector, false), AccountMeta::new(recipient, false), diff --git a/solana/bridge/program/src/vaa.rs b/solana/bridge/program/src/vaa.rs index 91ad55bb..693c3f93 100644 --- a/solana/bridge/program/src/vaa.rs +++ b/solana/bridge/program/src/vaa.rs @@ -123,7 +123,7 @@ pub struct ClaimableVAA<'b, T: DeserializePayload> { pub message: PayloadMessage<'b, T>, // Claim account to prevent double spending - pub claim: Claim<'b, { AccountState::Uninitialized }>, + pub claim: Mut>, } impl<'b, T: DeserializePayload> Deref for ClaimableVAA<'b, T> { diff --git a/solana/solitaire/program/src/processors/peel.rs b/solana/solitaire/program/src/processors/peel.rs index 60ebd1f1..e36473b6 100644 --- a/solana/solitaire/program/src/processors/peel.rs +++ b/solana/solitaire/program/src/processors/peel.rs @@ -230,7 +230,7 @@ impl< // It is also a malformed program to attempt to write to a non-writeable account. if !self.0.is_writable { - return Err(SolitaireError::NonWriteableAccount(*self.0.key)); + return Ok(()); } self.1.serialize(&mut *self.0.data.borrow_mut())?;