Skip to content

New feature 25 "Deterministic Finality and Ride V9" added.#1834

Open
alexeykiselev wants to merge 86 commits intomasterfrom
determenistic-finality-feature
Open

New feature 25 "Deterministic Finality and Ride V9" added.#1834
alexeykiselev wants to merge 86 commits intomasterfrom
determenistic-finality-feature

Conversation

@alexeykiselev
Copy link
Copy Markdown
Collaborator

No description provided.

@alexeykiselev alexeykiselev added wip This is a WIP, should not be merged right away awaiting-release Ready to be a part of a new release do not merge The PR is not ready to be merged labels Sep 22, 2025
alexeykiselev and others added 3 commits September 24, 2025 17:03
* Added bls signature methods

* Added comments

* Enforced no duplicates in signatures and public keys

* Fixed linter issues

* Added pop method

* Added public key validation

* Bls aggregated sig refactoring (#1838)

* BLS package refactoring.

Package renamed from blssig to bls.
Crypto primitives SecretKey, PublicKey and Signature were added.
Public functions Sing and Verify reimplemented to use new primitives.
Function to create aggregated signature from multiple Waves secrets keys
was removed because it was useful only in tests.
PoP functions moved to separate file.

* Added test on keys, signature and messages collected from Scala.

* Added tests on PoP functions.
Fixed review issues.

* Fixed linter issues.

* Function to create BLS secret key from a Waves secret key moved to bls_test package.
Function MustSignatureFromBytes removed.

---------

Co-authored-by: Alexey Kiselev <alexey.kiselev@gmail.com>
* Added block finality schemas

* Added protobuf schemas

* Updated protobuf generated files

* Gosec option to exclued generated files added to security workflow.

* Set protobuf-schemas submodule to track the branch.

Submodule updated to the latest commit.

* Generated protobuf code updated to the latest schema.

* Protobuf schemas updated and code regenerated.

* Tidy go modules.

---------

Co-authored-by: Alexey Kiselev <alexey.kiselev@gmail.com>
github-advanced-security[bot]

This comment was marked as outdated.

alexeykiselev and others added 17 commits September 30, 2025 10:49
* Ride version 9 added.
New ride function fillList added and tested.

* RideV9 functions replaceFirst and replaceAll implemented and tested.

* New RideV9 functions for bytes/string conversions with reduced complexity implemented and tested.
Old conversion functions refactored to use proper input and output limits.
RideV9 functions replaceFirst and replaceAll correct behavior on empty old string implemented.
Test naming changed to use fmt.Sprintf to support GoLand interface.

* Removed support for 'base16:' prefix for Ride byte conversion functions.
Tests modified accordingly.

* Added and tested check that Ride V9 scripts is not allowed before activation of DeterministicFinality feature.

* Meaningless comment removed.

---------

Co-authored-by: Nikolay Eskov <mr.eskov1@yandex.ru>
github-advanced-security[bot]

This comment was marked as resolved.

@nickeskov nickeskov temporarily deployed to Deploy-testnet-amd64 March 3, 2026 13:31 — with GitHub Actions Inactive
@alexeykiselev alexeykiselev temporarily deployed to Deploy-testnet-amd64 March 3, 2026 16:33 — with GitHub Actions Inactive
@alexeykiselev alexeykiselev temporarily deployed to Deploy-testnet-amd64 March 6, 2026 13:22 — with GitHub Actions Inactive
alexeykiselev and others added 9 commits March 10, 2026 20:13
* Added delayed finalization

* Added an extended log

* Finalized height is taken from endorsement to form finalization

* WIP: separated pending finalization update and promotion.

* Fix some TODO's.

* Fixed tests.

* Update pkg/state/state.go

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Nikolay Eskov <mr.eskov1@yandex.ru>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Comment thread pkg/state/appender.go Fixed
* Utility to create CommitToGeneration transactions added.
Utility readme file added. Main readme file updated.
Make file updated to build new utility.

* Review issues fixed.
Comment thread pkg/crypto/bls/bls.go
}
if cfg.preHash { // Perform additional pre-hashing of the seed.
h := sha256.New()
_, err := h.Write(seed)

Check failure

Code scanning / CodeQL

Use of a broken or weak cryptographic hashing algorithm on sensitive data High

Sensitive data (password)
is used in a hashing algorithm (SHA256) that is insecure for password hashing, since it is not a computationally expensive hash function.
Sensitive data (password)
is used in a hashing algorithm (SHA256) that is insecure for password hashing, since it is not a computationally expensive hash function.
Sensitive data (password)
is used in a hashing algorithm (SHA256) that is insecure for password hashing, since it is not a computationally expensive hash function.

Copilot Autofix

AI 10 days ago

Use a password-hard KDF for the optional pre-hash step instead of raw SHA-256.
Best fix here: replace the sha256.New() pre-hash block in pkg/crypto/bls/bls.go with scrypt.Key(...) using a fixed domain-separation salt (based on existing defaultSalt) and a 32-byte output, then feed that into cbls.KeyGen exactly as before.

This keeps functionality (deterministic derivation when preHash is enabled) while making the transformation computationally expensive and compliant with the rule intent.
Changes needed:

  • In pkg/crypto/bls/bls.go imports: remove crypto/sha256, add golang.org/x/crypto/scrypt.
  • In GenerateSecretKey pre-hash region (current lines ~75–82): replace SHA-256 hash logic with scrypt.Key(seed, []byte(defaultSalt), N, r, p, SecretKeySize) and assign result back to seed.
  • Keep existing error wrapping style.
Suggested changeset 1
pkg/crypto/bls/bls.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/pkg/crypto/bls/bls.go b/pkg/crypto/bls/bls.go
--- a/pkg/crypto/bls/bls.go
+++ b/pkg/crypto/bls/bls.go
@@ -2,13 +2,13 @@
 
 import (
 	"crypto/rand"
-	"crypto/sha256"
 	"errors"
 	"fmt"
 	"strings"
 
 	cbls "github.com/cloudflare/circl/sign/bls"
 	"github.com/mr-tron/base58"
+	"golang.org/x/crypto/scrypt"
 
 	"github.com/wavesplatform/gowaves/pkg/crypto"
 	"github.com/wavesplatform/gowaves/pkg/util/common"
@@ -73,12 +67,11 @@
 		}
 	}
 	if cfg.preHash { // Perform additional pre-hashing of the seed.
-		h := sha256.New()
-		_, err := h.Write(seed)
+		derivedSeed, err := scrypt.Key(seed, []byte(defaultSalt), 1<<15, 8, 1, SecretKeySize)
 		if err != nil {
 			return SecretKey{}, fmt.Errorf("failed to generate BLS secret key: %w", err)
 		}
-		seed = h.Sum(nil)
+		seed = derivedSeed
 	}
 	csk, err := cbls.KeyGen[cbls.G1](seed, cfg.salt, cfg.info)
 	if err != nil {
EOF
@@ -2,13 +2,13 @@

import (
"crypto/rand"
"crypto/sha256"
"errors"
"fmt"
"strings"

cbls "github.com/cloudflare/circl/sign/bls"
"github.com/mr-tron/base58"
"golang.org/x/crypto/scrypt"

"github.com/wavesplatform/gowaves/pkg/crypto"
"github.com/wavesplatform/gowaves/pkg/util/common"
@@ -73,12 +67,11 @@
}
}
if cfg.preHash { // Perform additional pre-hashing of the seed.
h := sha256.New()
_, err := h.Write(seed)
derivedSeed, err := scrypt.Key(seed, []byte(defaultSalt), 1<<15, 8, 1, SecretKeySize)
if err != nil {
return SecretKey{}, fmt.Errorf("failed to generate BLS secret key: %w", err)
}
seed = h.Sum(nil)
seed = derivedSeed
}
csk, err := cbls.KeyGen[cbls.G1](seed, cfg.salt, cfg.info)
if err != nil {
Copilot is powered by AI and may make mistakes. Always verify output.
@nickeskov nickeskov deployed to Deploy-testnet-amd64 April 6, 2026 12:06 — with GitHub Actions Active
* Added function to combine FinalizationVoting structures.
Test added.

* WIP: Generators set handling moved to separate storage entity.
Generators balances legacy state hash calculation moved to the entity also.
Test updated.

* WIP: Generators banning implemented, but not used yet.

* WIP: Propagation of new generators API to the call sites in progress.

* WIP: Usage of commitments storage replaced with calls to new generators set functions.
State API updated.

* Small modernize fix.

* WIP: More functionality moved out of commitments storage to generators storage.
Type of endorser index changed to uint32 for convenience.
Type EndorseBlock renamed to BlockEndorsement.
Unused or used in tests only functions of commitments removed.
Mocks regenerated, tests updated.

* Fixed old tests after merge.

* WIP: Move finalization code to a separate structure.

* WIP: Extracted separate structure to calculate cryptographic message of endorsement.
Refactored some BLS functions to hide Circl BLS signature.

* Storage finalizations renamed to finality.
Removed duplicated code of function LastFinalizedHeight and related.
Fixed height issue of generators set initialization.
All block finalization checks moved to processBlockFinalization function of finalizer structure.
Function calculateLastFinalazedHeight moved to finality structure.
Function Validate added to FinalizationVoting structure, it performs basic checks of the structure
without accessing the state.
Integration test IsolatedFinalitySuite reimplemented to support miner's commitment to generation.

* Real minimal generation balance value used to validate sufficiency of balance of generators.
Checks on sizes of conflicting and normal endorsements added.
Duplicated endorsement cryptographic message serialization functions removed.
Check on block generator absence in endorsements added.
Addition of block generator balance to total endorsements balance added.
Interface function CalculateVotingFinalization removed as unused.

* Log messages improvement.

* Review issues fixed for generators storage.
Function to clean generators before initialization added.
Index used to store the reference to block generator.

* Other review fixes, mostly comments.

* Panic replaces with error for block's generator retrieval.
Correct parameters of history storage for banned generators added.

* Review fixes.

* Logs added.
TODO removed.

* One more log added.
* WIP: Base itest suite added with support of feature 25 added.

* Fixed Docker connection API version.
Simple two node finality test added.

* Rise level of log message.

* Scala node commitment for generation added to finality smoke itest.
Ordering of commitments state hash records fixed with new key.

* Correct BLS keys generation for Go and Scala miners.
Updated genesis.json configuration to support go/scala/no -mining.
Enabled log level check added before querying latest finalized block height.

* Fixed BLS key generation for non-mining accounts.

* Copilot review issues fixed.
Function to retrieve and compare finalized blocks heights added and called in test.

* Review fixes.
Section about env vars added to itest README.
Comment on lines +93 to +95
if err := json.Unmarshal(data, &s); err != nil {
return fmt.Errorf("MiningType should be a string, got %s", data)
}

Check warning

Code scanning / Semgrep OSS

Semgrep Finding: semgrep.rules.if-incorrect-nil-err-return Warning

WARNING: A local variable 'err' is checked for nil, but a different variable is returned.
Ensure that the returned variable is the one that was checked or properly wrapped!
Comment on lines +93 to +95
if err := json.Unmarshal(data, &s); err != nil {
return fmt.Errorf("MiningType should be a string, got %s", data)
}

Check warning

Code scanning / Semgrep OSS

Semgrep Finding: semgrep.rules.if-inplace-func-incorrect-nil-err-return Warning

WARNING: A local variable 'err' is checked for nil, but a different variable is returned.
Ensure that the returned variable is the one that was checked or properly wrapped!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-release Ready to be a part of a new release do not merge The PR is not ready to be merged wip This is a WIP, should not be merged right away

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants