@@ -677,7 +677,8 @@ VM_SYSCALL_CPI_ENTRYPOINT( void * _vm,
677677
678678 fd_vm_t * vm = (fd_vm_t * )_vm ;
679679
680- FD_VM_CU_UPDATE ( vm , FD_VM_INVOKE_UNITS );
680+ /* https://github.com/anza-xyz/agave/blob/v3.1.2/program-runtime/src/cpi.rs#L815-L818 */
681+ FD_VM_CU_UPDATE ( vm , get_cpi_invoke_unit_cost ( vm -> instr_ctx -> bank ) );
681682
682683 /* Translate instruction ********************************************/
683684 /* translate_instruction is the first thing that agave does
@@ -718,7 +719,20 @@ VM_SYSCALL_CPI_ENTRYPOINT( void * _vm,
718719 /* Agave consumes CU in translate_instruction
719720 https://github.com/anza-xyz/agave/blob/838c1952595809a31520ff1603a13f2c9123aa51/programs/bpf_loader/src/syscalls/cpi.rs#L445 */
720721 if ( FD_FEATURE_ACTIVE_BANK ( vm -> instr_ctx -> bank , loosen_cpi_size_restriction ) ) {
721- FD_VM_CU_UPDATE ( vm , VM_SYSCALL_CPI_INSTR_DATA_LEN ( cpi_instruction ) / FD_VM_CPI_BYTES_PER_UNIT );
722+ ulong total_cu_translation_cost = VM_SYSCALL_CPI_INSTR_DATA_LEN ( cpi_instruction ) / FD_VM_CPI_BYTES_PER_UNIT ;
723+
724+ /* https://github.com/anza-xyz/agave/blob/v3.1.2/program-runtime/src/cpi.rs#L686-L699 */
725+ if ( FD_FEATURE_ACTIVE_BANK ( vm -> instr_ctx -> bank , increase_cpi_account_info_limit ) ) {
726+ /* Agave bills the same regardless of ABI */
727+ ulong account_meta_translation_cost =
728+ fd_ulong_sat_mul (
729+ VM_SYSCALL_CPI_INSTR_ACCS_LEN ( cpi_instruction ),
730+ FD_VM_RUST_ACCOUNT_META_SIZE ) /
731+ FD_VM_CPI_BYTES_PER_UNIT ;
732+ total_cu_translation_cost = fd_ulong_sat_add ( total_cu_translation_cost , account_meta_translation_cost );
733+ }
734+
735+ FD_VM_CU_UPDATE ( vm , total_cu_translation_cost );
722736 }
723737
724738 /* Final checks for translate_instruction
@@ -833,7 +847,15 @@ VM_SYSCALL_CPI_ENTRYPOINT( void * _vm,
833847 return FD_VM_SYSCALL_ERR_MAX_INSTRUCTION_ACCOUNT_INFOS_EXCEEDED ;
834848 }
835849
836- fd_pubkey_t const * acct_info_keys [ FD_CPI_MAX_ACCOUNT_INFOS ];
850+ /* Consume compute units proportional to the number of account infos, if
851+ increase_cpi_account_info_limit is active.
852+ https://github.com/anza-xyz/agave/blob/v3.1.2/program-runtime/src/cpi.rs#L968-L980 */
853+ if ( FD_FEATURE_ACTIVE_BANK ( vm -> instr_ctx -> bank , increase_cpi_account_info_limit ) ) {
854+ ulong account_infos_bytes = fd_ulong_sat_mul ( acct_info_cnt , VM_SYSCALL_CPI_ACC_INFO_SIZE );
855+ FD_VM_CU_UPDATE ( vm , account_infos_bytes / FD_VM_CPI_BYTES_PER_UNIT );
856+ }
857+
858+ fd_pubkey_t const * acct_info_keys [ FD_CPI_MAX_ACCOUNT_INFOS_SIMD_0339 ];
837859 for ( ulong acct_idx = 0UL ; acct_idx < acct_info_cnt ; acct_idx ++ ) {
838860 /* Translate each pubkey address specified in account_infos.
839861 Failed translation should lead to an access violation and
0 commit comments