Skip to main content

rialo_s_builtins/
lib.rs

1// Copyright (c) Subzero Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3// This file is either (a) original to Subzero Labs, Inc. or (b) derived from the Anza codebase and modified by Subzero Labs, Inc.
4
5//! Solana builtin programs.
6//!
7//! Warning: This crate is not for public consumption. It will change, and
8//! could possibly be removed altogether in the future. For now, it is purely
9//! for the purpose of managing the migration of builtins to Core BPF.
10//!
11//! It serves as a source of truth for:
12//! * The list of builtins that a Bank should add.
13//! * Which of those builtins have been assigned a feature gate to migrate to
14//!   Core BPF, as well as whether or not that feature gate has been activated.
15
16pub mod core_bpf_migration;
17pub mod prototype;
18
19use rialo_s_feature_set as feature_set;
20use rialo_s_sdk_ids::{bpf_loader, bpf_loader_deprecated, bpf_loader_upgradeable};
21
22use crate::{
23    core_bpf_migration::{CoreBpfMigrationConfig, CoreBpfMigrationTargetType},
24    prototype::{BuiltinPrototype, StatelessBuiltinPrototype},
25};
26
27macro_rules! testable_prototype {
28    ($prototype:ident {
29        core_bpf_migration_config: $core_bpf_migration_config:expr,
30        name: $name:ident,
31        $($field:ident : $value:expr),* $(,)?
32    }) => {
33        $prototype {
34            core_bpf_migration_config: {
35                #[cfg(not(feature = "dev-context-only-utils"))]
36                {
37                    $core_bpf_migration_config
38                }
39                #[cfg(feature = "dev-context-only-utils")]
40                {
41                    Some( test_only::$name::CONFIG )
42                }
43            },
44            name: stringify!($name),
45            $($field: $value),*
46        }
47    };
48}
49
50/// DEVELOPER: when a builtin is migrated to sbpf, please add its corresponding
51/// migration feature ID to solana-builtin-default-costs::BUILTIN_INSTRUCTION_COSTS,
52/// so the builtin's default cost can be determined properly based on feature status.
53/// When migration completed, and the feature gate is enabled everywhere, please
54/// remove that builtin entry from solana-builtin-default-costs::BUILTIN_INSTRUCTION_COSTS.
55pub static BUILTINS: &[BuiltinPrototype] = &[
56    testable_prototype!(BuiltinPrototype {
57        core_bpf_migration_config: None,
58        name: system_program,
59        enable_feature_id: None,
60        program_id: rialo_s_system_program::id(),
61        entrypoint: rialo_s_system_program::system_processor::Entrypoint::vm,
62    }),
63    BuiltinPrototype {
64        core_bpf_migration_config: Some(CoreBpfMigrationConfig {
65            source_buffer_address: buffer_accounts::config_program::id(),
66            upgrade_authority_address: None,
67            feature_id: rialo_s_feature_set::migrate_config_program_to_core_bpf::id(),
68            migration_target: CoreBpfMigrationTargetType::Builtin,
69            datapoint_name: "migrate_builtin_to_core_bpf_config_program",
70        }),
71        name: "config_program",
72        enable_feature_id: None,
73        program_id: rialo_s_config_program::id(),
74        entrypoint: rialo_s_config_program::config_processor::Entrypoint::vm,
75    },
76    testable_prototype!(BuiltinPrototype {
77        core_bpf_migration_config: None,
78        name: solana_bpf_loader_deprecated_program,
79        enable_feature_id: None,
80        program_id: bpf_loader_deprecated::id(),
81        entrypoint: rialo_s_bpf_loader_program::Entrypoint::vm,
82    }),
83    testable_prototype!(BuiltinPrototype {
84        core_bpf_migration_config: None,
85        name: rialo_s_bpf_loader_program,
86        enable_feature_id: None,
87        program_id: bpf_loader::id(),
88        entrypoint: rialo_s_bpf_loader_program::Entrypoint::vm,
89    }),
90    testable_prototype!(BuiltinPrototype {
91        core_bpf_migration_config: None,
92        name: solana_bpf_loader_upgradeable_program,
93        enable_feature_id: None,
94        program_id: bpf_loader_upgradeable::id(),
95        entrypoint: rialo_s_bpf_loader_program::Entrypoint::vm,
96    }),
97    testable_prototype!(BuiltinPrototype {
98        core_bpf_migration_config: None,
99        name: compute_budget_program,
100        enable_feature_id: None,
101        program_id: rialo_s_sdk_ids::compute_budget::id(),
102        entrypoint: rialo_s_compute_budget_program::Entrypoint::vm,
103    }),
104    testable_prototype!(BuiltinPrototype {
105        core_bpf_migration_config: None,
106        name: loader_v4,
107        enable_feature_id: Some(feature_set::enable_loader_v4::id()),
108        program_id: rialo_s_sdk_ids::loader_v4::id(),
109        entrypoint: rialo_s_loader_v4_program::Entrypoint::vm,
110    }),
111];
112
113pub static STATELESS_BUILTINS: &[StatelessBuiltinPrototype] = &[StatelessBuiltinPrototype {
114    core_bpf_migration_config: Some(CoreBpfMigrationConfig {
115        source_buffer_address: buffer_accounts::feature_gate_program::id(),
116        upgrade_authority_address: None,
117        feature_id: rialo_s_feature_set::migrate_feature_gate_program_to_core_bpf::id(),
118        migration_target: CoreBpfMigrationTargetType::Stateless,
119        datapoint_name: "migrate_stateless_to_core_bpf_feature_gate_program",
120    }),
121    name: "feature_gate_program",
122    program_id: rialo_s_sdk_ids::feature::id(),
123}];
124
125/// Live source buffer accounts for builtin migrations.
126mod buffer_accounts {
127    pub mod config_program {
128        rialo_s_pubkey::declare_id!("BuafH9fBv62u6XjzrzS4ZjAE8963ejqF5rt1f8Uga4Q3");
129    }
130    pub mod feature_gate_program {
131        rialo_s_pubkey::declare_id!("3D3ydPWvmEszrSjrickCtnyRSJm1rzbbSsZog8Ub6vLh");
132    }
133}
134
135// This module contains a number of arbitrary addresses used for testing Core
136// BPF migrations.
137// Since the list of builtins is static, using `declare_id!` with constant
138// values is arguably the least-overhead approach to injecting static addresses
139// into the builtins list for both the feature ID and the source program ID.
140// These arbitrary IDs can then be used to configure feature-activation runtime
141// tests.
142#[cfg(any(test, feature = "dev-context-only-utils"))]
143pub mod test_only {
144    use crate::core_bpf_migration::{CoreBpfMigrationConfig, CoreBpfMigrationTargetType};
145    pub mod system_program {
146        pub mod feature {
147            rialo_s_pubkey::declare_id!("AnjsdWg7LXFbjDdy78wncCJs9PyTdWpKkFmHAwQU1mQ6");
148        }
149        pub mod source_buffer {
150            rialo_s_pubkey::declare_id!("EDEhzg1Jk79Wrk4mwpRa7txjgRxcE6igXwd6egFDVhuz");
151        }
152        pub mod upgrade_authority {
153            rialo_s_pubkey::declare_id!("4d14UK2o1FKKoecEBWhVDZrBBbRuhug75G1j9XYCawC2");
154        }
155        pub const CONFIG: super::CoreBpfMigrationConfig = super::CoreBpfMigrationConfig {
156            source_buffer_address: source_buffer::id(),
157            upgrade_authority_address: Some(upgrade_authority::id()),
158            feature_id: feature::id(),
159            migration_target: super::CoreBpfMigrationTargetType::Builtin,
160            datapoint_name: "migrate_builtin_to_core_bpf_system_program",
161        };
162    }
163
164    pub mod solana_bpf_loader_deprecated_program {
165        pub mod feature {
166            rialo_s_pubkey::declare_id!("8gpakCv5Pk5PZGv9RUjzdkk2GVQPGx12cNRUDMQ3bP86");
167        }
168        pub mod source_buffer {
169            rialo_s_pubkey::declare_id!("DveUYB5m9G3ce4zpV3fxg9pCNkvH1wDsyd8XberZ47JL");
170        }
171        pub mod upgrade_authority {
172            rialo_s_pubkey::declare_id!("8Y5VTHdadnz4rZZWdUA4Qq2m2zWoCwwtb38spPZCXuGU");
173        }
174        pub const CONFIG: super::CoreBpfMigrationConfig = super::CoreBpfMigrationConfig {
175            source_buffer_address: source_buffer::id(),
176            upgrade_authority_address: Some(upgrade_authority::id()),
177            feature_id: feature::id(),
178            migration_target: super::CoreBpfMigrationTargetType::Builtin,
179            datapoint_name: "migrate_builtin_to_core_bpf_bpf_loader_deprecated_program",
180        };
181    }
182
183    pub mod rialo_s_bpf_loader_program {
184        pub mod feature {
185            rialo_s_pubkey::declare_id!("8yEdUm4SaP1yNq2MczEVdrM48SucvZCTDSqjcAKfYfL6");
186        }
187        pub mod source_buffer {
188            rialo_s_pubkey::declare_id!("2EWMYGJPuGLW4TexLLEMeXP2BkB1PXEKBFb698yw6LhT");
189        }
190        pub mod upgrade_authority {
191            rialo_s_pubkey::declare_id!("3sQ9VZ1Lvuvs6NpFXFV3ByFAf52ajPPdXwuhYERJR3iJ");
192        }
193        pub const CONFIG: super::CoreBpfMigrationConfig = super::CoreBpfMigrationConfig {
194            source_buffer_address: source_buffer::id(),
195            upgrade_authority_address: Some(upgrade_authority::id()),
196            feature_id: feature::id(),
197            migration_target: super::CoreBpfMigrationTargetType::Builtin,
198            datapoint_name: "migrate_builtin_to_core_bpf_bpf_loader_program",
199        };
200    }
201
202    pub mod solana_bpf_loader_upgradeable_program {
203        pub mod feature {
204            rialo_s_pubkey::declare_id!("oPQbVjgoQ7SaQmzZiiHW4xqHbh4BJqqrFhxEJZiMiwY");
205        }
206        pub mod source_buffer {
207            rialo_s_pubkey::declare_id!("6bTmA9iefD57GDoQ9wUjG8SeYkSpRw3EkKzxZCbhkavq");
208        }
209        pub mod upgrade_authority {
210            rialo_s_pubkey::declare_id!("CuJvJY1K2wx82oLrQGSSWtw4AF7nVifEHupzSC2KEcq5");
211        }
212        pub const CONFIG: super::CoreBpfMigrationConfig = super::CoreBpfMigrationConfig {
213            source_buffer_address: source_buffer::id(),
214            upgrade_authority_address: Some(upgrade_authority::id()),
215            feature_id: feature::id(),
216            migration_target: super::CoreBpfMigrationTargetType::Builtin,
217            datapoint_name: "migrate_builtin_to_core_bpf_bpf_loader_upgradeable_program",
218        };
219    }
220
221    pub mod compute_budget_program {
222        pub mod feature {
223            rialo_s_pubkey::declare_id!("D39vUspVfhjPVD7EtMJZrA5j1TSMp4LXfb43nxumGdHT");
224        }
225        pub mod source_buffer {
226            rialo_s_pubkey::declare_id!("KfX1oLpFC5CwmFeSgXrNcXaouKjFkPuSJ4UsKb3zKMX");
227        }
228        pub mod upgrade_authority {
229            rialo_s_pubkey::declare_id!("HGTbQhaCXNTbpgpLb2KNjqWSwpJyb2dqDB66Lc3Ph4aN");
230        }
231        pub const CONFIG: super::CoreBpfMigrationConfig = super::CoreBpfMigrationConfig {
232            source_buffer_address: source_buffer::id(),
233            upgrade_authority_address: Some(upgrade_authority::id()),
234            feature_id: feature::id(),
235            migration_target: super::CoreBpfMigrationTargetType::Builtin,
236            datapoint_name: "migrate_builtin_to_core_bpf_compute_budget_program",
237        };
238    }
239
240    pub mod loader_v4 {
241        pub mod feature {
242            rialo_s_pubkey::declare_id!("Cz5JthYp27KR3rwTCtVJhbRgwHCurbwcYX46D8setL22");
243        }
244        pub mod source_buffer {
245            rialo_s_pubkey::declare_id!("EH45pKy1kzjifB93wEJi91js3S4HETdsteywR7ZCNPn5");
246        }
247        pub mod upgrade_authority {
248            rialo_s_pubkey::declare_id!("AWbiYRbFts9GVX5uwUkwV46hTFP85PxCAM8e8ir8Hqtq");
249        }
250        pub const CONFIG: super::CoreBpfMigrationConfig = super::CoreBpfMigrationConfig {
251            source_buffer_address: source_buffer::id(),
252            upgrade_authority_address: Some(upgrade_authority::id()),
253            feature_id: feature::id(),
254            migration_target: super::CoreBpfMigrationTargetType::Builtin,
255            datapoint_name: "migrate_builtin_to_core_bpf_loader_v4_program",
256        };
257    }
258}
259
260#[cfg(test)]
261mod tests {
262    // Since a macro is used to initialize the test IDs from the `test_only`
263    // module, best to ensure the lists have the expected values within a test
264    // context.
265    #[test]
266    fn test_testable_prototypes() {
267        assert_eq!(
268            &super::BUILTINS[0].core_bpf_migration_config,
269            &Some(super::test_only::system_program::CONFIG)
270        );
271        // Config has a live migration config, so it has no test-only configs
272        // to test here.
273        assert_eq!(
274            &super::BUILTINS[2].core_bpf_migration_config,
275            &Some(super::test_only::solana_bpf_loader_deprecated_program::CONFIG)
276        );
277        assert_eq!(
278            &super::BUILTINS[3].core_bpf_migration_config,
279            &Some(super::test_only::rialo_s_bpf_loader_program::CONFIG)
280        );
281        assert_eq!(
282            &super::BUILTINS[4].core_bpf_migration_config,
283            &Some(super::test_only::solana_bpf_loader_upgradeable_program::CONFIG)
284        );
285        assert_eq!(
286            &super::BUILTINS[5].core_bpf_migration_config,
287            &Some(super::test_only::compute_budget_program::CONFIG)
288        );
289        assert_eq!(
290            &super::BUILTINS[6].core_bpf_migration_config,
291            &Some(super::test_only::loader_v4::CONFIG)
292        );
293        // TODO(SUB-1547): Plug in the new feature management program
294        // assert_eq!(
295        //     &super::BUILTINS[7].core_bpf_migration_config,
296        //     &Some(super::test_only::feature_management_program::CONFIG)
297        // );
298        // Feature Gate has a live migration config, so it has no test-only
299        // configs to test here.
300    }
301}