From 24ac59951e62bc13f91a28c722ffa2d6a55b4b14 Mon Sep 17 00:00:00 2001 From: Derek Chiang Date: Mon, 4 Sep 2017 16:11:33 -0700 Subject: [PATCH] contracts/chequebook/contract: fix two issues with Swarm chequebook contract 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. --- contracts/chequebook/contract/chequebook.sol | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/contracts/chequebook/contract/chequebook.sol b/contracts/chequebook/contract/chequebook.sol index eefe6c0637..845ba464b3 100644 --- a/contracts/chequebook/contract/chequebook.sol +++ b/contracts/chequebook/contract/chequebook.sol @@ -27,10 +27,11 @@ contract chequebook is mortal { if(owner != ecrecover(hash, sig_v, sig_r, sig_s)) return; // Attempt sending the difference between the cumulative amount on the cheque // and the cumulative amount on the last cashed cheque to beneficiary. - if (amount - sent[beneficiary] >= this.balance) { + uint256 diff = amount - sent[beneficiary]; + if (diff <= this.balance) { // update the cumulative amount before sending sent[beneficiary] = amount; - if (!beneficiary.send(amount - sent[beneficiary])) { + if (!beneficiary.send(diff)) { // Upon failure to execute send, revert everything throw; }