LCOV - code coverage report
Current view: top level - flamenco/runtime/program - fd_builtin_programs.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 52 77 67.5 %
Date: 2025-01-08 12:08:44 Functions: 3 3 100.0 %

          Line data    Source code
       1             : #include "fd_builtin_programs.h"
       2             : #include "../fd_acc_mgr.h"
       3             : #include "../fd_system_ids.h"
       4             : #include "../context/fd_exec_epoch_ctx.h"
       5             : #include "../context/fd_exec_slot_ctx.h"
       6             : 
       7             : /* BuiltIn programs need "bogus" executable accounts to exist.
       8             :    These are loaded and ignored during execution.
       9             : 
      10             :    Bogus accounts are marked as "executable", but their data is a
      11             :    hardcoded ASCII string. */
      12             : 
      13             : /* https://github.com/solana-labs/solana/blob/8f2c8b8388a495d2728909e30460aa40dcc5d733/sdk/src/native_loader.rs#L19 */
      14             : void
      15             : fd_write_builtin_bogus_account( fd_exec_slot_ctx_t * slot_ctx,
      16             :                                 uchar const          pubkey[ static 32 ],
      17             :                                 char const *         data,
      18      122400 :                                 ulong                sz ) {
      19             : 
      20      122400 :   fd_acc_mgr_t *      acc_mgr = slot_ctx->acc_mgr;
      21      122400 :   fd_funk_txn_t *     txn     = slot_ctx->funk_txn;
      22      122400 :   fd_pubkey_t const * key     = (fd_pubkey_t const *)pubkey;
      23      122400 :   FD_BORROWED_ACCOUNT_DECL(rec);
      24             : 
      25      122400 :   int err = fd_acc_mgr_modify( acc_mgr, txn, key, 1, sz, rec);
      26      122400 :   FD_TEST( !err );
      27             : 
      28      122400 :   rec->meta->dlen            = sz;
      29      122400 :   rec->meta->info.lamports   = 1UL;
      30      122400 :   rec->meta->info.rent_epoch = 0UL;
      31      122400 :   rec->meta->info.executable = 1;
      32      122400 :   fd_memcpy( rec->meta->info.owner, fd_solana_native_loader_id.key, 32 );
      33      122400 :   memcpy( rec->data, data, sz );
      34             : 
      35      122400 :   slot_ctx->slot_bank.capitalization++;
      36             : 
      37             :   // err = fd_acc_mgr_commit( acc_mgr, rec, slot_ctx );
      38      122400 :   FD_TEST( !err );
      39      122400 : }
      40             : 
      41             : /* https://github.com/solana-labs/solana/blob/8f2c8b8388a495d2728909e30460aa40dcc5d733/runtime/src/inline_spl_token.rs#L74 */
      42             : /* TODO: move this somewhere more appropiate */
      43             : static void
      44       12741 : write_inline_spl_native_mint_program_account( fd_exec_slot_ctx_t * slot_ctx ) {
      45             :   // really?! really!?
      46       12741 :   fd_epoch_bank_t const * epoch_bank = fd_exec_epoch_ctx_epoch_bank( slot_ctx->epoch_ctx );
      47       12741 :   if( epoch_bank->cluster_type != 3)
      48       12741 :     return;
      49             : 
      50           0 :   fd_acc_mgr_t *      acc_mgr = slot_ctx->acc_mgr;
      51           0 :   fd_funk_txn_t *     txn     = slot_ctx->funk_txn;
      52           0 :   fd_pubkey_t const * key     = (fd_pubkey_t const *)&fd_solana_spl_native_mint_id;
      53           0 :   FD_BORROWED_ACCOUNT_DECL(rec);
      54             : 
      55             :   /* https://github.com/solana-labs/solana/blob/8f2c8b8388a495d2728909e30460aa40dcc5d733/runtime/src/inline_spl_token.rs#L86-L90 */
      56           0 :   static uchar const data[] = {
      57           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,
      58           0 :       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      59           0 :       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
      60             : 
      61           0 :   int err = fd_acc_mgr_modify( acc_mgr, txn, key, 1, sizeof(data), rec );
      62           0 :   FD_TEST( !err );
      63             : 
      64           0 :   rec->meta->dlen            = sizeof(data);
      65           0 :   rec->meta->info.lamports   = 1000000000UL;
      66           0 :   rec->meta->info.rent_epoch = 1UL;
      67           0 :   rec->meta->info.executable = 0;
      68           0 :   fd_memcpy( rec->meta->info.owner, fd_solana_spl_token_id.key, 32 );
      69           0 :   memcpy( rec->data, data, sizeof(data) );
      70             : 
      71           0 :   FD_TEST( !err );
      72           0 : }
      73             : 
      74       12741 : void fd_builtin_programs_init( fd_exec_slot_ctx_t * slot_ctx ) {
      75             :   // https://github.com/anza-xyz/agave/blob/v2.0.1/runtime/src/bank/builtins/mod.rs#L33
      76             : 
      77       12741 :   fd_write_builtin_bogus_account( slot_ctx, fd_solana_system_program_id.key,         "system_program",         14UL );
      78       12741 :   fd_write_builtin_bogus_account( slot_ctx, fd_solana_vote_program_id.key,           "vote_program",           12UL );
      79             : 
      80       12741 :   if( !FD_FEATURE_ACTIVE( slot_ctx, migrate_stake_program_to_core_bpf ) ) {
      81       12741 :     fd_write_builtin_bogus_account( slot_ctx, fd_solana_stake_program_id.key,        "stake_program",          13UL );
      82       12741 :   }
      83             : 
      84       12741 :   if( !FD_FEATURE_ACTIVE( slot_ctx, migrate_config_program_to_core_bpf ) ) {
      85        1071 :     fd_write_builtin_bogus_account( slot_ctx, fd_solana_config_program_id.key,       "config_program",         14UL );
      86        1071 :   }
      87             : 
      88       12741 :   if( FD_FEATURE_ACTIVE( slot_ctx, enable_program_runtime_v2_and_loader_v4 ) ) {
      89           0 :     fd_write_builtin_bogus_account( slot_ctx, fd_solana_bpf_loader_v4_program_id.key,   "loader_v4",             9UL );
      90           0 :   }
      91             : 
      92       12741 :   if( !FD_FEATURE_ACTIVE( slot_ctx, migrate_address_lookup_table_program_to_core_bpf ) ) {
      93        1071 :     fd_write_builtin_bogus_account( slot_ctx, fd_solana_address_lookup_table_program_id.key, "address_lookup_table_program",          28UL );
      94        1071 :   }
      95             : 
      96       12741 :   fd_write_builtin_bogus_account( slot_ctx, fd_solana_bpf_loader_deprecated_program_id.key,  "solana_bpf_loader_deprecated_program",  36UL );
      97             : 
      98       12741 :   fd_write_builtin_bogus_account( slot_ctx, fd_solana_bpf_loader_program_id.key,             "solana_bpf_loader_program",             25UL );
      99       12741 :   fd_write_builtin_bogus_account( slot_ctx, fd_solana_bpf_loader_upgradeable_program_id.key, "solana_bpf_loader_upgradeable_program", 37UL );
     100             : 
     101       12741 :   fd_write_builtin_bogus_account( slot_ctx, fd_solana_compute_budget_program_id.key, "compute_budget_program", 22UL );
     102             : 
     103             :   //TODO: remove when no longer necessary
     104       12741 :   if( FD_FEATURE_ACTIVE( slot_ctx, zk_token_sdk_enabled ) ) {
     105        2049 :     fd_write_builtin_bogus_account( slot_ctx, fd_solana_zk_token_proof_program_id.key, "zk_token_proof_program", 22UL );
     106        2049 :   }
     107             : 
     108       12741 :   if( FD_FEATURE_ACTIVE( slot_ctx, zk_elgamal_proof_program_enabled ) ) {
     109        2469 :     fd_write_builtin_bogus_account( slot_ctx, fd_solana_zk_elgamal_proof_program_id.key, "zk_elgamal_proof_program", 24UL );
     110        2469 :   }
     111             : 
     112             :   /* Precompiles have empty account data */
     113       12741 :   if (slot_ctx->epoch_ctx->epoch_bank.cluster_version[0] < 2) {
     114           0 :     char data[1] = {1};
     115           0 :     fd_write_builtin_bogus_account( slot_ctx, fd_solana_keccak_secp_256k_program_id.key, data, 1 );
     116           0 :     fd_write_builtin_bogus_account( slot_ctx, fd_solana_ed25519_sig_verify_program_id.key, data, 1 );
     117           0 :     if (FD_FEATURE_ACTIVE( slot_ctx, enable_secp256r1_precompile ))
     118           0 :       fd_write_builtin_bogus_account( slot_ctx, fd_solana_secp256r1_program_id.key, data, 1 );
     119       12741 :   } else {
     120       12741 :     fd_write_builtin_bogus_account( slot_ctx, fd_solana_keccak_secp_256k_program_id.key, "", 0 );
     121       12741 :     fd_write_builtin_bogus_account( slot_ctx, fd_solana_ed25519_sig_verify_program_id.key, "", 0 );
     122       12741 :     if (FD_FEATURE_ACTIVE( slot_ctx, enable_secp256r1_precompile ))
     123        1071 :       fd_write_builtin_bogus_account( slot_ctx, fd_solana_secp256r1_program_id.key, "", 0 );
     124       12741 :   }
     125             : 
     126             :   /* Inline SPL token mint program ("inlined to avoid an external dependency on the spl-token crate") */
     127       12741 :   write_inline_spl_native_mint_program_account( slot_ctx );
     128       12741 : }

Generated by: LCOV version 1.14