Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Blockchain: a payment that was already mined can be submitted again, and it is accepted and mined a second time

Aperta
#16 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@tanujb03 ci sta già lavorando.

Dal 10/10/2026.

  • #18 di @tanujb03 — aperta

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
52/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
java

Direzione di ricerca

Start with the reproduction program in the issue, which uses Blockchain.addTransaction, minePending, balanceOf and isValid, plus Transaction.create in package minichain. Find where pending and mined transactions are stored and check whether the transaction id is ever compared against them. Done when the resubmitted transaction is refused, the balances stay at ravi=20 and asha=80, and isValid still returns true.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug good first issue

What I did

  1. Fresh checkout of main, JDK 17, Maven.
  2. mvn compile
  3. Save this as Replay.java in the project folder:
package minichain;

import java.security.KeyPair;
import java.security.KeyPairGenerator;

public class Replay {
    public static void main(String[] args) throws Exception {
        KeyPairGenerator g = KeyPairGenerator.getInstance("RSA");
        g.initialize(1024);
        KeyPair asha = g.generateKeyPair();

        Blockchain chain = new Blockchain(2);
        chain.minePending("asha");
        chain.minePending("asha");   // asha has 100 coins

        // asha makes ONE payment of 20 coins to ravi and it is mined
        Transaction pay = Transaction.create("asha", "ravi", 20, asha.getPrivate(), asha.getPublic());
        chain.addTransaction(pay);
        chain.minePending("m");
        System.out.println("after the one payment: ravi=" + chain.balanceOf("ravi") + ", asha=" + chain.balanceOf("asha"));

        // anyone can copy that transaction out of the chain and submit it again, unchanged
        Transaction copy = chain.getChain().get(3).getTransactions().get(0);
        chain.addTransaction(copy);
        chain.addTransaction(copy);
        chain.minePending("m");
        System.out.println("after resubmitting it twice: ravi=" + chain.balanceOf("ravi") + ", asha=" + chain.balanceOf("asha") + ", chain valid=" + chain.isValid());
    }
}
  1. Compile and run it (use : instead of ; on Linux/macOS):
mkdir out && javac -cp target/classes -d out Replay.java && java -cp "target/classes;out" minichain.Replay

What I expected
Asha authorised one 20-coin payment and was charged 60.

The README says: "The system uses digital signatures to prevent forging transactions." (README.md, Note on Security)

A payment asha made once should only be able to move her coins once. Submitting the same, unchanged transaction again should be refused.

What happened instead

after the one payment: ravi=20, asha=80
after resubmitting it twice: ravi=60, asha=40, chain valid=true

The same transaction id is accepted again (even twice in a row while it is still waiting to be mined), mined, and the chain stays valid. Asha authorised 20 coins and ends up paying 60. Nobody needs her private key: every mined transaction, with its id, public key and signature, is stored in the chain and in chain.dat.

Environment
main @ 0e92205, JDK 17, Maven 3.9.16, Windows 11.

I'd like to work on the fix for this.

Lingua principale
Java
Stelle
0
Fork
3
Merge medio
16h 38m
PR unite (30g)
7

Preparare l'ambiente

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di techcsispit/mini-chain

Tutte le issue di techcsispit/mini-chain

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.