Blockchain.isValid() does not verify sender balance, allowing blocks with negative balances to pass validation

Đang mở
#37 1 bình luận 0 reaction 1 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

@aadiitya2007 đang làm issue này rồi.

Từ ngày 29/10/2026.

  • #38 của @aadiitya2007 — đang mở

Đánh giá

Độ khó
4/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
20/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
java
Lĩnh vực
blockchain

Hướng nghiên cứu

Read Blockchain.isValid() and Blockchain.addTransaction() to compare block validation with pending transaction checks. Trace how balances and mining rewards are represented across blocks, then check the README’s validation and balance descriptions. Done means validation rejects a block sequence that makes any sender’s running balance negative; linked pull request #38 is already open.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

bug good first issue
Description

In mini-chain, regular transactions submitted locally check that the sender has sufficient balance:

In Blockchain.addTransaction():

if (balanceOf(tx.from()) < tx.amount()) {
    return false;
}

This prevents unconfirmed payments from entering the pending pool if the sender cannot afford them.

However, in Blockchain.isValid(), transactions inside mined blocks are only checked for digital signature validity and Merkle tree inclusion:

  • tx.hasValidSignature() verifies the cryptographic signature with the sender's public key.
  • block.getMerkleRoot() verifies that transaction hashes match the block header.

There is no check verifying whether the sender actually had sufficient coins at the time the block was accepted.

How the Issue Manifests:
  1. Bypassing the local pool: An adversary with a balance of 0 creates and signs a transaction transferring 1,000,000 coins to another wallet. While addTransaction() would reject this locally, a miner or external peer can include this signed transaction directly into a candidate block.
  2. Valid Cryptography & Proof of Work: Because the transaction was signed with the sender's valid private key, tx.hasValidSignature() evaluates to true. The miner calculates the Merkle root and solves the proof-of-work puzzle.
  3. Validation Bypass: When the blockchain is validated across peers via isValid(), the method only verifies the block hash, Merkle root, difficulty, and signatures. Since every cryptographic check passes, isValid() evaluates to true.
  4. State Distortion: Once the block is accepted into the chain, balanceOf(sender) becomes -1,000,000, and balanceOf(recipient) gains 1,000,000 unbacked coins that can now be spent across the network.

Expected Behavior

According to the README:

  • "Validation: isValid() returns false if anything in any mined block was changed or if any payment inside it is invalid."
  • "Balance: Starting at zero, add up all coins received and subtract all coins sent across every mined block."

A transaction spending more coins than the sender's accumulated balance is invalid. Blockchain.isValid() should ensure that no transaction in any block causes the sender's running balance to drop below zero. If an overspending transaction is encountered, isValid() should return false.


Proposed Solution

In Blockchain.isValid():

  1. Maintain a running balance tracker (e.g., Map<String, Integer> runningBalances = new HashMap<>()) as blocks are validated in sequence.
  2. Credit the mining reward to the miner (tx.to()).
  3. For standard user transactions:
    • Check if runningBalances.getOrDefault(tx.from(), 0) < tx.amount(). If so, return false.
    • Debit tx.from() and credit tx.to().
Ngôn ngữ chính
Java
Star
0
Fork
3
Merge trung bình
2 ngày 5 giờ
Pull request đã merge (30 ngày)
15

Chuẩn bị môi trường

  • Không có Dockerfile hay tệp Docker Compose
  • Có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của techcsispit/mini-chain

Tất cả issue của techcsispit/mini-chain

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.