BlockchainTest: signature tampering tests pass on the hash check; Block.mine() is a no-op so signature verification is not tested
Los mantenedores suelen responder en 2 días
Ya se ha fusionado un pull request relacionado.
- #20 de @tanujb03 — fusionado
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 25/100
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- Java
- Estrellas
- 0
- Forks
- 3
- Merge medio
- 2 d 5 h
- PR fusionados (30 d)
- 15
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Sin guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de techcsispit/mini-chain
-
Blockchain.isValid() does not verify sender balance, allowing blocks with negative balances to pass validationPosiblemente ocupada @aadiitya2007 la tomó hace 5 días. Abiertobug good first issue
Dificultad 4/5 1-2 días Aptitud para principiantes 20/100
techcsispit/mini-chain#37 · 1 comentario · 1 asignado ·
Los mantenedores suelen responder en 2 días
-
README says changing Block or Transaction makes chain.dat stop loading, but adding a field or method still loads itPosiblemente ocupada @tanujb03 la tomó hace 24 días. Abiertodocumentation good first issue
Dificultad 1/5 Menos de una hora Aptitud para principiantes 25/100
techcsispit/mini-chain#21 ·
Los mantenedores suelen responder en 2 días
Todos los issues de techcsispit/mini-chain
Issues similares
-
5.0.x backport enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 63/100
spring-cloud/spring-cloud-function#1507 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
open-learning-exchange/myplanet#18484 ·
Los mantenedores suelen responder en 1 día
-
ai-driven-fuzzing bug claude Minor
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
linagora/twake-calendar-side-service#1417 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
line/armeria#7109 · 3 reacciones ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
open-feature/java-sdk-contrib#1966 ·
Los mantenedores suelen responder en 1 día