Skip to content

[DO NOT MERGE] SF 2.0#7597

Draft
raduchis wants to merge 86 commits intofeat/supernova-async-execfrom
SF-2.0
Draft

[DO NOT MERGE] SF 2.0#7597
raduchis wants to merge 86 commits intofeat/supernova-async-execfrom
SF-2.0

Conversation

@raduchis
Copy link
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?

# Conflicts:
#	common/interface.go
#	factory/core/coreComponents.go
#	testscommon/processConfigsHandlerStub.go
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 about 1 month ago

In general, to fix this class of problem you should either (1) parse into a type whose bit size matches the target type, or (2) validate the parsed value against the min/max range of the target type before converting. For signed integers, both upper and lower bounds should be checked; for unsigned, only the upper bound is needed.

For this specific case in process/block/metablock.go, the best fix with minimal behavioral change is:

  • Parse epochs with ParseInt as now, but before assigning mp.nrEpochsChanges = int(epochs), ensure that epochs is within the valid range for int on the current platform.
  • We can obtain the platform‑specific int limits by converting from math.MinInt64 / math.MaxInt64? No: int bounds are not in math, but we can safely clamp using the range of int by comparing epochs against int(^uint(0)>>1) etc.—however that would require new helper code not present here. A simpler and still safe approach is to validate epochs against a reasonable application‑level bound that is safely within int on all platforms (e.g., math.MaxInt32), or derive the limit via a local const computed at compile time.
  • Since we are constrained to this snippet and cannot assume external helpers, a straightforward fix is:
    • Import "math" (already imported earlier for other purposes in this file? In the shown snippet it's not, so we need to add it).
    • Before converting, check that epochs is within [0, math.MaxInt32] (or similar), and if not, log an error and either clamp or fall back to a safe default (e.g. 0). Using math.MaxInt32 guarantees safety even on 32‑bit platforms where int’s max is math.MaxInt32.
  • This way, no behavior changes on 64‑bit platforms for "normal" values, but we avoid silent wrap on 32‑bit and make out‑of‑range values explicitly handled.

Concretely:

  • Add an import of the standard math package at the top of metablock.go.
  • In epochsFastForward, after parsing epochs and handling errors, add a bounds check: if epochs < 0 or epochs > math.MaxInt32, log and either set epochs to a safe fallback (e.g., 0) or return early. Then perform mp.nrEpochsChanges = int(epochs) only on validated epochs.
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"
@@ -2931,6 +2932,10 @@
 	if err != nil {
 		log.Error("epochfastforward", "epochs could not be parsed", tokens[1])
 	}
+	if epochs < 0 || epochs > math.MaxInt32 {
+		log.Error("epochfastforward", "epochs value out of allowed range", epochs, "maxAllowed", math.MaxInt32)
+		return
+	}
 
 	roundsPerEpoch, err := strconv.ParseInt(tokens[2], 10, 64)
 	if err != nil {
EOF
@@ -5,6 +5,7 @@
"encoding/hex"
"errors"
"fmt"
"math"
"math/big"
"strconv"
"strings"
@@ -2931,6 +2932,10 @@
if err != nil {
log.Error("epochfastforward", "epochs could not be parsed", tokens[1])
}
if epochs < 0 || epochs > math.MaxInt32 {
log.Error("epochfastforward", "epochs value out of allowed range", epochs, "maxAllowed", math.MaxInt32)
return
}

roundsPerEpoch, err := strconv.ParseInt(tokens[2], 10, 64)
if err != nil {
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
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.

3 participants