Skip to content

Commit b143950

Browse files
committed
Fix uint underflow during Keyper set activation
Before activating a new Keyper Set we wait until at least `DKGStartBlockDelta` blocks before the `activationBlockNumber`. Since all numbers involved are uints the condition could run into an underflow when the current block number is already higher than the `activationBlockNumber`.
1 parent 1eda352 commit b143950

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

rolling-shutter/keyper/keyper.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,9 @@ func (kpr *keyper) handleOnChainKeyperSetChanges(
261261
if err != nil {
262262
return err
263263
}
264-
if activationBlockNumber-l1BlockNumber > kpr.config.Shuttermint.DKGStartBlockDelta {
264+
// We *MUST* check if the l1BlockNumber is smaller than the activationBlockNumber since both are uint64 and therefore subtraction can never result in negative numbers.
265+
// This means that if we missed the activationBlockNumber we will never submit the config.
266+
if l1BlockNumber < activationBlockNumber && activationBlockNumber-l1BlockNumber > kpr.config.Shuttermint.DKGStartBlockDelta {
265267
log.Info().Interface("keyper-set", keyperSet).
266268
Uint64("l1-block-number", l1BlockNumber).
267269
Uint64("dkg-start-delta", kpr.config.Shuttermint.DKGStartBlockDelta).

rolling-shutter/medley/metricsserver/config.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,13 @@ func (mc *MetricsConfig) Validate() error {
3333

3434
func (mc *MetricsConfig) SetDefaultValues() error {
3535
mc.Enabled = false
36-
mc.Host = "[::]"
37-
mc.Port = 9191
3836
return nil
3937
}
4038

4139
func (mc *MetricsConfig) SetExampleValues() error {
40+
mc.Enabled = false
41+
mc.Host = "[::]"
42+
mc.Port = 9100
4243
return nil
4344
}
4445

rolling-shutter/snapshotkeyper/snapshotkeyper.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,9 @@ func (snkpr *snapshotkeyper) handleOnChainKeyperSetChanges(ctx context.Context,
228228
if err != nil {
229229
return err
230230
}
231-
if activationBlockNumber-l1BlockNumber > snkpr.config.Shuttermint.DKGStartBlockDelta {
231+
// We *MUST* check if the l1BlockNumber is smaller than the activationBlockNumber since both are uint64 and therefore subtraction can never result in negative numbers.
232+
// This means that if we missed the activationBlockNumber we will never submit the config.
233+
if l1BlockNumber < activationBlockNumber && activationBlockNumber-l1BlockNumber > snkpr.config.Shuttermint.DKGStartBlockDelta {
232234
log.Info().Interface("keyper-set", keyperSet).
233235
Uint64("l1-block-number", l1BlockNumber).
234236
Uint64("dkg-start-delta", snkpr.config.Shuttermint.DKGStartBlockDelta).

0 commit comments

Comments
 (0)