@@ -116,8 +116,10 @@ pub struct Attest<'b> {
116
116
/// Bridge config needed for fee calculation
117
117
pub wh_bridge : Mut < Info < ' b > > ,
118
118
119
- /// Account to store the posted message
120
- pub wh_message : P2WMessage < ' b > ,
119
+ /// Account to store the posted message.
120
+ /// This account is a PDA from the attestation contract
121
+ /// which is owned by the wormhole core contract.
122
+ pub wh_message : Mut < Info < ' b > > ,
121
123
122
124
/// Emitter of the VAA
123
125
pub wh_emitter : P2WEmitter < ' b > ,
@@ -147,14 +149,7 @@ pub fn attest(ctx: &ExecutionContext, accs: &mut Attest, data: AttestData) -> So
147
149
return Err ( SolitaireError :: Custom ( 4242 ) ) ;
148
150
}
149
151
150
- let wh_msg_drv_data = P2WMessageDrvData {
151
- message_owner : accs. payer . key . clone ( ) ,
152
- id : data. message_account_id ,
153
- } ;
154
-
155
152
accs. config . verify_derivation ( ctx. program_id , None ) ?;
156
- accs. wh_message
157
- . verify_derivation ( ctx. program_id , & wh_msg_drv_data) ?;
158
153
159
154
if accs. config . wh_prog != * accs. wh_prog . key {
160
155
trace ! ( & format!(
@@ -267,43 +262,24 @@ pub fn attest(ctx: &ExecutionContext, accs: &mut Attest, data: AttestData) -> So
267
262
ProgramError :: InvalidAccountData
268
263
} ) ?;
269
264
270
- // Adjust message account size if necessary.
271
- // NOTE: We assume that:
272
- // - the rent and size values are far away from
273
- // i64/u64/isize/usize overflow shenanigans (on the order of
274
- // single kilobytes).
275
- // - Pyth payload size change == Wormhole message size change (their metadata is constant-size)
276
- if accs. wh_message . is_initialized ( ) && accs. wh_message . payload . len ( ) != payload. len ( ) {
277
- // NOTE: Payload =/= account size (account size includes
278
- // surrounding wormhole data structure, payload is just the
279
- // Pyth bytes).
280
-
281
- // This value will be negative if we need to shrink down
282
- let old_account_size = accs. wh_message . info ( ) . data_len ( ) ;
283
-
284
- // How much payload size changes
285
- let payload_size_diff = payload. len ( ) as isize - old_account_size as isize ;
286
-
287
- // How big the overall account data becomes
288
- let new_account_size = ( old_account_size as isize + payload_size_diff) as usize ;
289
-
290
- // Adjust account size
291
- accs. wh_message . info ( ) . realloc ( new_account_size, false ) ?;
292
-
293
- // Exempt balance for adjusted size
294
- let new_msg_account_balance = Rent :: default ( ) . minimum_balance ( new_account_size) ;
295
-
296
- // How the account balance changes
297
- let balance_diff =
298
- new_msg_account_balance as i64 - accs. wh_message . info ( ) . lamports ( ) as i64 ;
299
-
300
- // How the diff affects payer balance
301
- let new_payer_balance = ( accs. payer . info ( ) . lamports ( ) as i64 - balance_diff) as u64 ;
302
-
303
- * * accs. wh_message . info ( ) . lamports . borrow_mut ( ) = new_msg_account_balance;
304
- * * accs. payer . info ( ) . lamports . borrow_mut ( ) = new_payer_balance;
265
+ let wh_msg_drv_data = P2WMessageDrvData {
266
+ message_owner : accs. payer . key . clone ( ) ,
267
+ batch_size : batch_attestation. price_attestations . len ( ) as u16 ,
268
+ id : data. message_account_id ,
269
+ } ;
305
270
306
- trace ! ( "After message size/balance adjustment" ) ;
271
+ if !P2WMessage :: key ( & wh_msg_drv_data, ctx. program_id ) . eq ( accs. wh_message . info ( ) . key ) {
272
+ trace ! (
273
+ "Invalid seeds for wh message pubkey. Expected {} with given seeds {:?}, got {}" ,
274
+ P2WMessage :: key( & wh_msg_drv_data, ctx. program_id) ,
275
+ P2WMessage :: seeds( & wh_msg_drv_data)
276
+ . iter_mut( )
277
+ . map( |seed| seed. as_slice( ) )
278
+ . collect:: <Vec <_>>( )
279
+ . as_slice( ) ,
280
+ accs. wh_message. info( ) . key
281
+ ) ;
282
+ return Err ( ProgramError :: InvalidSeeds . into ( ) ) ;
307
283
}
308
284
309
285
let ix = bridge:: instructions:: post_message_unreliable (
@@ -335,6 +311,7 @@ pub fn attest(ctx: &ExecutionContext, accs: &mut Attest, data: AttestData) -> So
335
311
) ) ;
336
312
337
313
trace ! ( "attest() finished, cross-calling wormhole" ) ;
314
+
338
315
invoke_signed (
339
316
& ix,
340
317
ctx. accounts ,
0 commit comments