Skip to content

feat: edsca implementation#142

Merged
BlobMaster41 merged 5 commits intomainfrom
feat/edsca
Feb 15, 2026
Merged

feat: edsca implementation#142
BlobMaster41 merged 5 commits intomainfrom
feat/edsca

Conversation

@BlobMaster41
Copy link
Collaborator

@BlobMaster41 BlobMaster41 commented Feb 15, 2026

Description

Introduce ECDSA sub-type and key-format discriminants and update verification plumbing. Rework Signatures enum and add ECDSASubType and ECDSAKeyFormat to support Ethereum (ecrecover, 65-byte) and Bitcoin (direct verify, 64-byte) verification models. Verify methods: verifyECDSASignature now delegates as Ethereum subtype; added verifyBitcoinECDSASignature (deprecated) for direct-verify flow. internalVerifyECDSA now accepts a subType, validates signature length per sub-type, encodes type/subtype/format into the host buffer, and enforces 32-byte hashes. validateSecp256k1PublicKey expanded to accept 33 (compressed), 64 (raw X||Y), 65 (uncompressed/hybrid) formats and improved error messages. Also fix consensus check logic to reject ECDSA when unsafe signatures are not allowed and add deprecation warnings advising use of consensus-aware verifySignature().

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Performance improvement
  • Refactoring (no functional changes)
  • Documentation update
  • CI/CD changes
  • Dependencies update

Checklist

Build & Tests

  • npm install completes without errors
  • npm test passes all tests

Code Quality

  • Code follows the project's coding standards
  • No new compiler warnings introduced
  • Error handling is appropriate
  • SafeMath used for all arithmetic operations

Documentation

  • Code comments added for complex logic
  • Public APIs are documented
  • README updated (if applicable)

Security

  • No sensitive data (keys, credentials) committed
  • No new security vulnerabilities introduced
  • No floating-point arithmetic used

OPNet Specific

  • Changes are compatible with existing smart contracts
  • WASM execution behavior is unchanged (or documented if changed)
  • Storage pointer allocation is correct
  • Reentrancy considerations addressed

Testing

Related Issues


By submitting this PR, I confirm that my contribution is made under the terms of the project's license.

Add Keccak-256, ECDSA support, and tests

Bump package to v1.11.0-rc.5 and add a native Keccak-256 implementation and test suite. Export keccak helpers from runtime/index and add keccak256, keccak256Concat, functionSelector, ethAddressFromPubKey, and low-level rot64 utilities. Extend signature handling: add ECDSA to SignaturesMethods, introduce verifyECDSASignature/internalVerifyECDSA and secp256k1 public-key validation, and update Blockchain.verifySignature to accept an explicit signatureType (with consensus checks, deprecation warnings, and error handling). Small API/behavior change in ExtendedAddress: use Revert for tweakedPublicKey validation. Includes comprehensive as-pect tests for keccak256 and rotation helpers.
Introduce ECDSA sub-type and key-format discriminants and update verification plumbing. Rework Signatures enum and add ECDSASubType and ECDSAKeyFormat to support Ethereum (ecrecover, 65-byte) and Bitcoin (direct verify, 64-byte) verification models. Verify methods: verifyECDSASignature now delegates as Ethereum subtype; added verifyBitcoinECDSASignature (deprecated) for direct-verify flow. internalVerifyECDSA now accepts a subType, validates signature length per sub-type, encodes type/subtype/format into the host buffer, and enforces 32-byte hashes. validateSecp256k1PublicKey expanded to accept 33 (compressed), 64 (raw X||Y), 65 (uncompressed/hybrid) formats and improved error messages. Also fix consensus check logic to reject ECDSA when unsafe signatures are not allowed and add deprecation warnings advising use of consensus-aware verifySignature().
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 introduces Keccak-256 hashing utilities and expands signature verification plumbing to support ECDSA (with Ethereum vs Bitcoin verification sub-types) alongside existing Schnorr/ML-DSA consensus-aware verification.

Changes:

  • Add a pure AssemblyScript Keccak-256 implementation (+ helper utilities) and a comprehensive as-pect test suite.
  • Rework signature method discriminants and add ECDSA sub-type/key-format tagging for host verification.
  • Update BlockchainEnvironment verification methods to handle ECDSA flows and tighten consensus gating; adjust ExtendedAddress to throw Revert for invalid key sizes.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/keccak256.spec.ts Adds Keccak-256 test vectors, boundary/edge tests, and rotation helper coverage.
runtime/hashing/keccak256.ts Implements Keccak-256 + helpers (keccak256Concat, functionSelector, ethAddressFromPubKey, rotations).
runtime/index.ts Exposes Keccak hashing utilities via the public runtime entrypoint.
runtime/env/consensus/Signatures.ts Redefines signature discriminants and introduces ECDSA subtype/key-format enums.
runtime/env/BlockchainEnvironment.ts Adds ECDSA verification methods and updates consensus-aware verifySignature control flow.
runtime/types/ExtendedAddress.ts Switches invalid tweaked key length from Error to Revert.
package.json Bumps package version to 1.11.0-rc.5.

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

