BlockchainTest: signature tampering tests pass on the hash check; Block.mine() is a no-op so signature verification is not tested
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 25/100
Research direction
Start in src/test/java/minichain/BlockchainTest.java, at tamperedAmountInvalidatesChain() and forgedSenderInvalidatesChain(), and read Block.mine(int) and the hash check at the top of Blockchain.isValid(). Re-mine the tampered block against a fresh hash so the signature check is reached. Done when the tests still pass with the hash check bypassed and fail once the signature check in isValid() is commented out. PR #20 is already open against this issue, so check it before starting.
Written by the indexing model from the issue text.
Description
What I did
- Fresh checkout of
main(commit0e92205), ran tests withmvn test(all 18 pass). - Checked the two tests in
src/test/java/minichain/BlockchainTest.javathat test tampering detection:tamperedAmountInvalidatesChain()forgedSenderInvalidatesChain()
- In both tests, after modifying a transaction in a block, the test calls:
tampered.mine(difficulty); assertFalse(chain.isValid(), "Blockchain should be invalid because of tampered transaction"); - Examined
Block.mine(int difficulty):public void mine(int difficulty) { String target = "0".repeat(difficulty); while (!hash.startsWith(target)) { nonce++; hash = computeHash(); } } - Tested mutation: in
Blockchain.java, commented out the signature check:
and ran// if (!tx.hasValidSignature()) return false;mvn test.
What I expected
The README states:
"The system uses digital signatures to prevent forging transactions."
The tampering tests are intended to verify that digital signatures prevent forging transactions and detect altered amounts/senders even if someone re-mines the block to produce a valid proof-of-work hash. If signature verification is removed, the signature tampering tests should fail.
What happened instead
Even with signature verification completely deleted, both tests still pass (18/18 tests green).
Because the block was already mined, hash already starts with "0".repeat(difficulty). The loop condition !hash.startsWith(target) evaluates to false immediately on entry.
As a result:
Block.mine()exits without incrementingnonceor callingcomputeHash().- The block's stored
hashremains the old hash from before tampering. - When
chain.isValid()runs, it checks:
and returnsif (!current.getHash().equals(current.computeHash())) return false;falseright there because the stored hash does not matchcomputeHash(). - Execution never reaches the signature check loop at the bottom of
isValid().
Additionally, in tamperedAmountInvalidatesChain(), the transaction modified (getTransactions().get(0)) is the mining reward transaction (from = "network"), which has no private key or signature check (hasValidSignature() returns true for network).
Environment
- JDK 17 / 21, Maven
upstream/main(commit0e92205)
I'd like to submit a PR to improve the test suite with proper re-mining so that signature verification is genuinely tested and isolated.
- Dominant language
- Java
- Stars
- 0
- Forks
- 3
- Avg merge
- 16h 38m
- Merged PRs (30d)
- 7
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from techcsispit/mini-chain
-
Tests: no test covers a payment of 0 or the genesis block meeting the difficultyPossibly taken @tanujb03 claimed this 2 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
techcsispit/mini-chain#23 ·
Maintainers usually reply within 1 day
-
README says changing Block or Transaction makes chain.dat stop loading, but adding a field or method still loads itPossibly taken @tanujb03 claimed this 2 days ago. Opendocumentation good first issue
Difficulty 1/5 Under an hour Newbie friendliness 25/100
techcsispit/mini-chain#21 ·
Maintainers usually reply within 1 day
-
Blockchain: a payment that was already mined can be submitted again, and it is accepted and mined a second timePossibly taken @tanujb03 claimed this 2 days ago. Openbug good first issue
Difficulty 3/5 1-2 days Newbie friendliness 52/100
techcsispit/mini-chain#16 ·
Maintainers usually reply within 1 day
-
A signed payment can be altered (payee and amount) and still pass signature verificationPossibly taken @tanujb03 claimed this 2 days ago. Openadvanced bug
Difficulty 3/5 1-2 days Newbie friendliness 55/100
techcsispit/mini-chain#15 ·
Maintainers usually reply within 1 day
All issues in techcsispit/mini-chain
Similar issues
-
needs-area-label
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
quelea-projection/Quelea#711 ·
-
bug pdd
Difficulty 2/5 Under an hour Newbie friendliness 67/100
objectionary/eo#9450 ·
Maintainers usually reply within 1 day
-
[EC2] DescribeAvailabilityZones should return real AWS error for unknown zone namePossibly taken @omatheusmesmo claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
area: core good first issue type: enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100