From 237d32359df4b23ea5333b472cab438a8edfbcef Mon Sep 17 00:00:00 2001 From: mbeylin Date: Fri, 6 Oct 2017 13:52:47 -0400 Subject: [PATCH] more re-entrancy protections, fixed small bug --- contracts/StandardBounties.sol | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/contracts/StandardBounties.sol b/contracts/StandardBounties.sol index db007ed..082433f 100644 --- a/contracts/StandardBounties.sol +++ b/contracts/StandardBounties.sol @@ -382,7 +382,7 @@ contract StandardBounties { bounties[_bountyId].balance -= bounties[_bountyId].fulfillmentAmount; if (bounties[_bountyId].paysTokens){ - tokenContracts[_bountyId].transfer(fulfillments[_bountyId][_fulfillmentId].fulfiller, bounties[_bountyId].fulfillmentAmount); + require(tokenContracts[_bountyId].transfer(fulfillments[_bountyId][_fulfillmentId].fulfiller, bounties[_bountyId].fulfillmentAmount)); } else { fulfillments[_bountyId][_fulfillmentId].fulfiller.transfer(bounties[_bountyId].fulfillmentAmount); } @@ -401,12 +401,13 @@ contract StandardBounties { transitionToState(_bountyId, BountyStages.Dead); uint difference = bounties[_bountyId].balance - bounties[_bountyId].owedAmount; bounties[_bountyId].balance = bounties[_bountyId].owedAmount; - if (bounties[_bountyId].paysTokens){ - tokenContracts[_bountyId].transfer(bounties[_bountyId].issuer, difference); - } else { - bounties[_bountyId].issuer.transfer(difference); + if (difference != 0){ + if (bounties[_bountyId].paysTokens){ + require(tokenContracts[_bountyId].transfer(bounties[_bountyId].issuer, difference)); + } else { + bounties[_bountyId].issuer.transfer(difference); + } } - BountyKilled(_bountyId); } @@ -507,17 +508,19 @@ contract StandardBounties { onlyIssuer(_bountyId) isAtStage(_bountyId, BountyStages.Draft) { + HumanStandardToken oldToken = tokenContracts[_bountyId]; + bool oldPaysTokens = bounties[_bountyId].paysTokens; + bounties[_bountyId].paysTokens = _newPaysTokens; + tokenContracts[_bountyId] = HumanStandardToken(_newTokenContract); if (bounties[_bountyId].balance > 0){ uint oldBalance = bounties[_bountyId].balance; bounties[_bountyId].balance = 0; - if (bounties[_bountyId].paysTokens){ - require(tokenContracts[_bountyId].transfer(bounties[_bountyId].issuer, oldBalance)); + if (oldPaysTokens){ + require(oldToken.transfer(bounties[_bountyId].issuer, oldBalance)); } else { bounties[_bountyId].issuer.transfer(oldBalance); } } - bounties[_bountyId].paysTokens = _newPaysTokens; - tokenContracts[_bountyId] = HumanStandardToken(_newTokenContract); BountyChanged(_bountyId); }