Skip to content

Commit

Permalink
fix: Update infinite approval checks (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
vbidin authored Mar 29, 2022
1 parent 889dbf7 commit 000174a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
12 changes: 1 addition & 11 deletions contracts/RevenueDistributionToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ contract RevenueDistributionToken is IRevenueDistributionToken, ERC20 {
require(assets_ != uint256(0), "RDT:B:ZERO_ASSETS");

if (caller_ != owner_) {
_reduceCallerAllowance(caller_, owner_, shares_);
_decreaseAllowance(owner_, caller_, shares_);
}

_burn(owner_, shares_);
Expand Down Expand Up @@ -276,16 +276,6 @@ contract RevenueDistributionToken is IRevenueDistributionToken, ERC20 {
/*** Internal Functions ***/
/**************************/

function _reduceCallerAllowance(address caller_, address owner_, uint256 shares_) internal {
uint256 callerAllowance = allowance[owner_][caller_]; // Cache to stack.

require(callerAllowance >= shares_, "RDT:CALLER_ALLOWANCE");

if (callerAllowance == type(uint256).max) return;

allowance[owner_][caller_] = callerAllowance - shares_;
}

function _divRoundUp(uint256 numerator_, uint256 divisor_) internal pure returns (uint256 result_) {
return (numerator_ / divisor_) + (numerator_ % divisor_ > 0 ? 1 : 0);
}
Expand Down
4 changes: 2 additions & 2 deletions contracts/test/RevenueDistributionToken.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2521,7 +2521,7 @@ contract RedeemFailureTests is RDTTestBase {
shareOwner.rdToken_deposit(address(rdToken), depositAmount);

shareOwner.erc20_approve(address(rdToken), address(notShareOwner), depositAmount - 1);
vm.expectRevert("RDT:CALLER_ALLOWANCE");
vm.expectRevert(ARITHMETIC_ERROR);
notShareOwner.rdToken_redeem(address(rdToken), depositAmount, address(shareOwner), address(shareOwner));

shareOwner.erc20_approve(address(rdToken), address(notShareOwner), depositAmount);
Expand Down Expand Up @@ -3373,7 +3373,7 @@ contract WithdrawFailureTests is RDTTestBase {
shareOwner.rdToken_deposit(address(rdToken), depositAmount);

shareOwner.erc20_approve(address(rdToken), address(notShareOwner), depositAmount - 1);
vm.expectRevert("RDT:CALLER_ALLOWANCE");
vm.expectRevert(ARITHMETIC_ERROR);
notShareOwner.rdToken_withdraw(address(rdToken), depositAmount, address(shareOwner), address(shareOwner));

shareOwner.erc20_approve(address(rdToken), address(notShareOwner), depositAmount);
Expand Down

0 comments on commit 000174a

Please sign in to comment.