diff --git a/src/flamenco/runtime/fd_executor.c b/src/flamenco/runtime/fd_executor.c index 42878f46c0..cddb9a6fef 100644 --- a/src/flamenco/runtime/fd_executor.c +++ b/src/flamenco/runtime/fd_executor.c @@ -704,8 +704,15 @@ fd_execute_instr( fd_exec_txn_ctx_t * txn_ctx, } txn_ctx->num_instructions++; fd_pubkey_t const * txn_accs = txn_ctx->accounts; - ulong starting_lamports = fd_instr_info_sum_account_lamports( instr ); - instr->starting_lamports = starting_lamports; + + ulong starting_lamports_h = 0; + ulong starting_lamports_l = 0; + int err = fd_instr_info_sum_account_lamports( instr, &starting_lamports_h, &starting_lamports_l ); + if( err ) { + return err; + } + instr->starting_lamports_h = starting_lamports_h; + instr->starting_lamports_l = starting_lamports_l; fd_exec_instr_ctx_t * parent = NULL; if( txn_ctx->instr_stack_sz ) @@ -754,11 +761,14 @@ fd_execute_instr( fd_exec_txn_ctx_t * txn_ctx, // FD_LOG_NOTICE(("COMPUTE METER END %lu %lu %lu %64J", before_instr_cus - txn_ctx->compute_meter, txn_ctx->compute_meter, txn_ctx->compute_unit_limit, sig )); if( exec_result == FD_EXECUTOR_INSTR_SUCCESS ) { - ulong ending_lamports = fd_instr_info_sum_account_lamports( instr ); - // FD_LOG_WARNING(("check lamports %lu %lu %lu", starting_lamports, instr->starting_lamports, ending_lamports )); + ulong ending_lamports_h = 0UL; + ulong ending_lamports_l = 0UL; + err = fd_instr_info_sum_account_lamports( instr, &ending_lamports_h, &ending_lamports_l ); + if( err ) { + return err; + } - if( starting_lamports != ending_lamports ) { - FD_LOG_WARNING(("starting lamports mismatched %lu %lu %lu", starting_lamports, instr->starting_lamports, ending_lamports )); + if( ending_lamports_l != starting_lamports_l || ending_lamports_h != starting_lamports_h ) { exec_result = FD_EXECUTOR_INSTR_ERR_UNBALANCED_INSTR; } diff --git a/src/flamenco/runtime/info/fd_instr_info.c b/src/flamenco/runtime/info/fd_instr_info.c index 65c1304285..2dd37dbf48 100644 --- a/src/flamenco/runtime/info/fd_instr_info.c +++ b/src/flamenco/runtime/info/fd_instr_info.c @@ -1,6 +1,7 @@ #include "fd_instr_info.h" #include "../fd_account.h" +#include "../../../util/bits/fd_uwide.h" /* demote_program_id() in https://github.com/solana-labs/solana/blob/061bed0a8ca80afb97f4438155e8a6b47bbf7f6d/sdk/program/src/message/versions/v0/loaded.rs#L150 */ int @@ -35,12 +36,15 @@ fd_convert_txn_instr_to_instr( fd_exec_txn_ctx_t * txn_ctx, fd_rawtxn_b_t const * txn_raw = txn_ctx->_txn_raw; const fd_pubkey_t * accounts = txn_ctx->accounts; - ulong starting_lamports = 0; - instr->program_id = txn_instr->program_id; + /* TODO: Lamport check may be redundant */ + ulong starting_lamports_h = 0; + ulong starting_lamports_l = 0; + + instr->program_id = txn_instr->program_id; instr->program_id_pubkey = accounts[txn_instr->program_id]; - instr->acct_cnt = txn_instr->acct_cnt; - instr->data_sz = txn_instr->data_sz; - instr->data = (uchar *)txn_raw->raw + txn_instr->data_off; + instr->acct_cnt = txn_instr->acct_cnt; + instr->data_sz = txn_instr->data_sz; + instr->data = (uchar *)txn_raw->raw + txn_instr->data_off; uchar acc_idx_seen[256]; memset(acc_idx_seen, 0, 256); @@ -57,10 +61,12 @@ fd_convert_txn_instr_to_instr( fd_exec_txn_ctx_t * txn_ctx, instr->is_duplicate[i] = acc_idx_seen[acc_idx]; if( FD_LIKELY( !acc_idx_seen[acc_idx] ) ) { /* This is the first time seeing this account */ - acc_idx_seen[acc_idx] = 1; if( instr->borrowed_accounts[i] != NULL && instr->borrowed_accounts[i]->const_meta != NULL ) { - starting_lamports += instr->borrowed_accounts[i]->const_meta->info.lamports; + fd_uwide_inc( &starting_lamports_h, &starting_lamports_l, + starting_lamports_h, starting_lamports_l, + instr->borrowed_accounts[i]->const_meta->info.lamports ); } + acc_idx_seen[acc_idx] = 1; } instr->acct_txn_idxs[i] = acc_idx; @@ -76,10 +82,12 @@ fd_convert_txn_instr_to_instr( fd_exec_txn_ctx_t * txn_ctx, } } - instr->starting_lamports = starting_lamports; + instr->starting_lamports_h = starting_lamports_h; + instr->starting_lamports_l = starting_lamports_l; + } -FD_FN_PURE int +int fd_instr_any_signed( fd_instr_info_t const * info, fd_pubkey_t const * pubkey ) { int is_signer = 0; @@ -90,20 +98,34 @@ fd_instr_any_signed( fd_instr_info_t const * info, return is_signer; } -/* - TODO: We should modify this function to handle overflows / other issues similar to Agave. - https://github.com/anza-xyz/agave/blob/9706a6464665f7ebd6ead47f0d12f853ccacbab9/sdk/src/transaction_context.rs#L407 -*/ -ulong -fd_instr_info_sum_account_lamports( fd_instr_info_t const * instr ) { - ulong total_lamports = 0; - for( ulong i = 0; i < instr->acct_cnt; i++ ) { - if( instr->borrowed_accounts[i] != NULL && !instr->is_duplicate[i] && instr->borrowed_accounts[i]->const_meta != NULL ) { - // FD_LOG_WARNING(("SUM INSTR INFO LAMPS: %32J %lu", instr->acct_pubkeys[i].key, instr->borrowed_accounts[i]->const_meta->info.lamports )); - total_lamports += instr->borrowed_accounts[i]->const_meta->info.lamports; +/* https://github.com/anza-xyz/agave/blob/9706a6464665f7ebd6ead47f0d12f853ccacbab9/sdk/src/transaction_context.rs#L40 */ +int +fd_instr_info_sum_account_lamports( fd_instr_info_t const * instr, + ulong * total_lamports_h, + ulong * total_lamports_l ) { + *total_lamports_h = 0UL; + *total_lamports_l = 0UL; + for( ulong i=0UL; iacct_cnt; ++i ) { + if( instr->borrowed_accounts[i] == NULL || + instr->is_duplicate[i] || + instr->borrowed_accounts[i]->const_meta == NULL ) { + continue; } + + /* Perform a checked add on a fd_uwide */ + ulong tmp_total_lamports_h = 0UL; + ulong tmp_total_lamports_l = 0UL; + + fd_uwide_inc( &tmp_total_lamports_h, &tmp_total_lamports_l, *total_lamports_h, *total_lamports_l, + instr->borrowed_accounts[i]->const_meta->info.lamports ); + + if( tmp_total_lamports_h < *total_lamports_h ) { + return FD_EXECUTOR_INSTR_ERR_ARITHMETIC_OVERFLOW; + } + + *total_lamports_h = tmp_total_lamports_h; + *total_lamports_l = tmp_total_lamports_l; } - // FD_LOG_WARNING(("SUM: %lu", total_lamports)); - return total_lamports; + return FD_EXECUTOR_INSTR_SUCCESS; } diff --git a/src/flamenco/runtime/info/fd_instr_info.h b/src/flamenco/runtime/info/fd_instr_info.h index 557ceb97e3..22c5ecbcf7 100644 --- a/src/flamenco/runtime/info/fd_instr_info.h +++ b/src/flamenco/runtime/info/fd_instr_info.h @@ -12,21 +12,23 @@ #define FD_INSTR_ACCT_MAX (256) struct fd_instr_info { - uchar program_id; - ushort data_sz; - ushort acct_cnt; + uchar program_id; + ushort data_sz; + ushort acct_cnt; - uchar * data; - fd_pubkey_t program_id_pubkey; + uchar * data; + fd_pubkey_t program_id_pubkey; - uchar acct_txn_idxs[FD_INSTR_ACCT_MAX]; - uchar acct_flags[FD_INSTR_ACCT_MAX]; - fd_pubkey_t acct_pubkeys[FD_INSTR_ACCT_MAX]; - uchar is_duplicate[FD_INSTR_ACCT_MAX]; + uchar acct_txn_idxs[FD_INSTR_ACCT_MAX]; + uchar acct_flags[FD_INSTR_ACCT_MAX]; + fd_pubkey_t acct_pubkeys[FD_INSTR_ACCT_MAX]; + uchar is_duplicate[FD_INSTR_ACCT_MAX]; fd_borrowed_account_t * borrowed_accounts[FD_INSTR_ACCT_MAX]; - ulong starting_lamports; + /* fd_uwide representation of uint_128 */ + ulong starting_lamports_h; + ulong starting_lamports_l; }; typedef struct fd_instr_info fd_instr_info_t; @@ -96,8 +98,10 @@ fd_instr_any_signed( fd_instr_info_t const * info, Aborts on integer overflow. */ -FD_FN_PURE ulong -fd_instr_info_sum_account_lamports( fd_instr_info_t const * instr ); +int +fd_instr_info_sum_account_lamports( fd_instr_info_t const * instr, + ulong * total_lamports_h, + ulong * total_lamports_l ); static inline void fd_instr_get_signers( fd_instr_info_t const * self, diff --git a/src/flamenco/runtime/program/fd_native_cpi.c b/src/flamenco/runtime/program/fd_native_cpi.c index 64b3df438a..7ba08cff22 100644 --- a/src/flamenco/runtime/program/fd_native_cpi.c +++ b/src/flamenco/runtime/program/fd_native_cpi.c @@ -1,6 +1,7 @@ #include "../fd_account.h" #include "../../vm/fd_vm_syscalls.h" #include "../../vm/fd_vm_interp.h" +#include "../../../util/bits/fd_uwide.h" int fd_native_cpi_execute_system_program_instruction( fd_exec_instr_ctx_t * ctx, @@ -20,7 +21,9 @@ fd_native_cpi_execute_system_program_instruction( fd_exec_instr_ctx_t * ctx, } } - ulong starting_lamports = 0; + /* TODO: Lamport check may be redundant */ + ulong starting_lamports_h = 0; + ulong starting_lamports_l = 0; uchar acc_idx_seen[256]; memset( acc_idx_seen, 0, 256 ); @@ -41,7 +44,9 @@ fd_native_cpi_execute_system_program_instruction( fd_exec_instr_ctx_t * ctx, /* This is the first time seeing this account */ acc_idx_seen[k] = 1; if( instr_info->borrowed_accounts[j]->const_meta != NULL ) { - starting_lamports += instr_info->borrowed_accounts[j]->const_meta->info.lamports; + fd_uwide_inc( &starting_lamports_h, &starting_lamports_l, + starting_lamports_h, starting_lamports_l, + instr_info->borrowed_accounts[j]->const_meta->info.lamports ); } } @@ -63,7 +68,8 @@ fd_native_cpi_execute_system_program_instruction( fd_exec_instr_ctx_t * ctx, } } - instr_info->starting_lamports = starting_lamports; + instr_info->starting_lamports_h = starting_lamports_h; + instr_info->starting_lamports_l = starting_lamports_l; } fd_bincode_encode_ctx_t ctx2; diff --git a/src/flamenco/runtime/program/fd_stake_program.c b/src/flamenco/runtime/program/fd_stake_program.c index 60258369a4..ed0c2768d9 100644 --- a/src/flamenco/runtime/program/fd_stake_program.c +++ b/src/flamenco/runtime/program/fd_stake_program.c @@ -905,15 +905,14 @@ stake_weighted_credits_observed( fd_stake_t const * stake, ulong absorbed_lamports, ulong absorbed_credits_observed, ulong * out ) { - // FIXME: FD_LIKELY - if( stake->credits_observed == absorbed_credits_observed ) { + if( FD_LIKELY( stake->credits_observed == absorbed_credits_observed ) ) { *out = stake->credits_observed; return 1; } else { /* total_stake = stake->delegation.stake + absorbed_lamports */ - ulong total_stake_h = 0; - ulong total_stake_l = 0; - fd_uwide_inc( &total_stake_h, &total_stake_l, 0, stake->delegation.stake, + ulong total_stake_h = 0UL; + ulong total_stake_l = 0UL; + fd_uwide_inc( &total_stake_h, &total_stake_l, 0UL, stake->delegation.stake, absorbed_lamports ); /* stake_weighted_credits = stake->credits_observed + stake->delegation.stake */ @@ -933,26 +932,26 @@ stake_weighted_credits_observed( fd_stake_t const * stake, ulong total_weighted_credits_partial_one_l; fd_uwide_add( &total_weighted_credits_partial_one_h, &total_weighted_credits_partial_one_l, stake_weighted_credits_h, stake_weighted_credits_l, - absorbed_weighted_credits_h, absorbed_weighted_credits_l, 0 ); + absorbed_weighted_credits_h, absorbed_weighted_credits_l, 0UL ); ulong total_weighted_credits_partial_two_h; ulong total_weighted_credits_partial_two_l; fd_uwide_add( &total_weighted_credits_partial_two_h, &total_weighted_credits_partial_two_l, total_weighted_credits_partial_one_h, total_weighted_credits_partial_one_l, - total_stake_h, total_stake_l, 0 ); + total_stake_h, total_stake_l, 0UL ); ulong total_weighted_credits_h; ulong total_weighted_credits_l; fd_uwide_dec( &total_weighted_credits_h, &total_weighted_credits_l, - total_weighted_credits_partial_two_h, total_weighted_credits_partial_two_l, 1 ); + total_weighted_credits_partial_two_h, total_weighted_credits_partial_two_l, 1UL ); /* FIXME: fd_uwide_div doesn't support denominator that is an fd_uwide */ /* res = totalWeighted_credits / total_stake */ ulong res_h; ulong res_l; - FD_TEST(( total_stake_h == 0 )); + FD_TEST( total_stake_h == 0UL ); fd_uwide_div( &res_h, &res_l, total_weighted_credits_h, total_weighted_credits_l, total_stake_l ); - FD_TEST(( res_h == 0 )); + FD_TEST( res_h == 0UL ); //*out = total_weighted_credits / total_stake; *out = res_l; return 1; diff --git a/src/flamenco/runtime/tests/run_ledger_tests.sh b/src/flamenco/runtime/tests/run_ledger_tests.sh index 3308ea209b..5c91bcabdc 100755 --- a/src/flamenco/runtime/tests/run_ledger_tests.sh +++ b/src/flamenco/runtime/tests/run_ledger_tests.sh @@ -276,9 +276,6 @@ if [[ $ON_DEMAND = 1 ]]; then $TILE_CPUS >& $LOG status=$? - if [ $status -ne 0 ]; then - echo_error "on demand 1 $LOG" - fi { set +x; } &> /dev/null echo_notice "Finished on-demand ingest and replay\n" fi diff --git a/src/flamenco/runtime/tests/run_ledger_tests_all.txt b/src/flamenco/runtime/tests/run_ledger_tests_all.txt index a2691c8ff0..44f1a0825b 100644 --- a/src/flamenco/runtime/tests/run_ledger_tests_all.txt +++ b/src/flamenco/runtime/tests/run_ledger_tests_all.txt @@ -22,3 +22,4 @@ src/flamenco/runtime/tests/run_ledger_tests.sh -l mainnet-257059815 -s snapshot- src/flamenco/runtime/tests/run_ledger_tests.sh -l mainnet-257061172 -s snapshot-257061172-8e6cUSMUx2VZZBDzwXjEY6bGkzPgnUmqrDyr4uErG8BF.tar.zst -p 16 -y 16 -m 5000000 -e 257061175 --zst src/flamenco/runtime/tests/run_ledger_tests.sh -l mainnet-257222682 -s snapshot-257222682-Dudsosehu5xdHbqzG5sy72qEu6KyS9FmHnW7oV8pRoNn.tar.zst -p 16 -y 16 -m 5000000 -e 257222688 --zst src/flamenco/runtime/tests/run_ledger_tests.sh -l mainnet-264890264 -s snapshot-264890263-G9sNBh5CPSU9A1nXtC6QE87o1NPkwyMPh7XVKG5mw1Ka.tar.zst -p 32 -y 16 -m 5000000 -e 264890265 --zst +src/flamenco/runtime/tests/run_ledger_tests.sh -l mainnet-257229353 -s snapshot-257229353-9wETKbJxKf7ceWxtLFJN8VffLQJ2xQVXLUgrXtp6UMx.tar.zst -p 16 -y 16 -m 5000000 -e 257229353 --zst diff --git a/src/flamenco/vm/fd_vm_syscalls.c b/src/flamenco/vm/fd_vm_syscalls.c index 58dedaba19..8205610d5b 100644 --- a/src/flamenco/vm/fd_vm_syscalls.c +++ b/src/flamenco/vm/fd_vm_syscalls.c @@ -15,6 +15,7 @@ #include "../runtime/context/fd_exec_txn_ctx.h" #include "../runtime/context/fd_exec_instr_ctx.h" #include "../../ballet/ed25519/fd_curve25519.h" +#include "../../util/bits/fd_uwide.h" #include #include @@ -717,7 +718,8 @@ fd_vm_syscall_cpi_c_instruction_to_instr( fd_vm_exec_context_t * ctx, } } - ulong starting_lamports = 0; + ulong starting_lamports_h = 0; + ulong starting_lamports_l = 0; uchar acc_idx_seen[256]; memset(acc_idx_seen, 0, 256); for( ulong i = 0; i < cpi_instr->accounts_len; i++ ) { @@ -742,7 +744,9 @@ fd_vm_syscall_cpi_c_instruction_to_instr( fd_vm_exec_context_t * ctx, /* This is the first time seeing this account */ acc_idx_seen[j] = 1; if( instr->borrowed_accounts[i]->const_meta != NULL ) { - starting_lamports += instr->borrowed_accounts[i]->const_meta->info.lamports; + fd_uwide_inc( &starting_lamports_h, &starting_lamports_l, + starting_lamports_h, starting_lamports_l, + instr->borrowed_accounts[i]->const_meta->info.lamports ); } } // TODO: should check the parent has writable flag set @@ -769,10 +773,11 @@ fd_vm_syscall_cpi_c_instruction_to_instr( fd_vm_exec_context_t * ctx, } } - instr->data_sz = (ushort)cpi_instr->data_len; - instr->data = (uchar *)cpi_instr_data; - instr->acct_cnt = (ushort)cpi_instr->accounts_len; - instr->starting_lamports = starting_lamports; + instr->starting_lamports_h = starting_lamports_h; + instr->starting_lamports_l = starting_lamports_l; + instr->data_sz = (ushort)cpi_instr->data_len; + instr->data = (uchar *)cpi_instr_data; + instr->acct_cnt = (ushort)cpi_instr->accounts_len; } @@ -797,7 +802,8 @@ fd_vm_syscall_cpi_rust_instruction_to_instr( fd_vm_exec_context_t const * ctx, } } - ulong starting_lamports = 0; + ulong starting_lamports_h = 0; + ulong starting_lamports_l = 0; uchar acc_idx_seen[256]; memset(acc_idx_seen, 0, 256); // FD_LOG_DEBUG(("Accounts cnt %lu %lu", ctx->instr_ctx->txn_ctx->accounts_cnt, ctx->instr_ctx->txn_ctx->txn_descriptor->acct_addr_cnt)); @@ -817,7 +823,9 @@ fd_vm_syscall_cpi_rust_instruction_to_instr( fd_vm_exec_context_t const * ctx, /* This is the first time seeing this account */ acc_idx_seen[j] = 1; if( instr->borrowed_accounts[i]->const_meta != NULL ) { - starting_lamports += instr->borrowed_accounts[i]->const_meta->info.lamports; + fd_uwide_inc( &starting_lamports_h, &starting_lamports_l, + starting_lamports_h, starting_lamports_l, + instr->borrowed_accounts[i]->const_meta->info.lamports ); } } @@ -844,12 +852,11 @@ fd_vm_syscall_cpi_rust_instruction_to_instr( fd_vm_exec_context_t const * ctx, } } - instr->data_sz = (ushort)cpi_instr->data.len; - instr->data = (uchar *)cpi_instr_data; - instr->acct_cnt = (ushort)cpi_instr->accounts.len; - instr->starting_lamports = starting_lamports; - - // FD_LOG_WARNING(("starting lamps CPI: %lu", instr->starting_lamports)); + instr->data_sz = (ushort)cpi_instr->data.len; + instr->data = (uchar *)cpi_instr_data; + instr->acct_cnt = (ushort)cpi_instr->accounts.len; + instr->starting_lamports_h = starting_lamports_h; + instr->starting_lamports_l = starting_lamports_l; } @@ -1593,9 +1600,6 @@ fd_vm_syscall_cpi_c( memcpy( acct_keys[i].uc, acct_addr->uc, sizeof(fd_pubkey_t) ); } - /* TODO: Dispatch CPI to executor. - For now, we'll just log parameters. */ - fd_instruction_account_t instruction_accounts[256]; ulong instruction_accounts_cnt; fd_instr_info_t cpi_instr; @@ -1603,7 +1607,7 @@ fd_vm_syscall_cpi_c( fd_vm_syscall_cpi_c_instruction_to_instr( ctx, instruction, accounts, signers, signers_seeds_cnt, data, &cpi_instr ); err = fd_vm_prepare_instruction(ctx->instr_ctx->instr, &cpi_instr, ctx->instr_ctx, instruction_accounts, &instruction_accounts_cnt, signers, signers_seeds_cnt ); if( err != 0 ) { - FD_LOG_WARNING(("PREPARE FAILED")); + FD_LOG_WARNING(("vm preparation failed")); return err; } @@ -1617,12 +1621,21 @@ fd_vm_syscall_cpi_c( return err; } - ulong caller_lamports = fd_instr_info_sum_account_lamports( ctx->instr_ctx->instr ); - if( caller_lamports != ctx->instr_ctx->instr->starting_lamports ) { + /* TODO: lamport checks in cpi_c may be redundant as it is checked in fd_execute_instr */ + ulong caller_lamports_h = 0; + ulong caller_lamports_l = 0; + int err_exec = fd_instr_info_sum_account_lamports( ctx->instr_ctx->instr, &caller_lamports_h, &caller_lamports_l ); + if( err_exec ) { + return FD_VM_SYSCALL_ERR_INSTR_ERR; + } + + if( caller_lamports_h != ctx->instr_ctx->instr->starting_lamports_h || + caller_lamports_l != ctx->instr_ctx->instr->starting_lamports_l ) { return FD_VM_SYSCALL_ERR_INSTR_ERR; } + ctx->instr_ctx->txn_ctx->compute_meter = ctx->compute_meter; - int err_exec = fd_execute_instr( ctx->instr_ctx->txn_ctx, &cpi_instr ); + err_exec = fd_execute_instr( ctx->instr_ctx->txn_ctx, &cpi_instr ); ulong instr_exec_res = (ulong)err_exec; // uchar * sig = (uchar *)ctx->instr_ctx->txn_ctx->_txn_raw->raw + ctx->instr_ctx->txn_ctx->txn_descriptor->signature_off; // FD_LOG_WARNING(( "CPI CUs CONSUMED: %lu %lu %lu %64J", ctx->compute_meter, ctx->instr_ctx->txn_ctx->compute_meter, ctx->compute_meter - ctx->instr_ctx->txn_ctx->compute_meter, sig)); @@ -1640,8 +1653,15 @@ fd_vm_syscall_cpi_c( if( FD_UNLIKELY( res != FD_VM_SYSCALL_SUCCESS ) ) return res; } - caller_lamports = fd_instr_info_sum_account_lamports( ctx->instr_ctx->instr ); - if( caller_lamports != ctx->instr_ctx->instr->starting_lamports ) { + caller_lamports_h = 0; + caller_lamports_l = 0; + err_exec = fd_instr_info_sum_account_lamports( ctx->instr_ctx->instr, &caller_lamports_h, &caller_lamports_l ); + if( err_exec ) { + return FD_VM_SYSCALL_ERR_INSTR_ERR; + } + + if( caller_lamports_h != ctx->instr_ctx->instr->starting_lamports_h || + caller_lamports_l != ctx->instr_ctx->instr->starting_lamports_l ) { return FD_VM_SYSCALL_ERR_INSTR_ERR; } @@ -1750,9 +1770,6 @@ fd_vm_syscall_cpi_rust( memcpy( acct_keys[i].uc, acct_addr->uc, sizeof(fd_pubkey_t) ); } - /* TODO: Dispatch CPI to executor. - For now, we'll just log parameters. */ - fd_instruction_account_t instruction_accounts[256]; ulong instruction_accounts_cnt; fd_instr_info_t cpi_instr; @@ -1760,7 +1777,7 @@ fd_vm_syscall_cpi_rust( fd_vm_syscall_cpi_rust_instruction_to_instr( ctx, instruction, accounts, signers, signers_seeds_cnt, data, &cpi_instr ); err = fd_vm_prepare_instruction(ctx->instr_ctx->instr, &cpi_instr, ctx->instr_ctx, instruction_accounts, &instruction_accounts_cnt, signers, signers_seeds_cnt ); if( err != 0 ) { - FD_LOG_WARNING(("PREPARE FAILED")); + FD_LOG_WARNING(("vm prepare failed")); return err; } @@ -1774,12 +1791,21 @@ fd_vm_syscall_cpi_rust( return err; } - ulong caller_lamports = fd_instr_info_sum_account_lamports( ctx->instr_ctx->instr ); - if( caller_lamports != ctx->instr_ctx->instr->starting_lamports ) { + /* TODO: lamport checks in cpi_c may be redundant as it is checked in fd_execute_instr */ + ulong caller_lamports_h = 0; + ulong caller_lamports_l = 0; + int err_exec = fd_instr_info_sum_account_lamports( ctx->instr_ctx->instr, &caller_lamports_h, &caller_lamports_l ); + if( err_exec ) { + return FD_VM_SYSCALL_ERR_INSTR_ERR; + } + + if( caller_lamports_h != ctx->instr_ctx->instr->starting_lamports_h || + caller_lamports_l != ctx->instr_ctx->instr->starting_lamports_l ) { return FD_VM_SYSCALL_ERR_INSTR_ERR; } + ctx->instr_ctx->txn_ctx->compute_meter = ctx->compute_meter; - int err_exec = fd_execute_instr( ctx->instr_ctx->txn_ctx, &cpi_instr ); + err_exec = fd_execute_instr( ctx->instr_ctx->txn_ctx, &cpi_instr ); ulong instr_exec_res = (ulong)err_exec; #ifdef VLOG uchar * sig = (uchar *)ctx->instr_ctx->txn_ctx->_txn_raw->raw + ctx->instr_ctx->txn_ctx->txn_descriptor->signature_off; @@ -1803,8 +1829,15 @@ fd_vm_syscall_cpi_rust( } } - caller_lamports = fd_instr_info_sum_account_lamports( ctx->instr_ctx->instr ); - if( caller_lamports != ctx->instr_ctx->instr->starting_lamports ) { + caller_lamports_h = 0; + caller_lamports_l = 0; + err_exec = fd_instr_info_sum_account_lamports( ctx->instr_ctx->instr, &caller_lamports_h, &caller_lamports_l ); + if( err_exec ) { + return FD_VM_SYSCALL_ERR_INSTR_ERR; + } + + if( caller_lamports_h != ctx->instr_ctx->instr->starting_lamports_h || + caller_lamports_l != ctx->instr_ctx->instr->starting_lamports_l ) { return FD_VM_SYSCALL_ERR_INSTR_ERR; }