Hack the rent exempt bug (#265)

* Hack the rent exempt bug

* Fix compile bug

* Fix account resize potential problem

* Use invoke transfer instead of playing with lamports
This commit is contained in:
Ali Behjati 2022-09-05 13:32:41 +02:00 committed by GitHub
parent 19e34f5c00
commit 5c48dacee0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 39 additions and 0 deletions

View File

@ -22,6 +22,8 @@ use solana_program::{
program_error::ProgramError,
pubkey::Pubkey,
rent::Rent,
system_instruction,
sysvar::Sysvar as SolanaSysvar,
};
use p2w_sdk::{
@ -332,5 +334,42 @@ pub fn attest(ctx: &ExecutionContext, accs: &mut Attest, data: AttestData) -> So
.as_slice(),
)?;
// NOTE: 2022-09-05
//
// This part is added to avoid rent exemption error that is introduced using
// a wrong implementation in solitaire
//
// This is done after the cross-contract call to get the proper account sizes
// and avoid breaking wormhole call.
//
// It can be removed once wormhole mitigates this problem and upgrades its contract
// Checking the message account balance
let wh_message_balance = accs.wh_message.info().lamports();
let wh_message_rent_exempt = Rent::get()?.minimum_balance(accs.wh_message.info().data_len());
if wh_message_balance < wh_message_rent_exempt {
let required_deposit = wh_message_rent_exempt - wh_message_balance;
let transfer_ix = system_instruction::transfer(
accs.payer.key,
accs.wh_message.info().key,
required_deposit,
);
invoke(&transfer_ix, ctx.accounts)?
}
// Checking the sequence account balance
let wh_sequence_balance = accs.wh_sequence.info().lamports();
let wh_sequence_rent_exempt = Rent::get()?.minimum_balance(accs.wh_sequence.data_len());
if wh_sequence_balance < wh_sequence_rent_exempt {
let required_deposit = wh_sequence_rent_exempt - wh_sequence_balance;
let transfer_ix =
system_instruction::transfer(accs.payer.key, accs.wh_sequence.key, required_deposit);
invoke(&transfer_ix, ctx.accounts)?
}
Ok(())
}