small bug fixes based on Berkely Blockchain team audit

This commit is contained in:
mbeylin 2017-10-19 16:03:57 -04:00
parent 7da4a5365a
commit d7d20f04a1
1 changed files with 15 additions and 19 deletions

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.11; pragma solidity 0.4.15;
import "./inherited/HumanStandardToken.sol"; import "./inherited/HumanStandardToken.sol";
/// @title StandardBounties /// @title StandardBounties
@ -16,7 +16,7 @@ contract StandardBounties {
event FulfillmentUpdated(uint _bountyId, uint _fulfillmentId); event FulfillmentUpdated(uint _bountyId, uint _fulfillmentId);
event FulfillmentAccepted(uint bountyId, address indexed fulfiller, uint256 indexed _fulfillmentId); event FulfillmentAccepted(uint bountyId, address indexed fulfiller, uint256 indexed _fulfillmentId);
event FulfillmentPaid(uint bountyId, address indexed fulfiller, uint256 indexed _fulfillmentId); event FulfillmentPaid(uint bountyId, address indexed fulfiller, uint256 indexed _fulfillmentId);
event BountyKilled(uint bountyId); event BountyKilled(uint bountyId, address indexed issuer);
event ContributionAdded(uint bountyId, address indexed contributor, uint256 value); event ContributionAdded(uint bountyId, address indexed contributor, uint256 value);
event DeadlineExtended(uint bountyId, uint newDeadline); event DeadlineExtended(uint bountyId, uint newDeadline);
event BountyChanged(uint bountyId); event BountyChanged(uint bountyId);
@ -74,11 +74,6 @@ contract StandardBounties {
* Modifiers * Modifiers
*/ */
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
modifier validateNotTooManyBounties(){ modifier validateNotTooManyBounties(){
require((bounties.length + 1) > bounties.length); require((bounties.length + 1) > bounties.length);
_; _;
@ -111,12 +106,13 @@ contract StandardBounties {
modifier transferredAmountEqualsValue(uint _bountyId, uint _amount) { modifier transferredAmountEqualsValue(uint _bountyId, uint _amount) {
if (bounties[_bountyId].paysTokens){ if (bounties[_bountyId].paysTokens){
require(msg.value == 0);
uint oldBalance = tokenContracts[_bountyId].balanceOf(this); uint oldBalance = tokenContracts[_bountyId].balanceOf(this);
if (_amount != 0){ if (_amount != 0){
require(tokenContracts[_bountyId].transferFrom(msg.sender, this, _amount)); require(tokenContracts[_bountyId].transferFrom(msg.sender, this, _amount));
} }
require((tokenContracts[_bountyId].balanceOf(this) - oldBalance) == _amount); require((tokenContracts[_bountyId].balanceOf(this) - oldBalance) == _amount);
require(msg.value == 0);
} else { } else {
require((_amount * 1 wei) == msg.value); require((_amount * 1 wei) == msg.value);
} }
@ -221,6 +217,7 @@ contract StandardBounties {
{ {
require (_value >= _fulfillmentAmount); require (_value >= _fulfillmentAmount);
if (_paysTokens){ if (_paysTokens){
require(msg.value == 0);
tokenContracts[bounties.length] = HumanStandardToken(_tokenContract); tokenContracts[bounties.length] = HumanStandardToken(_tokenContract);
require(tokenContracts[bounties.length].transferFrom(msg.sender, this, _value)); require(tokenContracts[bounties.length].transferFrom(msg.sender, this, _value));
} else { } else {
@ -256,9 +253,9 @@ contract StandardBounties {
function contribute (uint _bountyId, uint _value) function contribute (uint _bountyId, uint _value)
payable payable
public public
validateBountyArrayIndex(_bountyId)
isBeforeDeadline(_bountyId) isBeforeDeadline(_bountyId)
isNotDead(_bountyId) isNotDead(_bountyId)
validateBountyArrayIndex(_bountyId)
amountIsNotZero(_value) amountIsNotZero(_value)
transferredAmountEqualsValue(_bountyId, _value) transferredAmountEqualsValue(_bountyId, _value)
{ {
@ -275,9 +272,9 @@ contract StandardBounties {
function activateBounty(uint _bountyId, uint _value) function activateBounty(uint _bountyId, uint _value)
payable payable
public public
validateBountyArrayIndex(_bountyId)
isBeforeDeadline(_bountyId) isBeforeDeadline(_bountyId)
onlyIssuer(_bountyId) onlyIssuer(_bountyId)
validateBountyArrayIndex(_bountyId)
transferredAmountEqualsValue(_bountyId, _value) transferredAmountEqualsValue(_bountyId, _value)
{ {
bounties[_bountyId].balance += _value; bounties[_bountyId].balance += _value;
@ -337,8 +334,7 @@ contract StandardBounties {
} }
modifier enoughFundsToPay(uint _bountyId) { modifier enoughFundsToPay(uint _bountyId) {
require((bounties[_bountyId].owedAmount + require(bounties[_bountyId].balance >= (bounties[_bountyId].owedAmount + bounties[_bountyId].fulfillmentAmount));
bounties[_bountyId].fulfillmentAmount) <= bounties[_bountyId].balance);
_; _;
} }
@ -348,9 +344,9 @@ contract StandardBounties {
function acceptFulfillment(uint _bountyId, uint _fulfillmentId) function acceptFulfillment(uint _bountyId, uint _fulfillmentId)
public public
validateBountyArrayIndex(_bountyId) validateBountyArrayIndex(_bountyId)
validateFulfillmentArrayIndex(_bountyId, _fulfillmentId)
onlyIssuerOrArbiter(_bountyId) onlyIssuerOrArbiter(_bountyId)
isAtStage(_bountyId, BountyStages.Active) isAtStage(_bountyId, BountyStages.Active)
validateFulfillmentArrayIndex(_bountyId, _fulfillmentId)
fulfillmentNotYetAccepted(_bountyId, _fulfillmentId) fulfillmentNotYetAccepted(_bountyId, _fulfillmentId)
enoughFundsToPay(_bountyId) enoughFundsToPay(_bountyId)
{ {
@ -401,14 +397,14 @@ contract StandardBounties {
transitionToState(_bountyId, BountyStages.Dead); transitionToState(_bountyId, BountyStages.Dead);
uint difference = bounties[_bountyId].balance - bounties[_bountyId].owedAmount; uint difference = bounties[_bountyId].balance - bounties[_bountyId].owedAmount;
bounties[_bountyId].balance = bounties[_bountyId].owedAmount; bounties[_bountyId].balance = bounties[_bountyId].owedAmount;
if (difference != 0){ if (difference > 0){
if (bounties[_bountyId].paysTokens){ if (bounties[_bountyId].paysTokens){
require(tokenContracts[_bountyId].transfer(bounties[_bountyId].issuer, difference)); require(tokenContracts[_bountyId].transfer(bounties[_bountyId].issuer, difference));
} else { } else {
bounties[_bountyId].issuer.transfer(difference); bounties[_bountyId].issuer.transfer(difference);
} }
} }
BountyKilled(_bountyId); BountyKilled(_bountyId, msg.sender);
} }
modifier newDeadlineIsValid(uint _bountyId, uint _newDeadline) { modifier newDeadlineIsValid(uint _bountyId, uint _newDeadline) {
@ -445,7 +441,7 @@ contract StandardBounties {
} }
/// @dev changeBountyDeadline(): allows the issuer to change a bounty's issuer /// @dev changeBountyDeadline(): allows the issuer to change a bounty's deadline
/// @param _bountyId the index of the bounty /// @param _bountyId the index of the bounty
/// @param _newDeadline the new deadline for the bounty /// @param _newDeadline the new deadline for the bounty
function changeBountyDeadline(uint _bountyId, uint _newDeadline) function changeBountyDeadline(uint _bountyId, uint _newDeadline)
@ -459,7 +455,7 @@ contract StandardBounties {
BountyChanged(_bountyId); BountyChanged(_bountyId);
} }
/// @dev changeData(): allows the issuer to change a bounty's issuer /// @dev changeData(): allows the issuer to change a bounty's data
/// @param _bountyId the index of the bounty /// @param _bountyId the index of the bounty
/// @param _newData the new requirements of the bounty /// @param _newData the new requirements of the bounty
function changeBountyData(uint _bountyId, string _newData) function changeBountyData(uint _bountyId, string _newData)
@ -472,7 +468,7 @@ contract StandardBounties {
BountyChanged(_bountyId); BountyChanged(_bountyId);
} }
/// @dev changeBountyfulfillmentAmount(): allows the issuer to change a bounty's issuer /// @dev changeBountyfulfillmentAmount(): allows the issuer to change a bounty's fulfillment amount
/// @param _bountyId the index of the bounty /// @param _bountyId the index of the bounty
/// @param _newFulfillmentAmount the new fulfillment amount /// @param _newFulfillmentAmount the new fulfillment amount
function changeBountyFulfillmentAmount(uint _bountyId, uint _newFulfillmentAmount) function changeBountyFulfillmentAmount(uint _bountyId, uint _newFulfillmentAmount)
@ -485,7 +481,7 @@ contract StandardBounties {
BountyChanged(_bountyId); BountyChanged(_bountyId);
} }
/// @dev changeBountyArbiter(): allows the issuer to change a bounty's issuer /// @dev changeBountyArbiter(): allows the issuer to change a bounty's arbiter
/// @param _bountyId the index of the bounty /// @param _bountyId the index of the bounty
/// @param _newArbiter the new address of the arbiter /// @param _newArbiter the new address of the arbiter
function changeBountyArbiter(uint _bountyId, address _newArbiter) function changeBountyArbiter(uint _bountyId, address _newArbiter)