Summary
Shares are denominated in ETH-days, but in docs it's stated
Users generate userShares (dittoMatchedShares) denominated in ETH-seconds, by the product of the Order amount (in ETH) and time until match (in seconds)
Vulnerability Details
timeTillMatch is divided by days, but should be just multiplied with eth:
function increaseSharesOnMatch(
address asset,
STypes.Order memory order,
MTypes.Match memory matchTotal,
uint88 eth
) internal {
AppStorage storage s = appStorage();
uint32 timeTillMatch = getOffsetTime() - order.creationTime;
if (timeTillMatch > Constants.MIN_DURATION) {
@> uint88 shares = eth * (timeTillMatch / 1 days);
matchTotal.dittoMatchedShares += shares;
uint256 vault = s.asset[asset].vault;
s.vaultUser[vault][order.addr].dittoMatchedShares += shares;
}
}
Impact
Code is incorrect to spec
Tools Used
Manual Review
Recommendations
function increaseSharesOnMatch(
address asset,
STypes.Order memory order,
MTypes.Match memory matchTotal,
uint88 eth
) internal {
AppStorage storage s = appStorage();
uint32 timeTillMatch = getOffsetTime() - order.creationTime;
if (timeTillMatch > Constants.MIN_DURATION) {
- uint88 shares = eth * (timeTillMatch / 1 days);
+ uint88 shares = eth * timeTillMatch;
matchTotal.dittoMatchedShares += shares;
uint256 vault = s.asset[asset].vault;
s.vaultUser[vault][order.addr].dittoMatchedShares += shares;
}
}