-
Notifications
You must be signed in to change notification settings - Fork 1
pkc%feat(ecdsa): clean up API to better align with BLS, decouple codec from ecdsa, swap k256 for libsecp256k1, grind nonce for low R, add API symmetry CodeQL datasource and query
#45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f619b27
pkc%refac(ecdsa): tidy up `EcdsaError`
kwvg 91198b0
pkc%refac(ecdsa): drop the compact sign and recover convenience wrappers
kwvg d02c7cc
pkc%lint(codeql): document curve-specific API divergences
kwvg 7fd6197
pkc%refac(ecdsa): consolidate curve constants
kwvg 12f1876
pkc%refac(codec): make `codec` optional for `ecdsa`-restricted builds
kwvg 843b608
pkc%refac(ecdsa): rename `PubKeyHash` to `EcdsaPkHash`
kwvg dc0ef69
pkc%refac(ecdsa): bridge gap against BLS API, add `{from,to}_bytes()`
kwvg a101a69
pkc%feat(ecdsa): add scalar and point tweaks to bridge gap with BLS API
kwvg 5e2016a
pkc%feat(ecdsa): hardcode generator and verify against `k256`
kwvg c257972
pkc%perf(ecdsa): swap `k256` for `libsecp256k1` for perf, low-R grinding
kwvg fdf9906
pkc%feat(ecdsa): grind the nonce for a low R
kwvg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| /** | ||
| * Copyright (c) 2026-present, The Dash Core developers | ||
| * SPDX-License-Identifier: MIT | ||
| * See the accompanying file LICENSE or https://opensource.org/license/MIT | ||
| * | ||
| * @description Rules for dash-pkc. | ||
| */ | ||
|
|
||
| /** | ||
| * Holds if `name` belongs to `arm` alone for `role`, exempting the other arms | ||
| * from offering it. Rows live in `pkc.model.yml`. | ||
| * | ||
| * The rows name what an arm lacks rather than what the arms share, so a | ||
| * method added to one arm and forgotten in another is reported with no list | ||
| * to maintain. | ||
| */ | ||
| extensible predicate armOnly(string arm, string role, string name); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| # List of known asymmetries in the APIs exposed for curves offered by dash-pkc | ||
| extensions: | ||
| - addsTo: | ||
| pack: base-sdk/codeql-rust | ||
| extensible: armOnly | ||
| data: | ||
| # BLS | ||
| # Aggregation | ||
| - ["Bls", "SecretKey", "aggregate"] # Add secret keys | ||
| - ["Bls", "PublicKey", "aggregate"] # Add | ||
| - ["Bls", "PublicKey", "secure_aggregate"] # Add w/ binding against rogue keys | ||
| - ["Bls", "Signature", "aggregate"] # Add | ||
| - ["Bls", "Signature", "secure_aggregate"] # Add w/ binding against rogue keys | ||
| - ["Bls", "Signature", "sub_insecure"] # Subtract | ||
| - ["Bls", "Signature", "verify_aggregates"] # Verify multi-message, multiple signers | ||
| - ["Bls", "Signature", "fast_verify_aggregates"] # Verify single-message, multiple signers | ||
| - ["Bls", "Signature", "secure_verify_aggregates"] # Verify w/ binding against rogue keys | ||
| # Integrated Encryption Scheme | ||
| - ["Bls", "SecretKey", "dh_exchange"] # Derive shared secret | ||
| - ["Bls", "SecretKey", "ies_decrypt"] # Decrypt blob | ||
| - ["Bls", "SecretKey", "ies_decrypt_multi"] # Decrypt multi | ||
| - ["Bls", "PublicKey", "ies_encrypt"] # Encrypt blob | ||
| - ["Bls", "PublicKey", "ies_encrypt_multi"] # Encrypt multi | ||
| # Key derivation | ||
| - ["Bls", "SecretKey", "from_ikm"] # Run key material through a KDF | ||
| # Scheme transform | ||
| - ["Bls", "SecretKey", "to_scheme"] | ||
| - ["Bls", "PublicKey", "to_scheme"] | ||
| - ["Bls", "Signature", "to_scheme"] | ||
| - ["Bls", "SecretKey", "sign_with"] # Specify non-type-native scheme | ||
| - ["Bls", "PublicKey", "verify_with"] # Specify non-type-native scheme | ||
| # Proof of possession | ||
| - ["Bls", "SecretKey", "prove_possession"] # Prove | ||
| - ["Bls", "PublicKey", "verify_possession"] # Verify | ||
| # Threshold signatures | ||
| - ["Bls", "SecretKey", "split"] # Issue shares | ||
| - ["Bls", "SecretKey", "derive_share"] # Get share from master keys | ||
| - ["Bls", "PublicKey", "derive_share"] # Get share from master keys | ||
| - ["Bls", "Signature", "recover_shares"] # Get signature | ||
| - ["Bls", "PublicKey", "recover_shares"] # Get master public key | ||
| # ECDSA | ||
| # Compression | ||
| - ["Ecdsa", "SecretKey", "is_compressed"] # Form the derived key will take | ||
| - ["Ecdsa", "PublicKey", "is_compressed"] # Query | ||
| - ["Ecdsa", "PublicKey", "is_hybrid"] # Query legacy parity hint | ||
| - ["Ecdsa", "PublicKey", "decompress"] # Switch to uncompressed | ||
| - ["Ecdsa", "PublicKey", "to_compressed"] # Emit 33-byte SEC1 | ||
| - ["Ecdsa", "PublicKey", "to_uncompressed"] # Emit 65-byte SEC1 | ||
| - ["Ecdsa", "PublicKey", "to_hybrid"] # Emit 65-byte SEC1 w/ parity hint | ||
| - ["Ecdsa", "SkBytes", "is_compressed"] # Query | ||
| - ["Ecdsa", "PkBytes", "is_compressed"] # Query | ||
| - ["Ecdsa", "PkBytes", "size"] # Live length, since SEC1 is not fixed width | ||
| # Encoding | ||
| - ["Ecdsa", "Signature", "from_der"] # Read DER | ||
| - ["Ecdsa", "Signature", "to_der"] # Emit DER | ||
| - ["Ecdsa", "PkHash", "to_base58c"] # Emit Base58c address | ||
| - ["Ecdsa", "SkBytes", "from_wif"] # Read Base58c wallet import format | ||
| - ["Ecdsa", "SkBytes", "to_wif"] # Emit Base58c wallet import format | ||
| # Malleability | ||
| - ["Ecdsa", "Signature", "is_low_s"] # Query whether S is in the lower half | ||
| - ["Ecdsa", "Signature", "normalize_s"] # Move S into the lower half | ||
| # Misc. | ||
| - ["Ecdsa", "SecretKey", "negate"] # Flips the scalar | ||
| # Recoverable signatures | ||
| - ["Ecdsa", "SecretKey", "sign_recoverable"] # Sign | ||
| - ["Ecdsa", "PublicKey", "recover"] # Get public key from a signature |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| /** | ||
| * Copyright (c) 2026-present, The Dash Core developers | ||
| * SPDX-License-Identifier: MIT | ||
| * See the accompanying file LICENSE or https://opensource.org/license/MIT | ||
| * | ||
| * @id base-sdk/pkc-rules | ||
| * @name Rules for dash-pkc | ||
| * @description The arms must offer the same operations under the same names. | ||
| * @kind problem | ||
| * @precision high | ||
| * @problem.severity warning | ||
| * @tags maintainability | ||
| */ | ||
|
|
||
| import lib.filters | ||
| import lib.fmt | ||
| import lib.policy | ||
| import lib.pkc | ||
| import lib.traits | ||
| import rust | ||
|
|
||
| /** | ||
| * Holds if `t` is `arm`'s type for `role`, split off the name rather than the | ||
| * module so that every arm naming a role holds the same one. A role only one | ||
| * arm holds never pairs, and reports nothing. | ||
| */ | ||
| predicate armRole(TypeItem t, string arm, string role) { | ||
| isSourceType(t) and | ||
| isEnforcedCrate(fileOf(t)) and | ||
| exists(string name | | ||
| name = t.getName().getText() and | ||
| arm = name.regexpCapture("^(Bls|Ecdsa|Eddsa)([A-Z].*)$", 1) and | ||
| role = name.regexpCapture("^(Bls|Ecdsa|Eddsa)([A-Z].*)$", 2) | ||
| ) | ||
| } | ||
|
|
||
| /** Holds if `f` is `pub`, rather than restricted to a scope. */ | ||
| predicate isBarePub(Function f) { | ||
| exists(f.getVisibility()) and | ||
| not exists(f.getVisibility().getPath()) | ||
| } | ||
|
|
||
| /** | ||
| * Holds if `t` offers `name` as a public inherent method. | ||
| * | ||
| * Matched wherever the impl sits, not through `inherentImpl`, which the | ||
| * declaration order rule needs to be file-local; an arm spreads a type's | ||
| * methods over several modules. | ||
| * | ||
| * Macro-written impls are skipped, since what a macro grants a type follows | ||
| * from which macro it expands rather than from the arm. | ||
| */ | ||
| predicate publicMethod(TypeItem t, string name) { | ||
| exists(Impl i, Function f | | ||
| not exists(MacroItems m | i = m.getItem(_)) and | ||
| implSelfName(i) = t.getName().getText() and | ||
| not exists(implTraitName(i)) and | ||
| isEnforcedCrate(fileOf(i)) and | ||
| f = i.getAssocItemList().getAnAssocItem() and | ||
| isBarePub(f) and | ||
| not isTestCode(f) and | ||
| name = f.getName().getText() | ||
| ) | ||
| } | ||
|
|
||
| /** | ||
| * Holds if `lacks` is missing `name`, which `arm` offers for the same role. | ||
| */ | ||
| predicate shapeGap(TypeItem lacks, string role, string name, string arm) { | ||
| exists(TypeItem offers, string lacking | | ||
| armRole(offers, arm, role) and | ||
| armRole(lacks, lacking, role) and | ||
| lacking != arm and | ||
| publicMethod(offers, name) and | ||
| not publicMethod(lacks, name) and | ||
| not armOnly(arm, role, name) | ||
| ) | ||
| } | ||
|
|
||
| from TypeItem t, string role, string name, string arm | ||
| where shapeGap(t, role, name, arm) | ||
| select t, fmt("{0} offers {1}, {2} does not", arm + role, fmt("{0}()", name), t.getName().getText()) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| name: base-sdk/codeql-rust | ||
| version: 0.0.0 | ||
| dataExtensions: | ||
| - "**/*.model.yml" | ||
| dependencies: | ||
| codeql/rust-all: ~0.2.17 | ||
| codeql/rust-queries: ~0.1.38 |
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| // | ||
| // Copyright (c) 2026-present, The Dash Core developers | ||
| // SPDX-License-Identifier: MIT | ||
| // See the accompanying file LICENSE or https://opensource.org/license/MIT | ||
| // | ||
|
|
||
| //! secp256k1 constants. | ||
|
|
||
| use super::secret_bytes::ECDSA_SK_LEN; | ||
|
|
||
| use hex_conservative::hex; | ||
|
|
||
| /// DER lengths of a private key with a compressed and an uncompressed public | ||
| /// key respectively. | ||
| pub(super) const DER_SIZES: &[usize] = &[214, 279]; | ||
|
|
||
| /// ASN.1 object identifier for a prime-field curve. | ||
| pub(super) const OID_PRIME_FIELD: &[u8] = &hex!("2a8648ce3d0101"); | ||
|
|
||
| /// The field prime. | ||
| pub(super) const PRIME: &[u8; ECDSA_SK_LEN] = &hex!("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"); | ||
|
|
||
| /// The group order. | ||
| pub(super) const ORDER: &[u8; ECDSA_SK_LEN] = &hex!("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"); | ||
|
|
||
| /// The generator point in SEC1 uncompressed form. | ||
| pub(super) const GENERATOR: &[u8; 65] = &hex!( | ||
| "0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798\ | ||
| 483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8" | ||
| ); | ||
|
|
||
| /// The generator point in SEC1 compressed form. | ||
| pub(super) const GENERATOR_COMPRESSED: [u8; 33] = | ||
| hex!("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"); |
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.