New feature 25 "Deterministic Finality and Ride V9" added.#1834
New feature 25 "Deterministic Finality and Ride V9" added.#1834alexeykiselev wants to merge 86 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.
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 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.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.
| @@ -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 { |
* 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.
| 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
| 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
No description provided.