Skip to content

[wip] flamenco: activate precompiles at activation #5155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/flamenco/runtime/fd_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -2660,6 +2660,14 @@ fd_apply_builtin_program_feature_transitions( fd_exec_slot_ctx_t * slot_ctx,
}
}

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

} FD_SPAD_FRAME_END;
}

Expand Down
29 changes: 29 additions & 0 deletions src/flamenco/runtime/program/fd_builtin_programs.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "fd_builtin_programs.h"
#include "fd_precompiles.h"
#include "../fd_runtime.h"
#include "../fd_acc_mgr.h"
#include "../fd_system_ids.h"
Expand Down Expand Up @@ -26,6 +27,13 @@
builtin_program_id \
}

#define PRECOMPILE(program_id, feature_offset, verify_fn) \
{ \
program_id, \
feature_offset, \
verify_fn \
}

#define NO_CORE_BPF_MIGRATION_CONFIG NULL

#define DEFINE_CORE_BPF_MIGRATION_CONFIG(name, buffer_address, feature_offset, program_id) \
Expand Down Expand Up @@ -57,12 +65,23 @@ DEFINE_CORE_BPF_MIGRATION_CONFIG(STATELESS_TO_CORE_BPF_FEATURE_GATE_PROGRAM_CONF

#define FEATURE_PROGRAM_BUILTIN STATELESS_BUILTIN(&fd_solana_feature_program_id, MIGRATE_STATELESS_TO_CORE_BPF_FEATURE_GATE_PROGRAM_CONFIG)

#define SECP256R1_PROGRAM_BUILTIN PRECOMPILE(&fd_solana_secp256r1_program_id, offsetof(fd_features_t, enable_secp256r1_precompile), fd_precompile_secp256r1_verify)
#define KECCAK_SECP_PROGRAM_BUILTIN PRECOMPILE(&fd_solana_keccak_secp_256k_program_id, NO_ENABLE_FEATURE_ID, fd_precompile_secp256k1_verify)
#define ED25519_SV_PROGRAM_BUILTIN PRECOMPILE(&fd_solana_ed25519_sig_verify_program_id, NO_ENABLE_FEATURE_ID, fd_precompile_ed25519_verify)

/* https://github.com/anza-xyz/agave/blob/v2.1.0/runtime/src/bank/builtins/mod.rs#L133-L143 */
static const fd_stateless_builtin_program_t stateless_programs_builtins[] = {
FEATURE_PROGRAM_BUILTIN
};
#define STATELESS_BUILTINS_COUNT (sizeof(stateless_programs_builtins) / sizeof(fd_stateless_builtin_program_t))

static const fd_precompile_program_t precompiles[] = {
SECP256R1_PROGRAM_BUILTIN,
KECCAK_SECP_PROGRAM_BUILTIN,
ED25519_SV_PROGRAM_BUILTIN
};
#define PRECOMPILE_PROGRAMS_COUNT (sizeof(precompiles) / sizeof(fd_precompile_program_t))

/* https://github.com/anza-xyz/agave/blob/v2.1.0/runtime/src/bank/builtins/mod.rs#L34-L131 */
static fd_builtin_program_t const builtin_programs[] = {
SYSTEM_PROGRAM_BUILTIN,
Expand Down Expand Up @@ -250,6 +269,16 @@ fd_num_stateless_builtins( void ) {
return STATELESS_BUILTINS_COUNT;
}

fd_precompile_program_t const *
fd_precompiles( void ) {
return precompiles;
}

ulong
fd_num_precompiles( void ) {
return PRECOMPILE_PROGRAMS_COUNT;
}

uchar
fd_is_migrating_builtin_program( fd_exec_txn_ctx_t const * txn_ctx,
fd_pubkey_t const * pubkey,
Expand Down
13 changes: 13 additions & 0 deletions src/flamenco/runtime/program/fd_builtin_programs.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ struct fd_stateless_builtin_program {
};
typedef struct fd_stateless_builtin_program fd_stateless_builtin_program_t;

struct fd_precompile_program {
fd_pubkey_t const * pubkey;
ulong feature_offset;
int (*verify_fn)(fd_exec_instr_ctx_t*);
};
typedef struct fd_precompile_program fd_precompile_program_t;

FD_PROTOTYPES_BEGIN

/* Initialize the builtin program accounts */
Expand Down Expand Up @@ -79,6 +86,12 @@ fd_is_migrating_builtin_program( fd_exec_txn_ctx_t const * txn_ctx,
uchar
fd_is_non_migrating_builtin_program( fd_pubkey_t const * pubkey );

fd_precompile_program_t const *
fd_precompiles( void );

ulong
fd_num_precompiles( void );

FD_PROTOTYPES_END

#endif /* HEADER_fd_src_flamenco_runtime_program_fd_buildin_programs_h */
Loading