Skip to content

Commit

Permalink
Merge pull request #179 from dcrescimbeni/fix/dos-on-withdrawalTokens
Browse files Browse the repository at this point in the history
Fix/DOS on withdrawal tokens
  • Loading branch information
rossneilson authored Jun 21, 2022
2 parents ac3eca0 + be1532a commit c284fc7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions contracts/erc20guild/BaseERC20Guild.sol
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ contract BaseERC20Guild {
function withdrawTokens(uint256 tokenAmount) external virtual {
require(votingPowerOf(msg.sender) >= tokenAmount, "ERC20Guild: Unable to withdraw more tokens than locked");
require(tokensLocked[msg.sender].timestamp < block.timestamp, "ERC20Guild: Tokens still locked");
require(tokenAmount > 0, "ERC20Guild: amount of tokens to withdraw must be greater than 0");
tokensLocked[msg.sender].amount = tokensLocked[msg.sender].amount.sub(tokenAmount);
totalLocked = totalLocked.sub(tokenAmount);
tokenVault.withdraw(msg.sender, tokenAmount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ contract SnapshotERC20Guild is ERC20GuildUpgradeable {
"SnapshotERC20Guild: Unable to withdraw more tokens than locked"
);
require(tokensLocked[msg.sender].timestamp < block.timestamp, "SnapshotERC20Guild: Tokens still locked");
require(tokenAmount > 0, "SnapshotERC20Guild: amount of tokens to withdraw must be greater than 0");
_updateAccountSnapshot(msg.sender);
_updateTotalSupplySnapshot();
tokensLocked[msg.sender].amount = tokensLocked[msg.sender].amount.sub(tokenAmount);
Expand Down
5 changes: 5 additions & 0 deletions test/erc20guild/ERC20Guild.js
Original file line number Diff line number Diff line change
Expand Up @@ -1296,6 +1296,11 @@ contract("ERC20Guild", function (accounts) {
"ERC20: transfer amount exceeds balance"
);

// Cannot withdraw zero tokens
await expectRevert(
erc20Guild.withdrawTokens(0, { from: accounts[1] }),
"ERC20Guild: amount of tokens to withdraw must be greater than 0"
);
// Cant lock zero tokens
await expectRevert(
erc20Guild.lockTokens(0, { from: accounts[1] }),
Expand Down
6 changes: 6 additions & 0 deletions test/erc20guild/implementations/SnapshotERC2Guild.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,12 @@ contract("SnapshotERC20Guild", function (accounts) {
"ERC20: transfer amount exceeds balance"
);

// Cannot withdraw zero tokens
await expectRevert(
erc20Guild.withdrawTokens(0, { from: accounts[1] }),
"SnapshotERC20Guild: amount of tokens to withdraw must be greater than 0"
);

// try to release more than locked and fail
await expectRevert(
erc20Guild.withdrawTokens(50001, { from: accounts[1] }),
Expand Down

0 comments on commit c284fc7

Please sign in to comment.