Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Enhancement: Deterministic transaction hashing across all record fields

オープン 初心者向け
#29 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

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

2026年10月15日 から。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
74/100
issue の種類
機能追加
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
java
領域
blockchain

調査の方向性

src/main/java/minichain/Transaction.java の Transaction.toString()(49〜52行目付近)と、src/main/java/minichain/Block.java の Block.computeMerkleRoot() 内のリーフのループ(37〜39行目付近)から始めてください。Transaction に、レコードの各フィールドをダイジェスト化する hash() メソッドを追加し、その後リーフがそれを使うように変更します。BlockchainTest.java に、フィールドごとに1つずつハッシュが変わることを示すケースを追加し、既存のテストが固定の Merkle ルートをアサートしていないか確認してください。mvn clean test が通り、issue の受け入れ基準を満たしていれば完了です。

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

説明

Summary

Currently, Transaction does not have a dedicated cryptographic hash method. As a result, block transaction serialization and Merkle tree leaf computation rely on Transaction.toString():

return from + " -> " + to + ": " + amount;

This leaves out critical security fields: id, senderKey, and signature. An adversary or corrupted node could alter a transaction's ID, swap its public key, or tamper with its digital signature, and toString() would remain completely unchanged.

This issue proposes introducing a deterministic Transaction.hash() method that produces a SHA-256 digest covering all record fields, and updating Block.computeMerkleRoot() to use tx.hash() for leaf nodes.


Current Problem

  • Location: Transaction.java & Block.java
  • Behavior:
    In Block.computeMerkleRoot(), leaves are hashed as:
    tree.add(sha256(tx.toString()));
    
  • Vulnerability:
    Because toString() only serializes from, to, and amount, changes to:
    • id (e.g. replaying with altered transaction identifiers)
    • senderKey (e.g. swapping public keys)
    • signature (e.g. replacing with invalid signature bytes)
      do not change the output of tx.toString(), leaving the computed Merkle root unchanged if signatures are not checked independently.

Proposed Solution

  1. Add Deterministic Transaction.hash() (Transaction.java):
    Implement a hash() method that hashes all record fields deterministically using SHA-256:

    public String hash() {
        try {
            MessageDigest digest = MessageDigest.getInstance("SHA-256");
            digest.update(id.getBytes(StandardCharsets.UTF_8));
            digest.update(from.getBytes(StandardCharsets.UTF_8));
            digest.update(to.getBytes(StandardCharsets.UTF_8));
            digest.update(ByteBuffer.allocate(4).putInt(amount).array());
            if (senderKey != null) {
                digest.update(senderKey.getEncoded());
            }
            if (signature != null) {
                digest.update(signature);
            }
            return HexFormat.of().formatHex(digest.digest());
        } catch (NoSuchAlgorithmException e) {
            throw new IllegalStateException(e);
        }
    }
    
  2. Integrate with Merkle Tree Leaves (Block.java):
    Update Block.computeMerkleRoot() so the leaf nodes are built directly from tx.hash():

    for (Transaction tx : transactions) {
        tree.add(tx.hash());
    }
    
  3. Unit Tests (BlockchainTest.java):
    Add unit tests verifying that changing any individual field (id, amount, senderKey, or signature) results in a different tx.hash().


Acceptance Criteria

  • Transaction.hash() deterministically returns a 64-character SHA-256 hex string.
  • Modifying id, from, to, amount, senderKey, or signature produces a different hash.
  • Block.computeMerkleRoot() uses tx.hash() for tree leaf nodes.
  • All existing tests and new unit tests pass (mvn clean test).
主要言語
Java
スター
0
フォーク
3
平均マージ
16時間 38分
マージ済み PR(30日)
7

環境構築

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

はじめの一歩

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

techcsispit/mini-chain のほかの issue

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

似ている issue

Java の issue をもっと見る

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

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