Skip to content

Commit e50cf9f

Browse files
authored
Fix Rent exempt check (#145)
1 parent dbec1b9 commit e50cf9f

File tree

4 files changed

+18
-19
lines changed

4 files changed

+18
-19
lines changed

harness/src/lib.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -492,8 +492,8 @@ pub struct Mollusk {
492492
pub sysvars: Sysvars,
493493

494494
/// The callback which can be used to inspect invoke_context
495-
/// and extract low-level information such as bpf traces, transaction context,
496-
/// detailed timings, etc.
495+
/// and extract low-level information such as bpf traces, transaction
496+
/// context, detailed timings, etc.
497497
#[cfg(feature = "invocation-inspect-callback")]
498498
pub invocation_inspect_callback: Box<dyn InvocationInspectCallback>,
499499

@@ -524,13 +524,7 @@ pub struct EmptyInvocationInspectCallback;
524524

525525
#[cfg(feature = "invocation-inspect-callback")]
526526
impl InvocationInspectCallback for EmptyInvocationInspectCallback {
527-
fn before_invocation(
528-
&self,
529-
_: &Pubkey,
530-
_: &[u8],
531-
_: &[InstructionAccount],
532-
_: &InvokeContext,
533-
) {
527+
fn before_invocation(&self, _: &Pubkey, _: &[u8], _: &[InstructionAccount], _: &InvokeContext) {
534528
}
535529

536530
fn after_invocation(&self, _: &InvokeContext) {}
@@ -577,8 +571,9 @@ impl Default for Mollusk {
577571
}
578572

579573
impl CheckContext for Mollusk {
580-
fn is_rent_exempt(&self, lamports: u64, space: usize) -> bool {
581-
self.sysvars.rent.is_exempt(lamports, space)
574+
fn is_rent_exempt(&self, lamports: u64, space: usize, owner: Pubkey) -> bool {
575+
owner.eq(&Pubkey::default()) && lamports == 0
576+
|| self.sysvars.rent.is_exempt(lamports, space)
582577
}
583578
}
584579

harness/tests/bpf_program.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,8 @@ fn test_account_checks_rent_exemption() {
471471
}
472472

473473
impl CheckContext for TestCheckContext<'_> {
474-
fn is_rent_exempt(&self, lamports: u64, space: usize) -> bool {
475-
self.rent.is_exempt(lamports, space)
474+
fn is_rent_exempt(&self, lamports: u64, space: usize, owner: Pubkey) -> bool {
475+
owner.eq(&Pubkey::default()) && lamports == 0 || self.rent.is_exempt(lamports, space)
476476
}
477477
}
478478

result/src/check.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,8 @@ impl InstructionResult {
253253
true,
254254
context.is_rent_exempt(
255255
resulting_account.lamports,
256-
resulting_account.data.len()
256+
resulting_account.data.len(),
257+
resulting_account.owner,
257258
),
258259
);
259260
}
@@ -280,8 +281,11 @@ impl InstructionResult {
280281
}
281282
CheckType::AllRentExempt => {
282283
for (pubkey, account) in &self.resulting_accounts {
283-
let is_rent_exempt =
284-
context.is_rent_exempt(account.lamports(), account.data().len());
284+
let is_rent_exempt = context.is_rent_exempt(
285+
account.lamports(),
286+
account.data().len(),
287+
account.owner,
288+
);
285289
if !is_rent_exempt {
286290
pass &= throw!(
287291
c,

result/src/config.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Configuration and context for result validation.
22
3-
use solana_rent::Rent;
3+
use {solana_pubkey::Pubkey, solana_rent::Rent};
44

55
pub struct Config {
66
pub panic: bool,
@@ -24,8 +24,8 @@ impl Default for Config {
2424
/// one may wish to evaluate resulting account lamports with a custom `Rent`
2525
/// configuration. This trait allows such customization.
2626
pub trait CheckContext {
27-
fn is_rent_exempt(&self, lamports: u64, space: usize) -> bool {
28-
Rent::default().is_exempt(lamports, space)
27+
fn is_rent_exempt(&self, lamports: u64, space: usize, owner: Pubkey) -> bool {
28+
owner.eq(&Pubkey::default()) && lamports == 0 || Rent::default().is_exempt(lamports, space)
2929
}
3030
}
3131

0 commit comments

Comments
 (0)