Skip to content

Conversation

@icppWorld
Copy link

Fix for: #2

Modifies the secp256k1 signature format to utilize a 64-byte raw (r||s) format. This change affects both the signing and verification processes.

Ensures consistency in signature handling and resolves compatibility issues related to the previous DER-encoded format.

Modifies the secp256k1 signature format to utilize a 64-byte raw (r||s) format.
This change affects both the signing and verification processes.

Ensures consistency in signature handling and resolves compatibility issues related to the previous DER-encoded format.
@eliezhao
Copy link
Owner

Let me review the changes, and if everything looks good, it will be merged this week. Thanks for your contribution!

@eliezhao eliezhao requested a review from Copilot November 20, 2025 08:10
Copilot finished reviewing on behalf of eliezhao November 20, 2025 08:13
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates the secp256k1 signature format from DER-encoded to raw 64-byte r||s format to resolve compatibility issues. The change affects both signing and verification processes.

  • Updates signature encoding from sigencode_der_canonize to raw r||s format
  • Updates signature decoding from sigdecode_der to sigdecode_string
  • Updates docstring comments to reflect the new 64-byte raw signature format

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

msg,
hashfunc=hashlib.sha256,
sigencode=ecdsa_util.sigencode_der_canonize, # enforce low-S
sigencode=ecdsa_util.sigencode_string_canonize, # 64-byte raw r||s with canonical low-S
Copy link

Copilot AI Nov 20, 2025

Choose a reason for hiding this comment

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

The function sigencode_string_canonize does not exist in the ecdsa library (v0.19.1). The ecdsa library provides:

  • sigencode_string for raw r||s encoding (without canonicalization)
  • sigencode_der_canonize for DER encoding with canonical low-S

To achieve raw r||s format with canonical low-S, you may need to either:

  1. Use sigencode_string (which may already enforce low-S depending on the library version), or
  2. Implement a custom canonization wrapper function

This will cause a runtime AttributeError when attempting to sign with secp256k1.

Copilot uses AI. Check for mistakes.
Comment on lines 224 to +225
return self.vk.verify(
sig, msg, hashfunc=hashlib.sha256, sigdecode=ecdsa_util.sigdecode_der
sig, msg, hashfunc=hashlib.sha256, sigdecode=ecdsa_util.sigdecode_string
Copy link

Copilot AI Nov 20, 2025

Choose a reason for hiding this comment

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

[nitpick] This change introduces a breaking change: existing DER-encoded secp256k1 signatures will fail verification with the new sigdecode_string decoder. If there are existing signatures in the system that need to remain valid, consider:

  1. Adding backwards compatibility by trying both decoders
  2. Providing a migration path for existing signatures
  3. Documenting this as a breaking change in the release notes

Copilot uses AI. Check for mistakes.
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.

2 participants