From 770eaea178d175f419873a842f8cf765f1ed08e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Fingen?= Date: Mon, 14 May 2018 16:17:44 +0200 Subject: [PATCH] Add isInitialized to all state-changing public functions Closes #303. --- apps/finance/contracts/Finance.sol | 18 +++++++++--------- apps/token-manager/contracts/TokenManager.sol | 10 +++++----- apps/vault/contracts/Vault.sol | 3 ++- apps/voting/contracts/Voting.sol | 6 +++--- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/apps/finance/contracts/Finance.sol b/apps/finance/contracts/Finance.sol index d6f46a473c..42de246dbf 100644 --- a/apps/finance/contracts/Finance.sol +++ b/apps/finance/contracts/Finance.sol @@ -101,7 +101,7 @@ contract Finance is AragonApp { * @dev Sends ETH to Vault. Sends all the available balance. * @notice Allows to send ETH from this contract to Vault, to avoid locking them in contract forever. */ - function () public payable { + function () isInitialized public payable { _recordIncomingTransaction( ETH, msg.sender, @@ -165,7 +165,7 @@ contract Finance is AragonApp { * @param _operatorData Information attached to the transaction by the operator */ /* - function tokensReceived(address _operator, address _from, address _to, uint _amount, bytes _userData, bytes _operatorData) transitionsPeriod external { + function tokensReceived(address _operator, address _from, address _to, uint _amount, bytes _userData, bytes _operatorData) transitionsPeriod isInitialized external { _recordIncomingTransaction( msg.sender, _from, @@ -237,7 +237,7 @@ contract Finance is AragonApp { * @notice Change period duration to `(_periodDuration - _periodDuration % 86400) / 86400` day`_periodDuration >= 172800 ? 's' : ''`, effective for next accounting period. * @param _periodDuration Duration in seconds for accounting periods */ - function setPeriodDuration(uint64 _periodDuration) authP(CHANGE_PERIOD_ROLE, arr(uint256(_periodDuration), uint256(settings.periodDuration))) transitionsPeriod external { + function setPeriodDuration(uint64 _periodDuration) authP(CHANGE_PERIOD_ROLE, arr(uint256(_periodDuration), uint256(settings.periodDuration))) transitionsPeriod isInitialized external { require(_periodDuration >= 1 days); settings.periodDuration = _periodDuration; ChangePeriodDuration(_periodDuration); @@ -248,7 +248,7 @@ contract Finance is AragonApp { * @param _token Address for token * @param _amount New budget amount */ - function setBudget(address _token, uint256 _amount) authP(CHANGE_BUDGETS_ROLE, arr(_token, _amount, settings.budgets[_token])) transitionsPeriod external { + function setBudget(address _token, uint256 _amount) authP(CHANGE_BUDGETS_ROLE, arr(_token, _amount, settings.budgets[_token])) transitionsPeriod isInitialized external { settings.budgets[_token] = _amount; if (!settings.hasBudget[_token]) { settings.hasBudget[_token] = true; @@ -260,7 +260,7 @@ contract Finance is AragonApp { * @notice Remove spending limit for `_token.symbol(): string`. * @param _token Address for token */ - function removeBudget(address _token) authP(CHANGE_BUDGETS_ROLE, arr(_token, uint256(0), settings.budgets[_token])) transitionsPeriod external { + function removeBudget(address _token) authP(CHANGE_BUDGETS_ROLE, arr(_token, uint256(0), settings.budgets[_token])) transitionsPeriod isInitialized external { settings.hasBudget[_token] = false; SetBudget(_token, 0, false); } @@ -270,7 +270,7 @@ contract Finance is AragonApp { * @notice Execute pending payment #`_paymentId` * @param _paymentId Identifier for payment */ - function executePayment(uint256 _paymentId) authP(EXECUTE_PAYMENTS_ROLE, arr(_paymentId, payments[_paymentId].amount)) external { + function executePayment(uint256 _paymentId) authP(EXECUTE_PAYMENTS_ROLE, arr(_paymentId, payments[_paymentId].amount)) isInitialized external { require(nextPaymentTime(_paymentId) <= getTimestamp()); _executePayment(_paymentId); @@ -281,7 +281,7 @@ contract Finance is AragonApp { * @notice Execute pending payment #`_paymentId` * @param _paymentId Identifier for payment */ - function receiverExecutePayment(uint256 _paymentId) external { + function receiverExecutePayment(uint256 _paymentId) isInitialized external { require(nextPaymentTime(_paymentId) <= getTimestamp()); require(payments[_paymentId].receiver == msg.sender); @@ -293,7 +293,7 @@ contract Finance is AragonApp { * @param _paymentId Identifier for payment * @param _disabled Whether it will be disabled or enabled */ - function setPaymentDisabled(uint256 _paymentId, bool _disabled) authP(DISABLE_PAYMENTS_ROLE, arr(_paymentId)) external { + function setPaymentDisabled(uint256 _paymentId, bool _disabled) authP(DISABLE_PAYMENTS_ROLE, arr(_paymentId)) isInitialized external { payments[_paymentId].disabled = _disabled; ChangePaymentState(_paymentId, _disabled); } @@ -330,7 +330,7 @@ contract Finance is AragonApp { * @return success Boolean indicating whether the accounting period is the correct one (if false, * maxTransitions was surpased and another call is needed) */ - function tryTransitionAccountingPeriod(uint256 _maxTransitions) public returns (bool success) { + function tryTransitionAccountingPeriod(uint256 _maxTransitions) isInitialized public returns (bool success) { Period storage currentPeriod = periods[currentPeriodId()]; uint256 timestamp = getTimestamp(); diff --git a/apps/token-manager/contracts/TokenManager.sol b/apps/token-manager/contracts/TokenManager.sol index 8d57381dc2..a710707cba 100644 --- a/apps/token-manager/contracts/TokenManager.sol +++ b/apps/token-manager/contracts/TokenManager.sol @@ -154,7 +154,7 @@ contract TokenManager is ITokenController, AragonApp { // ,IForwarder makes cove * @param _holder Address getting vesting revoked * @param _vestingId Numeric id of the vesting */ - function revokeVesting(address _holder, uint256 _vestingId) authP(REVOKE_VESTINGS_ROLE, arr(_holder)) external { + function revokeVesting(address _holder, uint256 _vestingId) authP(REVOKE_VESTINGS_ROLE, arr(_holder)) isInitialized external { TokenVesting storage v = vestings[_holder][_vestingId]; require(v.revokable); @@ -181,7 +181,7 @@ contract TokenManager is ITokenController, AragonApp { // ,IForwarder makes cove * @dev IForwarder interface conformance. Forwards any token holder action. * @param _evmScript Script being executed */ - function forward(bytes _evmScript) public { + function forward(bytes _evmScript) isInitialized public { require(canForward(msg.sender, _evmScript)); bytes memory input = new bytes(0); // TODO: Consider input for this address[] memory blacklist = new address[](1); @@ -215,7 +215,7 @@ contract TokenManager is ITokenController, AragonApp { // ,IForwarder makes cove * @param _amount The amount of the transfer * @return False if the controller does not authorize the transfer */ - function onTransfer(address _from, address _to, uint _amount) public returns (bool) { + function onTransfer(address _from, address _to, uint _amount) isInitialized public returns (bool) { require(msg.sender == address(token)); bool includesTokenManager = _from == address(this) || _to == address(this); @@ -351,7 +351,7 @@ contract TokenManager is ITokenController, AragonApp { // ,IForwarder makes cove * @param _owner The address that sent the ether to create tokens * @return True if the ether is accepted, false for it to throw */ - function proxyPayment(address _owner) payable public returns (bool) { + function proxyPayment(address _owner) payable isInitialized public returns (bool) { // Even though it is tested, solidity-coverage doesnt get it because // MiniMeToken is not instrumented and entire tx is reverted require(msg.sender == address(token)); @@ -365,7 +365,7 @@ contract TokenManager is ITokenController, AragonApp { // ,IForwarder makes cove * @param _amount The amount in the `approve()` call * @return False if the controller does not authorize the approval */ - function onApprove(address _owner, address _spender, uint _amount) public returns (bool) { + function onApprove(address _owner, address _spender, uint _amount) isInitialized public returns (bool) { _owner; _spender; _amount; diff --git a/apps/vault/contracts/Vault.sol b/apps/vault/contracts/Vault.sol index f8a7c7f85f..1277d84fe6 100644 --- a/apps/vault/contracts/Vault.sol +++ b/apps/vault/contracts/Vault.sol @@ -54,7 +54,7 @@ contract Vault is VaultBase { connectors[ETH] = ethConnector; } - function () payable public { + function () payable isInitialized public { address token = ETH; // 4 (sig) + 32 (at least the token address to locate connector) @@ -74,6 +74,7 @@ contract Vault is VaultBase { function registerStandard(uint32 erc, uint32 interfaceDetectionERC, bytes4 interfaceID, address connector) authP(REGISTER_TOKEN_STANDARD, arr(uint256(erc), interfaceDetectionERC)) + isInitialized public { diff --git a/apps/voting/contracts/Voting.sol b/apps/voting/contracts/Voting.sol index 74b07534d8..c23fe66bc4 100644 --- a/apps/voting/contracts/Voting.sol +++ b/apps/voting/contracts/Voting.sol @@ -79,7 +79,7 @@ contract Voting is IForwarder, AragonApp { * @notice Change minimum acceptance quorum to `(_minAcceptQuorumPct - _minAcceptQuorumPct % 10^14) / 10^16`% * @param _minAcceptQuorumPct New acceptance quorum */ - function changeMinAcceptQuorumPct(uint256 _minAcceptQuorumPct) authP(MODIFY_QUORUM_ROLE, arr(_minAcceptQuorumPct, minAcceptQuorumPct)) external { + function changeMinAcceptQuorumPct(uint256 _minAcceptQuorumPct) authP(MODIFY_QUORUM_ROLE, arr(_minAcceptQuorumPct, minAcceptQuorumPct)) isInitialized external { require(_minAcceptQuorumPct > 0); require(supportRequiredPct >= _minAcceptQuorumPct); minAcceptQuorumPct = _minAcceptQuorumPct; @@ -114,7 +114,7 @@ contract Voting is IForwarder, AragonApp { * @param _supports Whether voter supports the vote * @param _executesIfDecided Whether the vote should execute its action if it becomes decided */ - function vote(uint256 _voteId, bool _supports, bool _executesIfDecided) external { + function vote(uint256 _voteId, bool _supports, bool _executesIfDecided) isInitialized external { require(canVote(_voteId, msg.sender)); _vote( _voteId, @@ -128,7 +128,7 @@ contract Voting is IForwarder, AragonApp { * @notice Execute the result of vote #`_voteId` * @param _voteId Id for vote */ - function executeVote(uint256 _voteId) external { + function executeVote(uint256 _voteId) isInitialized external { require(canExecute(_voteId)); _executeVote(_voteId); }