Skip to content

Commit d6a6180

Browse files
derekchiangfjl
authored andcommitted
contracts/chequebook: fix two contract issues (#15086)
This patch fixes the following issues: * The contract executes send() when it does not have enough balance. * The contract always sends a total amount of zero.
1 parent 9feec51 commit d6a6180

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

contracts/chequebook/contract/chequebook.sol

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ contract chequebook is mortal {
2727
if(owner != ecrecover(hash, sig_v, sig_r, sig_s)) return;
2828
// Attempt sending the difference between the cumulative amount on the cheque
2929
// and the cumulative amount on the last cashed cheque to beneficiary.
30-
if (amount - sent[beneficiary] >= this.balance) {
30+
uint256 diff = amount - sent[beneficiary];
31+
if (diff <= this.balance) {
3132
// update the cumulative amount before sending
3233
sent[beneficiary] = amount;
33-
if (!beneficiary.send(amount - sent[beneficiary])) {
34+
if (!beneficiary.send(diff)) {
3435
// Upon failure to execute send, revert everything
3536
throw;
3637
}

0 commit comments

Comments
 (0)