Skip to content

Commit 151e63a

Browse files
committed
fix: round thawing shares up (TRST-R07)
1 parent 9271b99 commit 151e63a

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

packages/horizon/contracts/staking/HorizonStaking.sol

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,9 +783,10 @@ contract HorizonStaking is HorizonStakingBase, IHorizonStakingMain {
783783

784784
// Calculate shares to issue
785785
// Thawing pool is reset/initialized when the pool is empty: prov.tokensThawing == 0
786+
// Round thawing shares up to ensure fairness and avoid undervaluing the shares due to rounding down.
786787
uint256 thawingShares = prov.tokensThawing == 0
787788
? _tokens
788-
: ((prov.sharesThawing * _tokens) / prov.tokensThawing);
789+
: ((prov.sharesThawing * _tokens + prov.tokensThawing - 1) / prov.tokensThawing);
789790
uint64 thawingUntil = uint64(block.timestamp + uint256(prov.thawingPeriod));
790791

791792
prov.sharesThawing = prov.sharesThawing + thawingShares;
@@ -907,6 +908,7 @@ contract HorizonStaking is HorizonStakingBase, IHorizonStakingMain {
907908
// delegation pool shares -> delegation pool tokens -> thawing pool shares
908909
// Thawing pool is reset/initialized when the pool is empty: prov.tokensThawing == 0
909910
uint256 tokens = (_shares * (pool.tokens - pool.tokensThawing)) / pool.shares;
911+
// Thawing shares are rounded down to protect the pool and avoid taking extra tokens from other participants.
910912
uint256 thawingShares = pool.tokensThawing == 0 ? tokens : ((tokens * pool.sharesThawing) / pool.tokensThawing);
911913
uint64 thawingUntil = uint64(block.timestamp + uint256(_provisions[_serviceProvider][_verifier].thawingPeriod));
912914

0 commit comments

Comments
 (0)