Skip to content

Commit c6d6387

Browse files
committed
feat: implement timestamp overflow via a large check
1 parent b3d8e0c commit c6d6387

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/IncentivizedMessageEscrow.sol

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,9 +810,18 @@ abstract contract IncentivizedMessageEscrow is IIncentivizedMessageEscrow, Bytes
810810
// Compute the reward distribution. We need the time it took to deliver the ack back.
811811
uint64 executionTime;
812812
unchecked {
813-
// Underflow is desired in this code chuck. It ensures that the code piece continues working
813+
// Overflow is desired in this code chuck. It ensures that the code piece continues working
814814
// past the time when uint64 stops working. *As long as any timedelta is less than uint64.
815815
executionTime = uint64(block.timestamp) - messageExecutionTimestamp;
816+
// Check if the overflow (/underflow) was because block.timestamp < messageExecutionTimestamp rather
817+
// than because block.timestamp has overflowed and messageExecutionTimestamp has now.
818+
// We do this by checking if executionTime is greater than an unrealistic period of time.
819+
// 32768 days is chosen since that is the neatest value close to the uint32 limit: 49710 days.
820+
// If this is the cause, we must assume that block.timestamp was slightly less than messageExecutionTimestamp
821+
// and an overflow happened and the execution time was set significantly too large as a result.
822+
// If this is true, then the delivery was quick (based on all available information) and the source to destination
823+
// should get everything.
824+
if (executionTime > 32768 days) executionTime = 0;
816825
}
817826
// The incentive scheme is as follows: When executionTime = targetDelta then
818827
// The rewards are distributed as per the incentive spec. If the time is less, then

0 commit comments

Comments
 (0)