Skip to content

Commit 9365937

Browse files
committed
Add comment about never updating nTimeOffset past 199 samples
Refer to issue #4521 for details.
1 parent 70d0325 commit 9365937

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/timedata.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,24 @@ void AddTimeData(const CNetAddr& ip, int64_t nTime)
4949
static CMedianFilter<int64_t> vTimeOffsets(200,0);
5050
vTimeOffsets.input(nOffsetSample);
5151
LogPrintf("Added time data, samples %d, offset %+d (%+d minutes)\n", vTimeOffsets.size(), nOffsetSample, nOffsetSample/60);
52+
53+
// There is a known issue here (see issue #4521):
54+
//
55+
// - The structure vTimeOffsets contains up to 200 elements, after which
56+
// any new element added to it will not increase its size, replacing the
57+
// oldest element.
58+
//
59+
// - The condition to update nTimeOffset includes checking whether the
60+
// number of elements in vTimeOffsets is odd, which will never happen after
61+
// there are 200 elements.
62+
//
63+
// But in this case the 'bug' is protective against some attacks, and may
64+
// actually explain why we've never seen attacks which manipulate the
65+
// clock offset.
66+
//
67+
// So we should hold off on fixing this and clean it up as part of
68+
// a timing cleanup that strengthens it in a number of other ways.
69+
//
5270
if (vTimeOffsets.size() >= 5 && vTimeOffsets.size() % 2 == 1)
5371
{
5472
int64_t nMedian = vTimeOffsets.median();

0 commit comments

Comments
 (0)