Skip to content

Commit bb76ab0

Browse files
committed
Add rent exemption check
1 parent a81c6c0 commit bb76ab0

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

program/src/oracle/oracle.c

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,30 @@
55
#include "oracle.h"
66
#include "upd_aggregate.h"
77

8+
// Returns the minimum number of lamports required to make an account
9+
// with dlen bytes of data rent exempt. These values were calculated
10+
// using the getMinimumBalanceForRentExemption RPC call, and are
11+
// guaranteed never to increase.
12+
static uint64_t rent_exempt_amount( uint64_t dlen )
13+
{
14+
switch ( dlen )
15+
{
16+
case sizeof( pc_map_table_t ):
17+
return 143821440;
18+
case PC_PROD_ACC_SIZE:
19+
return 4454400;
20+
case sizeof( pc_price_t ):
21+
return 23942400;
22+
default:
23+
return UINT64_MAX;
24+
}
25+
}
26+
27+
static bool is_rent_exempt( uint64_t lamports, uint64_t dlen )
28+
{
29+
return lamports >= rent_exempt_amount( dlen );
30+
}
31+
832
static bool valid_funding_account( SolAccountInfo *ka )
933
{
1034
return ka->is_signer &&
@@ -18,7 +42,8 @@ static bool valid_signable_account( SolParameters *prm,
1842
return ka->is_signer &&
1943
ka->is_writable &&
2044
SolPubkey_same( ka->owner, prm->program_id ) &&
21-
ka->data_len >= dlen;
45+
ka->data_len >= dlen &&
46+
is_rent_exempt( *ka->lamports, dlen );
2247
}
2348

2449
static bool valid_writable_account( SolParameters *prm,
@@ -27,7 +52,8 @@ static bool valid_writable_account( SolParameters *prm,
2752
{
2853
return ka->is_writable &&
2954
SolPubkey_same( ka->owner, prm->program_id ) &&
30-
ka->data_len >= dlen;
55+
ka->data_len >= dlen &&
56+
is_rent_exempt( *ka->lamports, dlen );
3157
}
3258

3359
static uint64_t init_mapping( SolParameters *prm, SolAccountInfo *ka )

0 commit comments

Comments
 (0)