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

Fix unsafe casting to uint256 #357

Merged
merged 1 commit into from
Dec 12, 2024
Merged
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
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
Loading