Enhancement: Migrate to native Ed25519 signatures and public-key address derivation

Cerrado
#31 1 comentario 0 reacciones 1 asignado Ver en GitHub

Los mantenedores suelen responder en 2 días

@sohanjadyal ya está trabajando en esto.

Desde el 17/10/2026.

  • #32 de @sohanjadyal — fusionado

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
35/100
Tipo de issue
Nueva funcionalidad
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
java

Línea de trabajo

Start with Main.java, Transaction.java, and Blockchain.java to trace key generation, signing, address validation, and CLI wallet handling; then review BlockchainTest.java, SignatureTamperingTest.java, and ReadmeRulesTest.java. Implementing the proposed migration spans identity, transaction validation, wallet behavior, and existing tests. Done means Ed25519 signatures verify, mismatched sender addresses are rejected, recipients can receive spendable funds, and the listed tests cover the changes.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

feature

Summary

The current cryptographic identity implementation in mini-chain relies on deprecated 1024-bit RSA keys and allows accounts to use arbitrary human-readable string aliases (e.g., "Alice", "Asha").

This architecture introduces two primary vulnerabilities:

  1. Deprecated Cryptography: 1024-bit RSA keys and signatures are bulky, slow, and cryptographically deprecated. Modern blockchains exclusively utilize Elliptic Curve cryptography (such as Ed25519 or secp256k1).
  2. Name Squatting & Front-Running: In Blockchain.java, the chain associates an arbitrary username with whichever public key is submitted first in knownKeys. A malicious participant can observe a pending transaction or front-run an identity, registering another user's name with their own key.

This issue proposes migrating key pairs and digital signatures to Java 17's native Ed25519 algorithm, deriving account addresses cryptographically from public keys, and ensuring recipient wallets are automatically initialized in the CLI.


Current Behavior & Code References

  1. RSA-1024 Key Generation & Signatures:
    • Main.java (L21–22): KeyPairGenerator.getInstance("RSA") with 1024-bit key length.
    • Transaction.java (L30, L44): Signature.getInstance("SHA256withRSA").
  2. Vulnerable Plaintext Key Binding:
    • Blockchain.java (L38–43):
      PublicKey known = knownKeys.get(tx.from());
      if (known == null) {
          knownKeys.put(tx.from(), tx.senderKey());
      } else if (!known.equals(tx.senderKey())) {
          throw new IllegalArgumentException("Transaction uses a different key...");
      }
      
      Because tx.from() is an arbitrary string, anyone can claim and lock another user's name before that user broadcasts their first transaction.

Proposed Solution

1. Upgrade Signatures to Native Java 17 Ed25519
  • Migrate key generation and signing to Ed25519 (EdDSA) with zero external dependencies:
    KeyPairGenerator generator = KeyPairGenerator.getInstance("Ed25519");
    Signature sig = Signature.getInstance("Ed25519");
    
  • Produces compact 32-byte public keys and 64-byte signatures natively supported in Java 17+.
2. Cryptographic Address Derivation
  • Add a helper method in Blockchain / Transaction:
    public static String deriveAddress(PublicKey key) {
        // Hex-encoded SHA-256 digest of key.getEncoded()
        ...
    }
    
  • Enforce in Blockchain.addTransaction() that for non-network transactions:
    • tx.from() must match the derived address of tx.senderKey().
    • Eliminates arbitrary username hijacking and front-running.
3. Recipient Wallet Handling in CLI (Main.java)
  • Update CLI address resolution so users can continue interacting with friendly names while underlying transactions bind cryptographically:
    • Map names to wallets locally in wallets.dat.
    • When sending to a new recipient name, automatically generate and save their wallet key pair (getWallet(to)) so funds sent to any user remain spendable.
4. Unit & Integration Tests
  • Update all test cases in BlockchainTest.java, SignatureTamperingTest.java, and ReadmeRulesTest.java to use Ed25519.
  • Add tests verifying:
    • Valid Ed25519 signing and verification.
    • Rejection of transactions where from does not match the derived address of senderKey.
    • Front-running protection across accounts.
Lenguaje dominante
Java
Estrellas
0
Forks
3
Merge medio
2 d 5 h
PR fusionados (30 d)
15

Preparar el entorno

  • Sin Dockerfile ni archivo de Docker Compose
  • Tiene una plantilla de pull request
  • Sin guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de techcsispit/mini-chain

Todos los issues de techcsispit/mini-chain

Issues similares

Más issues de Java

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.