Category: Coding Mistakes
Timestamp updated in memory instead of storage
Informational Severity
Informational Impact
N/A Likelihood
Description
The callback function (updateSlCallback
) used to update the stop loss also updates the Trade.timestamp
value, but this value is currently updated in memory and not in storage.
function updateSlCallback(AggregatorAnswer memory a)
external override onlyPriceAggregator {
//...
ITradingStorage.Trade memory t =
storageT.openTrades(o.trader, o.pairIndex, o.index);
if (
// ...
) {
storageT.updateSl(o.trader, o.pairIndex, o.index, o.newSl);
t.timestamp = block.timestamp;
emit SlUpdated(a.orderId, o.trader, o.pairIndex,
o.index, o.newSl, block.timestamp);
}
aggregator.unregisterPendingSlOrder(a.orderId);
}
The line t.timestamp = block.timestamp;
only writes to memory, and t
is not used after that. This results in no such change of timestamp being stored for that trade.
Impact
The timestamp will not be updated in storage.
Recommendations
We recommend using storage instead of memory so that the timestamp is updated.
Remediation
This issue has been acknowledged by Avantis Labs, Inc., and a fix was implemented in commit 20b78585↗.