Repository navigation
Enhancement: Migrate to native Ed25519 signatures and public-key address derivation (#31) - #32
Conversation
|
#30 is merged, please rebase onto main. Existing wallets.dat files hold RSA keys from #25, and signing with one now throws InvalidKeyException. Please migrate old wallets or discard them cleanly, and add a test for it. Also please say why the crypto change, address derivation and CLI redesign belong in one PR. |
|
Okay, I'll make the required changes |
|
@techcsispit Rebased on latest main (including #30), fixed the conflicts, and tackled the comments: Legacy wallets.dat cleanup On keeping the crypto migration, address derivation, and CLI changes in one PR
|
Closes #31
Note on PR Ordering &
serialVersionUIDNote
This PR is expected to be merged after PR #30.
Block.serialVersionUIDfrom3Lto4L.Block.serialVersionUIDto5L(and updatesREADME.md) to avoid serial version conflicts and ensure that chains saved under older formats (or pre-Ed25519 versions) trigger anInvalidClassExceptionand start fresh rather than failing validation silently.What I changed
SHA256withRSA(1024-bit RSA) with nativeEd25519(EdDSA) inTransaction.create()andTransaction.hasValidSignature().Main.getWallet()with nativeKeyPairGenerator.getInstance("Ed25519")(zero third-party dependencies).Transaction.deriveAddress(PublicKey)andBlockchain.deriveAddress(PublicKey)to derive account addresses via SHA-256 hex encoding of encoded public keys.Blockchain.addTransaction()thattx.from()must strictly matchderiveAddress(tx.senderKey()), preventing username squatting and front-running identity theft.Blockchain.isValid().Main.java) address resolution so users can continue interacting with friendly aliases ("asha","ravi") while underlying transactions bind cryptographically to derived public-key addresses.wallets.datwhen sending coins to a friendly name so funds remain spendable.Block.serialVersionUIDto5L& UpdatedREADME.md:Block'sserialVersionUIDis5Lfor Ed25519 signatures and address derivation.BlockchainTest.java,SignatureTamperingTest.java, andReadmeRulesTest.javato useEd25519.BlockchainTest.java:validEd25519SigningAndVerification: Verifies 64-byte Ed25519 signatures and tamper detection.rejectionOfTransactionsWhereFromDoesNotMatchDerivedAddress: Rejects transactions with arbitrary names or mismatched public keys.frontRunningProtectionAcrossAccounts: Verifies attacker cannot claim or spend another account's balance.How it works
Previously, mini-chain allowed accounts to register arbitrary human-readable string aliases (e.g., "Alice", "Asha"). In Blockchain.java, the chain associated an arbitrary username with whichever public key was submitted first in knownKeys. A malicious actor observing pending transactions could front-run a victim's chosen name with their own key, permanently locking the victim out. In addition, 1024-bit RSA keys and signatures were bulky, slow, and cryptographically deprecated.
This PR migrates key generation and signing to native Java 17 Ed25519 (EdDSA) with zero external dependencies, producing compact 32-byte public keys and 64-byte signatures. Account addresses are derived deterministically from public keys via a SHA-256 digest of key.getEncoded(). In Blockchain.addTransaction() and Blockchain.isValid(), tx.from() must strictly match the derived address of tx.senderKey(), eliminating front-running and username squatting entirely. In the CLI (Main.java), aliases are mapped locally in wallets.dat and recipient keypairs are automatically generated on first transfer so funds sent to any friendly name remain spendable.
Verification
All 36 automated unit and integration tests pass cleanly with
mvn clean test:Verification:
mvn clean testRuns all 36 tests across
BlockchainTest,SignatureTamperingTest, andReadmeRulesTest.mvn compile exec:javaand follow the steps given below:asha-> generates an Ed25519 wallet inwallets.datand awards 50 coins to her derived address.asha: 50.ashatoravi, amount20-> signs withasha's Ed25519 key, auto-createsravi's wallet, and queues payment.miner-> confirms the block.asha: 30,ravi: 20, andminer: 50.The chain is valid..The chain has been tampered with.(caught by Ed25519 digital signature verification).