New feature 25 "Deterministic Finality and Ride V9" added.#1834
Open
alexeykiselev wants to merge 84 commits intomasterfrom
Open
New feature 25 "Deterministic Finality and Ride V9" added.#1834alexeykiselev wants to merge 84 commits intomasterfrom
alexeykiselev wants to merge 84 commits intomasterfrom
Conversation
* 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>
* 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>
Proto code regenerated.
* Added ignoring of endorsement in some cases * Added verification of endorsements signatures * Fixed linter issues * Inverted statement * Added round changing * Changed to finalizing parent * Added a finalized height check * Changed height for current period * Fixed linter issues
…es SHA256 digest of the message. (#2016) Tests updated.
Mocks and new tests updated.
* 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>
* Utility to create CommitToGeneration transactions added. Utility readme file added. Main readme file updated. Make file updated to build new utility. * Review issues fixed.
| } | ||
| 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
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 1 day 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.goimports: removecrypto/sha256, addgolang.org/x/crypto/scrypt. - In
GenerateSecretKeypre-hash region (current lines ~75–82): replace SHA-256 hash logic withscrypt.Key(seed, []byte(defaultSalt), N, r, p, SecretKeySize)and assign result back toseed. - Keep existing error wrapping style.
Suggested changeset
1
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 { |
Copilot is powered by AI and may make mistakes. Always verify output.
* 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.