Skip to content

[DO NOT MERGE] SF 2.0#7597

Draft
raduchis wants to merge 87 commits intorc/supernovafrom
SF-2.0
Draft

[DO NOT MERGE] SF 2.0#7597
raduchis wants to merge 87 commits intorc/supernovafrom
SF-2.0

Conversation

@raduchis
Copy link
Copy Markdown
Contributor

@raduchis raduchis commented Jan 9, 2026

Reasoning behind the pull request

Proposed changes

Testing procedure

Pre-requisites

Based on the Contributing Guidelines the PR author and the reviewers must check the following requirements are met:

  • was the PR targeted to the correct branch?
  • if this is a larger feature that probably needs more than one PR, is there a feat branch created?
  • if this is a feat branch merging, do all satellite projects have a proper tag inside go.mod?

roundsPerEpochUint = minRoundModulus
}

mp.nrEpochsChanges = int(epochs)

Check failure

Code scanning / CodeQL

Incorrect conversion between integer types High

Incorrect conversion of a signed 64-bit integer from
strconv.ParseInt
to a lower bit size type int without an upper bound check.

Copilot Autofix

AI 12 days ago

In general, the problem is that a 64‑bit signed integer parsed from untrusted input is being converted to int without ensuring that the value fits in the target type’s range. The safe pattern is to either (a) parse directly to the final type’s bit size, or (b) keep the wider type and avoid down‑casting, or (c) add explicit upper and lower bounds checks before conversion, clamping/rejecting out‑of‑range values.

The best fix here, without changing existing functionality, is to keep parsing epochs as int64 but constrain it to a safe, reasonable range before converting to int. Because we cannot rely on the platform’s int size, we should use math.MaxInt32/math.MinInt32 as conservative limits, or explicitly document and enforce a smaller operational range. Also, negative or zero epochs do not make sense for “fast‑forwarding”, so we should reject non‑positive values. A straightforward solution in epochsFastForward is:

  • Import math (already used elsewhere in this file as per the initial snippet; if it wasn’t present we would add it).
  • After parsing epochs, before mp.nrEpochsChanges = int(epochs), add checks:
    • If epochs <= 0, log a warning and return without changing anything (or set to a default).
    • If epochs > math.MaxInt32, cap it at math.MaxInt32 or log and return. To strictly avoid silent truncation, it’s better to log and ignore the request or set it to a safe maximum instead of silently clipping.

Given the existing logging pattern and that epochsFastForward is a control operation, the least surprising behavior is to validate epochs and, on invalid values, log and return early without updating mp.nrEpochsChanges or mp.roundsModulus.

Concretely, in epochsFastForward in process/block/metablock.go:

  • After parsing epochs and roundsPerEpoch, add a block that:
    • Verifies epochs > 0.
    • Verifies epochs <= math.MaxInt32.
    • If either check fails, log a warning and return.
  • Leave the rest of the logic intact, so that on valid input behavior is unchanged.

Suggested changeset 1
process/block/metablock.go

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/process/block/metablock.go b/process/block/metablock.go
--- a/process/block/metablock.go
+++ b/process/block/metablock.go
@@ -5,6 +5,7 @@
 	"encoding/hex"
 	"errors"
 	"fmt"
+	"math"
 	"math/big"
 	"strconv"
 	"strings"
@@ -3011,11 +3012,23 @@
 	epochs, err := strconv.ParseInt(tokens[1], 10, 64)
 	if err != nil {
 		log.Error("epochfastforward", "epochs could not be parsed", tokens[1])
+		return
 	}
 
+	// validate epochs to avoid overflow when converting to int
+	if epochs <= 0 {
+		log.Warn("epochfastforward invalid epochs value; must be positive", "epochs", epochs)
+		return
+	}
+	if epochs > math.MaxInt32 {
+		log.Warn("epochfastforward epochs value too large; ignoring request", "epochs", epochs, "maxAllowed", math.MaxInt32)
+		return
+	}
+
 	roundsPerEpoch, err := strconv.ParseInt(tokens[2], 10, 64)
 	if err != nil {
 		log.Error("epochfastforward", "rounds could not be parsed", tokens[2])
+		return
 	}
 	roundsPerEpochUint := uint64(roundsPerEpoch)
 
EOF
@@ -5,6 +5,7 @@
"encoding/hex"
"errors"
"fmt"
"math"
"math/big"
"strconv"
"strings"
@@ -3011,11 +3012,23 @@
epochs, err := strconv.ParseInt(tokens[1], 10, 64)
if err != nil {
log.Error("epochfastforward", "epochs could not be parsed", tokens[1])
return
}

// validate epochs to avoid overflow when converting to int
if epochs <= 0 {
log.Warn("epochfastforward invalid epochs value; must be positive", "epochs", epochs)
return
}
if epochs > math.MaxInt32 {
log.Warn("epochfastforward epochs value too large; ignoring request", "epochs", epochs, "maxAllowed", math.MaxInt32)
return
}

roundsPerEpoch, err := strconv.ParseInt(tokens[2], 10, 64)
if err != nil {
log.Error("epochfastforward", "rounds could not be parsed", tokens[2])
return
}
roundsPerEpochUint := uint64(roundsPerEpoch)

Copilot is powered by AI and may make mistakes. Always verify output.
# Conflicts:
#	common/common.go
#	factory/core/coreComponents.go
# Conflicts:
#	common/interface.go
#	consensus/round/round.go
…SF-2.0

# Conflicts:
#	process/block/metablock.go
Base automatically changed from feat/supernova-async-exec to rc/supernova April 6, 2026 07:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants