You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
The value of calculateWithdrawableAmount is invalid. #467
WithdrawStorage.getLastCum If ulativeGlobalHoldersPrice is 0 and If the another Property already has a large amount of staking, Withdraw.ca lculateWithdrawableAmount will be displayed more often if the Property already has a lot of staking.
The correct answer is WithdrawStorage.getLastCum If ulativeGlobalHoldersPrice is 0, the first staked You need to keep track of the value of Policy.rewards.
It will cost you even more money for gas, but when you lockup.lockup WithdrawStorage.setLastCum You might want to call ulativeGlobalHoldersPrice
Expected behavior/contents
WithdrawStorage.getLastCumulativeGlobalHoldersPrice is 0 and property already has a large amount of staking, Withdraw.calculateWithdrawableAmount returns the correct value.
Actual behavior/contents
WithdrawStorage.getLastCumulativeGlobalHoldersPrice is 0 and property already has a large amount of staking, Withdraw.calculateWithdrawableAmount returns the correct value.
I noticed that Withdraw.calculateWithdrawableAmount is not necessarily an unfair value.
The basis for that value is Lockup.getCumulativeLockedUp vs. Lockup.getCumulativeLockedUpAll ratio; That ratio is the same as the percentage of total rewards to which the Property is entitled. The holder(owner) has all of its rights until the Property balance changes. There is no question as I that.
Now, is it wrong to set the LastCumulativeGlobalReward for the user who locked up first? I haven't organized my thoughts yet.
Based on the issue description, it appears that there's an inconsistency in how calculateWithdrawableAmount is handling cases where getLastCumulativeGlobalHoldersPrice is 0 and a property already has a large amount of staking. Specifically, it seems that the current implementation might not be correctly updating or retrieving the value of Policy.rewards.
Likely Root Cause
Incorrect Logic for Staked Value: The logic in calculateWithdrawableAmount may not be properly accounting for the initial staked value when getLastCumulativeGlobalHoldersPrice is 0.
Race Condition or Data Inconsistency: There might be a race condition where the state of Policy.rewards is not being updated correctly, leading to incorrect calculations.
Step-by-Step Fix Plan
Review calculateWithdrawableAmount Logic:
Ensure that the method checks if getLastCumulativeGlobalHoldersPrice is 0.
If it is 0, make sure that the initial staked value (Policy.rewards) is correctly retrieved and used in calculations.
Update State Management:
Ensure that any state changes (like updating Policy.rewards) are properly synchronized to avoid race conditions.
Add Debugging Statements:
Add logging or debugging statements before the calculation to verify the values of getLastCumulativeGlobalHoldersPrice and Policy.rewards.
Write Unit Tests:
Write unit tests that cover scenarios where getLastCumulativeGlobalHoldersPrice is 0 and a property already has a large amount of staking.
Ensure these tests pass with the new implementation.
Confidence Score
Confidence: 0.95
The issue seems clear enough from the description, but without direct access to the code, there's some uncertainty about the exact logic and state management. However, the symptoms suggest a straightforward fix.
Activity
aggre commentedon Jun 29, 2020
I noticed that
Withdraw.calculateWithdrawableAmountis not necessarily an unfair value.The basis for that value is
Lockup.getCumulativeLockedUpvs.Lockup.getCumulativeLockedUpAllratio; That ratio is the same as the percentage of total rewards to which the Property is entitled. The holder(owner) has all of its rights until the Property balance changes. There is no question as I that.Now, is it wrong to set the
LastCumulativeGlobalRewardfor the user who locked up first? I haven't organized my thoughts yet.Omcodes23 commentedon Mar 2, 2026
🤖 Crawly Smart Analysis
Analysis
Based on the issue description, it appears that there's an inconsistency in how
calculateWithdrawableAmountis handling cases wheregetLastCumulativeGlobalHoldersPriceis 0 and a property already has a large amount of staking. Specifically, it seems that the current implementation might not be correctly updating or retrieving the value ofPolicy.rewards.Likely Root Cause
calculateWithdrawableAmountmay not be properly accounting for the initial staked value whengetLastCumulativeGlobalHoldersPriceis 0.Policy.rewardsis not being updated correctly, leading to incorrect calculations.Step-by-Step Fix Plan
Review
calculateWithdrawableAmountLogic:getLastCumulativeGlobalHoldersPriceis 0.Policy.rewards) is correctly retrieved and used in calculations.Update State Management:
Policy.rewards) are properly synchronized to avoid race conditions.Add Debugging Statements:
getLastCumulativeGlobalHoldersPriceandPolicy.rewards.Write Unit Tests:
getLastCumulativeGlobalHoldersPriceis 0 and a property already has a large amount of staking.Confidence Score
Confidence: 0.95
The issue seems clear enough from the description, but without direct access to the code, there's some uncertainty about the exact logic and state management. However, the symptoms suggest a straightforward fix.
Suggested Target File Path
file_path: contracts/WithdrawStorage.sol
Memory key:
dev-protocol/protocol#467:2020-06-29T16:48:18+00:00