Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes DAO Final Audit Report #300

Merged
merged 27 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7719898
refactor(contracts/erc20): dont call snapshot too often when mint/bur…
AugustoL Jan 17, 2023
5214bac
refactor(contracts/dao): small refactor on withdrawRefundBalance in v…
AugustoL Jan 18, 2023
15dfede
fix(contracts/dao): _execute function in VotingMachine returns true i…
AugustoL Jan 18, 2023
eb93030
fix(contracts/dao): fix preBoostedProposalsCounter if max boosted pro…
AugustoL Jan 18, 2023
e10149f
refactor(contracts/dao): remove unnecessaty isSchemeRegistered flag i…
AugustoL Jan 18, 2023
c79ed50
fix(contracts/dao): send stake done in wrong option to dao avatar ins…
AugustoL Jan 19, 2023
045f7ba
refactor(contracts/dao): change calculateBoosteChange in VM to external
AugustoL Jan 19, 2023
407e113
refactor(contracts/dao): remove unused variable secondsFromTimeOutTil…
AugustoL Jan 19, 2023
5a5442f
refactor(contracts/dao): check totalOptions againts fixed NUM_OF_OPTI…
AugustoL Jan 19, 2023
58ce06c
refactor(contracts/dao): change state of scheme proposal before execu…
AugustoL Jan 19, 2023
b347ad2
refactor(contracts/dao): use reveer error message instead fo require …
AugustoL Jan 19, 2023
a7c6a2c
refactor(contracts/dao): make Scheme initializable and deploy it in t…
AugustoL Jan 23, 2023
2c6d099
refactor(contracts/dao): remove multiplyRealMath from VotingMachine
AugustoL Jan 23, 2023
03a138c
Merge branch 'v2.0' into fix-dao-final-audit-report
AugustoL Jan 23, 2023
8d02ecc
fix(contracts/dao): dont return stake on loosing option and check for…
AugustoL Feb 13, 2023
5b5c3e3
Merge remote-tracking branch 'upstream/v2.0' into fix-dao-final-audit…
AugustoL Feb 13, 2023
c4f4409
fix(contracts/dao): fix wrong name of UnclaimedDaoBounty event in VM …
AugustoL Feb 17, 2023
0067ddc
fix(contracts/dao): set staker amount to 0 before doing the transfer …
AugustoL Feb 17, 2023
8d92221
fix(contracts/dao): fix wrong condition check in VM redeem
AugustoL Feb 17, 2023
70f1414
fix(contracts/dao): fix VM redeem to allow dao avatar to claim stakes…
AugustoL Feb 21, 2023
3c111b6
Merge remote-tracking branch 'upstream/v2.0' into fix-dao-final-audit…
AugustoL Feb 21, 2023
897223b
fix(contracts/dao): add daoRedeemedWinnings and keep track of staking…
AugustoL Feb 22, 2023
72f02af
refactor(contracts/dao): remove unnecesary totalStakes in proposals s…
AugustoL Feb 22, 2023
9b5c4c8
fix(contracts/dao): removed unused totalStakes in proposal struct in VM
AugustoL Feb 23, 2023
b0f55c8
refactor(contracts/dao): check that proposal expired before daoRedeem…
AugustoL Feb 23, 2023
f99c903
fix(contracts/dao): cover case when a stake is done on NO by avatar a…
AugustoL Feb 27, 2023
deec1aa
fix(contracts/dao): add missing condition check in reedeem for avatar
AugustoL Mar 1, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 12 additions & 33 deletions contracts/dao/DAOController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ contract DAOController is Initializable {

struct Scheme {
bytes32 paramsHash; // a hash voting parameters of the scheme
bool isRegistered;
bool canManageSchemes;
bool canMakeAvatarCalls;
bool canChangeReputation;
Expand Down Expand Up @@ -61,19 +60,15 @@ contract DAOController is Initializable {
/// @notice Cannot unregister last scheme with manage schemes permission
error DAOController__CannotUnregisterLastSchemeWithManageSchemesPermission();

/// @notice Cannot register a scheme with paramsHash 0
error DAOController__CannotRegisterSchemeWithNullParamsHash();

/// @notice Sender is not the scheme that originally started the proposal
error DAOController__SenderIsNotTheProposer();

/// @notice Sender is not a registered scheme or proposal is not active
error DAOController__SenderIsNotRegisteredOrProposalIsInactive();

/// @dev Verify if scheme is registered
modifier onlyRegisteredScheme() {
if (!schemes[msg.sender].isRegistered) {
revert DAOController__SenderNotRegistered();
}
_;
}
/// @dev Verify if scheme can manage schemes
modifier onlyRegisteringSchemes() {
if (!schemes[msg.sender].canManageSchemes) {
Expand Down Expand Up @@ -111,7 +106,6 @@ contract DAOController is Initializable {
) public initializer {
schemes[scheme] = Scheme({
paramsHash: paramsHash,
isRegistered: true,
canManageSchemes: true,
canMakeAvatarCalls: true,
canChangeReputation: true
Expand All @@ -135,11 +129,15 @@ contract DAOController is Initializable {
bool canManageSchemes,
bool canMakeAvatarCalls,
bool canChangeReputation
) external onlyRegisteredScheme onlyRegisteringSchemes returns (bool success) {
) external onlyRegisteringSchemes returns (bool success) {
Scheme memory scheme = schemes[schemeAddress];

if (paramsHash == bytes32(0)) {
revert DAOController__CannotRegisterSchemeWithNullParamsHash();
}

// Add or change the scheme:
if ((!scheme.isRegistered || !scheme.canManageSchemes) && canManageSchemes) {
if (!scheme.canManageSchemes && canManageSchemes) {
schemesWithManageSchemesPermission = schemesWithManageSchemesPermission + 1;
} else if (scheme.canManageSchemes && !canManageSchemes) {
if (schemesWithManageSchemesPermission <= 1) {
Expand All @@ -150,7 +148,6 @@ contract DAOController is Initializable {

schemes[schemeAddress] = Scheme({
paramsHash: paramsHash,
isRegistered: true,
canManageSchemes: canManageSchemes,
canMakeAvatarCalls: canMakeAvatarCalls,
canChangeReputation: canChangeReputation
Expand All @@ -166,16 +163,11 @@ contract DAOController is Initializable {
* @param schemeAddress The address of the scheme to unregister/delete from `schemes` mapping
* @return success Success of the operation
*/
function unregisterScheme(address schemeAddress)
external
onlyRegisteredScheme
onlyRegisteringSchemes
returns (bool success)
{
function unregisterScheme(address schemeAddress) external onlyRegisteringSchemes returns (bool success) {
Scheme memory scheme = schemes[schemeAddress];

//check if the scheme is registered
if (_isSchemeRegistered(schemeAddress) == false) {
if (scheme.paramsHash == bytes32(0)) {
return false;
}

Expand Down Expand Up @@ -206,7 +198,7 @@ contract DAOController is Initializable {
bytes calldata data,
DAOAvatar avatar,
uint256 value
) external onlyRegisteredScheme onlyAvatarCallScheme returns (bool callSuccess, bytes memory callData) {
) external onlyAvatarCallScheme returns (bool callSuccess, bytes memory callData) {
return avatar.executeCall(to, data, value);
}

Expand Down Expand Up @@ -243,15 +235,6 @@ contract DAOController is Initializable {
reputationToken.transferOwnership(newOwner);
}

/**
* @dev Returns whether a scheme is registered or not
* @param scheme The address of the scheme
* @return isRegistered Whether a scheme is registered or not
*/
function isSchemeRegistered(address scheme) external view returns (bool isRegistered) {
return _isSchemeRegistered(scheme);
}

/**
* @dev Returns scheme paramsHash
* @param scheme The address of the scheme
Expand Down Expand Up @@ -300,10 +283,6 @@ contract DAOController is Initializable {
return schemesWithManageSchemesPermission;
}

function _isSchemeRegistered(address scheme) private view returns (bool) {
return (schemes[scheme].isRegistered);
}

/**
* @dev Function to get reputation token
* @return tokenAddress The reputation token set on controller.initialize
Expand Down
47 changes: 24 additions & 23 deletions contracts/dao/schemes/Scheme.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity ^0.8.17;

import "@openzeppelin/contracts/utils/Address.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "../../utils/PermissionRegistry.sol";
import "../DAOReputation.sol";
import "../DAOAvatar.sol";
Expand All @@ -25,7 +26,7 @@ import "../votingMachine/VotingMachineCallbacks.sol";
* Once the governance process ends on the voting machine the voting machine can execute the proposal winning option.
* If the wining option cant be executed successfully, it can be finished without execution once the maxTimesForExecution time passes.
*/
abstract contract Scheme is VotingMachineCallbacks {
abstract contract Scheme is Initializable, VotingMachineCallbacks {
using Address for address;

enum ProposalState {
Expand Down Expand Up @@ -59,9 +60,6 @@ abstract contract Scheme is VotingMachineCallbacks {

event ProposalStateChange(bytes32 indexed proposalId, uint256 indexed state);

/// @notice Emitted when its initialized twice
error Scheme__CannotInitTwice();

/// @notice Emitted if avatar address is zero
error Scheme__AvatarAddressCannotBeZero();

Expand Down Expand Up @@ -105,11 +103,7 @@ abstract contract Scheme is VotingMachineCallbacks {
address permissionRegistryAddress,
string calldata _schemeName,
uint256 _maxRepPercentageChange
) external {
if (address(avatar) != address(0)) {
revert Scheme__CannotInitTwice();
}

) external initializer {
if (avatarAddress == address(0)) {
revert Scheme__AvatarAddressCannotBeZero();
}
Expand Down Expand Up @@ -176,7 +170,8 @@ abstract contract Scheme is VotingMachineCallbacks {
}

/**
* @dev Execution of proposals, can only be called by the voting machine in which the vote is held.
* @dev Execute the proposal calls for the winning option,
* can only be called by the voting machine in which the vote is held.
* @param proposalId The ID of the voting in the voting machine
* @param winningOption The winning option in the voting machine
* @return success Success of the execution
Expand All @@ -193,13 +188,18 @@ abstract contract Scheme is VotingMachineCallbacks {
}
executingProposal = true;

Proposal memory proposal = proposals[proposalId];
Proposal storage proposal = proposals[proposalId];

if (proposal.state != ProposalState.Submitted) {
revert Scheme__ProposalMustBeSubmitted();
}

if (winningOption > 1) {
if (winningOption == 1) {
proposal.state = ProposalState.Rejected;
emit ProposalStateChange(proposalId, uint256(ProposalState.Rejected));
} else {
proposal.state = ProposalState.Passed;
emit ProposalStateChange(proposalId, uint256(ProposalState.Passed));
uint256 oldRepSupply = getNativeReputationTotalSupply();

permissionRegistry.setERC20Balances();
Expand Down Expand Up @@ -253,7 +253,8 @@ abstract contract Scheme is VotingMachineCallbacks {
}

/**
* @dev Finish a proposal and set the final state in storage
* @dev Finish a proposal and set the final state in storage without any execution.
* The only thing done here is a change in the proposal state in case the proposal was not executed.
* @param proposalId The ID of the voting in the voting machine
* @param winningOption The winning option in the voting machine
* @return success Proposal finish successfully
Expand All @@ -265,18 +266,18 @@ abstract contract Scheme is VotingMachineCallbacks {
returns (bool success)
{
Proposal storage proposal = proposals[proposalId];
if (proposal.state != ProposalState.Submitted) {
revert Scheme__ProposalMustBeSubmitted();
}

if (winningOption == 1) {
proposal.state = ProposalState.Rejected;
emit ProposalStateChange(proposalId, uint256(ProposalState.Rejected));
if (proposal.state == ProposalState.Submitted) {
if (winningOption == 1) {
proposal.state = ProposalState.Rejected;
emit ProposalStateChange(proposalId, uint256(ProposalState.Rejected));
} else {
proposal.state = ProposalState.Passed;
emit ProposalStateChange(proposalId, uint256(ProposalState.Passed));
}
return true;
} else {
proposal.state = ProposalState.Passed;
emit ProposalStateChange(proposalId, uint256(ProposalState.Passed));
return false;
}
return true;
}

/**
Expand Down
Loading