If my contract has a payout function like this
address bossAddress;
address employeeAddress;
uint256 bossSalary;
uint256 employeeSalary;
function payout (){
if (msg.sender==bossAddress){
employeeAddress.send(employeeSalary);
bossAddress.send(bossSalary);
selfdestruct(bossAddress);
}
}
Then, if I were a malicious boss, could I have exploited the payout such that only the boss gets paid?
A) If the employeeAddress is a contract, but bossAddress is a regular address, can I exploit the callstack attack so that the transaction fails on employeeAddress.send(employeeSalary), but continues to run bossAddress.send(bossSalary)? I guess what I'm asking is if both send calls reduces the callstack count, or just the send call that involves a contract address.
B) On the other hand, if the employee address is a contract that uses a lot of gas, I probably won't need to do any exploit, since the employeeAddress.send will fail from out of gass, then the boss should get paid both employeeSalary AND bossSalary, thanks to the selfdestruct() call.
C) And as a last point, is there a way to specify gas on the send call? This should prevent most out-of-gass errors in the case employeeAddress is actually a contract.
I just need to verify that my understanding of gas / callstack behavior is correct.