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

クローズ
#16 コメント 1 件 リアクション 0 件 担当者 1 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

@aadiitya2007 がすでに取り組んでいます。

2026年10月20日 から。

  • #18 @tanujb03 による — オープン
  • #34 @aadiitya2007 による — オープン

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
52/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
java

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Java
スター
0
フォーク
3
平均マージ
2日 5時間
マージ済み PR(30日)
15

環境構築

  • Dockerfile・Docker Compose ファイルなし
  • プルリクエストのテンプレートあり
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

techcsispit/mini-chain のほかの issue

techcsispit/mini-chain の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。