From 4ef51beb7ceae6a50fe3950c2ad1464a8584aa33 Mon Sep 17 00:00:00 2001 From: Kunal Bhargava Date: Wed, 18 Sep 2024 01:38:45 +0000 Subject: [PATCH] flamenco: remove sanitization checks --- src/flamenco/runtime/fd_executor.c | 101 ----------------------------- src/flamenco/runtime/fd_executor.h | 3 - src/flamenco/runtime/fd_runtime.c | 8 --- 3 files changed, 112 deletions(-) diff --git a/src/flamenco/runtime/fd_executor.c b/src/flamenco/runtime/fd_executor.c index fa317cf13a..1e4b35d1f1 100644 --- a/src/flamenco/runtime/fd_executor.c +++ b/src/flamenco/runtime/fd_executor.c @@ -364,107 +364,6 @@ fd_executor_check_txn_program_accounts_and_data_sz( fd_exec_txn_ctx_t * txn_ctx return FD_RUNTIME_EXECUTE_SUCCESS; } -// https://github.com/anza-xyz/agave/blob/df892c42418047ade3365c1b3ddcf6c45f95d1f1/svm/src/transaction_processor.rs#L523 -// This function combines the logic of load_program_accounts and load_program_with_pubkey -int -fd_executor_check_replenish_program_cache( fd_exec_txn_ctx_t * txn_ctx ) { - int err = FD_RUNTIME_EXECUTE_SUCCESS; - - for( ulong i=0UL; iaccounts_cnt; i++ ) { - FD_SCRATCH_SCOPE_BEGIN { - - int hit_max_limit = 0; - fd_borrowed_account_t * account = NULL; - err = fd_txn_borrowed_account_view_idx( txn_ctx, (uchar)i, &account ); - // https://github.com/anza-xyz/agave/blob/df892c42418047ade3365c1b3ddcf6c45f95d1f1/svm/src/program_loader.rs#L135 - if( FD_UNLIKELY( err!=FD_ACC_MGR_SUCCESS ) ) { - continue; - } - - // https://github.com/anza-xyz/agave/blob/df892c42418047ade3365c1b3ddcf6c45f95d1f1/svm/src/transaction_processor.rs#L254 - // Agave checks that the account owner is in PROGRAM_OWNERS (bpf_loader_upgradeable, bpf_loader, bpf_loader_deprecated, loader_v4) - // After that filtering, those accounts are used in replenish_program_cache to update the program cache - // Since we don't have a program cache, we only care about the checks that will cause sanitization errors - - // https://github.com/anza-xyz/agave/blob/df892c42418047ade3365c1b3ddcf6c45f95d1f1/svm/src/program_loader.rs#L72 - if( !memcmp( account->const_meta->info.owner, fd_solana_bpf_loader_v4_program_id.uc, sizeof(fd_pubkey_t) ) ) { - // ProgramAccountLoadResult::ProgramOfLoaderV4 - continue; - } - // https://github.com/anza-xyz/agave/blob/df892c42418047ade3365c1b3ddcf6c45f95d1f1/svm/src/program_loader.rs#L86 - if( !memcmp( account->const_meta->info.owner, fd_solana_bpf_loader_deprecated_program_id.uc, sizeof(fd_pubkey_t) ) ) { - // ProgramAccountLoadResult::ProgramOfLoaderV1 - // https://github.com/anza-xyz/agave/blob/df892c42418047ade3365c1b3ddcf6c45f95d1f1/svm/src/program_loader.rs#L139 - continue; - } - // https://github.com/anza-xyz/agave/blob/df892c42418047ade3365c1b3ddcf6c45f95d1f1/svm/src/program_loader.rs#L90 - if( !memcmp( account->const_meta->info.owner, fd_solana_bpf_loader_program_id.uc, sizeof(fd_pubkey_t) ) ) { - // ProgramAccountLoadResult::ProgramOfLoaderV2 - // https://github.com/anza-xyz/agave/blob/df892c42418047ade3365c1b3ddcf6c45f95d1f1/svm/src/program_loader.rs#L150 - continue; - } - // https://github.com/anza-xyz/agave/blob/df892c42418047ade3365c1b3ddcf6c45f95d1f1/svm/src/program_loader.rs#L94 - fd_bpf_upgradeable_loader_state_t program_loader_state[1] = {0}; - err = 0; - - // https://github.com/anza-xyz/agave/blob/df892c42418047ade3365c1b3ddcf6c45f95d1f1/svm/src/program_loader.rs#L94 - if( !memcmp( account->const_meta->info.owner, fd_solana_bpf_loader_upgradeable_program_id.uc, sizeof(fd_pubkey_t) ) ) { - if( read_bpf_upgradeable_loader_state_for_program( txn_ctx, (uchar) i, program_loader_state, &err ) && fd_bpf_upgradeable_loader_state_is_program( program_loader_state ) ) { // ProgramAccountLoadResult::ProgramOfLoaderV3 - fd_bincode_decode_ctx_t program_decode_ctx = { - .data = (uchar *)account->const_meta + account->const_meta->hlen, - .dataend = (char *) program_decode_ctx.data + account->const_meta->dlen, - .valloc = fd_scratch_virtual(), - }; - - fd_bpf_upgradeable_loader_state_t loader_state[1]; - fd_borrowed_account_t * programdata_account = NULL; - // https://github.com/anza-xyz/agave/blob/df892c42418047ade3365c1b3ddcf6c45f95d1f1/svm/src/program_loader.rs#L98 - if( FD_LIKELY( !fd_bpf_upgradeable_loader_state_decode( loader_state, &program_decode_ctx ) && - !fd_txn_borrowed_account_executable_view( txn_ctx, &loader_state->inner.program.programdata_address, &programdata_account) ) ) { - - fd_bincode_decode_ctx_t program_data_decode_ctx = { - .data = programdata_account->const_data, - .dataend = programdata_account->const_data + programdata_account->const_meta->dlen, - .valloc = fd_scratch_virtual(), - }; - fd_bpf_upgradeable_loader_state_t programdata_loader_state[1]; - - // https://github.com/anza-xyz/agave/blob/df892c42418047ade3365c1b3ddcf6c45f95d1f1/svm/src/program_loader.rs#L99 - if( FD_LIKELY( !fd_bpf_upgradeable_loader_state_decode( programdata_loader_state, &program_data_decode_ctx ) && fd_bpf_upgradeable_loader_state_is_program_data( programdata_loader_state ) ) ) { - - ulong acc_size = programdata_account->const_meta->dlen; - // https://github.com/anza-xyz/agave/blob/df892c42418047ade3365c1b3ddcf6c45f95d1f1/svm/src/program_loader.rs#L164 - if( acc_size<=PROGRAMDATA_METADATA_SIZE ) { - // https://github.com/anza-xyz/agave/blob/df892c42418047ade3365c1b3ddcf6c45f95d1f1/svm/src/transaction_processor.rs#L601 - hit_max_limit = 1; - } - - // https://github.com/anza-xyz/agave/blob/df892c42418047ade3365c1b3ddcf6c45f95d1f1/svm/src/program_loader.rs#L167 - ulong programdata_data_offset = PROGRAMDATA_METADATA_SIZE; - ulong programdata_data_len = fd_ulong_sat_sub( programdata_account->const_meta->dlen, programdata_data_offset ); - const uchar * programdata_data = programdata_account->const_data + programdata_data_offset; - - fd_sbpf_elf_info_t _elf_info[ 1UL ]; - fd_sbpf_elf_info_t * elf_info = fd_sbpf_elf_peek( _elf_info, programdata_data, programdata_data_len, 0 ); - if( FD_UNLIKELY( !elf_info ) ) { - hit_max_limit = 1; - } - } - } - } - } - - if( hit_max_limit ) { - // https://github.com/anza-xyz/agave/blob/df892c42418047ade3365c1b3ddcf6c45f95d1f1/svm/src/transaction_processor.rs#L271 - return FD_RUNTIME_TXN_ERR_PROGRAM_CACHE_HIT_MAX_LIMIT; - } - - } FD_SCRATCH_SCOPE_END; - } - - return FD_RUNTIME_EXECUTE_SUCCESS; -} - /* https://github.com/anza-xyz/agave/blob/89050f3cb7e76d9e273f10bea5e8207f2452f79f/svm/src/account_loader.rs#L101-L126 */ static int fd_should_set_exempt_rent_epoch_max( fd_exec_slot_ctx_t * slot_ctx, diff --git a/src/flamenco/runtime/fd_executor.h b/src/flamenco/runtime/fd_executor.h index e32a2f0586..9581cabbc6 100644 --- a/src/flamenco/runtime/fd_executor.h +++ b/src/flamenco/runtime/fd_executor.h @@ -136,9 +136,6 @@ fd_executor_instr_strerror( int err ); int fd_executor_check_txn_program_accounts_and_data_sz( fd_exec_txn_ctx_t * txn_ctx ); -int -fd_executor_check_replenish_program_cache( fd_exec_txn_ctx_t * txn_ctx ); - static inline int fd_exec_consume_cus( fd_exec_txn_ctx_t * txn_ctx, ulong cus ) { diff --git a/src/flamenco/runtime/fd_runtime.c b/src/flamenco/runtime/fd_runtime.c index 08b76510f1..c0f48c7b32 100644 --- a/src/flamenco/runtime/fd_runtime.c +++ b/src/flamenco/runtime/fd_runtime.c @@ -927,14 +927,6 @@ fd_runtime_pre_execute_check( fd_execute_txn_task_info_t * task_info ) { return; } - // https://github.com/anza-xyz/agave/blob/df892c42418047ade3365c1b3ddcf6c45f95d1f1/svm/src/transaction_processor.rs#L264 - err = fd_executor_check_replenish_program_cache( txn_ctx ); - if( FD_UNLIKELY( err!=FD_RUNTIME_EXECUTE_SUCCESS ) ) { - task_info->txn->flags = 0U; - task_info->exec_res = err; - return; - } - /* https://github.com/anza-xyz/agave/blob/16de8b75ebcd57022409b422de557dd37b1de8db/svm/src/account_loader.rs#L278-L284 */ err = fd_executor_check_txn_program_accounts_and_data_sz( txn_ctx ); if( FD_UNLIKELY( err!=FD_RUNTIME_EXECUTE_SUCCESS ) ) {