Comment on lines +1210 to +1212
* Host buffer layout: [type(1), subtype(1), ...pubkey_material]
* type = SignaturesMethods.ECDSA (0x00)
* subtype = ECDSASubType.Ethereum (0x00) or ECDSASubType.Bitcoin (0x01)
Copy link

Copilot AI Feb 15, 2026

Choose a reason for hiding this comment

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

The doc comment for the ECDSA host buffer layout says [type(1), subtype(1), ...pubkey_material], but the implementation actually writes three header bytes (type, subtype, formatTag) before the pubkey. Please update the comment to reflect the real buffer layout so host/SDK implementers don’t miss the format byte.

Suggested change
* Host buffer layout: [type(1), subtype(1), ...pubkey_material]
* type = SignaturesMethods.ECDSA (0x00)
* subtype = ECDSASubType.Ethereum (0x00) or ECDSASubType.Bitcoin (0x01)
* Host buffer layout: [type(1), subtype(1), format(1), ...pubkey_material]
* type = SignaturesMethods.ECDSA (0x00)
* subtype = ECDSASubType.Ethereum (0x00) or ECDSASubType.Bitcoin (0x01)
* format = ECDSAKeyFormat tag describing the public key encoding

Copilot uses AI. Check for mistakes.
Comment on lines +966 to +967
ERROR(
`Please consider migrating to a more secure, quantum-resistant signature scheme like ML-DSA as ECDSA signatures are vulnerable to quantum attacks. You may still use this via Blockchain.verifyECDSASignature() if needed, but it is not recommended for long-term security.`,
Copy link

Copilot AI Feb 15, 2026

Choose a reason for hiding this comment

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

verifySignature() now accepts signatureType: SignaturesMethods, but the ECDSA branch only emits an ERROR(...) message and then falls through to the generic Revert at the end, so callers can’t actually request ECDSA verification here. Since this method takes an ExtendedAddress (not an ECDSA public key), it would be clearer to explicitly reject SignaturesMethods.ECDSA with a direct Revert that points to verifyECDSASignature() / verifyBitcoinECDSASignature(), and keep the parameter semantics focused on Schnorr vs ML-DSA (or revert back to a forceMLDSA flag).

Suggested change
ERROR(
`Please consider migrating to a more secure, quantum-resistant signature scheme like ML-DSA as ECDSA signatures are vulnerable to quantum attacks. You may still use this via Blockchain.verifyECDSASignature() if needed, but it is not recommended for long-term security.`,
throw new Revert(
'ECDSA verification is not supported by Blockchain.verifySignature(); use Blockchain.verifyECDSASignature() or Blockchain.verifyBitcoinECDSASignature() instead.',

Copilot uses AI. Check for mistakes.
Comment on lines +171 to +184
/**
* Compute Ethereum-style address from uncompressed public key.
* address = keccak256(pubkey)[12:32]
*
* @param publicKey - 64-byte uncompressed public key (without 0x04 prefix)
* @returns 20-byte Ethereum address as Uint8Array
*/
export function ethAddressFromPubKey(publicKey: Uint8Array): Uint8Array {
const hash = keccak256(publicKey);
const addr = new Uint8Array(20);
for (let i: i32 = 0; i < 20; i++) {
addr[i] = hash[12 + i];
}
return addr;
Copy link

Copilot AI Feb 15, 2026

Choose a reason for hiding this comment

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

ethAddressFromPubKey() documents publicKey as a 64-byte uncompressed key (X||Y without 0x04), but it doesn’t validate the input length. As a public API this can silently produce incorrect addresses if callers pass a 33/65-byte SEC1 key by mistake; consider enforcing publicKey.length === 64 (and throwing/reverting with a clear message) to prevent misuse.

Copilot uses AI. Check for mistakes.
Replace the boolean forceMLDSA parameter in docs/examples with a SignaturesMethods enum (SignaturesMethods.Schnorr / SignaturesMethods.MLDSA) and update all sample code to import and use it. Add documentation for deprecated ECDSA verification (Ethereum ecrecover and Bitcoin direct models) gated by the UNSAFE_QUANTUM_SIGNATURES_ALLOWED flag, plus new API entries for verifyECDSASignature and verifyBitcoinECDSASignature. Document built-in Ethereum-compatible Keccak-256 helpers (keccak256, keccak256Concat, functionSelector, ethAddressFromPubKey) and update capability matrices, diagrams, and examples to reflect support, deprecation notices, and consensus-aware behavior.
@BlobMaster41 BlobMaster41 merged commit e8e4647 into main Feb 15, 2026
2 checks passed
@BlobMaster41 BlobMaster41 changed the title Feat/edsca feat: edsca implementation Feb 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request new-feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments