Skip to content

[Feat] Sui Core changes - #19193

Merged
chris-de-leon-cll merged 29 commits into
developfrom
sish/sui-core
Sep 16, 2025
Merged

chris-de-leon-cll merged 29 commits into
developfrom
sish/sui-core

Conversation

@stackman27

@stackman27 stackman27 commented Sep 3, 2025 •

Copy link
Copy Markdown
Contributor

Requires

Supports

imported changes from: #17618


// newFrom creates a new Account from a provided random reader
func newFrom(reader io.Reader) (Key, error) {
pub, priv, err := ed25519.GenerateKey(reader)

Check failure

Code scanning / CodeQL

Use of insufficient randomness as the key of a cryptographic algorithm

This cryptographic algorithm depends on a [random number](1) generated with a cryptographically weak RNG.

Copilot Autofix

AI about 1 year ago

The optimal fix is to ensure that all functions using insecure randomness (math/rand) for key generation, such as MustNewInsecure, and helper utilities like NewRandReaderFromSeed, are only compiled as part of test code. In Go, this is typically done by moving such code into files with the _test.go suffix or files gated by //go:build !production && test (or similar) build tags. The goals are:

  • To prevent the accidental use of test-only, insecure RNGs in production code.
  • To clarify to static analysis tools that insecure RNG usage is safe, as it is test-only and not used in mainline binaries.
  • Not to change existing public APIs or test logic, just to make it impossible to use these methods in real deployments.

The most effective way here is:

  • Move all code that uses math/rand as a cryptographically insecure test utility (e.g., NewRandReaderFromSeed in keystest/seedable_rand_reader.go) into a file named seedable_rand_reader_test.go, or gate it with a //go:build test-only build constraint.
  • Similarly, ensure instantiation of test keys with these insecure sources (e.g., MustNewInsecure) is contained to test/fixture files, not main code.

This makes the intention and constraints explicit, avoids tainting the main codebase with insecure paths, and resolves the static analysis finding correctly.


Suggested changeset 2
core/services/keystore/keys/suikey/key.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/core/services/keystore/keys/suikey/key.go b/core/services/keystore/keys/suikey/key.go
--- a/core/services/keystore/keys/suikey/key.go
+++ b/core/services/keystore/keys/suikey/key.go
@@ -40,6 +40,8 @@
 	return newFrom(cryptorand.Reader)
 }
 
+//go:build testutil
+
 // MustNewInsecure returns an Account if no error
 func MustNewInsecure(reader io.Reader) Key {
 	key, err := newFrom(reader)
EOF
@@ -40,6 +40,8 @@
return newFrom(cryptorand.Reader)
}

//go:build testutil

// MustNewInsecure returns an Account if no error
func MustNewInsecure(reader io.Reader) Key {
key, err := newFrom(reader)
core/internal/testutils/keystest/seedable_rand_reader.go
Outside changed files

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/core/internal/testutils/keystest/seedable_rand_reader.go b/core/internal/testutils/keystest/seedable_rand_reader.go
--- a/core/internal/testutils/keystest/seedable_rand_reader.go
+++ b/core/internal/testutils/keystest/seedable_rand_reader.go
@@ -1,3 +1,5 @@
+//go:build testutil
+
 package keystest
 
 import (
EOF
@@ -1,3 +1,5 @@
//go:build testutil

package keystest

import (
Copilot is powered by AI and may make mistakes. Always verify output.
}

// newFrom creates a new Account from a provided random reader
func newFrom(reader io.Reader) (Key, error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking at the issue raised below, do we use this function in production or only in test?

Comment thread go.md Resolved
@jmank88

jmank88 commented Sep 15, 2025

Copy link
Copy Markdown
Contributor

You could consider updating testdata/scripts/multi-chain-loop.txtar as well, like in #17867
Otherwise I will pick it up there after merge.

cfal
cfal previously approved these changes Sep 15, 2025
jmank88
jmank88 previously approved these changes Sep 16, 2025
@cl-sonarqube-production

Copy link
Copy Markdown

Quality Gate failed Quality Gate failed

Failed conditions
13.4% Duplication on New Code (required ≤ 10%)

See analysis details on SonarQube

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants