Skip to content

Commit

Permalink
add enable_secp256r1_precompile feature
Browse files Browse the repository at this point in the history
  • Loading branch information
kbhargava-jump committed Nov 15, 2024
1 parent 9981618 commit 3932d00
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 7 deletions.
8 changes: 8 additions & 0 deletions src/flamenco/features/fd_features_generated.c
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,12 @@ fd_feature_id_t const ids[] = {
.name = "partitioned_epoch_rewards_superfeature",
.cleaned_up = {UINT_MAX, UINT_MAX, UINT_MAX} },

{ .index = offsetof(fd_features_t, enable_secp256r1_precompile)>>3,
.id = {"\x0d\x06\x71\xf0\x4f\xe3\x38\x2c\x46\xac\x54\x4a\xad\x9b\x98\x50\xa8\xa0\x26\x18\x41\x58\x58\xbf\xe8\xf0\xca\x6c\x04\x32\x18\x93"},
/* sr11RdZWgbHTHxSroPALe6zgaT5A1K9LcE4nfsZS4gi */
.name = "enable_secp256r1_precompile",
.cleaned_up = {UINT_MAX, UINT_MAX, UINT_MAX} },

{ .index = ULONG_MAX }
};

Expand Down Expand Up @@ -1443,6 +1449,7 @@ fd_feature_id_query( ulong prefix ) {
case 0x0b9047b5bb9ef961: return &ids[ 200 ];
case 0xa5a66405d0ab6309: return &ids[ 201 ];
case 0x81fcbfa0d0f6b105: return &ids[ 202 ];
case 0x2c38e34ff071060d: return &ids[ 203 ];
default: break;
}

