From fa7d7fcc42c2c8145539a5a27235a3a38381fb70 Mon Sep 17 00:00:00 2001 From: zah Date: Tue, 28 Jun 2022 23:50:40 +0300 Subject: [PATCH] Avoid overflow in the initial 'nextExchangeTransitionConfTime' calculation (#3809) --- beacon_chain/nimbus_beacon_node.nim | 14 +++++++++++--- vendor/nim-chronos | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/beacon_chain/nimbus_beacon_node.nim b/beacon_chain/nimbus_beacon_node.nim index 47b9959b4..e3794d7b1 100644 --- a/beacon_chain/nimbus_beacon_node.nim +++ b/beacon_chain/nimbus_beacon_node.nim @@ -712,11 +712,19 @@ proc init*(T: type BeaconNode, else: nil - bellatrixEpochTime = - genesisTime + cfg.BELLATRIX_FORK_EPOCH * SLOTS_PER_EPOCH * SECONDS_PER_SLOT + maxSecondsInMomentType = Moment.high.epochSeconds + # If the Bellatrix epoch is above this value, the calculation + # below will overflow. This happens in practice for networks + # where the `BELLATRIX_FORK_EPOCH` is not yet specified. + maxSupportedBellatrixEpoch = (maxSecondsInMomentType.uint64 - genesisTime) div + (SLOTS_PER_EPOCH * SECONDS_PER_SLOT) + bellatrixEpochTime = if cfg.BELLATRIX_FORK_EPOCH < maxSupportedBellatrixEpoch: + int64(genesisTime + cfg.BELLATRIX_FORK_EPOCH * SLOTS_PER_EPOCH * SECONDS_PER_SLOT) + else: + maxSecondsInMomentType nextExchangeTransitionConfTime = - max(Moment.init(int64 bellatrixEpochTime, Second), + max(Moment.init(bellatrixEpochTime, Second), Moment.now) let node = BeaconNode( diff --git a/vendor/nim-chronos b/vendor/nim-chronos index 2a5095505..a5bc5ca99 160000 --- a/vendor/nim-chronos +++ b/vendor/nim-chronos @@ -1 +1 @@ -Subproject commit 2a5095505f771610f9559d2e774b2a9561f01101 +Subproject commit a5bc5ca996ab72c1c5dda7d5b922b536f39f603e