Skip to content

Commit

Permalink
fix audit comments
Browse files Browse the repository at this point in the history
  • Loading branch information
elshan-eth committed Jan 29, 2024
1 parent bbffde3 commit b1fd1ff
Show file tree
Hide file tree
Showing 9 changed files with 253 additions and 288 deletions.
82 changes: 43 additions & 39 deletions contracts/contracts/DevRewardDistributor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,47 +17,56 @@ contract DevRewardDistributor {

/**
* @notice Reward token
**/
*
*/
FluenceToken public immutable token;

/**
* @notice DAO timelock contract address
**/
*
*/
Executor public immutable executor;

/**
* @notice Canceler address (e.g. FluenceMultisig)
**/
*
*/
address public immutable canceler;

/**
* @notice Claiming end time
**/
*
*/
uint256 public immutable claimingEndTime;

/**
* @notice Time when this contract was deployed
**/
*
*/
uint256 public immutable deployTime;

/**
* @notice Merkle root from rewards tree
**/
*
*/
bytes32 public immutable merkleRoot;

/**
* @notice Period for dividing the reward
**/
*
*/
uint256 public immutable halvePeriod;

/**
* @notice Initial user's reward
**/
*
*/
uint256 public immutable initialReward;

/**
* @notice Bitmap with claimed users ids
**/
*
*/
mapping(uint256 => uint256) private claimedBitMap;

/**
Expand All @@ -66,18 +75,15 @@ contract DevRewardDistributor {
* @param account - reward account
* @param amount - reward amount
* @param leaf - leaf with user's info in reward tree
**/
event Claimed(
uint256 userId,
address account,
uint256 amount,
bytes32 leaf
);
*
*/
event Claimed(uint256 indexed userId, address account, uint256 amount, bytes32 leaf);

/**
* @notice Emitted when claiming period is ended and tokens transfer to the executor
* @param amount - remainder balance
**/
*
*/
event TransferUnclaimed(uint256 amount);

/**
Expand All @@ -88,7 +94,8 @@ contract DevRewardDistributor {
* @param _initialReward - initial user reward
* @param _claimingPeriod - claiming period
* @param _canceler - can cancel distribution, and withdraw to _executor.
**/
*
*/
constructor(
FluenceToken _token,
Executor _executor,
Expand All @@ -111,10 +118,7 @@ contract DevRewardDistributor {
}

modifier whenClaimingIs(bool isActive) {
require(
isClaimingActive() == isActive,
"Claiming status is not as expected"
);
require(isClaimingActive() == isActive, "Claiming status is not as expected");
_;
}

Expand All @@ -124,7 +128,8 @@ contract DevRewardDistributor {
* @param merkleProof - merkle proof for leaf
* @param temporaryAddress - temporary Ethereum address that's used only for signing
* @param signature - signature of temporary Ethereum address
**/
*
*/
function claimTokens(
uint32 userId,
bytes32[] calldata merkleProof,
Expand All @@ -135,14 +140,9 @@ contract DevRewardDistributor {

bytes32 leaf = keccak256(abi.encodePacked(userId, temporaryAddress));

require(
MerkleProof.verify(merkleProof, merkleRoot, leaf),
"Valid proof required"
);
require(MerkleProof.verify(merkleProof, merkleRoot, leaf), "Valid proof required");

bytes32 msgHash = keccak256(
abi.encodePacked("\x19Ethereum Signed Message:\n20", msg.sender)
);
bytes32 msgHash = keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n20", msg.sender));

address signer = ECDSA.recover(msgHash, signature);
require(signer == temporaryAddress, "Invalid signature");
Expand All @@ -158,14 +158,16 @@ contract DevRewardDistributor {

/**
* @notice used to move any remaining tokens out of the contract to Executor after expiration
**/
*
*/
function transferUnclaimed() external whenClaimingIs(false) {
_withdraw();
}

/**
* @notice used to move any remaining tokens out of the contract to Executor (DAO) in emergency situation.
**/
*
*/
function withdraw() external {
require(msg.sender == canceler, "Only canceler can withdraw");
_withdraw();
Expand All @@ -175,7 +177,8 @@ contract DevRewardDistributor {
* @notice checks claimed bitMap for userId
* @dev fork from uniswap merkle distributor, unmodified
* @return - boolean
**/
*
*/
function isClaimed(uint256 index) public view returns (bool) {
uint256 claimedWordIndex = index / 256;
uint256 claimedBitIndex = index % 256;
Expand All @@ -187,15 +190,17 @@ contract DevRewardDistributor {
/**
* @notice Checking if claiming is active
* @return - boolean
**/
*
*/
function isClaimingActive() public view returns (bool) {
return block.timestamp < claimingEndTime;
}

/**
* @notice Get current user's reward
* @return - boolean
**/
*
*/
function currentReward() public view returns (uint256) {
if (!isClaimingActive()) {
return 0;
Expand All @@ -210,13 +215,12 @@ contract DevRewardDistributor {
/**
* @notice Sets a given user by index to claimed
* @dev taken from uniswap merkle distributor, unmodified
**/
*
*/
function _setClaimed(uint256 index) private {
uint256 claimedWordIndex = index / 256;
uint256 claimedBitIndex = index % 256;
claimedBitMap[claimedWordIndex] =
claimedBitMap[claimedWordIndex] |
(1 << claimedBitIndex);
claimedBitMap[claimedWordIndex] = claimedBitMap[claimedWordIndex] | (1 << claimedBitIndex);
}

function _withdraw() private {
Expand Down
27 changes: 9 additions & 18 deletions contracts/contracts/FluenceToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,25 @@ contract FluenceToken is
_disableInitializers();
}

function initialize(
string memory name_,
string memory symbol_,
uint256 totalSupply_
) public initializer {
function initialize(string memory name_, string memory symbol_, uint256 totalSupply_) public initializer {
__ERC20_init(name_, symbol_);
__ERC20Permit_init(name_);
__ERC20Votes_init();

__Ownable_init(msg.sender);
__UUPSUpgradeable_init();

_mint(msg.sender, totalSupply_);
}

function _update(
address from,
address to,
uint256 value
) internal override(ERC20Upgradeable, ERC20VotesUpgradeable) {
function _update(address from, address to, uint256 value)
internal
override(ERC20Upgradeable, ERC20VotesUpgradeable)
{
super._update(from, to, value);
}

function nonces(
address owner
)
public
view
override(ERC20PermitUpgradeable, NoncesUpgradeable)
returns (uint256)
{
function nonces(address owner) public view override(ERC20PermitUpgradeable, NoncesUpgradeable) returns (uint256) {
return super.nonces(owner);
}

Expand Down
Loading

0 comments on commit b1fd1ff

Please sign in to comment.