@@ -135,7 +135,7 @@ pub struct TransferBurn<'info> {
135135impl < ' info > TransferBurn < ' info > {
136136 // Manually validate accounts instead of using anchor constraints
137137 // so that the context can be shared (nested contexts do not support instruction args)
138- pub fn validate_accounts ( & self , args : & TransferArgs ) -> Result < ( Pubkey , u8 ) > {
138+ pub fn validate_accounts ( & self , args : & TransferArgs ) -> Result < u8 > {
139139 let inbox_rate_limit = Pubkey :: create_program_address (
140140 & [
141141 InboxRateLimit :: SEED_PREFIX ,
@@ -161,35 +161,27 @@ impl<'info> TransferBurn<'info> {
161161 return err ! ( ErrorCode :: ConstraintAddress ) ;
162162 }
163163
164- // Owner of the $M token account depends on whether this function
165- // was called directly or by tranfer_extension_burn.
166- let session_owner_seed = if self . common . from . owner . eq ( self . token_authority . key ) {
167- self . common . payer . key ( )
168- } else {
169- self . common . from . owner . key ( )
170- } ;
171-
172- let ( session_authority, session_authority_bump) = Pubkey :: find_program_address (
173- & [
174- crate :: SESSION_AUTHORITY_SEED ,
175- session_owner_seed. as_ref ( ) ,
176- args. keccak256 ( ) . as_ref ( ) ,
177- ] ,
178- & crate :: ID ,
179- ) ;
180- if !self . session_authority . key ( ) . eq ( & session_authority) {
181- return err ! ( ErrorCode :: ConstraintAddress ) ;
182- }
183-
184- Ok ( ( session_owner_seed, session_authority_bump) )
164+ let session_authority_bump = get_session_authority (
165+ self . common . payer . key ,
166+ args. amount ,
167+ args. recipient_chain ,
168+ args. recipient_address ,
169+ args. should_queue ,
170+ self . session_authority . key ,
171+ // We already validated the session in transfer_extension_burn.
172+ // Also, the amount argument is different after converting to $M.
173+ !self . common . from . owner . eq ( self . token_authority . key ) ,
174+ ) ?;
175+
176+ Ok ( session_authority_bump)
185177 }
186178}
187179
188180pub fn transfer_burn < ' info > (
189181 ctx : Context < ' _ , ' _ , ' _ , ' info , TransferBurn < ' info > > ,
190182 args : TransferArgs ,
191183) -> Result < ( ) > {
192- let ( session_owner_seed , session_authority_bump) = ctx. accounts . validate_accounts ( & args) ?;
184+ let session_authority_bump = ctx. accounts . validate_accounts ( & args) ?;
193185
194186 let accs = ctx. accounts ;
195187
@@ -245,7 +237,7 @@ pub fn transfer_burn<'info>(
245237 accs. common . mint . decimals ,
246238 & [ & [
247239 crate :: SESSION_AUTHORITY_SEED ,
248- session_owner_seed . as_ref ( ) ,
240+ accs . common . payer . key . as_ref ( ) ,
249241 args. keccak256 ( ) . as_ref ( ) ,
250242 & [ session_authority_bump] ,
251243 ] ] ,
@@ -347,3 +339,35 @@ fn insert_into_outbox(
347339
348340 Ok ( ( ) )
349341}
342+
343+ pub fn get_session_authority (
344+ payer : & Pubkey ,
345+ amount : u64 ,
346+ recipient_chain : ChainId ,
347+ recipient_address : [ u8 ; 32 ] ,
348+ should_queue : bool ,
349+ expected : & Pubkey ,
350+ validate : bool ,
351+ ) -> Result < u8 > {
352+ let ( session_authority, bump) = Pubkey :: find_program_address (
353+ & [
354+ crate :: SESSION_AUTHORITY_SEED ,
355+ payer. as_ref ( ) ,
356+ TransferArgs {
357+ amount,
358+ recipient_chain,
359+ recipient_address,
360+ should_queue,
361+ }
362+ . keccak256 ( )
363+ . as_ref ( ) ,
364+ ] ,
365+ & crate :: ID ,
366+ ) ;
367+
368+ if validate && !session_authority. eq ( expected) {
369+ return err ! ( ErrorCode :: ConstraintAddress ) ;
370+ }
371+
372+ Ok ( bump)
373+ }
0 commit comments