LCOV - code coverage report
Current view: top level - flamenco/runtime - fd_executor.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 7 991 0.7 %
Date: 2025-12-13 04:39:40 Functions: 1 42 2.4 %

          Line data    Source code
       1             : #include "fd_executor.h"
       2             : #include "fd_acc_mgr.h"
       3             : #include "fd_bank.h"
       4             : #include "fd_runtime.h"
       5             : #include "fd_runtime_err.h"
       6             : 
       7             : #include "fd_system_ids.h"
       8             : #include "program/fd_address_lookup_table_program.h"
       9             : #include "program/fd_bpf_loader_program.h"
      10             : #include "program/fd_loader_v4_program.h"
      11             : #include "program/fd_compute_budget_program.h"
      12             : #include "program/fd_config_program.h"
      13             : #include "program/fd_precompiles.h"
      14             : #include "program/fd_stake_program.h"
      15             : #include "program/fd_system_program.h"
      16             : #include "program/fd_builtin_programs.h"
      17             : #include "program/fd_vote_program.h"
      18             : #include "program/fd_zk_elgamal_proof_program.h"
      19             : #include "sysvar/fd_sysvar_cache.h"
      20             : #include "sysvar/fd_sysvar_epoch_schedule.h"
      21             : #include "sysvar/fd_sysvar_instructions.h"
      22             : #include "sysvar/fd_sysvar_rent.h"
      23             : #include "sysvar/fd_sysvar_slot_history.h"
      24             : #include "tests/fd_dump_pb.h"
      25             : 
      26             : #include "../log_collector/fd_log_collector.h"
      27             : #include "../types/fd_types_yaml.h"
      28             : 
      29             : #include "../../ballet/base58/fd_base58.h"
      30             : 
      31             : #include "../../util/bits/fd_uwide.h"
      32             : 
      33             : #include <assert.h>
      34             : #include <math.h>
      35             : #include <stdio.h>   /* snprintf(3) */
      36             : #include <fcntl.h>   /* openat(2) */
      37             : #include <unistd.h>  /* write(3) */
      38             : #include <time.h>
      39             : 
      40             : struct fd_native_prog_info {
      41             :   fd_pubkey_t key;
      42             :   fd_exec_instr_fn_t fn;
      43             :   uchar is_bpf_loader;
      44             :   ulong feature_enable_offset; /* offset to the feature that enables this program, if any */
      45             : };
      46             : typedef struct fd_native_prog_info fd_native_prog_info_t;
      47             : 
      48             : /* https://github.com/anza-xyz/agave/blob/v2.2.13/svm-rent-collector/src/rent_state.rs#L5-L15 */
      49             : struct fd_rent_state {
      50             :   uint  discriminant;
      51             :   ulong lamports;
      52             :   ulong data_size;
      53             : };
      54             : typedef struct fd_rent_state fd_rent_state_t;
      55             : 
      56           0 : #define FD_RENT_STATE_UNINITIALIZED (0U)
      57           0 : #define FD_RENT_STATE_RENT_PAYING   (1U)
      58           0 : #define FD_RENT_STATE_RENT_EXEMPT   (2U)
      59             : 
      60             : #define MAP_PERFECT_NAME fd_native_program_fn_lookup_tbl
      61             : #define MAP_PERFECT_LG_TBL_SZ 4
      62             : #define MAP_PERFECT_T fd_native_prog_info_t
      63           0 : #define MAP_PERFECT_HASH_C 478U
      64             : #define MAP_PERFECT_KEY key.uc
      65             : #define MAP_PERFECT_KEY_T fd_pubkey_t const *
      66             : #define MAP_PERFECT_ZERO_KEY  (0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0)
      67             : #define MAP_PERFECT_COMPLEX_KEY 1
      68           0 : #define MAP_PERFECT_KEYS_EQUAL(k1,k2) (!memcmp( (k1), (k2), 32UL ))
      69             : 
      70           0 : #define PERFECT_HASH( u ) (((MAP_PERFECT_HASH_C*(u))>>28)&0xFU)
      71             : 
      72             : #define MAP_PERFECT_HASH_PP( a00,a01,a02,a03,a04,a05,a06,a07,a08,a09,a10,a11,a12,a13,a14,a15, \
      73             :                              a16,a17,a18,a19,a20,a21,a22,a23,a24,a25,a26,a27,a28,a29,a30,a31) \
      74             :                                           PERFECT_HASH( (a08 | (a09<<8) | (a10<<16) | (a11<<24)) )
      75           0 : #define MAP_PERFECT_HASH_R( ptr ) PERFECT_HASH( fd_uint_load_4( (uchar const *)ptr + 8UL ) )
      76             : 
      77             : #define MAP_PERFECT_0       ( VOTE_PROG_ID            ), .fn = fd_vote_program_execute,                      .is_bpf_loader = 0, .feature_enable_offset = ULONG_MAX
      78             : #define MAP_PERFECT_1       ( SYS_PROG_ID             ), .fn = fd_system_program_execute,                    .is_bpf_loader = 0, .feature_enable_offset = ULONG_MAX
      79             : #define MAP_PERFECT_2       ( CONFIG_PROG_ID          ), .fn = fd_config_program_execute,                    .is_bpf_loader = 0, .feature_enable_offset = ULONG_MAX
      80             : #define MAP_PERFECT_3       ( STAKE_PROG_ID           ), .fn = fd_stake_program_execute,                     .is_bpf_loader = 0, .feature_enable_offset = ULONG_MAX
      81             : #define MAP_PERFECT_4       ( COMPUTE_BUDGET_PROG_ID  ), .fn = fd_compute_budget_program_execute,            .is_bpf_loader = 0, .feature_enable_offset = ULONG_MAX
      82             : #define MAP_PERFECT_5       ( ADDR_LUT_PROG_ID        ), .fn = fd_address_lookup_table_program_execute,      .is_bpf_loader = 0, .feature_enable_offset = ULONG_MAX
      83             : #define MAP_PERFECT_6       ( ZK_EL_GAMAL_PROG_ID     ), .fn = fd_executor_zk_elgamal_proof_program_execute, .is_bpf_loader = 0, .feature_enable_offset = ULONG_MAX
      84             : #define MAP_PERFECT_7       ( BPF_LOADER_1_PROG_ID    ), .fn = fd_bpf_loader_program_execute,                .is_bpf_loader = 1, .feature_enable_offset = ULONG_MAX
      85             : #define MAP_PERFECT_8       ( BPF_LOADER_2_PROG_ID    ), .fn = fd_bpf_loader_program_execute,                .is_bpf_loader = 1, .feature_enable_offset = ULONG_MAX
      86             : #define MAP_PERFECT_9       ( BPF_UPGRADEABLE_PROG_ID ), .fn = fd_bpf_loader_program_execute,                .is_bpf_loader = 1, .feature_enable_offset = ULONG_MAX
      87             : #define MAP_PERFECT_10      ( LOADER_V4_PROG_ID       ), .fn = fd_loader_v4_program_execute,                 .is_bpf_loader = 1, .feature_enable_offset = offsetof( fd_features_t, enable_loader_v4 )
      88             : 
      89             : #include "../../util/tmpl/fd_map_perfect.c"
      90             : #undef PERFECT_HASH
      91             : 
      92             : #define MAP_PERFECT_NAME fd_native_precompile_program_fn_lookup_tbl
      93             : #define MAP_PERFECT_LG_TBL_SZ 2
      94             : #define MAP_PERFECT_T fd_native_prog_info_t
      95           0 : #define MAP_PERFECT_HASH_C 63546U
      96             : #define MAP_PERFECT_KEY key.uc
      97             : #define MAP_PERFECT_KEY_T fd_pubkey_t const *
      98             : #define MAP_PERFECT_ZERO_KEY  (0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0)
      99             : #define MAP_PERFECT_COMPLEX_KEY 1
     100           0 : #define MAP_PERFECT_KEYS_EQUAL(k1,k2) (!memcmp( (k1), (k2), 32UL ))
     101             : 
     102           0 : #define PERFECT_HASH( u ) (((MAP_PERFECT_HASH_C*(u))>>30)&0x3U)
     103             : 
     104             : #define MAP_PERFECT_HASH_PP( a00,a01,a02,a03,a04,a05,a06,a07,a08,a09,a10,a11,a12,a13,a14,a15, \
     105             :                              a16,a17,a18,a19,a20,a21,a22,a23,a24,a25,a26,a27,a28,a29,a30,a31) \
     106             :                                           PERFECT_HASH( (a00 | (a01<<8)) )
     107           0 : #define MAP_PERFECT_HASH_R( ptr ) PERFECT_HASH( fd_uint_load_2( (uchar const *)ptr ) )
     108             : 
     109             : #define MAP_PERFECT_0      ( ED25519_SV_PROG_ID      ), .fn = fd_precompile_ed25519_verify
     110             : #define MAP_PERFECT_1      ( KECCAK_SECP_PROG_ID     ), .fn = fd_precompile_secp256k1_verify
     111             : #define MAP_PERFECT_2      ( SECP256R1_PROG_ID       ), .fn = fd_precompile_secp256r1_verify
     112             : 
     113             : #include "../../util/tmpl/fd_map_perfect.c"
     114             : #undef PERFECT_HASH
     115             : 
     116             : fd_exec_instr_fn_t
     117           0 : fd_executor_lookup_native_precompile_program( fd_txn_account_t const * prog_acc ) {
     118           0 :   fd_pubkey_t const * pubkey                = prog_acc->pubkey;
     119           0 :   const fd_native_prog_info_t null_function = {0};
     120           0 :   return fd_native_precompile_program_fn_lookup_tbl_query( pubkey, &null_function )->fn;
     121           0 : }
     122             : 
     123             : uchar
     124           0 : fd_executor_pubkey_is_bpf_loader( fd_pubkey_t const * pubkey ) {
     125           0 :   fd_native_prog_info_t const null_function = {0};
     126           0 :   return fd_native_program_fn_lookup_tbl_query( pubkey, &null_function )->is_bpf_loader;
     127           0 : }
     128             : 
     129             : uchar
     130             : fd_executor_program_is_active( fd_bank_t *         bank,
     131           0 :                                fd_pubkey_t const * pubkey ) {
     132           0 :   fd_native_prog_info_t const null_function = {0};
     133           0 :   ulong feature_offset = fd_native_program_fn_lookup_tbl_query( pubkey, &null_function )->feature_enable_offset;
     134             : 
     135           0 :   return feature_offset==ULONG_MAX ||
     136           0 :          FD_FEATURE_ACTIVE_BANK_OFFSET( bank, feature_offset );
     137           0 : }
     138             : 
     139             : /* fd_executor_lookup_native_program returns the appropriate instruction processor for the given
     140             :    native program ID. Returns NULL if given ID is not a recognized native program.
     141             :    https://github.com/anza-xyz/agave/blob/v2.2.6/program-runtime/src/invoke_context.rs#L520-L544 */
     142             : static int
     143             : fd_executor_lookup_native_program( fd_txn_account_t const * prog_acc,
     144             :                                    fd_bank_t *              bank,
     145             :                                    fd_exec_instr_fn_t *     native_prog_fn,
     146           0 :                                    uchar *                  is_precompile ) {
     147             :   /* First lookup to see if the program key is a precompile */
     148           0 :   *is_precompile = 0;
     149           0 :   *native_prog_fn = fd_executor_lookup_native_precompile_program( prog_acc );
     150           0 :   if( FD_UNLIKELY( *native_prog_fn!=NULL ) ) {
     151           0 :     *is_precompile = 1;
     152           0 :     return 0;
     153           0 :   }
     154             : 
     155           0 :   fd_pubkey_t const * pubkey = prog_acc->pubkey;
     156           0 :   fd_pubkey_t const * owner  = fd_txn_account_get_owner( prog_acc );
     157             : 
     158             :   /* Native programs should be owned by the native loader...
     159             :      This will not be the case though once core programs are migrated to BPF. */
     160           0 :   int is_native_program = !memcmp( owner, fd_solana_native_loader_id.key, sizeof(fd_pubkey_t) );
     161             : 
     162           0 :   if( !is_native_program ) {
     163           0 :     if( FD_UNLIKELY( !fd_executor_pubkey_is_bpf_loader( owner ) ) ) {
     164           0 :       return FD_EXECUTOR_INSTR_ERR_UNSUPPORTED_PROGRAM_ID;
     165           0 :     }
     166           0 :   }
     167             : 
     168           0 :   fd_pubkey_t const * lookup_pubkey = is_native_program ? pubkey : owner;
     169             : 
     170             :   /* Migrated programs must be executed via the corresponding BPF
     171             :      loader(s), not natively. This check is performed at the transaction
     172             :      level, but we re-check to please the instruction level (and below)
     173             :      fuzzers. */
     174           0 :   uchar has_migrated;
     175           0 :   if( FD_UNLIKELY( fd_is_migrating_builtin_program( bank, lookup_pubkey, &has_migrated ) && has_migrated ) ) {
     176           0 :     *native_prog_fn = NULL;
     177           0 :     return FD_EXECUTOR_INSTR_ERR_UNSUPPORTED_PROGRAM_ID;
     178           0 :   }
     179             : 
     180             :   /* We perform feature gate checks here to emulate the absence of
     181             :      a native program in Agave's ProgramCache when the program's feature
     182             :      gate is not activated.
     183             :      https://github.com/anza-xyz/agave/blob/v3.0.3/program-runtime/src/invoke_context.rs#L546-L549 */
     184             : 
     185           0 :   if( FD_UNLIKELY( !fd_executor_program_is_active( bank, lookup_pubkey ) ) ) {
     186           0 :     *native_prog_fn = NULL;
     187           0 :     return FD_EXECUTOR_INSTR_ERR_UNSUPPORTED_PROGRAM_ID;
     188           0 :   }
     189             : 
     190           0 :   fd_native_prog_info_t const null_function = {0};
     191           0 :   *native_prog_fn                           = fd_native_program_fn_lookup_tbl_query( lookup_pubkey, &null_function )->fn;
     192           0 :   return 0;
     193           0 : }
     194             : 
     195             : /* https://github.com/anza-xyz/agave/blob/v2.2.13/svm-rent-collector/src/svm_rent_collector.rs#L117-L136 */
     196             : static uchar
     197             : fd_executor_rent_transition_allowed( fd_rent_state_t const * pre_rent_state,
     198           0 :                                      fd_rent_state_t const * post_rent_state ) {
     199           0 :   switch( post_rent_state->discriminant ) {
     200           0 :     case FD_RENT_STATE_UNINITIALIZED:
     201           0 :     case FD_RENT_STATE_RENT_EXEMPT: {
     202           0 :       return 1;
     203           0 :     }
     204           0 :     case FD_RENT_STATE_RENT_PAYING: {
     205           0 :       switch( pre_rent_state->discriminant ) {
     206           0 :         case FD_RENT_STATE_UNINITIALIZED:
     207           0 :         case FD_RENT_STATE_RENT_EXEMPT: {
     208           0 :           return 0;
     209           0 :         }
     210           0 :         case FD_RENT_STATE_RENT_PAYING: {
     211           0 :           return post_rent_state->data_size==pre_rent_state->data_size &&
     212           0 :                  post_rent_state->lamports<=pre_rent_state->lamports;
     213           0 :         }
     214           0 :         default: {
     215           0 :           __builtin_unreachable();
     216           0 :         }
     217           0 :       }
     218           0 :     }
     219           0 :     default: {
     220           0 :       __builtin_unreachable();
     221           0 :     }
     222           0 :   }
     223           0 : }
     224             : 
     225             : /* https://github.com/anza-xyz/agave/blob/v2.2.13/svm-rent-collector/src/svm_rent_collector.rs#L61-L77 */
     226             : static int
     227             : fd_executor_check_rent_state_with_account( fd_txn_account_t const * account,
     228             :                                            fd_rent_state_t const *  pre_rent_state,
     229           0 :                                            fd_rent_state_t const *  post_rent_state ) {
     230           0 :   if( FD_UNLIKELY( memcmp( account->pubkey->key, fd_sysvar_incinerator_id.key, sizeof(fd_pubkey_t) ) &&
     231           0 :                    !fd_executor_rent_transition_allowed( pre_rent_state, post_rent_state ) ) ) {
     232           0 :     return FD_RUNTIME_TXN_ERR_INSUFFICIENT_FUNDS_FOR_RENT;
     233           0 :   }
     234           0 :   return FD_RUNTIME_EXECUTE_SUCCESS;
     235           0 : }
     236             : 
     237             : /* https://github.com/anza-xyz/agave/blob/v2.2.13/svm-rent-collector/src/svm_rent_collector.rs#L87-L101 */
     238             : fd_rent_state_t
     239           0 : fd_executor_get_account_rent_state( fd_txn_account_t const * account, fd_rent_t const * rent ) {
     240             :   /* https://github.com/anza-xyz/agave/blob/v2.2.13/svm-rent-collector/src/svm_rent_collector.rs#L88-L89 */
     241           0 :   if( fd_txn_account_get_lamports( account )==0UL ) {
     242           0 :     return (fd_rent_state_t){
     243           0 :       .discriminant = FD_RENT_STATE_UNINITIALIZED
     244           0 :     };
     245           0 :   }
     246             : 
     247             :   /* https://github.com/anza-xyz/agave/blob/v2.2.13/svm-rent-collector/src/svm_rent_collector.rs#L90-L94 */
     248           0 :   if( fd_txn_account_get_lamports( account )>=fd_rent_exempt_minimum_balance( rent, fd_txn_account_get_data_len( account ) ) ) {
     249           0 :     return (fd_rent_state_t){
     250           0 :       .discriminant = FD_RENT_STATE_RENT_EXEMPT
     251           0 :     };
     252           0 :   }
     253             : 
     254             :   /* https://github.com/anza-xyz/agave/blob/v2.2.13/svm-rent-collector/src/svm_rent_collector.rs#L95-L99 */
     255           0 :   return (fd_rent_state_t){
     256           0 :     .discriminant = FD_RENT_STATE_RENT_PAYING,
     257           0 :     .lamports     = fd_txn_account_get_lamports( account ),
     258           0 :     .data_size    = fd_txn_account_get_data_len( account )
     259           0 :   };
     260           0 : }
     261             : 
     262             : /* https://github.com/anza-xyz/agave/blob/v2.2.13/svm/src/account_loader.rs#L293-L342 */
     263             : static int
     264             : fd_validate_fee_payer( fd_txn_account_t * account,
     265             :                        fd_rent_t const *  rent,
     266           0 :                        ulong              fee ) {
     267             :   /* https://github.com/anza-xyz/agave/blob/v2.2.13/svm/src/account_loader.rs#L301-L304 */
     268           0 :   if( FD_UNLIKELY( fd_txn_account_get_lamports( account )==0UL ) ) {
     269           0 :     FD_LOG_DEBUG(( "Fee payer doesn't exist %s", FD_BASE58_ENC_32_ALLOCA( account->pubkey ) ));
     270           0 :     return FD_RUNTIME_TXN_ERR_ACCOUNT_NOT_FOUND;
     271           0 :   }
     272             : 
     273             :   /* https://github.com/anza-xyz/agave/blob/v2.2.13/svm/src/account_loader.rs#L305-L308 */
     274           0 :   int system_account_kind = fd_get_system_account_kind( account );
     275           0 :   if( FD_UNLIKELY( system_account_kind==FD_SYSTEM_PROGRAM_NONCE_ACCOUNT_KIND_UNKNOWN ) ) {
     276           0 :     return FD_RUNTIME_TXN_ERR_INVALID_ACCOUNT_FOR_FEE;
     277           0 :   }
     278             : 
     279             :   /* https://github.com/anza-xyz/agave/blob/v2.2.13/svm/src/account_loader.rs#L309-L318 */
     280           0 :   ulong min_balance = 0UL;
     281           0 :   if( system_account_kind==FD_SYSTEM_PROGRAM_NONCE_ACCOUNT_KIND_NONCE ) {
     282           0 :     min_balance = fd_rent_exempt_minimum_balance( rent, FD_SYSTEM_PROGRAM_NONCE_DLEN );
     283           0 :   }
     284             : 
     285             :   /* https://github.com/anza-xyz/agave/blob/v2.2.13/svm/src/account_loader.rs#L320-L327 */
     286           0 :   if( FD_UNLIKELY( min_balance>fd_txn_account_get_lamports( account ) ||
     287           0 :                    fee>fd_txn_account_get_lamports( account )-min_balance ) ) {
     288           0 :     return FD_RUNTIME_TXN_ERR_INSUFFICIENT_FUNDS_FOR_FEE;
     289           0 :   }
     290             : 
     291             :   /* https://github.com/anza-xyz/agave/blob/v2.2.13/svm/src/account_loader.rs#L329 */
     292           0 :   fd_rent_state_t payer_pre_rent_state = fd_executor_get_account_rent_state( account, rent );
     293             : 
     294             :   /* https://github.com/anza-xyz/agave/blob/v2.2.13/svm/src/account_loader.rs#L330-L332 */
     295           0 :   int err = fd_txn_account_checked_sub_lamports( account, fee );
     296           0 :   if( FD_UNLIKELY( err!=FD_EXECUTOR_INSTR_SUCCESS ) ) {
     297           0 :     return FD_RUNTIME_TXN_ERR_INSUFFICIENT_FUNDS_FOR_FEE;
     298           0 :   }
     299             : 
     300             :   /* https://github.com/anza-xyz/agave/blob/v2.2.13/svm/src/account_loader.rs#L334 */
     301           0 :   fd_rent_state_t payer_post_rent_state = fd_executor_get_account_rent_state( account, rent );
     302             : 
     303             :   /* https://github.com/anza-xyz/agave/blob/v2.2.13/svm/src/account_loader.rs#L335-L342 */
     304           0 :   return fd_executor_check_rent_state_with_account( account, &payer_pre_rent_state, &payer_post_rent_state );
     305           0 : }
     306             : 
     307             : static int
     308             : fd_executor_check_status_cache( fd_txncache_t *     status_cache,
     309             :                                 fd_bank_t *         bank,
     310             :                                 fd_txn_in_t const * txn_in,
     311           0 :                                 fd_txn_out_t *      txn_out ) {
     312           0 :   if( FD_UNLIKELY( !status_cache ) ) {
     313           0 :     return FD_RUNTIME_EXECUTE_SUCCESS;
     314           0 :   }
     315             : 
     316           0 :   if( FD_UNLIKELY( txn_out->accounts.nonce_idx_in_txn!=ULONG_MAX ) ) {
     317             :     /* In Agave, durable nonce transactions are inserted to the status
     318             :        cache the same as any others, but this is only to serve RPC
     319             :        requests, they do not need to be in there for correctness as the
     320             :        nonce mechanism itself prevents double spend.  We skip this logic
     321             :        entirely to simplify and improve performance of the txn cache. */
     322           0 :     return FD_RUNTIME_EXECUTE_SUCCESS;
     323           0 :   }
     324             : 
     325             :   /* Compute the blake3 hash of the transaction message
     326             :      https://github.com/anza-xyz/agave/blob/v2.1.7/sdk/program/src/message/versions/mod.rs#L159-L167 */
     327           0 :   fd_blake3_t b3[1];
     328           0 :   fd_blake3_init( b3 );
     329           0 :   fd_blake3_append( b3, "solana-tx-message-v1", 20UL );
     330           0 :   fd_blake3_append( b3, ((uchar *)txn_in->txn->payload + TXN( txn_in->txn )->message_off),(ulong)( txn_in->txn->payload_sz - TXN( txn_in->txn )->message_off ) );
     331           0 :   fd_blake3_fini( b3, &txn_out->details.blake_txn_msg_hash );
     332             : 
     333           0 :   fd_hash_t * blockhash = (fd_hash_t *)((uchar *)txn_in->txn->payload + TXN( txn_in->txn )->recent_blockhash_off);
     334           0 :   int found = fd_txncache_query( status_cache, bank->txncache_fork_id, blockhash->uc, txn_out->details.blake_txn_msg_hash.uc );
     335           0 :   if( FD_UNLIKELY( found ) ) return FD_RUNTIME_TXN_ERR_ALREADY_PROCESSED;
     336             : 
     337           0 :   return FD_RUNTIME_EXECUTE_SUCCESS;
     338           0 : }
     339             : 
     340             : /* https://github.com/anza-xyz/agave/blob/v2.3.1/runtime/src/bank/check_transactions.rs#L77-L141 */
     341             : static int
     342             : fd_executor_check_transaction_age_and_compute_budget_limits( fd_runtime_t *      runtime,
     343             :                                                              fd_bank_t *         bank,
     344             :                                                              fd_txn_in_t const * txn_in,
     345           0 :                                                              fd_txn_out_t *      txn_out ) {
     346             :   /* Note that in Agave, although this function is called after the
     347             :      compute budget limits are sanitized, if the transaction age checks
     348             :      fail, then we return the transaction age error instead of the
     349             :      compute budget error.
     350             :      https://github.com/anza-xyz/agave/blob/v2.3.1/runtime/src/bank/check_transactions.rs#L128-L136 */
     351           0 :   int err = fd_check_transaction_age( runtime, bank, txn_in, txn_out );
     352           0 :   if( FD_UNLIKELY( err!=FD_RUNTIME_EXECUTE_SUCCESS ) ) {
     353           0 :     return err;
     354           0 :   }
     355             : 
     356             :   /* https://github.com/anza-xyz/agave/blob/v2.3.1/runtime/src/bank/check_transactions.rs#L103 */
     357           0 :   err = fd_sanitize_compute_unit_limits( txn_out );
     358           0 :   if( FD_UNLIKELY( err!=FD_RUNTIME_EXECUTE_SUCCESS ) ) {
     359           0 :     return err;
     360           0 :   }
     361             : 
     362           0 :   return FD_RUNTIME_EXECUTE_SUCCESS;
     363           0 : }
     364             : 
     365             : /* https://github.com/anza-xyz/agave/blob/v2.0.9/runtime/src/bank.rs#L3239-L3251 */
     366             : static inline ulong
     367           0 : get_transaction_account_lock_limit( fd_bank_t * bank ) {
     368           0 :   return fd_ulong_if( FD_FEATURE_ACTIVE_BANK( bank, increase_tx_account_lock_limit ), MAX_TX_ACCOUNT_LOCKS, 64UL );
     369           0 : }
     370             : 
     371             : /* https://github.com/anza-xyz/agave/blob/v2.3.1/runtime/src/bank/check_transactions.rs#L61-L75 */
     372             : int
     373             : fd_executor_check_transactions( fd_runtime_t *      runtime,
     374             :                                 fd_bank_t *         bank,
     375             :                                 fd_txn_in_t const * txn_in,
     376           0 :                                 fd_txn_out_t *      txn_out ) {
     377             :   /* https://github.com/anza-xyz/agave/blob/v2.3.1/runtime/src/bank/check_transactions.rs#L68-L73 */
     378           0 :   int err = fd_executor_check_transaction_age_and_compute_budget_limits( runtime, bank, txn_in, txn_out );
     379           0 :   if( FD_UNLIKELY( err!=FD_RUNTIME_EXECUTE_SUCCESS ) ) {
     380           0 :     return err;
     381           0 :   }
     382             : 
     383             :   /* https://github.com/anza-xyz/agave/blob/v2.3.1/runtime/src/bank/check_transactions.rs#L74 */
     384           0 :   err = fd_executor_check_status_cache( runtime->status_cache, bank, txn_in, txn_out );
     385           0 :   if( FD_UNLIKELY( err!=FD_RUNTIME_EXECUTE_SUCCESS ) ) {
     386           0 :     return err;
     387           0 :   }
     388             : 
     389           0 :   return FD_RUNTIME_EXECUTE_SUCCESS;
     390           0 : }
     391             : 
     392             : /* `verify_transaction()` is the first function called in the
     393             :    transaction execution pipeline. It is responsible for deserializing
     394             :    the transaction, verifying the message hash (sigverify), verifying
     395             :    the precompiles, and processing compute budget instructions. We
     396             :    leave sigverify out for now to easily bypass this function's
     397             :    checks for fuzzing.
     398             : 
     399             :    TODO: Maybe support adding sigverify in here, and toggling it
     400             :    on/off with a flag.
     401             : 
     402             :    https://github.com/anza-xyz/agave/blob/v2.3.1/runtime/src/bank.rs#L5725-L5753 */
     403             : int
     404             : fd_executor_verify_transaction( fd_bank_t *         bank,
     405             :                                 fd_txn_in_t const * txn_in,
     406           0 :                                 fd_txn_out_t *      txn_out ) {
     407           0 :   int err = FD_RUNTIME_EXECUTE_SUCCESS;
     408             : 
     409             :   /* https://github.com/anza-xyz/agave/blob/v2.2.13/svm/src/transaction_processor.rs#L566-L569 */
     410           0 :   err = fd_executor_compute_budget_program_execute_instructions( bank, txn_in, txn_out );
     411           0 :   if( FD_UNLIKELY( err ) ) return err;
     412             : 
     413           0 :   return FD_RUNTIME_EXECUTE_SUCCESS;
     414           0 : }
     415             : 
     416             : /* https://github.com/anza-xyz/agave/blob/v2.0.9/svm/src/account_loader.rs#L410-427 */
     417             : static int
     418             : accumulate_and_check_loaded_account_data_size( ulong   acc_size,
     419             :                                                ulong   requested_loaded_accounts_data_size,
     420           0 :                                                ulong * accumulated_account_size ) {
     421           0 :   *accumulated_account_size = fd_ulong_sat_add( *accumulated_account_size, acc_size );
     422           0 :   if( FD_UNLIKELY( *accumulated_account_size>requested_loaded_accounts_data_size ) ) {
     423           0 :     return FD_RUNTIME_TXN_ERR_MAX_LOADED_ACCOUNTS_DATA_SIZE_EXCEEDED;
     424           0 :   }
     425           0 :   return FD_RUNTIME_EXECUTE_SUCCESS;
     426           0 : }
     427             : 
     428             : /* This function contains special casing for loading and collecting rent from
     429             :    each transaction account. The logic is as follows:
     430             :      1. If the account is the instructions sysvar, then load in the compiled
     431             :         instructions from the transactions into the sysvar's data.
     432             :      2. If the account is a fee payer, then it is already loaded.
     433             :      3. Otherwise load in the account from the accounts DB. If the account is
     434             :         writable and exists, try to collect rent from it.
     435             : 
     436             :    Returns the loaded transaction account size, which is the value that
     437             :    must be used when accumulating and checking against the
     438             :    transactions's loaded account data size limit.
     439             : 
     440             :    Agave relies on this function to actually load accounts from their
     441             :    accounts db. However, since our accounts model is slightly different,
     442             :    our account loading logic is handled earlier in the transaction
     443             :    execution pipeline within `fd_executor_setup_accounts_for_txn()`.
     444             :    Therefore, the name of this function is slightly misleading - we
     445             :    don't actually load accounts here, but we still need to collect
     446             :    rent from writable accounts and accumulate the transaction's
     447             :    total loaded account size.
     448             : 
     449             :    https://github.com/anza-xyz/agave/blob/v2.3.1/svm/src/account_loader.rs#L199-L228 */
     450             : static ulong
     451             : load_transaction_account( fd_bank_t *         bank,
     452             :                           fd_txn_in_t const * txn_in,
     453             :                           fd_txn_out_t *      txn_out,
     454             :                           fd_txn_account_t *  acct,
     455             :                           uchar               is_writable,
     456             :                           uchar               unknown_acc,
     457           0 :                           ulong               txn_idx ) {
     458             : 
     459             :   /* Handling the sysvar instructions account explictly.
     460             :      https://github.com/anza-xyz/agave/blob/v2.3.1/svm/src/account_loader.rs#L817-L824 */
     461           0 :   if( FD_UNLIKELY( !memcmp( acct->pubkey->key, fd_sysvar_instructions_id.key, sizeof(fd_pubkey_t) ) ) ) {
     462             :     /* The sysvar instructions account cannot be "loaded" since it's
     463             :        constructed by the SVM and modified within each transaction's
     464             :        instruction execution only, so it incurs a loaded size cost
     465             :        of 0. */
     466           0 :     fd_sysvar_instructions_serialize_account( bank, txn_in, txn_out, txn_idx );
     467           0 :     return 0UL;
     468           0 :   }
     469             : 
     470             :   /* This next block calls `account_loader::load_transaction_account()`
     471             :      which loads the account from the accounts db. If the account exists
     472             :      and is writable, collect rent from it.
     473             : 
     474             :      https://github.com/anza-xyz/agave/blob/v2.3.1/svm/src/account_loader.rs#L828-L835 */
     475           0 :   if( FD_LIKELY( !unknown_acc ) ) {
     476             :     /* SIMD-0186 introduces a base account size of 64 bytes for all
     477             :        transaction counts that exist prior to the transaction's
     478             :        execution.
     479             : 
     480             :        https://github.com/anza-xyz/agave/blob/v2.3.1/svm/src/account_loader.rs#L204-L208 */
     481           0 :     ulong base_account_size = FD_FEATURE_ACTIVE_BANK( bank, formalize_loaded_transaction_data_size ) ? FD_TRANSACTION_ACCOUNT_BASE_SIZE : 0UL;
     482             : 
     483             :     /* https://github.com/anza-xyz/agave/blob/v2.3.1/svm/src/account_loader.rs#L828-L835 */
     484           0 :     if( is_writable ) {
     485           0 :       acct->starting_lamports = fd_txn_account_get_lamports( acct ); /* TODO: why do we do this everywhere? */
     486           0 :     }
     487           0 :     return fd_ulong_sat_add( base_account_size, fd_txn_account_get_data_len( acct ) );
     488           0 :   }
     489             : 
     490             :   /* The rest of this function is a no-op for us since we already set up
     491             :      the transaction accounts for unknown accounts within
     492             :      `fd_executor_setup_accounts_for_txn()`. We also do not need to
     493             :      add a base cost to the loaded account size because the SIMD
     494             :      states that accounts that do not exist prior to the transaction's
     495             :      execution should not incur a loaded size cost.
     496             :      https://github.com/anza-xyz/agave/blob/v2.2.0/svm/src/account_loader.rs#L566-L577 */
     497           0 :   return 0UL;
     498           0 : }
     499             : 
     500             : /* This big function contains a lot of logic and special casing for loading transaction accounts.
     501             :    Because of the `enable_transaction_loading_failure_fees` feature, it is imperative that we
     502             :    are conformant with Agave's logic here and reject / accept transactions here where they do.
     503             : 
     504             :    In the firedancer client only some of these steps are necessary because
     505             :    all of the accounts are loaded in from the accounts db into borrowed
     506             :    accounts already.
     507             : 
     508             :    https://github.com/anza-xyz/agave/blob/v2.3.1/svm/src/account_loader.rs#L691-L807 */
     509             : static int
     510             : fd_executor_load_transaction_accounts_old( fd_runtime_t *      runtime,
     511             :                                            fd_bank_t *         bank,
     512             :                                            fd_txn_in_t const * txn_in,
     513           0 :                                            fd_txn_out_t *      txn_out ) {
     514           0 :   ulong requested_loaded_accounts_data_size = txn_out->details.compute_budget.loaded_accounts_data_size_limit;
     515             : 
     516             :   /* https://github.com/anza-xyz/agave/blob/v2.2.0/svm/src/account_loader.rs#L429-L443 */
     517           0 :   for( ushort i=0; i<txn_out->accounts.accounts_cnt; i++ ) {
     518           0 :     fd_txn_account_t * acct = &txn_out->accounts.accounts[i];
     519           0 :     uchar unknown_acc = !!(fd_runtime_get_account_at_index( txn_in, txn_out, i, &acct, fd_runtime_account_check_exists ) ||
     520           0 :                             fd_txn_account_get_lamports( acct )==0UL);
     521           0 :     uchar is_writable = !!(fd_runtime_account_is_writable_idx( txn_in, txn_out, bank, i ));
     522             : 
     523             :     /* Collect the fee payer account separately (since it was already)
     524             :        loaded during fee payer validation.
     525             : 
     526             :        https://github.com/anza-xyz/agave/blob/v2.3.1/svm/src/account_loader.rs#L727-L729 */
     527           0 :     if( FD_UNLIKELY( i==FD_FEE_PAYER_TXN_IDX ) ) {
     528             :       /* Note that the dlen for most fee payers is 0, but we want to
     529             :          consider the case where the fee payer is a nonce account.
     530             :          We also don't need to add a base account size to this value
     531             :          because this branch would only be taken BEFORE SIMD-0186
     532             :          is enabled. */
     533           0 :       int err = accumulate_and_check_loaded_account_data_size( fd_txn_account_get_data_len( acct ),
     534           0 :                                                                requested_loaded_accounts_data_size,
     535           0 :                                                                &txn_out->details.loaded_accounts_data_size );
     536           0 :       if( FD_UNLIKELY( err!=FD_RUNTIME_EXECUTE_SUCCESS ) ) {
     537           0 :         return err;
     538           0 :       }
     539           0 :       continue;
     540           0 :     }
     541             : 
     542             :     /* https://github.com/anza-xyz/agave/blob/v2.3.1/svm/src/account_loader.rs#L733-L740 */
     543           0 :     ulong loaded_acc_size = load_transaction_account( bank, txn_in, txn_out, acct, is_writable, unknown_acc, i );
     544           0 :     int err = accumulate_and_check_loaded_account_data_size( loaded_acc_size,
     545           0 :                                                              requested_loaded_accounts_data_size,
     546           0 :                                                              &txn_out->details.loaded_accounts_data_size );
     547             : 
     548           0 :     if( FD_UNLIKELY( err!=FD_RUNTIME_EXECUTE_SUCCESS ) ) {
     549           0 :       return err;
     550           0 :     }
     551           0 :   }
     552             : 
     553             :   /* TODO: Consider using a hash set (if its more performant) */
     554           0 :   ushort            instr_cnt             = TXN( txn_in->txn )->instr_cnt;
     555           0 :   fd_pubkey_t       validated_loaders[instr_cnt];
     556           0 :   ushort            validated_loaders_cnt = 0;
     557           0 :   fd_funk_txn_xid_t xid                   = { .ul = { fd_bank_slot_get( bank ), bank->idx } };
     558             : 
     559             :   /* The logic below handles special casing with loading instruction accounts.
     560             :      https://github.com/anza-xyz/agave/blob/v2.2.0/svm/src/account_loader.rs#L445-L525 */
     561           0 :   for( ushort i=0; i<instr_cnt; i++ ) {
     562           0 :     fd_txn_instr_t const * instr = &TXN( txn_in->txn )->instr[i];
     563             : 
     564             :     /* https://github.com/anza-xyz/agave/blob/v2.2.0/svm/src/account_loader.rs#L449-L451 */
     565           0 :     if( FD_UNLIKELY( !memcmp( txn_out->accounts.account_keys[ instr->program_id ].key, fd_solana_native_loader_id.key, sizeof(fd_pubkey_t) ) ) ) {
     566           0 :       continue;
     567           0 :     }
     568             : 
     569             :     /* Mimicking `load_account()` here with 0-lamport check as well.
     570             :        https://github.com/anza-xyz/agave/blob/v2.2.0/svm/src/account_loader.rs#L455-L462 */
     571           0 :     fd_txn_account_t * program_account = NULL;
     572           0 :     int err = fd_runtime_get_account_at_index( txn_in,
     573           0 :                                                txn_out,
     574           0 :                                                instr->program_id,
     575           0 :                                                &program_account,
     576           0 :                                                fd_runtime_account_check_exists );
     577           0 :     if( FD_UNLIKELY( err!=FD_ACC_MGR_SUCCESS || fd_txn_account_get_lamports( program_account )==0UL ) ) {
     578           0 :       return FD_RUNTIME_TXN_ERR_PROGRAM_ACCOUNT_NOT_FOUND;
     579           0 :     }
     580             : 
     581             :     /* https://github.com/anza-xyz/agave/blob/v2.2.0/svm/src/account_loader.rs#L474-L477 */
     582           0 :     if( !memcmp( fd_txn_account_get_owner( program_account ), fd_solana_native_loader_id.key, sizeof(fd_pubkey_t) ) ) {
     583           0 :       continue;
     584           0 :     }
     585             : 
     586             :     /* https://github.com/anza-xyz/agave/blob/v2.2.0/svm/src/account_loader.rs#L479-L522 */
     587           0 :     uchar loader_seen = 0;
     588           0 :     for( ushort j=0; j<validated_loaders_cnt; j++ ) {
     589           0 :       if( !memcmp( validated_loaders[j].key, fd_txn_account_get_owner( program_account ), sizeof(fd_pubkey_t) ) ) {
     590             :         /* If the owner account has already been seen, skip the owner checks
     591             :            and do not acccumulate the account size. */
     592           0 :         loader_seen = 1;
     593           0 :         break;
     594           0 :       }
     595           0 :     }
     596           0 :     if( loader_seen ) continue;
     597             : 
     598             :     /* The agave client does checks on the program account's owners as well.
     599             :        However, it is important to not do these checks multiple times as the
     600             :        total size of accounts and their owners are accumulated: duplicate owners
     601             :        should be avoided.
     602             :        https://github.com/anza-xyz/agave/blob/v2.2.0/svm/src/account_loader.rs#L496-L517 */
     603           0 :     fd_txn_account_t owner_account[1];
     604           0 :     err = fd_txn_account_init_from_funk_readonly( owner_account,
     605           0 :                                                   fd_txn_account_get_owner( program_account ),
     606           0 :                                                   runtime->funk,
     607           0 :                                                   &xid );
     608           0 :     if( FD_UNLIKELY( err!=FD_ACC_MGR_SUCCESS ) ) {
     609             :       /* https://github.com/anza-xyz/agave/blob/v2.2.0/svm/src/account_loader.rs#L520 */
     610           0 :       return FD_RUNTIME_TXN_ERR_PROGRAM_ACCOUNT_NOT_FOUND;
     611           0 :     }
     612             : 
     613             : 
     614             :     /* https://github.com/anza-xyz/agave/blob/v2.2.0/svm/src/account_loader.rs#L502-L510 */
     615           0 :     if( FD_UNLIKELY( memcmp( fd_txn_account_get_owner( owner_account ), fd_solana_native_loader_id.key, sizeof(fd_pubkey_t) ) ) ) {
     616           0 :       return FD_RUNTIME_TXN_ERR_INVALID_PROGRAM_FOR_EXECUTION;
     617           0 :     }
     618             : 
     619             :     /* Count the owner's data in the loaded account size for program accounts.
     620             :        However, it is important to not double count repeated owners.
     621             :        https://github.com/anza-xyz/agave/blob/v2.2.0/svm/src/account_loader.rs#L511-L517 */
     622           0 :     err = accumulate_and_check_loaded_account_data_size( fd_txn_account_get_data_len( owner_account ),
     623           0 :                                                          requested_loaded_accounts_data_size,
     624           0 :                                                          &txn_out->details.loaded_accounts_data_size );
     625           0 :     if( FD_UNLIKELY( err!=FD_RUNTIME_EXECUTE_SUCCESS ) ) {
     626           0 :       return err;
     627           0 :     }
     628             : 
     629           0 :     fd_memcpy( validated_loaders[ validated_loaders_cnt++ ].key, owner_account->pubkey, sizeof(fd_pubkey_t) );
     630           0 :   }
     631             : 
     632           0 :   return FD_RUNTIME_EXECUTE_SUCCESS;
     633           0 : }
     634             : 
     635             : /* https://github.com/anza-xyz/agave/blob/v2.3.1/svm/src/account_loader.rs#L494-L515 */
     636             : static int
     637             : fd_increase_calculated_data_size( fd_txn_out_t * txn_out,
     638           0 :                                   ulong          data_size_delta ) {
     639             :   /* https://github.com/anza-xyz/agave/blob/v2.3.1/svm/src/account_loader.rs#L500-L503 */
     640           0 :   if( FD_UNLIKELY( data_size_delta>UINT_MAX ) ) {
     641           0 :     return FD_RUNTIME_TXN_ERR_MAX_LOADED_ACCOUNTS_DATA_SIZE_EXCEEDED;
     642           0 :   }
     643             : 
     644             :   /* https://github.com/anza-xyz/agave/blob/v2.3.1/svm/src/account_loader.rs#L505-L507 */
     645           0 :   txn_out->details.loaded_accounts_data_size = fd_ulong_sat_add( txn_out->details.loaded_accounts_data_size, data_size_delta );
     646             : 
     647           0 :   if( FD_UNLIKELY( txn_out->details.loaded_accounts_data_size>txn_out->details.compute_budget.loaded_accounts_data_size_limit ) ) {
     648           0 :     return FD_RUNTIME_TXN_ERR_MAX_LOADED_ACCOUNTS_DATA_SIZE_EXCEEDED;
     649           0 :   }
     650             : 
     651           0 :   return FD_RUNTIME_EXECUTE_SUCCESS;
     652           0 : }
     653             : 
     654             : /* This function is represented as a closure in Agave.
     655             :    https://github.com/anza-xyz/agave/blob/v2.3.1/svm/src/account_loader.rs#L578-L640 */
     656             : static int
     657             : fd_collect_loaded_account( fd_runtime_t *           runtime,
     658             :                            fd_txn_out_t *           txn_out,
     659             :                            fd_bank_t *              bank,
     660             :                            fd_txn_account_t const * account,
     661             :                            ulong                    loaded_acc_size,
     662             :                            fd_pubkey_t *            additional_loaded_account_keys,
     663           0 :                            ulong *                  additional_loaded_account_keys_cnt ) {
     664             : 
     665             :   /* https://github.com/anza-xyz/agave/blob/v2.3.1/svm/src/account_loader.rs#L586-L590 */
     666           0 :   int err = fd_increase_calculated_data_size( txn_out, loaded_acc_size );
     667           0 :   if( FD_UNLIKELY( err!=FD_RUNTIME_EXECUTE_SUCCESS ) ) {
     668           0 :     return err;
     669           0 :   }
     670             : 
     671             :   /* The remainder of this function is a deep-nested set of if
     672             :      statements. I've inverted the logic to make it easier to read.
     673             :      The purpose of the following code is to ensure that loader v3
     674             :      programdata accounts are accounted for exactly once in the account
     675             :      loading logic.
     676             : 
     677             :      https://github.com/anza-xyz/agave/blob/v2.3.1/svm/src/account_loader.rs#L611 */
     678           0 :   if( FD_LIKELY( memcmp( fd_txn_account_get_owner( account ), fd_solana_bpf_loader_upgradeable_program_id.key, sizeof(fd_pubkey_t) ) ) ) {
     679           0 :     return FD_RUNTIME_EXECUTE_SUCCESS;
     680           0 :   }
     681             : 
     682             :   /* Try to read the program state
     683             :      https://github.com/anza-xyz/agave/blob/v2.3.1/svm/src/account_loader.rs#L612-L634 */
     684           0 :   fd_bpf_upgradeable_loader_state_t loader_state[1];
     685           0 :   err = fd_bpf_loader_program_get_state( account, loader_state );
     686           0 :   if( FD_UNLIKELY( err!=FD_EXECUTOR_INSTR_SUCCESS ) ) {
     687           0 :     return FD_RUNTIME_EXECUTE_SUCCESS;
     688           0 :   }
     689             : 
     690             :   /* Make sure the account is a v3 program */
     691           0 :   if( !fd_bpf_upgradeable_loader_state_is_program( loader_state ) ) {
     692           0 :     return FD_RUNTIME_EXECUTE_SUCCESS;
     693           0 :   }
     694             : 
     695             :   /* Iterate through the account keys and make sure the programdata
     696             :      account is not present so it doesn't get loaded twice.
     697             :      https://github.com/anza-xyz/agave/blob/v2.3.1/svm/src/account_loader.rs#L617 */
     698           0 :   for( ushort i=0; i<txn_out->accounts.accounts_cnt; i++ ) {
     699           0 :     if( FD_UNLIKELY( !memcmp( &txn_out->accounts.account_keys[i], &loader_state->inner.program.programdata_address, sizeof(fd_pubkey_t) ) ) ) {
     700           0 :       return FD_RUNTIME_EXECUTE_SUCCESS;
     701           0 :     }
     702           0 :   }
     703             : 
     704             :   /* Check that the programdata account has not been already counted
     705             :      https://github.com/anza-xyz/agave/blob/v2.3.1/svm/src/account_loader.rs#L618 */
     706           0 :   for( ushort i=0; i<*additional_loaded_account_keys_cnt; i++ ) {
     707           0 :     if( FD_UNLIKELY( !memcmp( &additional_loaded_account_keys[i], &loader_state->inner.program.programdata_address, sizeof(fd_pubkey_t) ) ) ) {
     708           0 :       return FD_RUNTIME_EXECUTE_SUCCESS;
     709           0 :     }
     710           0 :   }
     711             : 
     712             :   /* Load the programdata account from Funk to read the programdata length */
     713           0 :   fd_txn_account_t  programdata_account[1];
     714           0 :   fd_funk_txn_xid_t xid = { .ul = { fd_bank_slot_get( bank ), bank->idx } };
     715           0 :   err = fd_txn_account_init_from_funk_readonly( programdata_account,
     716           0 :                                                 &loader_state->inner.program.programdata_address,
     717           0 :                                                 runtime->funk,
     718           0 :                                                 &xid );
     719           0 :   if( FD_UNLIKELY( err!=FD_ACC_MGR_SUCCESS ) ) {
     720           0 :     return FD_RUNTIME_EXECUTE_SUCCESS;
     721           0 :   }
     722             : 
     723             :   /* Try to accumulate the programdata's data size
     724             :      https://github.com/anza-xyz/agave/blob/v2.3.1/svm/src/account_loader.rs#L625-L630 */
     725           0 :   ulong programdata_size_delta = fd_ulong_sat_add( FD_TRANSACTION_ACCOUNT_BASE_SIZE,
     726           0 :                                                    fd_txn_account_get_data_len( programdata_account ) );
     727           0 :   err = fd_increase_calculated_data_size( txn_out, programdata_size_delta );
     728           0 :   if( FD_UNLIKELY( err!=FD_RUNTIME_EXECUTE_SUCCESS ) ) {
     729           0 :     return err;
     730           0 :   }
     731             : 
     732             :   /* Add the programdata account to the list of loaded programdata accounts
     733             :      https://github.com/anza-xyz/agave/blob/v2.3.1/svm/src/account_loader.rs#L631 */
     734           0 :   fd_memcpy(
     735           0 :     &additional_loaded_account_keys[(*additional_loaded_account_keys_cnt)++],
     736           0 :     &loader_state->inner.program.programdata_address,
     737           0 :     sizeof(fd_pubkey_t) );
     738             : 
     739           0 :   return FD_RUNTIME_EXECUTE_SUCCESS;
     740           0 : }
     741             : 
     742             : /* Simplified transaction loading logic for SIMD-0186 which does the
     743             :    following:
     744             :    - Calculates the loaded data size for each address lookup table
     745             :    - Calculates the loaded data size for each transaction account
     746             :    - Calculates the loaded data size for each v3 programdata account
     747             :      not directly referenced in the transaction accounts
     748             :    - Collects rent from all referenced transaction accounts (excluding
     749             :      the fee payer)
     750             :    - Validates that each program invoked in a top-level instruction
     751             :      exists, is executable, and is owned by either the native loader
     752             :      or a bpf loader
     753             : 
     754             :    https://github.com/anza-xyz/agave/blob/v2.3.1/svm/src/account_loader.rs#L550-L689 */
     755             : static int
     756             : fd_executor_load_transaction_accounts_simd_186( fd_runtime_t *      runtime,
     757             :                                                 fd_bank_t *         bank,
     758             :                                                 fd_txn_in_t const * txn_in,
     759           0 :                                                 fd_txn_out_t *      txn_out ) {
     760             :   /* Programdata accounts that are loaded by this transaction.
     761             :      We keep track of these to ensure they are not counted twice.
     762             :      https://github.com/anza-xyz/agave/blob/v2.3.1/svm/src/account_loader.rs#L559 */
     763           0 :   fd_pubkey_t additional_loaded_account_keys[ FD_TXN_ACCT_ADDR_MAX ] = { 0 };
     764           0 :   ulong       additional_loaded_account_keys_cnt                     = 0UL;
     765             : 
     766             :   /* Charge a base fee for each address lookup table.
     767             :      https://github.com/anza-xyz/agave/blob/v2.3.1/svm/src/account_loader.rs#L570-L576 */
     768           0 :   ulong aluts_size = fd_ulong_sat_mul( TXN( txn_in->txn )->addr_table_lookup_cnt,
     769           0 :                                        FD_ADDRESS_LOOKUP_TABLE_BASE_SIZE );
     770           0 :   int err = fd_increase_calculated_data_size( txn_out, aluts_size );
     771           0 :   if( FD_UNLIKELY( err!=FD_RUNTIME_EXECUTE_SUCCESS ) ) {
     772           0 :     return err;
     773           0 :   }
     774             : 
     775             :   /* https://github.com/anza-xyz/agave/blob/v2.3.1/svm/src/account_loader.rs#L642-L660 */
     776           0 :   for( ushort i=0; i<txn_out->accounts.accounts_cnt; i++ ) {
     777           0 :     fd_txn_account_t * acct = &txn_out->accounts.accounts[i];
     778           0 :     uchar unknown_acc = !!(fd_runtime_get_account_at_index( txn_in, txn_out, i, &acct, fd_runtime_account_check_exists ) ||
     779           0 :                             fd_txn_account_get_lamports( acct )==0UL);
     780           0 :     uchar is_writable = !!(fd_runtime_account_is_writable_idx( txn_in, txn_out, bank, i ));
     781             : 
     782             :     /* Collect the fee payer account separately (since it was already)
     783             :        loaded during fee payer validation.
     784             : 
     785             :        https://github.com/anza-xyz/agave/blob/v2.3.1/svm/src/account_loader.rs#L644-L648 */
     786           0 :     if( FD_UNLIKELY( i==FD_FEE_PAYER_TXN_IDX ) ) {
     787             :       /* Note that the dlen for most fee payers is 0, but we want to
     788             :          consider the case where the fee payer is a nonce account.
     789             :          We also must add a base account size to this value
     790             :          because this branch would only be taken AFTER SIMD-0186
     791             :          is enabled. */
     792           0 :       ulong loaded_acc_size = fd_ulong_sat_add( FD_TRANSACTION_ACCOUNT_BASE_SIZE,
     793           0 :                                                 fd_txn_account_get_data_len( acct ) );
     794           0 :       int err = fd_collect_loaded_account(
     795           0 :         runtime,
     796           0 :         txn_out,
     797           0 :         bank,
     798           0 :         acct,
     799           0 :         loaded_acc_size,
     800           0 :         additional_loaded_account_keys,
     801           0 :         &additional_loaded_account_keys_cnt );
     802           0 :       if( FD_UNLIKELY( err!=FD_RUNTIME_EXECUTE_SUCCESS ) ) {
     803           0 :         return err;
     804           0 :       }
     805           0 :       continue;
     806           0 :     }
     807             : 
     808             :     /* Load and collect any remaining accounts
     809             :        https://github.com/anza-xyz/agave/blob/v2.3.1/svm/src/account_loader.rs#L652-L659 */
     810           0 :     ulong loaded_acc_size = load_transaction_account( bank, txn_in, txn_out, acct, is_writable, unknown_acc, i );
     811           0 :     int err = fd_collect_loaded_account(
     812           0 :       runtime,
     813           0 :       txn_out,
     814           0 :       bank,
     815           0 :       acct,
     816           0 :       loaded_acc_size,
     817           0 :       additional_loaded_account_keys,
     818           0 :       &additional_loaded_account_keys_cnt );
     819           0 :     if( FD_UNLIKELY( err!=FD_RUNTIME_EXECUTE_SUCCESS ) ) {
     820           0 :       return err;
     821           0 :     }
     822           0 :   }
     823             : 
     824             :   /* https://github.com/anza-xyz/agave/blob/v2.3.1/svm/src/account_loader.rs#L662-L686 */
     825           0 :   ushort instr_cnt = TXN( txn_in->txn )->instr_cnt;
     826           0 :   for( ushort i=0; i<instr_cnt; i++ ) {
     827           0 :     fd_txn_instr_t const * instr = &TXN( txn_in->txn )->instr[i];
     828             : 
     829             :     /* Mimicking `load_account()` here with 0-lamport check as well.
     830             :        https://github.com/anza-xyz/agave/blob/v2.3.1/svm/src/account_loader.rs#L663-L666 */
     831           0 :     fd_txn_account_t * program_account;
     832           0 :     int err = fd_runtime_get_account_at_index( txn_in,
     833           0 :                                                txn_out,
     834           0 :                                                instr->program_id,
     835           0 :                                                &program_account,
     836           0 :                                                fd_runtime_account_check_exists );
     837           0 :     if( FD_UNLIKELY( err!=FD_ACC_MGR_SUCCESS || fd_txn_account_get_lamports( program_account )==0UL ) ) {
     838           0 :       return FD_RUNTIME_TXN_ERR_PROGRAM_ACCOUNT_NOT_FOUND;
     839           0 :     }
     840             : 
     841             :     /* https://github.com/anza-xyz/agave/blob/v2.3.1/svm/src/account_loader.rs#L677-L681 */
     842           0 :     fd_pubkey_t const * owner_id = fd_txn_account_get_owner( program_account );
     843           0 :     if( FD_UNLIKELY( memcmp( owner_id->key, fd_solana_native_loader_id.key, sizeof(fd_pubkey_t) ) &&
     844           0 :                      !fd_executor_pubkey_is_bpf_loader( owner_id ) ) ) {
     845           0 :       return FD_RUNTIME_TXN_ERR_INVALID_PROGRAM_FOR_EXECUTION;
     846           0 :     }
     847           0 :   }
     848             : 
     849           0 :   return FD_RUNTIME_EXECUTE_SUCCESS;
     850           0 : }
     851             : 
     852             : /* https://github.com/anza-xyz/agave/blob/v2.3.1/svm/src/account_loader.rs#L518-L548 */
     853             : int
     854             : fd_executor_load_transaction_accounts( fd_runtime_t *      runtime,
     855             :                                        fd_bank_t *         bank,
     856             :                                        fd_txn_in_t const * txn_in,
     857           0 :                                        fd_txn_out_t *      txn_out ) {
     858           0 :   if( FD_FEATURE_ACTIVE_BANK( bank, formalize_loaded_transaction_data_size ) ) {
     859           0 :     return fd_executor_load_transaction_accounts_simd_186( runtime, bank, txn_in, txn_out );
     860           0 :   } else {
     861           0 :     return fd_executor_load_transaction_accounts_old( runtime, bank, txn_in, txn_out );
     862           0 :   }
     863           0 : }
     864             : 
     865             : /* https://github.com/anza-xyz/agave/blob/838c1952595809a31520ff1603a13f2c9123aa51/accounts-db/src/account_locks.rs#L118 */
     866             : int
     867             : fd_executor_validate_account_locks( fd_bank_t *          bank,
     868           0 :                                     fd_txn_out_t const * txn_out ) {
     869             :   /* Ensure the number of account keys does not exceed the transaction lock limit
     870             :      https://github.com/anza-xyz/agave/blob/v2.2.17/accounts-db/src/account_locks.rs#L121 */
     871           0 :   ulong tx_account_lock_limit = get_transaction_account_lock_limit( bank );
     872           0 :   if( FD_UNLIKELY( txn_out->accounts.accounts_cnt>tx_account_lock_limit ) ) {
     873           0 :     return FD_RUNTIME_TXN_ERR_TOO_MANY_ACCOUNT_LOCKS;
     874           0 :   }
     875             : 
     876             :   /* Duplicate account check
     877             :      https://github.com/anza-xyz/agave/blob/v2.2.17/accounts-db/src/account_locks.rs#L123 */
     878           0 :   for( ushort i=0; i<txn_out->accounts.accounts_cnt; i++ ) {
     879           0 :     for( ushort j=(ushort)(i+1U); j<txn_out->accounts.accounts_cnt; j++ ) {
     880           0 :       if( FD_UNLIKELY( !memcmp( &txn_out->accounts.account_keys[i], &txn_out->accounts.account_keys[j], sizeof(fd_pubkey_t) ) ) ) {
     881           0 :         return FD_RUNTIME_TXN_ERR_ACCOUNT_LOADED_TWICE;
     882           0 :       }
     883           0 :     }
     884           0 :   }
     885             : 
     886             :   /* https://github.com/anza-xyz/agave/blob/v2.2.17/accounts-db/src/account_locks.rs#L124-L126 */
     887           0 :   return FD_RUNTIME_EXECUTE_SUCCESS;
     888           0 : }
     889             : 
     890             : /* https://github.com/anza-xyz/agave/blob/v2.3.1/compute-budget/src/compute_budget_limits.rs#L62-L70 */
     891             : static ulong
     892           0 : fd_get_prioritization_fee( fd_compute_budget_details_t const * compute_budget_details ) {
     893           0 :   uint128 micro_lamport_fee = fd_uint128_sat_mul( compute_budget_details->compute_unit_price, compute_budget_details->compute_unit_limit );
     894           0 :   uint128 fee = fd_uint128_sat_add( micro_lamport_fee, MICRO_LAMPORTS_PER_LAMPORT-1UL ) / MICRO_LAMPORTS_PER_LAMPORT;
     895           0 :   return fee>(uint128)ULONG_MAX ? ULONG_MAX : (ulong)fee;
     896           0 : }
     897             : 
     898             : static void
     899             : fd_executor_calculate_fee( fd_bank_t *      bank,
     900             :                            fd_txn_out_t *   txn_out,
     901             :                            fd_txn_t const * txn_descriptor,
     902             :                            uchar const *    payload,
     903             :                            ulong *          ret_execution_fee,
     904           0 :                            ulong *          ret_priority_fee ) {
     905             :   /* The execution fee is just the signature fee. The priority fee
     906             :      is calculated based on the compute budget details.
     907             :      https://github.com/anza-xyz/agave/blob/v3.0.3/fee/src/lib.rs#L65-L84 */
     908             : 
     909             :   // let signature_fee = Self::get_num_signatures_in_message(message) .saturating_mul(fee_structure.lamports_per_signature);
     910           0 :   ulong num_signatures = txn_descriptor->signature_cnt;
     911           0 :   for (ushort i=0; i<txn_descriptor->instr_cnt; ++i ) {
     912           0 :     fd_txn_instr_t const * txn_instr  = &txn_descriptor->instr[i];
     913           0 :     fd_pubkey_t *          program_id = &txn_out->accounts.account_keys[txn_instr->program_id];
     914           0 :     if( !memcmp(program_id->uc, fd_solana_keccak_secp_256k_program_id.key, sizeof(fd_pubkey_t)) ||
     915           0 :         !memcmp(program_id->uc, fd_solana_ed25519_sig_verify_program_id.key, sizeof(fd_pubkey_t)) ||
     916           0 :         (!memcmp(program_id->uc, fd_solana_secp256r1_program_id.key, sizeof(fd_pubkey_t)) && FD_FEATURE_ACTIVE_BANK( bank, enable_secp256r1_precompile )) ) {
     917           0 :       if( !txn_instr->data_sz ) {
     918           0 :         continue;
     919           0 :       }
     920           0 :       uchar const * data = payload + txn_instr->data_off;
     921           0 :       num_signatures     = fd_ulong_sat_add(num_signatures, (ulong)(data[0]));
     922           0 :     }
     923           0 :   }
     924           0 :   *ret_execution_fee = FD_RUNTIME_FEE_STRUCTURE_LAMPORTS_PER_SIGNATURE * num_signatures;
     925           0 :   *ret_priority_fee  = fd_get_prioritization_fee( &txn_out->details.compute_budget );
     926           0 : }
     927             : 
     928             : /* This function creates a rollback account for just the fee payer. Although Agave
     929             :    also sets up rollback accounts for both the fee payer and nonce account here,
     930             :    we already set up the rollback nonce account in earlier sanitization checks. Here
     931             :    we have to capture the entire fee payer record so that if the transaction fails,
     932             :    the fee payer state can be rolled back to it's state pre-transaction, and then debited
     933             :    any transaction fees.
     934             : 
     935             :    Our implementation is slightly different than Agave's in several ways:
     936             :    1. The rollback nonce account has already been set up when checking the transaction age
     937             :    2. When the nonce and fee payer accounts are the same...
     938             :       - Agave copies the data from the rollback nonce account into the rollback fee payer account,
     939             :         and then uses that new fee payer account as the rollback account.
     940             :       - We simply set the rent epoch and lamports of the rollback nonce account (since the other fields
     941             :         of the account do not change)
     942             : 
     943             :    https://github.com/anza-xyz/agave/blob/v2.2.13/svm/src/rollback_accounts.rs#L34-L77 */
     944             : static void
     945             : fd_executor_create_rollback_fee_payer_account( fd_runtime_t *      runtime,
     946             :                                                fd_bank_t *         bank,
     947             :                                                fd_txn_in_t const * txn_in,
     948             :                                                fd_txn_out_t *      txn_out,
     949           0 :                                                ulong               total_fee ) {
     950           0 :   fd_pubkey_t *      fee_payer_key = &txn_out->accounts.account_keys[FD_FEE_PAYER_TXN_IDX];
     951           0 :   fd_txn_account_t * rollback_fee_payer_acc;
     952             : 
     953             :   /* When setting the data of the rollback fee payer, there is an edge
     954             :      case where the fee payer is the nonce account.  In this case, we
     955             :      can just deduct fees from the nonce account and return, because
     956             :      we save the nonce account in the commit phase anyways. */
     957           0 :   if( FD_UNLIKELY( txn_out->accounts.nonce_idx_in_txn==FD_FEE_PAYER_TXN_IDX ) ) {
     958           0 :     rollback_fee_payer_acc = txn_out->accounts.rollback_nonce;
     959           0 :   } else {
     960           0 :     fd_account_meta_t const * meta = NULL;
     961           0 :     if( FD_UNLIKELY( txn_in->bundle.is_bundle ) ) {
     962           0 :       int is_found = 0;
     963           0 :       for( ulong i=txn_in->bundle.prev_txn_cnt; i>0UL && !is_found; i-- ) {;
     964           0 :         fd_txn_in_t const *  prev_txn_in  = txn_in->bundle.prev_txn_ins[ i-1 ];
     965           0 :         fd_txn_out_t const * prev_txn_out = txn_in->bundle.prev_txn_outs[ i-1 ];
     966           0 :         for( ushort j=0UL; j<prev_txn_out->accounts.accounts_cnt; j++ ) {
     967           0 :           if( !memcmp( &prev_txn_out->accounts.account_keys[ j ], fee_payer_key, sizeof(fd_pubkey_t) ) &&
     968           0 :             fd_runtime_account_is_writable_idx( prev_txn_in, prev_txn_out, bank, j ) ) {
     969             :             /* Found the account in a previous transaction */
     970           0 :             meta = prev_txn_out->accounts.accounts[ j ].meta;
     971           0 :             is_found = 1;
     972           0 :             break;
     973           0 :           }
     974           0 :         }
     975           0 :       }
     976           0 :     }
     977             : 
     978           0 :     int err = FD_ACC_MGR_SUCCESS;
     979           0 :     if( !meta ) {
     980           0 :       fd_funk_txn_xid_t xid = { .ul = { fd_bank_slot_get( bank ), bank->idx } };
     981           0 :       meta = fd_funk_get_acc_meta_readonly(
     982           0 :           runtime->funk,
     983           0 :           &xid,
     984           0 :           fee_payer_key,
     985           0 :           NULL,
     986           0 :           &err,
     987           0 :           NULL );
     988           0 :     }
     989             : 
     990           0 :     uchar * fee_payer_data = txn_in->exec_accounts->rollback_fee_payer_mem;
     991           0 :     fd_memcpy( fee_payer_data, (uchar *)meta, sizeof(fd_account_meta_t) + meta->dlen );
     992           0 :     if( FD_UNLIKELY( !fd_txn_account_join( fd_txn_account_new(
     993           0 :           txn_out->accounts.rollback_fee_payer,
     994           0 :           fee_payer_key,
     995           0 :           (fd_account_meta_t *)fee_payer_data,
     996           0 :           1 ) ) ) ) {
     997           0 :       FD_LOG_CRIT(( "Failed to join txn account" ));
     998           0 :     }
     999             : 
    1000           0 :     rollback_fee_payer_acc = txn_out->accounts.rollback_fee_payer;
    1001           0 :   }
    1002             : 
    1003             :   /* Deduct the transaction fees from the rollback account. Because of prior checks, this should never fail. */
    1004           0 :   if( FD_UNLIKELY( fd_txn_account_checked_sub_lamports( rollback_fee_payer_acc, total_fee ) ) ) {
    1005           0 :     FD_LOG_ERR(( "fd_executor_create_rollback_fee_payer_account(): failed to deduct fees from rollback account" ));
    1006           0 :   }
    1007           0 : }
    1008             : 
    1009             : /* https://github.com/anza-xyz/agave/blob/v2.2.13/svm/src/transaction_processor.rs#L557-L634 */
    1010             : int
    1011             : fd_executor_validate_transaction_fee_payer( fd_runtime_t *      runtime,
    1012             :                                             fd_bank_t *         bank,
    1013             :                                             fd_txn_in_t const * txn_in,
    1014           0 :                                             fd_txn_out_t *      txn_out ) {
    1015             :   /* https://github.com/anza-xyz/agave/blob/v2.2.13/svm/src/transaction_processor.rs#L574-L580 */
    1016           0 :   fd_txn_account_t * fee_payer_rec = NULL;
    1017           0 :   int err = fd_runtime_get_account_at_index( txn_in,
    1018           0 :                                              txn_out,
    1019           0 :                                              FD_FEE_PAYER_TXN_IDX,
    1020           0 :                                              &fee_payer_rec,
    1021           0 :                                              fd_runtime_account_check_fee_payer_writable );
    1022           0 :   if( FD_UNLIKELY( err!=FD_ACC_MGR_SUCCESS ) ) {
    1023           0 :     FD_LOG_DEBUG(( "Fee payer isn't writable %s", FD_BASE58_ENC_32_ALLOCA( fee_payer_rec->pubkey ) ));
    1024           0 :     return FD_RUNTIME_TXN_ERR_ACCOUNT_NOT_FOUND;
    1025           0 :   }
    1026             : 
    1027             : 
    1028             :   /* Calculate transaction fees
    1029             :      https://github.com/anza-xyz/agave/blob/v2.2.13/svm/src/transaction_processor.rs#L597-L606 */
    1030           0 :   ulong execution_fee = 0UL;
    1031           0 :   ulong priority_fee  = 0UL;
    1032             : 
    1033           0 :   fd_executor_calculate_fee( bank, txn_out, TXN( txn_in->txn ), txn_in->txn->payload, &execution_fee, &priority_fee );
    1034           0 :   ulong total_fee = fd_ulong_sat_add( execution_fee, priority_fee );
    1035             : 
    1036           0 :   if( !FD_FEATURE_ACTIVE_BANK( bank, remove_rounding_in_fee_calculation ) ) {
    1037           0 :     total_fee = fd_rust_cast_double_to_ulong( round( (double)total_fee ) );
    1038           0 :   }
    1039             : 
    1040             :   /* https://github.com/anza-xyz/agave/blob/v2.2.13/svm/src/transaction_processor.rs#L609-L616 */
    1041           0 :   err = fd_validate_fee_payer( fee_payer_rec, fd_bank_rent_query( bank ), total_fee );
    1042           0 :   if( FD_UNLIKELY( err ) ) {
    1043           0 :     return err;
    1044           0 :   }
    1045             : 
    1046             :   /* Create the rollback fee payer account
    1047             :      https://github.com/anza-xyz/agave/blob/v2.2.13/svm/src/transaction_processor.rs#L620-L626 */
    1048           0 :   fd_executor_create_rollback_fee_payer_account( runtime, bank, txn_in, txn_out, total_fee );
    1049             : 
    1050             :   /* Set the starting lamports (to avoid unbalanced lamports issues in instruction execution) */
    1051           0 :   fee_payer_rec->starting_lamports = fd_txn_account_get_lamports( fee_payer_rec ); /* TODO: why do we do this everywhere? */
    1052             : 
    1053           0 :   txn_out->details.execution_fee = execution_fee;
    1054           0 :   txn_out->details.priority_fee  = priority_fee;
    1055             : 
    1056           0 :   return FD_RUNTIME_EXECUTE_SUCCESS;
    1057           0 : }
    1058             : 
    1059             : /* Simply unpacks the account keys from the serialized transaction and
    1060             :    sets them in the txn_out. */
    1061             : void
    1062             : fd_executor_setup_txn_account_keys( fd_txn_in_t const * txn_in,
    1063           0 :                                     fd_txn_out_t *      txn_out ) {
    1064           0 :   txn_out->accounts.accounts_cnt = (uchar)TXN( txn_in->txn )->acct_addr_cnt;
    1065           0 :   fd_pubkey_t * tx_accs = (fd_pubkey_t *)((uchar *)txn_in->txn->payload + TXN( txn_in->txn )->acct_addr_off);
    1066             : 
    1067             :   // Set up accounts in the transaction body and perform checks
    1068           0 :   for( ulong i = 0UL; i < TXN( txn_in->txn )->acct_addr_cnt; i++ ) {
    1069           0 :     txn_out->accounts.account_keys[i] = tx_accs[i];
    1070           0 :   }
    1071           0 : }
    1072             : 
    1073             : /* Resolves any address lookup tables referenced in the transaction and adds
    1074             :    them to the transaction's account keys. Returns 0 on success or if the transaction
    1075             :    is a legacy transaction, and an FD_RUNTIME_TXN_ERR_* on failure. */
    1076             : int
    1077             : fd_executor_setup_txn_alut_account_keys( fd_runtime_t *      runtime,
    1078             :                                          fd_bank_t *         bank,
    1079             :                                          fd_txn_in_t const * txn_in,
    1080           0 :                                          fd_txn_out_t *      txn_out ) {
    1081           0 :   if( TXN( txn_in->txn )->transaction_version == FD_TXN_V0 ) {
    1082             :     /* https://github.com/anza-xyz/agave/blob/368ea563c423b0a85cc317891187e15c9a321521/runtime/src/bank/address_lookup_table.rs#L44-L48 */
    1083           0 :     fd_sysvar_cache_t const * sysvar_cache = fd_bank_sysvar_cache_query( bank );
    1084           0 :     fd_slot_hash_t const * slot_hashes = fd_sysvar_cache_slot_hashes_join_const( sysvar_cache );
    1085           0 :     if( FD_UNLIKELY( !slot_hashes ) ) {
    1086           0 :       FD_LOG_DEBUG(( "fd_executor_setup_txn_alut_account_keys(): failed to get slot hashes" ));
    1087           0 :       return FD_RUNTIME_TXN_ERR_ACCOUNT_NOT_FOUND;
    1088           0 :     }
    1089           0 :     fd_funk_txn_xid_t xid       = { .ul = { fd_bank_slot_get( bank ), bank->idx } };
    1090           0 :     fd_acct_addr_t *  accts_alt = (fd_acct_addr_t *) fd_type_pun( &txn_out->accounts.account_keys[txn_out->accounts.accounts_cnt] );
    1091           0 :     int err = fd_runtime_load_txn_address_lookup_tables( TXN( txn_in->txn ),
    1092           0 :                                                          txn_in->txn->payload,
    1093           0 :                                                          runtime->funk,
    1094           0 :                                                          &xid,
    1095           0 :                                                          fd_bank_slot_get( bank ),
    1096           0 :                                                          slot_hashes,
    1097           0 :                                                          accts_alt );
    1098           0 :     fd_sysvar_cache_slot_hashes_leave_const( sysvar_cache, slot_hashes );
    1099           0 :     txn_out->accounts.accounts_cnt += TXN( txn_in->txn )->addr_table_adtl_cnt;
    1100           0 :     if( FD_UNLIKELY( err!=FD_RUNTIME_EXECUTE_SUCCESS ) ) return err;
    1101             : 
    1102           0 :   }
    1103           0 :   return FD_RUNTIME_EXECUTE_SUCCESS;
    1104           0 : }
    1105             : 
    1106             : /* https://github.com/anza-xyz/agave/blob/v2.0.0/sdk/src/transaction_context.rs#L319-L357 */
    1107             : static inline int
    1108             : fd_txn_ctx_push( fd_runtime_t *      runtime,
    1109             :                  fd_txn_in_t const * txn_in,
    1110             :                  fd_txn_out_t *      txn_out,
    1111           0 :                  fd_instr_info_t *   instr ) {
    1112             :   /* Earlier checks in the permalink are redundant since Agave maintains instr stack and trace accounts separately
    1113             :      https://github.com/anza-xyz/agave/blob/v2.0.0/sdk/src/transaction_context.rs#L327-L328 */
    1114           0 :   ulong starting_lamports_h = 0UL;
    1115           0 :   ulong starting_lamports_l = 0UL;
    1116           0 :   int err = fd_instr_info_sum_account_lamports( instr,
    1117           0 :                                                 txn_out,
    1118           0 :                                                 &starting_lamports_h,
    1119           0 :                                                 &starting_lamports_l );
    1120           0 :   if( FD_UNLIKELY( err ) ) {
    1121           0 :     return err;
    1122           0 :   }
    1123           0 :   instr->starting_lamports_h = starting_lamports_h;
    1124           0 :   instr->starting_lamports_l = starting_lamports_l;
    1125             : 
    1126             :   /* Check that the caller's lamport sum has not changed.
    1127             :      https://github.com/anza-xyz/agave/blob/v2.0.0/sdk/src/transaction_context.rs#L329-L340 */
    1128           0 :   if( runtime->instr.stack_sz>0 ) {
    1129             :     /* https://github.com/anza-xyz/agave/blob/v2.0.0/sdk/src/transaction_context.rs#L330 */
    1130           0 :     fd_exec_instr_ctx_t const * caller_instruction_context = &runtime->instr.stack[ runtime->instr.stack_sz-1 ];
    1131             : 
    1132             :     /* https://github.com/anza-xyz/agave/blob/v2.0.0/sdk/src/transaction_context.rs#L331-L332 */
    1133           0 :     ulong original_caller_lamport_sum_h = caller_instruction_context->instr->starting_lamports_h;
    1134           0 :     ulong original_caller_lamport_sum_l = caller_instruction_context->instr->starting_lamports_l;
    1135             : 
    1136             :     /* https://github.com/anza-xyz/agave/blob/v2.0.0/sdk/src/transaction_context.rs#L333-L334 */
    1137           0 :     ulong current_caller_lamport_sum_h = 0UL;
    1138           0 :     ulong current_caller_lamport_sum_l = 0UL;
    1139           0 :     int err = fd_instr_info_sum_account_lamports( caller_instruction_context->instr,
    1140           0 :                                                   caller_instruction_context->txn_out,
    1141           0 :                                                   &current_caller_lamport_sum_h,
    1142           0 :                                                   &current_caller_lamport_sum_l );
    1143           0 :     if( FD_UNLIKELY( err ) ) {
    1144           0 :       return err;
    1145           0 :     }
    1146             : 
    1147             :     /* https://github.com/anza-xyz/agave/blob/v2.0.0/sdk/src/transaction_context.rs#L335-L339 */
    1148           0 :     if( FD_UNLIKELY( current_caller_lamport_sum_h!=original_caller_lamport_sum_h ||
    1149           0 :                      current_caller_lamport_sum_l!=original_caller_lamport_sum_l ) ) {
    1150           0 :       return FD_EXECUTOR_INSTR_ERR_UNBALANCED_INSTR;
    1151           0 :     }
    1152           0 :   }
    1153             : 
    1154             :   /* Note that we don't update the trace length here - since the caller
    1155             :      allocates out of the trace array, they are also responsible for
    1156             :      incrementing the trace length variable.
    1157             :      https://github.com/anza-xyz/agave/blob/v2.0.0/sdk/src/transaction_context.rs#L347-L351 */
    1158           0 :   if( FD_UNLIKELY( runtime->instr.trace_length>FD_MAX_INSTRUCTION_TRACE_LENGTH ) ) {
    1159           0 :     return FD_EXECUTOR_INSTR_ERR_MAX_INSN_TRACE_LENS_EXCEEDED;
    1160           0 :   }
    1161             : 
    1162             :   /* https://github.com/anza-xyz/agave/blob/v2.0.0/sdk/src/transaction_context.rs#L352-L356 */
    1163           0 :   if( FD_UNLIKELY( runtime->instr.stack_sz>=FD_MAX_INSTRUCTION_STACK_DEPTH ) ) {
    1164           0 :     return FD_EXECUTOR_INSTR_ERR_CALL_DEPTH;
    1165           0 :   }
    1166           0 :   runtime->instr.stack_sz++;
    1167             : 
    1168             :   /* A beloved refactor moves sysvar instructions updating to the instruction level as of v2.2.12...
    1169             :      https://github.com/anza-xyz/agave/blob/v2.2.12/transaction-context/src/lib.rs#L396-L407 */
    1170           0 :   int idx = fd_runtime_find_index_of_account( txn_out, &fd_sysvar_instructions_id );
    1171           0 :   if( FD_UNLIKELY( idx!=-1 ) ) {
    1172             :     /* https://github.com/anza-xyz/agave/blob/v2.2.12/transaction-context/src/lib.rs#L397-L400 */
    1173           0 :     fd_txn_account_t * sysvar_instructions_account = NULL;
    1174           0 :     err = fd_runtime_get_account_at_index( txn_in, txn_out, (ushort)idx, &sysvar_instructions_account, NULL );
    1175           0 :     if( FD_UNLIKELY( err ) ) {
    1176           0 :       return FD_EXECUTOR_INSTR_ERR_MISSING_ACC;
    1177           0 :     }
    1178             : 
    1179             :     /* https://github.com/anza-xyz/agave/blob/v2.2.12/transaction-context/src/lib.rs#L401-L402 */
    1180           0 :     if( FD_UNLIKELY( !fd_txn_account_try_borrow_mut( sysvar_instructions_account ) ) ) {
    1181           0 :       return FD_EXECUTOR_INSTR_ERR_ACC_BORROW_FAILED;
    1182           0 :     }
    1183             : 
    1184             :     /* https://github.com/anza-xyz/agave/blob/v2.2.12/transaction-context/src/lib.rs#L403-L406 */
    1185           0 :     fd_sysvar_instructions_update_current_instr_idx( sysvar_instructions_account, (ushort)runtime->instr.current_idx );
    1186           0 :     fd_txn_account_drop( sysvar_instructions_account );
    1187           0 :   }
    1188             : 
    1189           0 :   return FD_EXECUTOR_INSTR_SUCCESS;
    1190           0 : }
    1191             : 
    1192             : /* Pushes a new instruction onto the instruction stack and trace. This check loops through all instructions in the current call stack
    1193             :    and checks for reentrancy violations. If successful, simply increments the instruction stack and trace size and returns. It is
    1194             :    the responsibility of the caller to populate the newly pushed instruction fields, which are undefined otherwise.
    1195             : 
    1196             :    https://github.com/anza-xyz/agave/blob/v2.0.0/program-runtime/src/invoke_context.rs#L246-L290 */
    1197             : int
    1198             : fd_instr_stack_push( fd_runtime_t *      runtime,
    1199             :                      fd_txn_in_t const * txn_in,
    1200             :                      fd_txn_out_t *      txn_out,
    1201           0 :                      fd_instr_info_t *   instr ) {
    1202             :   /* Agave keeps a vector of vectors called program_indices that stores the program_id index for each instruction within the transaction.
    1203             :      https://github.com/anza-xyz/agave/blob/v2.1.7/svm/src/account_loader.rs#L347-L402
    1204             :      If and only if the program_id is the native loader, then the vector for respective specific instruction (account_indices) is empty.
    1205             :      https://github.com/anza-xyz/agave/blob/v2.1.7/svm/src/account_loader.rs#L350-L358
    1206             :      While trying to push a new instruction onto the instruction stack, if the vector for the respective instruction is empty, Agave throws UnsupportedProgramId
    1207             :      https://github.com/anza-xyz/agave/blob/v2.1.7/program-runtime/src/invoke_context.rs#L253-L255
    1208             :      The only way for the vector to be empty is if the program_id is the native loader, so we can a program_id check here
    1209             :      */
    1210             : 
    1211             :   /* https://github.com/anza-xyz/agave/blob/v2.2.0/program-runtime/src/invoke_context.rs#L250-L252 */
    1212           0 :   fd_pubkey_t const * program_id_pubkey = NULL;
    1213           0 :   int err = fd_runtime_get_key_of_account_at_index( txn_out,
    1214           0 :                                                     instr->program_id,
    1215           0 :                                                     &program_id_pubkey );
    1216           0 :   if( FD_UNLIKELY( err ) ) {
    1217           0 :     return FD_EXECUTOR_INSTR_ERR_UNSUPPORTED_PROGRAM_ID;
    1218           0 :   }
    1219             : 
    1220             :   /* https://github.com/anza-xyz/agave/blob/v2.0.0/program-runtime/src/invoke_context.rs#L256-L286 */
    1221           0 :   if( runtime->instr.stack_sz ) {
    1222             :     /* https://github.com/anza-xyz/agave/blob/v2.0.0/program-runtime/src/invoke_context.rs#L261-L285 */
    1223           0 :     uchar contains = 0;
    1224           0 :     uchar is_last  = 0;
    1225             : 
    1226             :     // Checks all previous instructions in the stack for reentrancy
    1227           0 :     for( uchar level=0; level<runtime->instr.stack_sz; level++ ) {
    1228           0 :       fd_exec_instr_ctx_t * instr_ctx = &runtime->instr.stack[level];
    1229             :       // Optimization: compare program id index instead of pubkey since account keys are unique
    1230           0 :       if( instr->program_id == instr_ctx->instr->program_id ) {
    1231             :         // Reentrancy not allowed unless caller is calling itself
    1232           0 :         if( level == runtime->instr.stack_sz-1 ) {
    1233           0 :           is_last = 1;
    1234           0 :         }
    1235           0 :         contains = 1;
    1236           0 :       }
    1237           0 :     }
    1238             :     /* https://github.com/anza-xyz/agave/blob/v2.0.0/program-runtime/src/invoke_context.rs#L282-L285 */
    1239           0 :     if( FD_UNLIKELY( contains && !is_last ) ) {
    1240           0 :       return FD_EXECUTOR_INSTR_ERR_REENTRANCY_NOT_ALLOWED;
    1241           0 :     }
    1242           0 :   }
    1243             :   /* "Push" a new instruction onto the stack by simply incrementing the stack and trace size counters
    1244             :      https://github.com/anza-xyz/agave/blob/v2.0.0/program-runtime/src/invoke_context.rs#L289 */
    1245           0 :   return fd_txn_ctx_push( runtime, txn_in, txn_out, instr );
    1246           0 : }
    1247             : 
    1248             : /* Pops an instruction from the instruction stack. Agave's implementation performs instruction balancing checks every time pop is called,
    1249             :    but error codes returned from `pop` are only used if the program's execution was successful. Therefore, we can optimize our code by only
    1250             :    checking for unbalanced instructions if the program execution was successful within fd_execute_instr.
    1251             : 
    1252             :    https://github.com/anza-xyz/agave/blob/v2.0.0/program-runtime/src/invoke_context.rs#L293-L298 */
    1253             : int
    1254             : fd_instr_stack_pop( fd_runtime_t *          runtime,
    1255             :                     fd_txn_out_t *          txn_out,
    1256           0 :                     fd_instr_info_t const * instr ) {
    1257             :   /* https://github.com/anza-xyz/agave/blob/v2.0.0/sdk/src/transaction_context.rs#L362-L364 */
    1258           0 :   if( FD_UNLIKELY( runtime->instr.stack_sz==0 ) ) {
    1259           0 :     return FD_EXECUTOR_INSTR_ERR_CALL_DEPTH;
    1260           0 :   }
    1261           0 :   runtime->instr.stack_sz--;
    1262             : 
    1263             :   /* Verify all executable accounts have no outstanding refs
    1264             :      https://github.com/anza-xyz/agave/blob/v2.1.14/sdk/src/transaction_context.rs#L367-L371 */
    1265           0 :   for( ushort i=0; i<instr->acct_cnt; i++ ) {
    1266           0 :     ushort idx_in_txn = instr->accounts[i].index_in_transaction;
    1267           0 :     fd_txn_account_t * account = &txn_out->accounts.accounts[ idx_in_txn ];
    1268           0 :     if( FD_UNLIKELY( fd_txn_account_is_executable( account ) &&
    1269           0 :                      fd_txn_account_is_borrowed( account ) ) ) {
    1270           0 :       return FD_EXECUTOR_INSTR_ERR_ACC_BORROW_OUTSTANDING;
    1271           0 :     }
    1272           0 :   }
    1273             : 
    1274             :   /* Verify lamports are balanced before and after instruction
    1275             :      https://github.com/anza-xyz/agave/blob/v2.0.0/sdk/src/transaction_context.rs#L366-L380 */
    1276           0 :   ulong ending_lamports_h = 0UL;
    1277           0 :   ulong ending_lamports_l = 0UL;
    1278           0 :   int err = fd_instr_info_sum_account_lamports( instr,
    1279           0 :                                                 txn_out,
    1280           0 :                                                 &ending_lamports_h,
    1281           0 :                                                 &ending_lamports_l );
    1282           0 :   if( FD_UNLIKELY( err ) ) {
    1283           0 :     return err;
    1284           0 :   }
    1285           0 :   if( FD_UNLIKELY( ending_lamports_l != instr->starting_lamports_l || ending_lamports_h != instr->starting_lamports_h ) ) {
    1286           0 :    return FD_EXECUTOR_INSTR_ERR_UNBALANCED_INSTR;
    1287           0 :   }
    1288             : 
    1289           0 :   return FD_EXECUTOR_INSTR_SUCCESS;;
    1290           0 : }
    1291             : 
    1292             : /* This function mimics Agave's `.and(self.pop())` functionality,
    1293             :    where we always pop the instruction stack no matter what the error code is.
    1294             :    https://github.com/anza-xyz/agave/blob/v2.2.12/program-runtime/src/invoke_context.rs#L480 */
    1295             : static inline int
    1296             : fd_execute_instr_end( fd_exec_instr_ctx_t * instr_ctx,
    1297             :                       fd_instr_info_t *     instr,
    1298           0 :                       int                   instr_exec_result ) {
    1299           0 :   int stack_pop_err = fd_instr_stack_pop( instr_ctx->runtime, instr_ctx->txn_out, instr );
    1300             : 
    1301             :   /* Only report the stack pop error on success */
    1302           0 :   if( FD_UNLIKELY( instr_exec_result==FD_EXECUTOR_INSTR_SUCCESS && stack_pop_err ) ) {
    1303           0 :     FD_TXN_PREPARE_ERR_OVERWRITE( instr_ctx->txn_out );
    1304           0 :     FD_TXN_ERR_FOR_LOG_INSTR( instr_ctx->txn_out, stack_pop_err, instr_ctx->txn_out->err.exec_err_idx );
    1305           0 :     instr_exec_result = stack_pop_err;
    1306           0 :   }
    1307             : 
    1308           0 :   return instr_exec_result;
    1309           0 : }
    1310             : 
    1311             : int
    1312             : fd_execute_instr( fd_runtime_t *      runtime,
    1313             :                   fd_bank_t *         bank,
    1314             :                   fd_txn_in_t const * txn_in,
    1315             :                   fd_txn_out_t *      txn_out,
    1316           0 :                   fd_instr_info_t *   instr ) {
    1317           0 :   fd_sysvar_cache_t const * sysvar_cache = fd_bank_sysvar_cache_query( bank );
    1318           0 :   int instr_exec_result = fd_instr_stack_push( runtime, txn_in, txn_out, instr );
    1319           0 :   if( FD_UNLIKELY( instr_exec_result ) ) {
    1320           0 :     FD_TXN_PREPARE_ERR_OVERWRITE( txn_out );
    1321           0 :     FD_TXN_ERR_FOR_LOG_INSTR( txn_out, instr_exec_result, txn_out->err.exec_err_idx );
    1322           0 :     return instr_exec_result;
    1323           0 :   }
    1324             : 
    1325             :   /* `process_executable_chain()`
    1326             :       https://github.com/anza-xyz/agave/blob/v2.2.12/program-runtime/src/invoke_context.rs#L512-L619 */
    1327           0 :   fd_exec_instr_ctx_t * ctx = &runtime->instr.stack[ runtime->instr.stack_sz - 1 ];
    1328           0 :   *ctx = (fd_exec_instr_ctx_t) {
    1329           0 :     .instr        = instr,
    1330           0 :     .sysvar_cache = sysvar_cache,
    1331           0 :     .runtime      = runtime,
    1332           0 :     .txn_in       = txn_in,
    1333           0 :     .txn_out      = txn_out,
    1334           0 :     .bank         = bank,
    1335           0 :   };
    1336           0 :   fd_base58_encode_32( txn_out->accounts.accounts[ instr->program_id ].pubkey->uc, NULL, ctx->program_id_base58 );
    1337             : 
    1338             :   /* Look up the native program. We check for precompiles within the lookup function as well.
    1339             :      https://github.com/anza-xyz/agave/blob/v2.1.6/svm/src/message_processor.rs#L88 */
    1340           0 :   fd_exec_instr_fn_t native_prog_fn;
    1341           0 :   uchar              is_precompile;
    1342           0 :   int                err = fd_executor_lookup_native_program( &txn_out->accounts.accounts[ instr->program_id ],
    1343           0 :                                                               bank,
    1344           0 :                                                               &native_prog_fn,
    1345           0 :                                                               &is_precompile );
    1346             : 
    1347           0 :   if( FD_UNLIKELY( err ) ) {
    1348           0 :     FD_TXN_PREPARE_ERR_OVERWRITE( txn_out );
    1349           0 :     FD_TXN_ERR_FOR_LOG_INSTR( txn_out, err, txn_out->err.exec_err_idx );
    1350           0 :     return err;
    1351           0 :   }
    1352             : 
    1353           0 :   if( FD_LIKELY( native_prog_fn!=NULL ) ) {
    1354             :     /* If this branch is taken, we've found an entrypoint to execute. */
    1355           0 :     fd_log_collector_program_invoke( ctx );
    1356             : 
    1357             :     /* Only reset the return data when executing a native builtin program (not a precompile)
    1358             :        https://github.com/anza-xyz/agave/blob/v2.1.6/program-runtime/src/invoke_context.rs#L536-L537 */
    1359           0 :     if( FD_LIKELY( !is_precompile ) ) {
    1360           0 :       txn_out->details.return_data.len = 0;
    1361           0 :     }
    1362             : 
    1363             :     /* Execute the native program. */
    1364           0 :     instr_exec_result = native_prog_fn( ctx );
    1365           0 :   } else {
    1366             :     /* Unknown program. In this case specifically, we should not log the program id. */
    1367           0 :     instr_exec_result = FD_EXECUTOR_INSTR_ERR_UNSUPPORTED_PROGRAM_ID;
    1368           0 :     FD_TXN_PREPARE_ERR_OVERWRITE( txn_out );
    1369           0 :     FD_TXN_ERR_FOR_LOG_INSTR( txn_out, instr_exec_result, txn_out->err.exec_err_idx );
    1370           0 :     return fd_execute_instr_end( ctx, instr, instr_exec_result );
    1371           0 :   }
    1372             : 
    1373           0 :   if( FD_LIKELY( instr_exec_result==FD_EXECUTOR_INSTR_SUCCESS ) ) {
    1374             :     /* Log success */
    1375           0 :     fd_log_collector_program_success( ctx );
    1376           0 :   } else {
    1377             :     /* Log failure cases.
    1378             :        We assume that the correct type of error is stored in ctx.
    1379             :        Syscalls are expected to log when the error is generated, while
    1380             :        native programs will be logged here.
    1381             :        (This is because syscall errors often carry data with them.)
    1382             : 
    1383             :        TODO: This hackily handles cases where the exec_err and exec_err_kind
    1384             :        is not set yet. We should change our native programs to set
    1385             :        this in their respective processors. */
    1386           0 :     if( !txn_out->err.exec_err ) {
    1387           0 :       FD_TXN_PREPARE_ERR_OVERWRITE( txn_out );
    1388           0 :       FD_TXN_ERR_FOR_LOG_INSTR( txn_out, instr_exec_result, txn_out->err.exec_err_idx );
    1389           0 :       fd_log_collector_program_failure( ctx );
    1390           0 :     } else {
    1391           0 :       fd_log_collector_program_failure( ctx );
    1392           0 :       FD_TXN_PREPARE_ERR_OVERWRITE( txn_out );
    1393           0 :       FD_TXN_ERR_FOR_LOG_INSTR( txn_out, instr_exec_result, txn_out->err.exec_err_idx );
    1394           0 :     }
    1395           0 :   }
    1396             : 
    1397           0 :   return fd_execute_instr_end( ctx, instr, instr_exec_result );
    1398           0 : }
    1399             : 
    1400             : void
    1401             : fd_executor_reclaim_account( fd_txn_account_t *  account,
    1402           0 :                              ulong               slot ) {
    1403           0 :   fd_txn_account_set_slot( account, slot );
    1404           0 :   if( FD_UNLIKELY( fd_txn_account_get_lamports( account )==0UL ) ) {
    1405           0 :     fd_txn_account_set_data_len( account, 0UL );
    1406           0 :     fd_txn_account_clear_owner( account );
    1407           0 :   }
    1408           0 : }
    1409             : 
    1410             : static fd_txn_account_t *
    1411             : fd_executor_setup_txn_account( fd_runtime_t *      runtime,
    1412             :                                fd_bank_t *         bank,
    1413             :                                fd_txn_in_t const * txn_in,
    1414             :                                fd_txn_out_t *      txn_out,
    1415           0 :                                ushort              idx ) {
    1416             : 
    1417             :   /* To setup a transaction account, we need to first retrieve a
    1418             :      read-only handle to the account from the database. */
    1419             : 
    1420           0 :   fd_pubkey_t * acc = &txn_out->accounts.account_keys[ idx ];
    1421             : 
    1422             : 
    1423           0 :   fd_account_meta_t const * meta = NULL;
    1424           0 :   if( txn_in->bundle.is_bundle ) {
    1425             :     /* If we are in a bundle, that means that the latest version of an
    1426             :        account may be a transaction account from a previous transaction
    1427             :        and not in the accounts database.  This means we have to
    1428             :        reference the previous transaction's account.  Because we are in
    1429             :        a bundle, we know that the transaction accounts for all previous
    1430             :        bundle transactions are valid.  We will also assume that the
    1431             :        transactions are in execution order.
    1432             : 
    1433             :        TODO: This lookup can be made more performant by using a map
    1434             :        from pubkey to the bundle transaction index and only inserting
    1435             :        or updating when the account is writable. */
    1436             : 
    1437           0 :     int is_found = 0;
    1438           0 :     for( ulong i=txn_in->bundle.prev_txn_cnt; i>0UL && !is_found; i-- ) {
    1439           0 :       fd_txn_in_t const *  prev_txn_in  = txn_in->bundle.prev_txn_ins[ i-1 ];
    1440           0 :       fd_txn_out_t const * prev_txn_out = txn_in->bundle.prev_txn_outs[ i-1 ];
    1441           0 :       for( ushort j=0UL; j<prev_txn_out->accounts.accounts_cnt; j++ ) {
    1442           0 :         if( !memcmp( &prev_txn_out->accounts.account_keys[ j ], acc, sizeof(fd_pubkey_t) ) && fd_runtime_account_is_writable_idx( prev_txn_in, prev_txn_out, bank, j ) ) {
    1443             :           /* Found the account in a previous transaction */
    1444           0 :           meta = prev_txn_out->accounts.accounts[ j ].meta;
    1445           0 :           is_found = 1;
    1446           0 :           break;
    1447           0 :         }
    1448           0 :       }
    1449           0 :     }
    1450           0 :   }
    1451             : 
    1452           0 :   int err = FD_ACC_MGR_SUCCESS;
    1453           0 :   if( FD_LIKELY( !meta ) ) {
    1454           0 :     fd_funk_txn_xid_t xid = { .ul = { fd_bank_slot_get( bank ), bank->idx } };
    1455           0 :     meta = fd_funk_get_acc_meta_readonly(
    1456           0 :         runtime->funk,
    1457           0 :         &xid,
    1458           0 :         acc,
    1459           0 :         NULL,
    1460           0 :         &err,
    1461           0 :         NULL );
    1462           0 :   }
    1463             :   /* If there is an error with a read from the accounts database, it is
    1464             :      unexpected unless the account does not exist. */
    1465           0 :   if( FD_UNLIKELY( err!=FD_ACC_MGR_SUCCESS && err!=FD_ACC_MGR_ERR_UNKNOWN_ACCOUNT ) ) {
    1466           0 :     FD_LOG_CRIT(( "fd_txn_account_init_from_funk_readonly err=%d", err ));
    1467           0 :   }
    1468             : 
    1469           0 :   fd_txn_account_t *  txn_account  = &txn_out->accounts.accounts[ idx ];
    1470           0 :   int                 is_writable  = fd_runtime_account_is_writable_idx( txn_in, txn_out, bank, idx ) || idx==FD_FEE_PAYER_TXN_IDX;
    1471           0 :   fd_account_meta_t * account_meta = NULL;
    1472             : 
    1473           0 :   if( is_writable ) {
    1474             :     /* If the account is writable or a fee payer, then we need to create
    1475             :        staging regions for the account. If the account exists, we need to
    1476             :        copy the account data into the staging area; otherwise, we need to
    1477             :        initialize a new metadata. */
    1478             : 
    1479           0 :     uchar * new_raw_data = txn_in->exec_accounts->accounts_mem[idx];
    1480           0 :     ulong   dlen         = !!meta ? meta->dlen : 0UL;
    1481             : 
    1482           0 :     if( FD_LIKELY( meta ) ) {
    1483             :       /* Account exists, copy the data into the staging area */
    1484           0 :       fd_memcpy( new_raw_data, (uchar *)meta, sizeof(fd_account_meta_t)+dlen );
    1485           0 :     } else {
    1486             :       /* Account did not exist, set up metadata */
    1487           0 :       fd_account_meta_init( (fd_account_meta_t *)new_raw_data );
    1488           0 :     }
    1489             : 
    1490           0 :     account_meta = (fd_account_meta_t *)new_raw_data;
    1491             : 
    1492           0 :   } else {
    1493             :     /* If the account is not writable, then we can simply initialize
    1494             :        the txn account with the read-only accountsdb record. However,
    1495             :        if the account does not exist, we need to initialize a new
    1496             :        metadata. */
    1497             : 
    1498           0 :     if( FD_LIKELY( err==FD_ACC_MGR_SUCCESS ) ) {
    1499           0 :       account_meta = (fd_account_meta_t *)meta;
    1500           0 :     } else {
    1501           0 :       uchar * mem = txn_in->exec_accounts->accounts_mem[idx];
    1502           0 :       account_meta = (fd_account_meta_t *)mem;
    1503           0 :       fd_account_meta_init( account_meta );
    1504           0 :     }
    1505           0 :   }
    1506             : 
    1507           0 :   if( FD_UNLIKELY( !fd_txn_account_join( fd_txn_account_new(
    1508           0 :       txn_account,
    1509           0 :       acc,
    1510           0 :       account_meta,
    1511           0 :       is_writable ) ) ) ) {
    1512           0 :     FD_LOG_CRIT(( "Failed to join txn account" ));
    1513           0 :   }
    1514             : 
    1515           0 :   return txn_account;
    1516           0 : }
    1517             : 
    1518             : static void
    1519             : fd_executor_setup_executable_account( fd_runtime_t *           runtime,
    1520             :                                       fd_bank_t *              bank,
    1521             :                                       fd_txn_account_t const * account,
    1522           0 :                                       ushort *                 executable_idx ) {
    1523           0 :   fd_bpf_upgradeable_loader_state_t program_loader_state[1];
    1524           0 :   int err = fd_bpf_loader_program_get_state( account, program_loader_state );
    1525           0 :   if( FD_UNLIKELY( err!=FD_EXECUTOR_INSTR_SUCCESS ) ) {
    1526           0 :     return;
    1527           0 :   }
    1528             : 
    1529           0 :   if( !fd_bpf_upgradeable_loader_state_is_program( program_loader_state ) ) {
    1530           0 :     return;
    1531           0 :   }
    1532             : 
    1533             :   /* Attempt to load the program data account from funk. This prevents any unknown program
    1534             :       data accounts from getting loaded into the executable accounts list. If such a program is
    1535             :       invoked, the call will fail at the instruction execution level since the programdata
    1536             :       account will not exist within the executable accounts list. */
    1537           0 :   fd_pubkey_t *     programdata_acc = &program_loader_state->inner.program.programdata_address;
    1538           0 :   fd_funk_txn_xid_t xid             = { .ul = { fd_bank_slot_get( bank ), bank->idx } };
    1539           0 :   if( FD_LIKELY( fd_txn_account_init_from_funk_readonly( &runtime->executable.accounts[ *executable_idx ],
    1540           0 :                                                          programdata_acc,
    1541           0 :                                                          runtime->funk,
    1542           0 :                                                          &xid )==0 ) ) {
    1543           0 :     (*executable_idx)++;
    1544           0 :   }
    1545           0 : }
    1546             : 
    1547             : void
    1548             : fd_executor_setup_accounts_for_txn( fd_runtime_t *      runtime,
    1549             :                                     fd_bank_t *         bank,
    1550             :                                     fd_txn_in_t const * txn_in,
    1551           0 :                                     fd_txn_out_t *      txn_out ) {
    1552             : 
    1553           0 :   ushort executable_idx = 0U;
    1554           0 :   fd_memset( txn_out->accounts.accounts, 0, sizeof(fd_txn_account_t) * txn_out->accounts.accounts_cnt );
    1555             : 
    1556           0 :   for( ushort i=0; i<txn_out->accounts.accounts_cnt; i++ ) {
    1557           0 :     fd_txn_account_t * txn_account = fd_executor_setup_txn_account( runtime, bank, txn_in, txn_out, i );
    1558             : 
    1559           0 :     if( FD_UNLIKELY( txn_account &&
    1560           0 :                      memcmp( fd_txn_account_get_owner( txn_account ), fd_solana_bpf_loader_upgradeable_program_id.key, sizeof(fd_pubkey_t) ) == 0 ) ) {
    1561           0 :       fd_executor_setup_executable_account( runtime, bank, txn_account, &executable_idx );
    1562           0 :     }
    1563           0 :   }
    1564             : 
    1565           0 : # if FD_HAS_FLATCC
    1566             :   /* Dumping ELF files to protobuf, if applicable */
    1567           0 :   int dump_elf_to_pb = runtime->log.capture_ctx &&
    1568           0 :                        fd_bank_slot_get( bank ) >= runtime->log.capture_ctx->dump_proto_start_slot &&
    1569           0 :                        runtime->log.capture_ctx->dump_elf_to_pb;
    1570           0 :   if( FD_UNLIKELY( dump_elf_to_pb ) ) {
    1571           0 :     for( ushort i=0; i<txn_out->accounts.accounts_cnt; i++ ) {
    1572           0 :       fd_dump_elf_to_protobuf( runtime, bank, txn_in, &txn_out->accounts.accounts[i] );
    1573           0 :     }
    1574           0 :   }
    1575           0 : # endif
    1576             : 
    1577           0 :   txn_out->accounts.nonce_idx_in_txn = ULONG_MAX;
    1578           0 :   runtime->executable.cnt            = executable_idx;
    1579           0 : }
    1580             : 
    1581             : int
    1582             : fd_executor_txn_verify( fd_txn_p_t *  txn_p,
    1583           0 :                         fd_sha512_t * shas[ FD_TXN_ACTUAL_SIG_MAX ] ) {
    1584           0 :   fd_txn_t * txn = TXN( txn_p );
    1585             : 
    1586           0 :   uchar * signatures = txn_p->payload + txn->signature_off;
    1587           0 :   uchar * pubkeys    = txn_p->payload + txn->acct_addr_off;
    1588           0 :   uchar * msg        = txn_p->payload + txn->message_off;
    1589           0 :   ulong   msg_sz     = txn_p->payload_sz - txn->message_off;
    1590             : 
    1591           0 :   int res = fd_ed25519_verify_batch_single_msg( msg, msg_sz, signatures, pubkeys, shas, txn->signature_cnt );
    1592           0 :   if( FD_UNLIKELY( res != FD_ED25519_SUCCESS ) ) {
    1593           0 :     return FD_RUNTIME_TXN_ERR_SIGNATURE_FAILURE;
    1594           0 :   }
    1595             : 
    1596           0 :   return FD_RUNTIME_EXECUTE_SUCCESS;
    1597           0 : }
    1598             : 
    1599             : int
    1600             : fd_execute_txn( fd_runtime_t *      runtime,
    1601             :                 fd_bank_t *         bank,
    1602             :                 fd_txn_in_t const * txn_in,
    1603           0 :                 fd_txn_out_t *      txn_out ) {
    1604             : 
    1605           0 :   bool dump_insn = runtime->log.capture_ctx && fd_bank_slot_get( bank ) >= runtime->log.capture_ctx->dump_proto_start_slot && runtime->log.capture_ctx->dump_instr_to_pb;
    1606           0 :   (void)dump_insn;
    1607             : 
    1608           0 :   fd_txn_t const * txn = TXN( txn_in->txn );
    1609             : 
    1610             :   /* Initialize log collection. */
    1611           0 :   fd_log_collector_init( runtime->log.log_collector, runtime->log.enable_log_collector );
    1612             : 
    1613           0 :   for( ushort i=0; i<TXN( txn_in->txn )->instr_cnt; i++ ) {
    1614             :     /* Set up the instr info for the current instruction */
    1615           0 :     fd_instr_info_t * instr_info = &runtime->instr.trace[runtime->instr.trace_length++];
    1616           0 :     fd_instr_info_init_from_txn_instr(
    1617           0 :         instr_info,
    1618           0 :         bank,
    1619           0 :         txn_in,
    1620           0 :         txn_out,
    1621           0 :         &txn->instr[i]
    1622           0 :     );
    1623             : 
    1624           0 : #   if FD_HAS_FLATCC
    1625           0 :     if( FD_UNLIKELY( dump_insn ) ) {
    1626             :       // Capture the input and convert it into a Protobuf message
    1627           0 :       fd_dump_instr_to_protobuf( runtime, bank, txn_in, txn_out, instr_info, i );
    1628           0 :     }
    1629           0 : #   endif
    1630             : 
    1631             :     /* Update the current executing instruction index */
    1632           0 :     runtime->instr.current_idx = i;
    1633             : 
    1634             :     /* Execute the current instruction */
    1635           0 :     int instr_exec_result = fd_execute_instr( runtime, bank, txn_in, txn_out, instr_info );
    1636           0 :     if( FD_UNLIKELY( instr_exec_result!=FD_EXECUTOR_INSTR_SUCCESS ) ) {
    1637           0 :       if( txn_out->err.exec_err_idx==INT_MAX ) {
    1638           0 :         txn_out->err.exec_err_idx = i;
    1639           0 :       }
    1640           0 :       return FD_RUNTIME_TXN_ERR_INSTRUCTION_ERROR;
    1641           0 :     }
    1642           0 :   }
    1643             : 
    1644             :   /* TODO: This function needs to be split out of fd_execute_txn and be placed
    1645             :       into the replay tile once it is implemented. */
    1646           0 :   return fd_executor_txn_check( bank, txn_out );
    1647           0 : }
    1648             : 
    1649             : int
    1650             : fd_executor_txn_check( fd_bank_t *    bank,
    1651           0 :                        fd_txn_out_t * txn_out ) {
    1652           0 :   fd_rent_t const * rent = fd_bank_rent_query( bank );
    1653             : 
    1654           0 :   ulong starting_lamports_l = 0;
    1655           0 :   ulong starting_lamports_h = 0;
    1656             : 
    1657           0 :   ulong ending_lamports_l = 0;
    1658           0 :   ulong ending_lamports_h = 0;
    1659             : 
    1660             :   /* https://github.com/anza-xyz/agave/blob/b2c388d6cbff9b765d574bbb83a4378a1fc8af32/svm/src/account_rent_state.rs#L63 */
    1661           0 :   for( ulong idx = 0; idx < txn_out->accounts.accounts_cnt; idx++ ) {
    1662           0 :     fd_txn_account_t * b = &txn_out->accounts.accounts[idx];
    1663             : 
    1664             :     // Was this account written to?
    1665             :     /* TODO: Clean this logic up... lots of redundant checks with our newer account loading model.
    1666             :        We should be using the rent transition checking logic instead, along with a small refactor
    1667             :        to keep check ordering consistent. */
    1668           0 :     if( fd_txn_account_get_meta( b )!=NULL ) {
    1669           0 :       fd_uwide_inc( &ending_lamports_h, &ending_lamports_l, ending_lamports_h, ending_lamports_l, fd_txn_account_get_lamports( b ) );
    1670             : 
    1671             :       /* Rent states are defined as followed:
    1672             :          - lamports == 0                      -> Uninitialized
    1673             :          - 0 < lamports < rent_exempt_minimum -> RentPaying
    1674             :          - lamports >= rent_exempt_minimum    -> RentExempt
    1675             :          In Agave, 'self' refers to our 'after' state. */
    1676           0 :       uchar after_uninitialized  = fd_txn_account_get_lamports( b ) == 0;
    1677           0 :       uchar after_rent_exempt    = fd_txn_account_get_lamports( b ) >= fd_rent_exempt_minimum_balance( rent, fd_txn_account_get_data_len( b ) );
    1678             : 
    1679             :       /* https://github.com/anza-xyz/agave/blob/b2c388d6cbff9b765d574bbb83a4378a1fc8af32/svm/src/account_rent_state.rs#L96 */
    1680           0 :       if( FD_LIKELY( memcmp( b->pubkey->key, fd_sysvar_incinerator_id.key, sizeof(fd_pubkey_t) ) != 0 ) ) {
    1681             :         /* https://github.com/anza-xyz/agave/blob/b2c388d6cbff9b765d574bbb83a4378a1fc8af32/svm/src/account_rent_state.rs#L44 */
    1682           0 :         if( after_uninitialized || after_rent_exempt ) {
    1683             :           // no-op
    1684           0 :         } else {
    1685             :           /* https://github.com/anza-xyz/agave/blob/b2c388d6cbff9b765d574bbb83a4378a1fc8af32/svm/src/account_rent_state.rs#L45-L59 */
    1686           0 :           uchar before_uninitialized = b->starting_dlen == ULONG_MAX || b->starting_lamports == 0;
    1687           0 :           uchar before_rent_exempt   = b->starting_dlen != ULONG_MAX && b->starting_lamports >= fd_rent_exempt_minimum_balance( rent, b->starting_dlen );
    1688             : 
    1689             :           /* https://github.com/anza-xyz/agave/blob/b2c388d6cbff9b765d574bbb83a4378a1fc8af32/svm/src/account_rent_state.rs#L50 */
    1690           0 :           if( before_uninitialized || before_rent_exempt ) {
    1691           0 :             FD_LOG_DEBUG(( "Rent exempt error for %s Curr len %lu Starting len %lu Curr lamports %lu Starting lamports %lu Curr exempt %lu Starting exempt %lu",
    1692           0 :                            FD_BASE58_ENC_32_ALLOCA( b->pubkey->uc ),
    1693           0 :                            fd_txn_account_get_data_len( b ),
    1694           0 :                            b->starting_dlen,
    1695           0 :                            fd_txn_account_get_lamports( b ),
    1696           0 :                            b->starting_lamports,
    1697           0 :                            fd_rent_exempt_minimum_balance( rent, fd_txn_account_get_data_len( b ) ),
    1698           0 :                            fd_rent_exempt_minimum_balance( rent, b->starting_dlen ) ));
    1699             :             /* https://github.com/anza-xyz/agave/blob/b2c388d6cbff9b765d574bbb83a4378a1fc8af32/svm/src/account_rent_state.rs#L104 */
    1700           0 :             return FD_RUNTIME_TXN_ERR_INSUFFICIENT_FUNDS_FOR_RENT;
    1701             :           /* https://github.com/anza-xyz/agave/blob/b2c388d6cbff9b765d574bbb83a4378a1fc8af32/svm/src/account_rent_state.rs#L56 */
    1702           0 :           } else if( (fd_txn_account_get_data_len( b ) == b->starting_dlen) && fd_txn_account_get_lamports( b ) <= b->starting_lamports ) {
    1703             :             // no-op
    1704           0 :           } else {
    1705           0 :             FD_LOG_DEBUG(( "Rent exempt error for %s Curr len %lu Starting len %lu Curr lamports %lu Starting lamports %lu Curr exempt %lu Starting exempt %lu",
    1706           0 :                            FD_BASE58_ENC_32_ALLOCA( b->pubkey->uc ),
    1707           0 :                            fd_txn_account_get_data_len( b ),
    1708           0 :                            b->starting_dlen,
    1709           0 :                            fd_txn_account_get_lamports( b ),
    1710           0 :                            b->starting_lamports,
    1711           0 :                            fd_rent_exempt_minimum_balance( rent, fd_txn_account_get_data_len( b ) ),
    1712           0 :                            fd_rent_exempt_minimum_balance( rent, b->starting_dlen ) ));
    1713             :             /* https://github.com/anza-xyz/agave/blob/b2c388d6cbff9b765d574bbb83a4378a1fc8af32/svm/src/account_rent_state.rs#L104 */
    1714           0 :             return FD_RUNTIME_TXN_ERR_INSUFFICIENT_FUNDS_FOR_RENT;
    1715           0 :           }
    1716           0 :         }
    1717           0 :       }
    1718             : 
    1719           0 :       if( b->starting_lamports != ULONG_MAX ) {
    1720           0 :         fd_uwide_inc( &starting_lamports_h, &starting_lamports_l, starting_lamports_h, starting_lamports_l, b->starting_lamports );
    1721           0 :       }
    1722           0 :     }
    1723           0 :   }
    1724             : 
    1725             :   /* https://github.com/anza-xyz/agave/blob/b2c388d6cbff9b765d574bbb83a4378a1fc8af32/svm/src/transaction_processor.rs#L839-L845 */
    1726           0 :   if( FD_UNLIKELY( ending_lamports_l!=starting_lamports_l || ending_lamports_h!=starting_lamports_h ) ) {
    1727           0 :     FD_LOG_DEBUG(( "Lamport sum mismatch: starting %lx%lx ending %lx%lx", starting_lamports_h, starting_lamports_l, ending_lamports_h, ending_lamports_l ));
    1728           0 :     return FD_RUNTIME_TXN_ERR_UNBALANCED_TRANSACTION;
    1729           0 :   }
    1730             : 
    1731           0 :   return FD_RUNTIME_EXECUTE_SUCCESS;
    1732           0 : }
    1733             : 
    1734             : int
    1735             : fd_executor_consume_cus( fd_txn_out_t * txn_out,
    1736           3 :                          ulong          cus ) {
    1737           3 :   ulong new_cus   =  txn_out->details.compute_budget.compute_meter - cus;
    1738           3 :   int   underflow = (txn_out->details.compute_budget.compute_meter < cus);
    1739           3 :   if( FD_UNLIKELY( underflow ) ) {
    1740           0 :     txn_out->details.compute_budget.compute_meter = 0UL;
    1741           0 :     return FD_EXECUTOR_INSTR_ERR_COMPUTE_BUDGET_EXCEEDED;
    1742           0 :   }
    1743           3 :   txn_out->details.compute_budget.compute_meter = new_cus;
    1744           3 :   return FD_EXECUTOR_INSTR_SUCCESS;
    1745           3 : }
    1746             : 
    1747             : /* fd_executor_instr_strerror() returns the error message corresponding to err,
    1748             :    intended to be logged by log_collector, or an empty string if the error code
    1749             :    should be omitted in logs for whatever reason.  Omitted examples are success,
    1750             :    fatal (placeholder just in firedancer), custom error.
    1751             :    See also fd_log_collector_program_failure(). */
    1752             : FD_FN_CONST char const *
    1753           0 : fd_executor_instr_strerror( int err ) {
    1754             : 
    1755           0 :   switch( err ) {
    1756           0 :   case FD_EXECUTOR_INSTR_SUCCESS                                : return ""; // not used
    1757           0 :   case FD_EXECUTOR_INSTR_ERR_FATAL                              : return ""; // not used
    1758           0 :   case FD_EXECUTOR_INSTR_ERR_GENERIC_ERR                        : return "generic instruction error";
    1759           0 :   case FD_EXECUTOR_INSTR_ERR_INVALID_ARG                        : return "invalid program argument";
    1760           0 :   case FD_EXECUTOR_INSTR_ERR_INVALID_INSTR_DATA                 : return "invalid instruction data";
    1761           0 :   case FD_EXECUTOR_INSTR_ERR_INVALID_ACC_DATA                   : return "invalid account data for instruction";
    1762           0 :   case FD_EXECUTOR_INSTR_ERR_ACC_DATA_TOO_SMALL                 : return "account data too small for instruction";
    1763           0 :   case FD_EXECUTOR_INSTR_ERR_INSUFFICIENT_FUNDS                 : return "insufficient funds for instruction";
    1764           0 :   case FD_EXECUTOR_INSTR_ERR_INCORRECT_PROGRAM_ID               : return "incorrect program id for instruction";
    1765           0 :   case FD_EXECUTOR_INSTR_ERR_MISSING_REQUIRED_SIGNATURE         : return "missing required signature for instruction";
    1766           0 :   case FD_EXECUTOR_INSTR_ERR_ACC_ALREADY_INITIALIZED            : return "instruction requires an uninitialized account";
    1767           0 :   case FD_EXECUTOR_INSTR_ERR_UNINITIALIZED_ACCOUNT              : return "instruction requires an initialized account";
    1768           0 :   case FD_EXECUTOR_INSTR_ERR_UNBALANCED_INSTR                   : return "sum of account balances before and after instruction do not match";
    1769           0 :   case FD_EXECUTOR_INSTR_ERR_MODIFIED_PROGRAM_ID                : return "instruction illegally modified the program id of an account";
    1770           0 :   case FD_EXECUTOR_INSTR_ERR_EXTERNAL_ACCOUNT_LAMPORT_SPEND     : return "instruction spent from the balance of an account it does not own";
    1771           0 :   case FD_EXECUTOR_INSTR_ERR_EXTERNAL_DATA_MODIFIED             : return "instruction modified data of an account it does not own";
    1772           0 :   case FD_EXECUTOR_INSTR_ERR_READONLY_LAMPORT_CHANGE            : return "instruction changed the balance of a read-only account";
    1773           0 :   case FD_EXECUTOR_INSTR_ERR_READONLY_DATA_MODIFIED             : return "instruction modified data of a read-only account";
    1774           0 :   case FD_EXECUTOR_INSTR_ERR_DUPLICATE_ACCOUNT_IDX              : return "instruction contains duplicate accounts";
    1775           0 :   case FD_EXECUTOR_INSTR_ERR_EXECUTABLE_MODIFIED                : return "instruction changed executable bit of an account";
    1776           0 :   case FD_EXECUTOR_INSTR_ERR_RENT_EPOCH_MODIFIED                : return "instruction modified rent epoch of an account";
    1777           0 :   case FD_EXECUTOR_INSTR_ERR_NOT_ENOUGH_ACC_KEYS                : return "insufficient account keys for instruction";
    1778           0 :   case FD_EXECUTOR_INSTR_ERR_ACC_DATA_SIZE_CHANGED              : return "program other than the account's owner changed the size of the account data";
    1779           0 :   case FD_EXECUTOR_INSTR_ERR_ACC_NOT_EXECUTABLE                 : return "instruction expected an executable account";
    1780           0 :   case FD_EXECUTOR_INSTR_ERR_ACC_BORROW_FAILED                  : return "instruction tries to borrow reference for an account which is already borrowed";
    1781           0 :   case FD_EXECUTOR_INSTR_ERR_ACC_BORROW_OUTSTANDING             : return "instruction left account with an outstanding borrowed reference";
    1782           0 :   case FD_EXECUTOR_INSTR_ERR_DUPLICATE_ACCOUNT_OUT_OF_SYNC      : return "instruction modifications of multiply-passed account differ";
    1783           0 :   case FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR                         : return ""; // custom handling via txn_ctx->err.custom_err
    1784           0 :   case FD_EXECUTOR_INSTR_ERR_INVALID_ERR                        : return "program returned invalid error code";
    1785           0 :   case FD_EXECUTOR_INSTR_ERR_EXECUTABLE_DATA_MODIFIED           : return "instruction changed executable accounts data";
    1786           0 :   case FD_EXECUTOR_INSTR_ERR_EXECUTABLE_LAMPORT_CHANGE          : return "instruction changed the balance of an executable account";
    1787           0 :   case FD_EXECUTOR_INSTR_ERR_EXECUTABLE_ACCOUNT_NOT_RENT_EXEMPT : return "executable accounts must be rent exempt";
    1788           0 :   case FD_EXECUTOR_INSTR_ERR_UNSUPPORTED_PROGRAM_ID             : return "Unsupported program id";
    1789           0 :   case FD_EXECUTOR_INSTR_ERR_CALL_DEPTH                         : return "Cross-program invocation call depth too deep";
    1790           0 :   case FD_EXECUTOR_INSTR_ERR_MISSING_ACC                        : return "An account required by the instruction is missing";
    1791           0 :   case FD_EXECUTOR_INSTR_ERR_REENTRANCY_NOT_ALLOWED             : return "Cross-program invocation reentrancy not allowed for this instruction";
    1792           0 :   case FD_EXECUTOR_INSTR_ERR_MAX_SEED_LENGTH_EXCEEDED           : return "Length of the seed is too long for address generation";
    1793           0 :   case FD_EXECUTOR_INSTR_ERR_INVALID_SEEDS                      : return "Provided seeds do not result in a valid address";
    1794           0 :   case FD_EXECUTOR_INSTR_ERR_INVALID_REALLOC                    : return "Failed to reallocate account data";
    1795           0 :   case FD_EXECUTOR_INSTR_ERR_COMPUTE_BUDGET_EXCEEDED            : return "Computational budget exceeded";
    1796           0 :   case FD_EXECUTOR_INSTR_ERR_PRIVILEGE_ESCALATION               : return "Cross-program invocation with unauthorized signer or writable account";
    1797           0 :   case FD_EXECUTOR_INSTR_ERR_PROGRAM_ENVIRONMENT_SETUP_FAILURE  : return "Failed to create program execution environment";
    1798           0 :   case FD_EXECUTOR_INSTR_ERR_PROGRAM_FAILED_TO_COMPLETE         : return "Program failed to complete";
    1799           0 :   case FD_EXECUTOR_INSTR_ERR_PROGRAM_FAILED_TO_COMPILE          : return "Program failed to compile";
    1800           0 :   case FD_EXECUTOR_INSTR_ERR_ACC_IMMUTABLE                      : return "Account is immutable";
    1801           0 :   case FD_EXECUTOR_INSTR_ERR_INCORRECT_AUTHORITY                : return "Incorrect authority provided";
    1802           0 :   case FD_EXECUTOR_INSTR_ERR_BORSH_IO_ERROR                     : return "Failed to serialize or deserialize account data"; // truncated
    1803           0 :   case FD_EXECUTOR_INSTR_ERR_ACC_NOT_RENT_EXEMPT                : return "An account does not have enough lamports to be rent-exempt";
    1804           0 :   case FD_EXECUTOR_INSTR_ERR_INVALID_ACC_OWNER                  : return "Invalid account owner";
    1805           0 :   case FD_EXECUTOR_INSTR_ERR_ARITHMETIC_OVERFLOW                : return "Program arithmetic overflowed";
    1806           0 :   case FD_EXECUTOR_INSTR_ERR_UNSUPPORTED_SYSVAR                 : return "Unsupported sysvar";
    1807           0 :   case FD_EXECUTOR_INSTR_ERR_ILLEGAL_OWNER                      : return "Provided owner is not allowed";
    1808           0 :   case FD_EXECUTOR_INSTR_ERR_MAX_ACCS_DATA_ALLOCS_EXCEEDED      : return "Accounts data allocations exceeded the maximum allowed per transaction";
    1809           0 :   case FD_EXECUTOR_INSTR_ERR_MAX_ACCS_EXCEEDED                  : return "Max accounts exceeded";
    1810           0 :   case FD_EXECUTOR_INSTR_ERR_MAX_INSN_TRACE_LENS_EXCEEDED       : return "Max instruction trace length exceeded";
    1811           0 :   case FD_EXECUTOR_INSTR_ERR_BUILTINS_MUST_CONSUME_CUS          : return "Builtin programs must consume compute units";
    1812           0 :   default: break;
    1813           0 :   }
    1814             : 
    1815           0 :   return "";
    1816           0 : }
    1817             : 
    1818             : // This is purely linker magic to force the inclusion of the yaml type walker so that it is
    1819             : // available for debuggers
    1820             : void
    1821           0 : fd_debug_symbology(void) {
    1822           0 :   (void)fd_get_types_yaml();
    1823           0 : }

Generated by: LCOV version 1.14