Skip to content

Commit 2c1d548

Browse files
flamenco: activate precompiles at activation
1 parent a45df74 commit 2c1d548

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

src/flamenco/runtime/fd_runtime.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2660,6 +2660,14 @@ fd_apply_builtin_program_feature_transitions( fd_exec_slot_ctx_t * slot_ctx,
26602660
}
26612661
}
26622662

2663+
/* https://github.com/anza-xyz/agave/blob/c1080de464cfb578c301e975f498964b5d5313db/runtime/src/bank.rs#L6795-L6805 */
2664+
fd_precompile_program_t const * precompiles = fd_precompiles();
2665+
for( ulong i=0UL; i<fd_num_precompiles(); i++ ) {
2666+
if( FD_FEATURE_JUST_ACTIVATED_OFFSET( slot_ctx, precompiles[i].feature_offset ) ) {
2667+
fd_write_builtin_account( slot_ctx, *precompiles[i].pubkey, "", 0 );
2668+
}
2669+
}
2670+
26632671
} FD_SPAD_FRAME_END;
26642672
}
26652673

src/flamenco/runtime/program/fd_builtin_programs.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "fd_builtin_programs.h"
2+
#include "fd_precompiles.h"
23
#include "../fd_runtime.h"
34
#include "../fd_acc_mgr.h"
45
#include "../fd_system_ids.h"
@@ -26,6 +27,13 @@
2627
builtin_program_id \
2728
}
2829

30+
#define PRECOMPILE(program_id, feature_offset, verify_fn) \
31+
{ \
32+
program_id, \
33+
feature_offset, \
34+
verify_fn \
35+
}
36+
2937
#define NO_CORE_BPF_MIGRATION_CONFIG NULL
3038

3139
#define DEFINE_CORE_BPF_MIGRATION_CONFIG(name, buffer_address, feature_offset, program_id) \
@@ -57,12 +65,23 @@ DEFINE_CORE_BPF_MIGRATION_CONFIG(STATELESS_TO_CORE_BPF_FEATURE_GATE_PROGRAM_CONF
5765

5866
#define FEATURE_PROGRAM_BUILTIN STATELESS_BUILTIN(&fd_solana_feature_program_id, MIGRATE_STATELESS_TO_CORE_BPF_FEATURE_GATE_PROGRAM_CONFIG)
5967

68+
#define SECP256R1_PROGRAM_BUILTIN PRECOMPILE(&fd_solana_secp256r1_program_id, offsetof(fd_features_t, enable_secp256r1_precompile), fd_precompile_secp256r1_verify)
69+
#define KECCAK_SECP_PROGRAM_BUILTIN PRECOMPILE(&fd_solana_keccak_secp_256k_program_id, NO_ENABLE_FEATURE_ID, fd_precompile_secp256k1_verify)
70+
#define ED25519_SV_PROGRAM_BUILTIN PRECOMPILE(&fd_solana_ed25519_sig_verify_program_id, NO_ENABLE_FEATURE_ID, fd_precompile_ed25519_verify)
71+
6072
/* https://github.com/anza-xyz/agave/blob/v2.1.0/runtime/src/bank/builtins/mod.rs#L133-L143 */
6173
static const fd_stateless_builtin_program_t stateless_programs_builtins[] = {
6274
FEATURE_PROGRAM_BUILTIN
6375
};
6476
#define STATELESS_BUILTINS_COUNT (sizeof(stateless_programs_builtins) / sizeof(fd_stateless_builtin_program_t))
6577

78+
static const fd_precompile_program_t precompiles[] = {
79+
SECP256R1_PROGRAM_BUILTIN,
80+
KECCAK_SECP_PROGRAM_BUILTIN,
81+
ED25519_SV_PROGRAM_BUILTIN
82+
};
83+
#define PRECOMPILE_PROGRAMS_COUNT (sizeof(precompiles) / sizeof(fd_precompile_program_t))
84+
6685
/* https://github.com/anza-xyz/agave/blob/v2.1.0/runtime/src/bank/builtins/mod.rs#L34-L131 */
6786
static fd_builtin_program_t const builtin_programs[] = {
6887
SYSTEM_PROGRAM_BUILTIN,
@@ -250,6 +269,16 @@ fd_num_stateless_builtins( void ) {
250269
return STATELESS_BUILTINS_COUNT;
251270
}
252271

272+
fd_precompile_program_t const *
273+
fd_precompiles( void ) {
274+
return precompiles;
275+
}
276+
277+
ulong
278+
fd_num_precompiles( void ) {
279+
return PRECOMPILE_PROGRAMS_COUNT;
280+
}
281+
253282
uchar
254283
fd_is_migrating_builtin_program( fd_exec_txn_ctx_t const * txn_ctx,
255284
fd_pubkey_t const * pubkey,

src/flamenco/runtime/program/fd_builtin_programs.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ struct fd_stateless_builtin_program {
3939
};
4040
typedef struct fd_stateless_builtin_program fd_stateless_builtin_program_t;
4141

42+
struct fd_precompile_program {
43+
fd_pubkey_t const * pubkey;
44+
ulong feature_offset;
45+
int (*verify_fn)(fd_exec_instr_ctx_t*);
46+
};
47+
typedef struct fd_precompile_program fd_precompile_program_t;
48+
4249
FD_PROTOTYPES_BEGIN
4350

4451
/* Initialize the builtin program accounts */
@@ -79,6 +86,12 @@ fd_is_migrating_builtin_program( fd_exec_txn_ctx_t const * txn_ctx,
7986
uchar
8087
fd_is_non_migrating_builtin_program( fd_pubkey_t const * pubkey );
8188

89+
fd_precompile_program_t const *
90+
fd_precompiles( void );
91+
92+
ulong
93+
fd_num_precompiles( void );
94+
8295
FD_PROTOTYPES_END
8396

8497
#endif /* HEADER_fd_src_flamenco_runtime_program_fd_buildin_programs_h */

0 commit comments

Comments
 (0)