Expand Down Expand Up @@ -1654,5 +1661,6 @@ FD_STATIC_ASSERT( offsetof( fd_features_t, zk_elgamal_proof_program_enabled
FD_STATIC_ASSERT( offsetof( fd_features_t, move_stake_and_move_lamports_ixs )>>3==200UL, layout );
FD_STATIC_ASSERT( offsetof( fd_features_t, deprecate_legacy_vote_ixs )>>3==201UL, layout );
FD_STATIC_ASSERT( offsetof( fd_features_t, partitioned_epoch_rewards_superfeature )>>3==202UL, layout );
FD_STATIC_ASSERT( offsetof( fd_features_t, enable_secp256r1_precompile )>>3==203UL, layout );

FD_STATIC_ASSERT( sizeof( fd_features_t )>>3==FD_FEATURE_ID_CNT, layout );
3 changes: 2 additions & 1 deletion src/flamenco/features/fd_features_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

/* FEATURE_ID_CNT is the number of features in ids */

#define FD_FEATURE_ID_CNT (203UL)
#define FD_FEATURE_ID_CNT (204UL)

union fd_features {

Expand Down Expand Up @@ -216,6 +216,7 @@ union fd_features {
/* 0x0b9047b5bb9ef961 */ ulong move_stake_and_move_lamports_ixs;
/* 0xa5a66405d0ab6309 */ ulong deprecate_legacy_vote_ixs;
/* 0x81fcbfa0d0f6b105 */ ulong partitioned_epoch_rewards_superfeature;
/* 0x2c38e34ff071060d */ ulong enable_secp256r1_precompile;
};

};
3 changes: 2 additions & 1 deletion src/flamenco/features/feature_map.json
Original file line number Diff line number Diff line change
Expand Up @@ -201,5 +201,6 @@
{"name":"zk_elgamal_proof_program_enabled","pubkey":"zkhiy5oLowR7HY4zogXjCjeMXyruLqBwSWH21qcFtnv"},
{"name":"move_stake_and_move_lamports_ixs","pubkey":"7bTK6Jis8Xpfrs8ZoUfiMDPazTcdPcTWheZFJTA5Z6X4"},
{"name":"deprecate_legacy_vote_ixs","pubkey":"depVvnQ2UysGrhwdiwU42tCadZL8GcBb1i2GYhMopQv"},
{"name":"partitioned_epoch_rewards_superfeature","pubkey":"PERzQrt5gBD1XEe2c9XdFWqwgHY3mr7cYWbm5V772V8"}
{"name":"partitioned_epoch_rewards_superfeature","pubkey":"PERzQrt5gBD1XEe2c9XdFWqwgHY3mr7cYWbm5V772V8"},
{"name": "enable_secp256r1_precompile","pubkey":"sr11RdZWgbHTHxSroPALe6zgaT5A1K9LcE4nfsZS4gi"}
]
2 changes: 1 addition & 1 deletion src/flamenco/runtime/fd_executor.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ fd_executor_verify_precompiles( fd_exec_txn_ctx_t * txn_ctx ) {
FD_TXN_ERR_FOR_LOG_INSTR( txn_ctx, err, i );
return FD_RUNTIME_TXN_ERR_INSTRUCTION_ERROR;
}
} else if( !memcmp( program_id, &fd_solana_secp256r1_program_id, sizeof(fd_pubkey_t) )) {
} else if( !memcmp( program_id, &fd_solana_secp256r1_program_id, sizeof(fd_pubkey_t)) && FD_FEATURE_ACTIVE( txn_ctx->slot_ctx, enable_secp256r1_precompile ) ) {
err = fd_precompile_secp256r1_verify( txn_ctx, instr );
if( FD_UNLIKELY( err ) ) {
FD_TXN_ERR_FOR_LOG_INSTR( txn_ctx, err, i );
Expand Down
2 changes: 1 addition & 1 deletion src/flamenco/runtime/fd_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -3112,7 +3112,7 @@ fd_runtime_calculate_fee(fd_exec_txn_ctx_t *txn_ctx,
fd_pubkey_t *program_id = &txn_ctx->accounts[txn_instr->program_id];
if (memcmp(program_id->uc, fd_solana_keccak_secp_256k_program_id.key, sizeof(fd_pubkey_t)) == 0 ||
memcmp(program_id->uc, fd_solana_ed25519_sig_verify_program_id.key, sizeof(fd_pubkey_t)) == 0 ||
memcmp(program_id->uc, fd_solana_secp256r1_program_id.key, sizeof(fd_pubkey_t)) == 0)
(memcmp(program_id->uc, fd_solana_secp256r1_program_id.key, sizeof(fd_pubkey_t)) == 0 && FD_FEATURE_ACTIVE( txn_ctx->slot_ctx, enable_secp256r1_precompile )))
{
if (txn_instr->data_sz == 0)
{
Expand Down
6 changes: 3 additions & 3 deletions src/flamenco/vm/syscall/fd_vm_syscall_cpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,10 +454,10 @@ fd_vm_syscall_cpi_check_id( fd_pubkey_t const * program_id,
https://github.com/solana-labs/solana/blob/2afde1b028ed4593da5b6c735729d8994c4bfac6/sdk/src/precompiles.rs#L93
*/
static inline int
fd_vm_syscall_cpi_is_precompile( fd_pubkey_t const * program_id ) {
fd_vm_syscall_cpi_is_precompile( fd_pubkey_t const * program_id, fd_exec_slot_ctx_t const * slot_ctx ) {
return fd_vm_syscall_cpi_check_id(program_id, fd_solana_keccak_secp_256k_program_id.key) |
fd_vm_syscall_cpi_check_id(program_id, fd_solana_ed25519_sig_verify_program_id.key) |
fd_vm_syscall_cpi_check_id(program_id, fd_solana_secp256r1_program_id.key);
( fd_vm_syscall_cpi_check_id(program_id, fd_solana_secp256r1_program_id.key) && FD_FEATURE_ACTIVE( slot_ctx, enable_secp256r1_precompile ) );
}

/* fd_vm_syscall_cpi_check_authorized_program corresponds to
Expand All @@ -483,7 +483,7 @@ fd_vm_syscall_cpi_check_authorized_program( fd_pubkey_t const * program_i
|| (FD_FEATURE_ACTIVE(slot_ctx, enable_bpf_loader_set_authority_checked_ix)
&& (instruction_data_len != 0 && instruction_data[0] == 7)) /* is_set_authority_checked_instruction() */
|| (instruction_data_len != 0 && instruction_data[0] == 5))) /* is_close_instruction */
|| fd_vm_syscall_cpi_is_precompile(program_id));
|| fd_vm_syscall_cpi_is_precompile(program_id, slot_ctx));
}

/**********************************************************************
Expand Down

0 comments on commit 3932d00

Please sign in to comment.