Skip to content

Commit

Permalink
La audit fixes (#116)
Browse files Browse the repository at this point in the history
- [x] close #90 
- [x] close #91 
- [x] close #92 
- [x] close #93 
- [x] close #95 
- [x] close #96  
- [x] close #97
- [x] close #98
- [x] close #119

---------

Co-authored-by: Alberto Granzotto <[email protected]>
  • Loading branch information
sirnicolaz and vrde authored Oct 20, 2023
1 parent 4e4c782 commit b5e785b
Show file tree
Hide file tree
Showing 45 changed files with 235 additions and 97 deletions.
32 changes: 20 additions & 12 deletions contracts/GovernanceToken/GovernanceToken.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;
pragma solidity 0.8.16;

import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
Expand Down Expand Up @@ -46,6 +46,10 @@ contract GovernanceToken is Initializable, HasRole, GovernanceTokenSnapshot {
string memory name,
string memory symbol
) public initializer {
require(
address(roles) != address(0),
"GovernanceToken: 0x0 not allowed"
);
_initialize(name, symbol);
_setRoles(roles);
}
Expand Down Expand Up @@ -154,6 +158,15 @@ contract GovernanceToken is Initializable, HasRole, GovernanceTokenSnapshot {
uint256 amount
) public virtual onlyRole(Roles.RESOLUTION_ROLE) {
_mint(to, amount);

if (
_shareholderRegistry.isAtLeast(
_shareholderRegistry.CONTRIBUTOR_STATUS(),
to
)
) {
_redemptionController.afterMint(to, amount);
}
}

/**
Expand Down Expand Up @@ -292,16 +305,6 @@ contract GovernanceToken is Initializable, HasRole, GovernanceTokenSnapshot {
super._afterTokenTransfer(from, to, amount);
_voting.afterTokenTransfer(from, to, amount);

if (
from == address(0) &&
_shareholderRegistry.isAtLeast(
_shareholderRegistry.CONTRIBUTOR_STATUS(),
to
)
) {
_redemptionController.afterMint(to, amount);
}

// Invariants
require(
balanceOf(from) >= _vestingBalance[from],
Expand Down Expand Up @@ -342,7 +345,12 @@ contract GovernanceToken is Initializable, HasRole, GovernanceTokenSnapshot {
* @param amount Amount of external tokens to wrap.
*/
function _wrap(address from, uint amount) internal virtual {
tokenExternal.transferFrom(from, address(this), amount);
require(
tokenExternal.transferFrom(from, address(this), amount),
"GovernanceToken: transfer failed"
);
require(amount > 0, "GovernanceToken: attempt to wrap 0 tokens");

uint256 settlementTimestamp = block.timestamp + settlementPeriod;
depositedTokens[from].push(
DepositedTokens(amount, settlementTimestamp)
Expand Down
8 changes: 5 additions & 3 deletions contracts/GovernanceToken/GovernanceTokenBase.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.16;
pragma solidity 0.8.16;

import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import "../RedemptionController/IRedemptionController.sol";
Expand Down Expand Up @@ -69,7 +68,10 @@ abstract contract GovernanceTokenBase is ERC20Upgradeable, IGovernanceToken {
//}

function _unwrap(address from, address to, uint amount) internal virtual {
tokenExternal.transfer(to, amount);
require(
tokenExternal.transfer(to, amount),
"GovernanceToken: transfer failed"
);
super._burn(from, amount);
}

Expand Down
3 changes: 1 addition & 2 deletions contracts/GovernanceToken/GovernanceTokenSnapshot.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.16;
pragma solidity 0.8.16;

import "@openzeppelin/contracts/utils/Arrays.sol";
import "./IGovernanceToken.sol";
Expand Down
3 changes: 1 addition & 2 deletions contracts/GovernanceToken/IGovernanceToken.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.16;
pragma solidity 0.8.16;

import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
import "../extensions/ISnapshot.sol";
Expand Down
14 changes: 9 additions & 5 deletions contracts/InternalMarket/InternalMarket.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.16;
pragma solidity 0.8.16;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
Expand All @@ -23,13 +22,18 @@ contract InternalMarket is Initializable, HasRole, InternalMarketBase {
/**
* @dev Initializes the contract with the given roles and internal token.
* @param roles DAORoles instance containing custom access control roles.
* @param tokenInternal_ Reference to governance token.
* @param governanceToken Reference to governance token.
*/
function initialize(
DAORoles roles,
IGovernanceToken tokenInternal_
IGovernanceToken governanceToken
) public initializer {
_initialize(tokenInternal_, 7 days);
require(
address(roles) != address(0) &&
address(governanceToken) != address(0),
"InternalMarket: 0x0 not allowed"
);
_initialize(governanceToken, 7 days);
_setRoles(roles);
}

Expand Down
3 changes: 1 addition & 2 deletions contracts/InternalMarket/InternalMarketBase.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.16;
pragma solidity 0.8.16;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "../ShareholderRegistry/IShareholderRegistry.sol";
Expand Down
3 changes: 1 addition & 2 deletions contracts/NeokingdomToken/INeokingdomToken.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.16;
pragma solidity 0.8.16;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

Expand Down
2 changes: 1 addition & 1 deletion contracts/NeokingdomToken/NeokingdomToken.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
pragma solidity 0.8.16;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
Expand Down
3 changes: 1 addition & 2 deletions contracts/RedemptionController/IRedemptionController.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.16;
pragma solidity 0.8.16;

import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
Expand Down
7 changes: 5 additions & 2 deletions contracts/RedemptionController/RedemptionController.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.16;
pragma solidity 0.8.16;

import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "./RedemptionControllerBase.sol";
Expand Down Expand Up @@ -36,6 +35,10 @@ contract RedemptionController is
* @param roles The addresses of DAORoles for this contract.
*/
function initialize(DAORoles roles) public initializer {
require(
address(roles) != address(0),
"RedemptionController: 0x0 not allowed"
);
_setRoles(roles);
_initialize();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;
pragma solidity 0.8.16;

import "./IRedemptionController.sol";

Expand Down
30 changes: 8 additions & 22 deletions contracts/ResolutionManager/ResolutionManager.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;
pragma solidity 0.8.16;

import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import { Roles } from "../extensions/Roles.sol";
Expand All @@ -26,6 +26,13 @@ contract ResolutionManager is Initializable, ResolutionManagerBase, HasRole {
IGovernanceToken governanceToken,
IVoting voting
) public initializer {
require(
address(roles) != address(0) &&
address(shareholderRegistry) != address(0) &&
address(governanceToken) != address(0) &&
address(voting) != address(0),
"ResolutionManager: 0x0 not allowed"
);
_setRoles(roles);
_initialize(shareholderRegistry, governanceToken, voting);
}
Expand Down Expand Up @@ -167,13 +174,6 @@ contract ResolutionManager is Initializable, ResolutionManagerBase, HasRole {
* @param resolutionId The id of the resolution to approve.
*/
function approveResolution(uint256 resolutionId) external virtual {
require(
_shareholderRegistry.isAtLeast(
_shareholderRegistry.MANAGING_BOARD_STATUS(),
_msgSender()
),
"Resolution: only managing board can approve"
);
_approveResolution(resolutionId);
}

Expand All @@ -182,13 +182,6 @@ contract ResolutionManager is Initializable, ResolutionManagerBase, HasRole {
* @param resolutionId The id of the resolution to reject.
*/
function rejectResolution(uint256 resolutionId) external virtual {
require(
_shareholderRegistry.isAtLeast(
_shareholderRegistry.MANAGING_BOARD_STATUS(),
_msgSender()
),
"Resolution: only managing board can reject"
);
_rejectResolution(resolutionId);
}

Expand All @@ -209,13 +202,6 @@ contract ResolutionManager is Initializable, ResolutionManagerBase, HasRole {
address[] memory executionTo,
bytes[] memory executionData
) external virtual {
require(
_shareholderRegistry.isAtLeast(
_shareholderRegistry.MANAGING_BOARD_STATUS(),
_msgSender()
),
"Resolution: only managing board can update"
);
_updateResolution(
resolutionId,
dataURI,
Expand Down
5 changes: 2 additions & 3 deletions contracts/ResolutionManager/ResolutionManagerBase.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.16;
pragma solidity 0.8.16;

import "../ShareholderRegistry/IShareholderRegistry.sol";
import "../GovernanceToken/IGovernanceToken.sol";
Expand Down Expand Up @@ -267,7 +266,7 @@ abstract contract ResolutionManagerBase {
bool isNegative,
address[] memory executionTo,
bytes[] memory executionData
) internal virtual onlyPending(resolutionId) {
) internal virtual onlyPending(resolutionId) exists(resolutionId) {
emit ResolutionUpdated(msg.sender, resolutionId);

Resolution storage resolution = resolutions[resolutionId];
Expand Down
3 changes: 1 addition & 2 deletions contracts/ShareholderRegistry/IShareholderRegistry.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.16;
pragma solidity 0.8.16;

import "../extensions/ISnapshot.sol";

Expand Down
7 changes: 5 additions & 2 deletions contracts/ShareholderRegistry/ShareholderRegistry.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.16;
pragma solidity 0.8.16;

import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "./ShareholderRegistrySnapshot.sol";
Expand Down Expand Up @@ -29,6 +28,10 @@ contract ShareholderRegistry is
string memory name,
string memory symbol
) public initializer {
require(
address(roles) != address(0),
"ShareholderRegistry: 0x0 not allowed"
);
_initialize(name, symbol);
_setRoles(roles);
}
Expand Down
16 changes: 10 additions & 6 deletions contracts/ShareholderRegistry/ShareholderRegistryBase.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
// SPDX-License-Identifier: MIT

// TODO: update _statuses when account has no shares
// TODO: check who can move shares

pragma solidity ^0.8.16;
pragma solidity 0.8.16;

import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import "@openzeppelin/contracts/utils/Address.sol";
import "../Voting/IVoting.sol";

contract ShareholderRegistryBase is ERC20Upgradeable {
Expand Down Expand Up @@ -40,6 +37,10 @@ contract ShareholderRegistryBase is ERC20Upgradeable {
}

function _setStatus(bytes32 status, address account) internal virtual {
require(
!Address.isContract(account),
"ShareholderRegistry: cannot set status for smart contract"
);
require(
status == 0 || isAtLeast(SHAREHOLDER_STATUS, account),
"ShareholderRegistry: address has no tokens"
Expand Down Expand Up @@ -83,7 +84,10 @@ contract ShareholderRegistryBase is ERC20Upgradeable {
) internal view virtual returns (bool) {
return
balance > 0 &&
// shareholder < investor < contributor < managing board
// investor < contributor < managing board
// TODO: shareholder is currently equivalent to investor.
// We need to verify with the lawyer whether we can remove it
// completely from the smart contracts.
(status == INVESTOR_STATUS ||
status == SHAREHOLDER_STATUS ||
status == accountStatus ||
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/ERC20Snapshot.sol)

pragma solidity ^0.8.16;
pragma solidity 0.8.16;

import "./ShareholderRegistryBase.sol";
import "../extensions/Snapshottable.sol";
Expand Down
3 changes: 1 addition & 2 deletions contracts/Voting/IVoting.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.16;
pragma solidity 0.8.16;

import "../extensions/ISnapshot.sol";

Expand Down
5 changes: 3 additions & 2 deletions contracts/Voting/Voting.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;
pragma solidity 0.8.16;

import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "../ShareholderRegistry/IShareholderRegistry.sol";
Expand All @@ -18,6 +18,7 @@ contract Voting is VotingSnapshot, Initializable, HasRole {
* @param roles Instance of a DAORoles contract.
*/
function initialize(DAORoles roles) public initializer {
require(address(roles) != address(0), "Voting: 0x0 not allowed");
_setRoles(roles);
}

Expand Down Expand Up @@ -95,7 +96,7 @@ contract Voting is VotingSnapshot, Initializable, HasRole {

/**
* @notice Hook called on every governance token transfer.
* @dev Only the governance token can call this method.
* @dev Called by GovernanceToken and ShareholderRegistry.
* @param from The sender's address.
* @param to The receiver's address.
* @param amount The amount transferred.
Expand Down
2 changes: 1 addition & 1 deletion contracts/Voting/VotingBase.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;
pragma solidity 0.8.16;

import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
import "../ShareholderRegistry/IShareholderRegistry.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/Voting/VotingSnapshot.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;
pragma solidity 0.8.16;

import "@openzeppelin/contracts/utils/Arrays.sol";
import "../extensions/Snapshottable.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/extensions/DAORoles.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;
pragma solidity 0.8.16;

import "@openzeppelin/contracts/access/AccessControl.sol";

Expand Down
Loading

0 comments on commit b5e785b

Please sign in to comment.