@@ -20,9 +20,8 @@ struct fd_borrowed_account {
2020 fd_txn_account_t * acct;
2121 fd_exec_instr_ctx_t const * instr_ctx;
2222
23- /* Agave's index_in_instruction includes program and instruction accounts,
24- with the program account occupying index 0,
25- so the value for instruction accounts will be off by one. */
23+ /* index_in_instruction will be USHORT_MAX for borrowed program accounts because
24+ they are not stored in the list of instruction accounts in the instruction context */
2625 ushort index_in_instruction;
2726};
2827typedef struct fd_borrowed_account fd_borrowed_account_t ;
@@ -294,7 +293,7 @@ fd_borrowed_account_is_executable_internal( fd_borrowed_account_t const * borrow
294293 fd_borrowed_account_is_executable ( borrowed_acct );
295294}
296295
297- /* fd_borrowed_account_is_signer mirror the Agave functions
296+ /* fd_borrowed_account_is_signer mirrors the Agave function
298297 solana_sdk::transaction_context::BorrowedAccount::is_signer.
299298 Returns 1 if the account is a signer or is writable and 0 otherwise.
300299
@@ -305,27 +304,14 @@ fd_borrowed_account_is_signer( fd_borrowed_account_t const * borrowed_acct ) {
305304 fd_exec_instr_ctx_t const * instr_ctx = borrowed_acct->instr_ctx ;
306305 fd_instr_info_t const * instr = instr_ctx->instr ;
307306
308- /* The index in instruction is 1-indexed for instruction accounts, with the program account
309- occupying index 0. */
310- if ( FD_UNLIKELY ( borrowed_acct->index_in_instruction > instr_ctx->instr ->acct_cnt ) ) {
307+ if ( FD_UNLIKELY ( borrowed_acct->index_in_instruction >=instr_ctx->instr ->acct_cnt ) ) {
311308 return 0 ;
312309 }
313310
314- /* Check if account is a program account
315- https://github.com/anza-xyz/agave/blob/v2.1.14/sdk/src/transaction_context.rs#L1053 */
316- if ( FD_UNLIKELY ( borrowed_acct->index_in_instruction <
317- fd_exec_instr_ctx_get_number_of_program_accounts ( instr_ctx ) ) ) {
318- return 0 ;
319- }
320-
321- /* Converts the index_in_instruction
322- into an instruction account index by subtracting the number of program accounts.
323- https://github.com/anza-xyz/agave/blob/v2.1.14/sdk/src/transaction_context.rs#L1045-L1046 */
324- ulong idx = fd_ulong_sat_sub ( (ulong)borrowed_acct->index_in_instruction , fd_exec_instr_ctx_get_number_of_program_accounts ( instr_ctx ) );
325- return fd_instr_acc_is_signer_idx ( instr, idx );
311+ return fd_instr_acc_is_signer_idx ( instr, borrowed_acct->index_in_instruction );
326312}
327313
328- /* fd_borrowed_account_is_writer mirror the Agave functions
314+ /* fd_borrowed_account_is_writer mirrors the Agave function
329315 solana_sdk::transaction_context::BorrowedAccount::is_writer.
330316 Returns 1 if the account is a signer or is writable and 0 otherwise.
331317
@@ -336,24 +322,11 @@ fd_borrowed_account_is_writable( fd_borrowed_account_t const * borrowed_acct ) {
336322 fd_exec_instr_ctx_t const * instr_ctx = borrowed_acct->instr_ctx ;
337323 fd_instr_info_t const * instr = instr_ctx->instr ;
338324
339- /* The index in instruction is 1-indexed for instruction accounts, with the program account
340- occupying index 0. */
341- if ( FD_UNLIKELY ( borrowed_acct->index_in_instruction > instr_ctx->instr ->acct_cnt ) ) {
342- return 0 ;
343- }
344-
345- /* Check if account is a program account
346- https://github.com/anza-xyz/agave/blob/v2.1.14/sdk/src/transaction_context.rs#L1053 */
347- if ( FD_UNLIKELY ( borrowed_acct->index_in_instruction <
348- fd_exec_instr_ctx_get_number_of_program_accounts ( instr_ctx ) ) ) {
325+ if ( FD_UNLIKELY ( borrowed_acct->index_in_instruction >=instr_ctx->instr ->acct_cnt ) ) {
349326 return 0 ;
350327 }
351328
352- /* Converts the index_in_instruction
353- into an instruction account index by subtracting the number of program accounts.
354- https://github.com/anza-xyz/agave/blob/v2.1.14/sdk/src/transaction_context.rs#L1058-L1059 */
355- ulong idx = fd_ulong_sat_sub ( (ulong)borrowed_acct->index_in_instruction , fd_exec_instr_ctx_get_number_of_program_accounts ( instr_ctx ) );
356- return fd_instr_acc_is_writable_idx ( instr, idx );
329+ return fd_instr_acc_is_writable_idx ( instr, borrowed_acct->index_in_instruction );
357330}
358331
359332/* fd_borrowed_account_is_owned_by_current_program mirrors Agave's
0 commit comments