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

chore(contracts): fixed critical security issues #59

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
23 changes: 13 additions & 10 deletions contracts/protocol/Sector3DAO.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,32 +54,34 @@ contract Sector3DAO {
owner = owner_;
}

modifier onlyOwner() {
require(msg.sender == owner, "You are not authorized to perform this action.");
_;
}


/**
* Updates the DAO's name.
*/
function setName(string calldata name_) public {
require(msg.sender == owner, "You aren't the owner");
function setName(string calldata name_) public onlyOwner {
name = name_;
}

/**
* Updates the DAO's purpose.
*/
function setPurpose(string calldata purpose_) public {
require(msg.sender == owner, "You aren't the owner");
function setPurpose(string calldata purpose_) public onlyOwner {
purpose = purpose_;
}

/**
* Updates the DAO's token.
*/
function setToken(address token_) public {
require(msg.sender == owner, "You aren't the owner");
function setToken(address token_) public onlyOwner {
token = token_;
}

function deployPriority(string calldata title, address rewardToken, uint16 epochDurationInDays, uint256 epochBudget, address gatingNFT) public returns (Sector3DAOPriority) {
require(msg.sender == owner, "You aren't the owner");
function deployPriority(string calldata title, address rewardToken, uint16 epochDurationInDays, uint256 epochBudget, address gatingNFT) public onlyOwner returns (Sector3DAOPriority) {
Sector3DAOPriority priority = new Sector3DAOPriority(address(this), title, rewardToken, epochDurationInDays, epochBudget, gatingNFT);
priorities.push(priority);
return priority;
Expand All @@ -89,8 +91,7 @@ contract Sector3DAO {
return priorities;
}

function removePriority(Sector3DAOPriority priority) public {
require(msg.sender == owner, "You aren't the owner");
function removePriority(Sector3DAOPriority priority) public onlyOwner {
Sector3DAOPriority[] memory prioritiesAfterRemoval = new Sector3DAOPriority[](priorities.length - 1);
uint16 prioritiesIndex = 0;
for (uint16 i = 0; i < prioritiesAfterRemoval.length; i++) {
Expand All @@ -102,4 +103,6 @@ contract Sector3DAO {
}
priorities = prioritiesAfterRemoval;
}


}
14 changes: 12 additions & 2 deletions contracts/protocol/Sector3DAOFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,21 @@ contract Sector3DAOFactory {

address[] public daos;

error YouAreNotAuthorized();

constructor() {
owner = msg.sender;
}

function setOwner(address owner_) public {


modifier onlyOwner() {
require(msg.sender == owner, "You are not authorized to perform this action.");
_;
}


function setOwner(address owner_) public onlyOwner {
require(msg.sender == owner, "You aren't the owner");
owner = owner_;
}
Expand All @@ -28,7 +38,7 @@ contract Sector3DAOFactory {
return address(dao);
}

function removeDAO(address dao) public {
function removeDAO(address dao) public onlyOwner {
require(msg.sender == owner, "You aren't the owner");
address[] memory daosAfterRemoval = new address[](daos.length - 1);
uint16 daosIndex = 0;
Expand Down
39 changes: 24 additions & 15 deletions contracts/protocol/Sector3DAOPriority.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ contract Sector3DAOPriority is IPriority {
error NoRewardForEpoch();
error RewardAlreadyClaimed();
error NoGatingNFTOwnership();
error InvalidInput();

constructor(address dao_, string memory title_, address rewardToken_, uint16 epochDurationInDays, uint256 epochBudget_, address gatingNFT_) {
dao = dao_;
Expand All @@ -53,22 +54,27 @@ contract Sector3DAOPriority is IPriority {
*/
function addContribution(string memory description, string memory proofURL, uint8 hoursSpent, uint8 alignmentPercentage) public {
if (address(gatingNFT) != address(0x0)) {
if (gatingNFT.balanceOf(msg.sender) == 0) {
revert NoGatingNFTOwnership();
}
if (gatingNFT.balanceOf(msg.sender) == 0) {
revert NoGatingNFTOwnership();
}
}
if(bytes(description).length == 0 || bytes(proofURL).length == 0){
revert InvalidInput();
}
uint16 epochIndex = getEpochIndex();
Contribution memory contribution = Contribution({
timestamp: block.timestamp,
epochIndex: getEpochIndex(),
contributor: msg.sender,
description: description,
proofURL: proofURL,
hoursSpent: hoursSpent,
alignmentPercentage: alignmentPercentage
timestamp: block.timestamp,
epochIndex: epochIndex,
contributor: msg.sender,
description: description,
proofURL: proofURL,
hoursSpent: hoursSpent,
alignmentPercentage: alignmentPercentage
});
contributions.push(contribution);
emit ContributionAdded(contribution);
}
}


function getContributions() public view returns (Contribution[] memory) {
return contributions;
Expand Down Expand Up @@ -113,11 +119,12 @@ contract Sector3DAOPriority is IPriority {
if (rewardClaimed) {
revert RewardAlreadyClaimed();
}
rewardToken.transfer(msg.sender, epochReward);

claims[epochIndex][msg.sender] = true;
claimsBalance += epochReward;
require(rewardToken.transfer(msg.sender, epochReward), "Reward transfer failed");
emit RewardClaimed(epochIndex, msg.sender, epochReward);
}
}

/**
* Calculates a contributor's token allocation of the budget for a given epoch.
Expand All @@ -129,13 +136,15 @@ contract Sector3DAOPriority is IPriority {
return epochBudget * allocationPercentage / 100;
}

/**
* Checks if a contributor's reward has been claimed for a given epoch.

/**
* Checks if a contributor's reward has been claimed for a given epoch.
*/
function isRewardClaimed(uint16 epochIndex, address contributor) public view returns (bool) {
return claims[epochIndex][contributor];
}


/**
* Calculates a contributor's percentage allocation of the budget for a given epoch.
*
Expand Down