Skip to content

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?

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 4 days ago

In general, the fix is to avoid converting a parsed int64 to a smaller integer type without bounding it first. Either parse directly with the bit size of the destination type, or clamp/check the value before conversion. Here we must keep the existing interface and behavior, so we will add validation around epochs before assigning it to mp.nrEpochsChanges.

Concretely, in epochsFastForward we should (1) ensure epochs is non‑negative, since a negative number of epoch changes makes no sense and would cause nrEpochsChanges to be negative; and (2) ensure epochs is not larger than math.MaxInt so that casting to int is safe on all platforms. If the value is out of bounds, we’ll log and return early without modifying nrEpochsChanges or roundsModulus (similar to how other parse errors are handled). We already import math/big but not math; we will add an import of the standard math package and use math.MaxInt as the upper bound. The only changes are: add math to the imports and update the body of epochsFastForward around the use of epochs and the assignment to mp.nrEpochsChanges.

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"
@@ -2921,11 +2922,17 @@
 	epochs, err := strconv.ParseInt(tokens[1], 10, 64)
 	if err != nil {
 		log.Error("epochfastforward", "epochs could not be parsed", tokens[1])
+		return
 	}
+	if epochs < 0 || epochs > int64(math.MaxInt) {
+		log.Error("epochfastforward", "epochs out of allowed range", epochs)
+		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"
@@ -2921,11 +2922,17 @@
epochs, err := strconv.ParseInt(tokens[1], 10, 64)
if err != nil {
log.Error("epochfastforward", "epochs could not be parsed", tokens[1])
return
}
if epochs < 0 || epochs > int64(math.MaxInt) {
log.Error("epochfastforward", "epochs out of allowed range", epochs)
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.
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