Skip to content

Commit bccc89b

Browse files
authored
Return 0 if overflow in releasable (#122)
* Return 0 if overflow in `releasable` * Update contracts/finance/VestingWalletConfidential.sol * typo
1 parent 71a7a43 commit bccc89b

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

contracts/finance/VestingWalletConfidential.sol

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ abstract contract VestingWalletConfidential is OwnableUpgradeable, ReentrancyGua
6262
* {IConfidentialFungibleToken} contract.
6363
*/
6464
function releasable(address token) public virtual returns (euint64) {
65-
return FHE.asEuint64(FHE.sub(vestedAmount(token, uint64(block.timestamp)), released(token)));
65+
euint128 vestedAmount_ = vestedAmount(token, uint64(block.timestamp));
66+
euint128 releasedAmount = released(token);
67+
ebool success = FHE.ge(vestedAmount_, releasedAmount);
68+
return FHE.select(success, FHE.asEuint64(FHE.sub(vestedAmount_, releasedAmount)), FHE.asEuint64(0));
6669
}
6770

6871
/**
@@ -75,6 +78,7 @@ abstract contract VestingWalletConfidential is OwnableUpgradeable, ReentrancyGua
7578
FHE.allowTransient(amount, token);
7679
euint64 amountSent = IConfidentialFungibleToken(token).confidentialTransfer(owner(), amount);
7780

81+
// This could overflow if the total supply is resent `type(uint128).max/type(uint64).max` times. This is an accepted risk.
7882
euint128 newReleasedAmount = FHE.add(released(token), amountSent);
7983
FHE.allow(newReleasedAmount, owner());
8084
FHE.allowThis(newReleasedAmount);

0 commit comments

Comments
 (0)