Skip to content

Commit

Permalink
Revert "flamenco: remove lamport checks in CPI" (#3104)
Browse files Browse the repository at this point in the history
This reverts commit 75b12d7.
  • Loading branch information
kbhargava-jump authored Oct 11, 2024
1 parent 2023968 commit e3cf3f1
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/flamenco/vm/syscall/fd_vm_syscall_cpi_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,18 @@ VM_SYSCALL_CPI_ENTRYPOINT( void * _vm,
err = VM_SYSCALL_CPI_TRANSLATE_AND_UPDATE_ACCOUNTS_FUNC( vm, instruction_accounts, instruction_accounts_cnt, acc_infos, acct_info_cnt, callee_account_keys, caller_accounts_to_update, &caller_accounts_to_update_len );
if( FD_UNLIKELY( err ) ) return err;

/* Check that the caller lamports haven't changed */
ulong caller_lamports_h = 0UL;
ulong caller_lamports_l = 0UL;

err = fd_instr_info_sum_account_lamports( vm->instr_ctx->instr, &caller_lamports_h, &caller_lamports_l );
if ( FD_UNLIKELY( err ) ) return FD_VM_ERR_INSTR_ERR;

if( caller_lamports_h != vm->instr_ctx->instr->starting_lamports_h ||
caller_lamports_l != vm->instr_ctx->instr->starting_lamports_l ) {
return FD_VM_ERR_INSTR_ERR;
}

/* Set the transaction compute meter to be the same as the VM's compute meter,
so that the callee cannot use compute units that the caller has already used. */
vm->instr_ctx->txn_ctx->compute_meter = vm->cu;
Expand Down Expand Up @@ -739,6 +751,16 @@ VM_SYSCALL_CPI_ENTRYPOINT( void * _vm,
}
}

caller_lamports_h = 0UL;
caller_lamports_l = 0UL;
err = fd_instr_info_sum_account_lamports( vm->instr_ctx->instr, &caller_lamports_h, &caller_lamports_l );
if ( FD_UNLIKELY( err ) ) return FD_VM_ERR_INSTR_ERR;

if( caller_lamports_h != vm->instr_ctx->instr->starting_lamports_h ||
caller_lamports_l != vm->instr_ctx->instr->starting_lamports_l ) {
return FD_VM_ERR_INSTR_ERR;
}

return FD_VM_SUCCESS;
}

Expand Down

0 comments on commit e3cf3f1

Please sign in to comment.