Skip to content

Commit

Permalink
fix unsafe casting to uint256 (#357)
Browse files Browse the repository at this point in the history
  • Loading branch information
Spablob authored Dec 12, 2024
1 parent 06cf9b0 commit a43e174
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions contracts/lib/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,10 @@ library Errors {

/// @notice Same from and to address.
error IpRoyaltyVault__SameFromToAddress(address vault, address from);

/// @notice Negative value for casting to uint256.
error IpRoyaltyVault__NegativeValueUnsafeCastingToUint256();

////////////////////////////////////////////////////////////////////////////
// Vault Controller //
////////////////////////////////////////////////////////////////////////////
Expand Down
4 changes: 3 additions & 1 deletion contracts/modules/royalty/policies/IpRoyaltyVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,9 @@ contract IpRoyaltyVault is IIpRoyaltyVault, ERC20Upgradeable, ReentrancyGuardUpg
uint256 accBalance = $.vaultAccBalances[token];
uint256 userAmount = balanceOf(claimer);
int256 rewardDebt = $.claimerRevenueDebt[token][claimer];
return uint256(int256((accBalance * userAmount) / totalSupply()) - rewardDebt);
int256 pending = int256((accBalance * userAmount) / totalSupply()) - rewardDebt;
if (pending < 0) revert Errors.IpRoyaltyVault__NegativeValueUnsafeCastingToUint256();
return uint256(pending);
}

/// @dev Returns the storage struct of IpRoyaltyVault
Expand Down

0 comments on commit a43e174

Please sign in to comment.