Skip to content

🧪 [testing improvement] Add test for zero private key in ECDSA#34

Open
tanm-sys wants to merge 1 commit into
mainfrom
add-ecdsa-invalid-private-key-test-10862263643748643601
Open

🧪 [testing improvement] Add test for zero private key in ECDSA#34
tanm-sys wants to merge 1 commit into
mainfrom
add-ecdsa-invalid-private-key-test-10862263643748643601

Conversation

@tanm-sys

Copy link
Copy Markdown
Owner

🎯 What: The testing gap addressed is the lack of test for catching a zeroed private key byte array passed during the construction of an ECDSA signing request.
📊 Coverage: A new test test_zero_private_key was added to verify the zero private key scenario, ensuring it correctly returns Error::InvalidPrivateKey.
Result: Test coverage is improved, adding a safety net to ensure that improper inputs like a zeroed private key are appropriately handled when generating a signing request in ECDSA.


PR created automatically by Jules for task 10862263643748643601 started by @tanm-sys

@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@coderabbitai

coderabbitai Bot commented May 21, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@tanm-sys has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 53 minutes and 3 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4ef63c1d-9698-4fcb-a7a5-d26ec497e36e

📥 Commits

Reviewing files that changed from the base of the PR and between 8ef8a1a and 19381a2.

📒 Files selected for processing (2)
  • forge-ec-signature/src/ecdsa.rs
  • target/.rustc_info.json
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch add-ecdsa-invalid-private-key-test-10862263643748643601

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.


#[test]
fn test_zero_private_key() {
let secret_key_bytes = [0u8; 32];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

SUGGESTION: Variable name is misleading — secret_key_bytes suggests raw untrusted input bytes, but [0u8; 32] here is encoding a concrete scalar value (zero), not a generic byte slice read from an external source. Consider renaming to zero_scalar_bytes or zero_key_bytes to disambiguate intent from the from_bytes(...).unwrap() call on the next line.

#[test]
fn test_zero_private_key() {
let secret_key_bytes = [0u8; 32];
let secret_key = <Secp256k1 as forge_ec_core::Curve>::Scalar::from_bytes(&secret_key_bytes).unwrap();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

WARNING: from_bytes(...).unwrap() relies on the downstream sign_internal guard at ecdsa.rs:103 (which checks sk.is_zero() || !sk.ct_lt(&order)) to catch the zero-key case. If the validation in sign_internal were ever refactored or replaced, this unwrap() would silently panic rather than return the expected Error::InvalidPrivateKey. For defensive robustness against future refactors of private-key validation in sign_internal, consider replacing unwrap() with an explicit .map_err(|_| Error::InvalidPrivateKey)?. This also makes the intent that the input must represent a valid non-zero scalar clear at every layer.

@kilo-code-bot

kilo-code-bot Bot commented May 21, 2026

Copy link
Copy Markdown

Code Review Summary

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
WARNING 1
SUGGESTION 1
Inline Comments (2)
File Line Severity Issue
forge-ec-signature/src/ecdsa.rs 494 SUGGESTION Variable name secret_key_bytes is misleading — it encodes a concrete scalar (zero), not raw untrusted input
forge-ec-signature/src/ecdsa.rs 495 WARNING from_bytes(...).unwrap() should be replaced with `map_err(
Other Observations (not in diff)

target/.rustc_info.json — tracked build artifact modified unintentionally

  • This file is listed in .gitignore under /target/ but is git ls-files-tracked, meaning it was committed before the ignore rule was added.
  • The PR changes it from a tanmay-machine build (rustc 1.91.1, fingerprint 900410...) to a jules-machine build (rustc 1.94.0, fingerprint 460940...). This diff is an artifact of the generation environment and should never be part of a PR.
  • Action needed: Run git rm --cached target/.rustc_info.json and verify the file is excluded, or force-remove this file from the tree to prevent future noise.
  • Additional untracked target/ files may exist — given the /target/ directory is active, it is likely that compiled .rlib, .so, and .a artifacts for the workspace crates are also tracked and silently accumulating changes. git ls-files target/ should be checked.

test_zero_private_key covers only one rejection path in sign_internal

  • sign_internal at line 103 rejects keys with sk.is_zero() || !bool::from(sk.ct_lt(&order)) — the latter catches keys >= the curve order. No test exercises that overflow/out-of-range path. Adding a test for an oversized key (e.g. [0xff; 32] which exceeds the Secp256k1 field prime) would improve coverage of the second guard. This is outside the diff, so not posted inline.
Files Reviewed (2 files)
  • forge-ec-signature/src/ecdsa.rs — 2 issues
  • target/.rustc_info.json — 1 observation (tracked build artifact)

Reviewed by step-3.5-flash · 479,383 tokens

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.

1 participant