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 140841 : ulong sz ) {
19 :
20 140841 : fd_acc_mgr_t * acc_mgr = slot_ctx->acc_mgr;
21 140841 : fd_funk_txn_t * txn = slot_ctx->funk_txn;
22 140841 : fd_pubkey_t const * key = (fd_pubkey_t const *)pubkey;
23 140841 : FD_BORROWED_ACCOUNT_DECL(rec);
24 :
25 140841 : int err = fd_acc_mgr_modify( acc_mgr, txn, key, 1, sz, rec);
26 140841 : FD_TEST( !err );
27 :
28 140841 : rec->meta->dlen = sz;
29 140841 : rec->meta->info.lamports = 1UL;
30 140841 : rec->meta->info.rent_epoch = 0UL;
31 140841 : rec->meta->info.executable = 1;
32 140841 : fd_memcpy( rec->meta->info.owner, fd_solana_native_loader_id.key, 32 );
33 140841 : memcpy( rec->data, data, sz );
34 :
35 140841 : slot_ctx->slot_bank.capitalization++;
36 :
37 : // err = fd_acc_mgr_commit( acc_mgr, rec, slot_ctx );
38 140841 : FD_TEST( !err );
39 140841 : }
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 : void
44 11370 : write_inline_spl_native_mint_program_account( fd_exec_slot_ctx_t * slot_ctx ) {
45 : // really?! really!?
46 11370 : fd_epoch_bank_t const * epoch_bank = fd_exec_epoch_ctx_epoch_bank( slot_ctx->epoch_ctx );
47 11370 : if( epoch_bank->cluster_type != 3)
48 11370 : 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 11370 : 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 11370 : fd_write_builtin_bogus_account( slot_ctx, fd_solana_system_program_id.key, "system_program", 14UL );
78 11370 : fd_write_builtin_bogus_account( slot_ctx, fd_solana_vote_program_id.key, "vote_program", 12UL );
79 11370 : fd_write_builtin_bogus_account( slot_ctx, fd_solana_stake_program_id.key, "stake_program", 13UL );
80 11370 : fd_write_builtin_bogus_account( slot_ctx, fd_solana_config_program_id.key, "config_program", 14UL );
81 :
82 11370 : if( FD_FEATURE_ACTIVE( slot_ctx, enable_program_runtime_v2_and_loader_v4 ) ) {
83 0 : fd_write_builtin_bogus_account( slot_ctx, fd_solana_bpf_loader_v4_program_id.key, "loader_v4", 9UL );
84 0 : }
85 :
86 11370 : fd_write_builtin_bogus_account( slot_ctx, fd_solana_address_lookup_table_program_id.key, "address_lookup_table_program", 28UL );
87 11370 : fd_write_builtin_bogus_account( slot_ctx, fd_solana_bpf_loader_deprecated_program_id.key, "solana_bpf_loader_deprecated_program", 36UL );
88 :
89 11370 : fd_write_builtin_bogus_account( slot_ctx, fd_solana_bpf_loader_program_id.key, "solana_bpf_loader_program", 25UL );
90 11370 : fd_write_builtin_bogus_account( slot_ctx, fd_solana_bpf_loader_upgradeable_program_id.key, "solana_bpf_loader_upgradeable_program", 37UL );
91 :
92 11370 : fd_write_builtin_bogus_account( slot_ctx, fd_solana_compute_budget_program_id.key, "compute_budget_program", 22UL );
93 :
94 : //TODO: remove when no longer necessary
95 11370 : if( FD_FEATURE_ACTIVE( slot_ctx, zk_token_sdk_enabled ) ) {
96 2004 : fd_write_builtin_bogus_account( slot_ctx, fd_solana_zk_token_proof_program_id.key, "zk_token_proof_program", 22UL );
97 2004 : }
98 :
99 11370 : if( FD_FEATURE_ACTIVE( slot_ctx, zk_elgamal_proof_program_enabled ) ) {
100 2397 : fd_write_builtin_bogus_account( slot_ctx, fd_solana_zk_elgamal_proof_program_id.key, "zk_elgamal_proof_program", 24UL );
101 2397 : }
102 :
103 : /* Precompiles have empty account data */
104 11370 : if (slot_ctx->epoch_ctx->epoch_bank.cluster_version[0] < 2) {
105 0 : char data[1] = {1};
106 0 : fd_write_builtin_bogus_account( slot_ctx, fd_solana_keccak_secp_256k_program_id.key, data, 1 );
107 0 : fd_write_builtin_bogus_account( slot_ctx, fd_solana_ed25519_sig_verify_program_id.key, data, 1 );
108 0 : fd_write_builtin_bogus_account( slot_ctx, fd_solana_secp256r1_program_id.key, data, 1 );
109 11370 : } else {
110 11370 : fd_write_builtin_bogus_account( slot_ctx, fd_solana_keccak_secp_256k_program_id.key, "", 0 );
111 11370 : fd_write_builtin_bogus_account( slot_ctx, fd_solana_ed25519_sig_verify_program_id.key, "", 0 );
112 11370 : fd_write_builtin_bogus_account( slot_ctx, fd_solana_secp256r1_program_id.key, "", 0 );
113 11370 : }
114 :
115 : /* Inline SPL token mint program ("inlined to avoid an external dependency on the spl-token crate") */
116 11370 : write_inline_spl_native_mint_program_account( slot_ctx );
117 11370 : }
|