LCOV - code coverage report
Current view: top level - flamenco/runtime - fd_account_old.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 55 0.0 %
Date: 2024-11-13 11:58:15 Functions: 0 92 0.0 %

          Line data    Source code
       1             : #ifndef HEADER_fd_src_flamenco_runtime_fd_account_old_h
       2             : #define HEADER_fd_src_flamenco_runtime_fd_account_old_h
       3             : 
       4             : #include "../../ballet/txn/fd_txn.h"
       5             : #include "program/fd_program_util.h"
       6             : #include "sysvar/fd_sysvar_rent.h"
       7             : #include "fd_system_ids.h"
       8             : #include "fd_runtime.h"
       9             : #include <assert.h>
      10             : 
      11             : /* Represents the lamport balance associated with an account. */
      12             : typedef ulong fd_acc_lamports_t;
      13             : 
      14             : // Once these settle out, we will switch almost everything to not be inlined
      15             : 
      16             : static inline void *
      17           0 : fd_account_get_data(fd_account_meta_t * m) {
      18           0 :   return ((char *) m) + m->hlen;
      19           0 : }
      20             : 
      21             : // TODO: Confirm if the program id pubkey actually corresponds to the last program id
      22             : // Returns true if the owner of this account is the current `InstructionContext`s last program (instruction wide)
      23             : static inline
      24           0 : int fd_account_is_owned_by_current_program2(const fd_exec_instr_ctx_t *ctx, const fd_account_meta_t * acct, FD_FN_UNUSED int *err) {
      25           0 :   return memcmp( &ctx->instr->program_id_pubkey, acct->info.owner, sizeof(fd_pubkey_t) ) == 0;
      26           0 : }
      27             : 
      28             : static inline
      29           0 : int fd_account_can_data_be_changed2(fd_exec_instr_ctx_t *ctx, fd_account_meta_t const * acct, fd_pubkey_t const * key,  int *err) {
      30           0 : 
      31           0 :   if (fd_account_is_executable( acct )) {
      32           0 :     *err = FD_EXECUTOR_INSTR_ERR_EXECUTABLE_DATA_MODIFIED;
      33           0 :     return 0;
      34           0 :   }
      35           0 : 
      36           0 :   if (!fd_instr_acc_is_writable(ctx->instr, key)) {
      37           0 :     *err = FD_EXECUTOR_INSTR_ERR_READONLY_DATA_MODIFIED;
      38           0 :     return 0;
      39           0 :   }
      40           0 : 
      41           0 :   if (!fd_account_is_owned_by_current_program2(ctx, acct, err)) {
      42           0 :     *err = FD_EXECUTOR_INSTR_ERR_EXTERNAL_DATA_MODIFIED;
      43           0 :     return 0;
      44           0 :   }
      45           0 : 
      46           0 :   return 1;
      47           0 : }
      48             : 
      49             : static inline
      50             : int fd_account_set_executable2( fd_exec_instr_ctx_t * ctx,
      51             :                                 fd_pubkey_t const * program_acc, 
      52             :                                 fd_account_meta_t * metadata, 
      53           0 :                                 char is_executable ) {
      54           0 :   fd_rent_t rent;
      55           0 :   fd_rent_new( &rent );
      56           0 :   if( fd_sysvar_rent_read( &rent, ctx->slot_ctx ) ) {
      57           0 :     ulong min_balance = fd_rent_exempt_minimum_balance( &rent, metadata->dlen );
      58           0 :     if (metadata->info.lamports < min_balance) {
      59           0 :       return FD_EXECUTOR_INSTR_ERR_EXECUTABLE_ACCOUNT_NOT_RENT_EXEMPT;
      60           0 :     }
      61           0 : 
      62           0 :     if (0 != memcmp(metadata->info.owner, fd_solana_bpf_loader_program_id.key, sizeof(fd_pubkey_t)) &&
      63           0 :         0 != memcmp(metadata->info.owner, fd_solana_bpf_loader_upgradeable_program_id.key, sizeof(fd_pubkey_t))) {
      64           0 :       return FD_EXECUTOR_INSTR_ERR_EXECUTABLE_MODIFIED;
      65           0 :     }
      66           0 : 
      67           0 :     if (!fd_instr_acc_is_writable(ctx->instr, program_acc)) {
      68           0 :       return FD_EXECUTOR_INSTR_ERR_EXECUTABLE_MODIFIED;
      69           0 :     }
      70           0 : 
      71           0 :     if (metadata->info.executable && !is_executable) {
      72           0 :       return FD_EXECUTOR_INSTR_ERR_EXECUTABLE_MODIFIED;
      73           0 :     }
      74           0 : 
      75           0 :     if (metadata->info.executable == is_executable) {
      76           0 :       return 0;
      77           0 :     }
      78           0 :   }
      79           0 : 
      80           0 :   metadata->info.executable = !!is_executable;
      81           0 :   return 0;
      82           0 : }
      83             : 
      84             : #endif

Generated by: LCOV version 1.14