Blockchain: a payment that was already mined can be submitted again, and it is accepted and mined a second time
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 52/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- java
- Domain
- blockchain, security
Research direction
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.
Written by the indexing model from the issue text.
Description
What I did
- Fresh checkout of
main, JDK 17, Maven. mvn compile- Save this as
Replay.javain 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());
}
}
- 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.
- 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 4 days ago. Opengood first issue tests
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
techcsispit/mini-chain#23 ·
Maintainers usually reply within 1 day
-
Enhancement: Modernize Cryptographic & Data Architecture (Merkle Trees, Ed25519, Deterministic Hashing & Address Derivation)Possibly taken @sohanjadyal claimed this 1 day ago. Openadvanced feature
Difficulty 5/5 Over a week Newbie friendliness 35/100
techcsispit/mini-chain#27 · 1 comment · 1 assignee ·
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 4 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
-
BlockchainTest: signature tampering tests pass on the hash check; Block.mine() is a no-op so signature verification is not testedPossibly taken @tanujb03 claimed this 4 days ago. Opengood first issue tests
Difficulty 3/5 1-2 days Newbie friendliness 25/100
techcsispit/mini-chain#19 ·
Maintainers usually reply within 1 day
-
A signed payment can be altered (payee and amount) and still pass signature verificationPossibly taken @tanujb03 claimed this 4 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
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
bug new windows
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
GantMan/jail-monkey#380 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
objectionary/jucs#145 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
objectionary/lints#1559 ·
Maintainers usually reply within 2 days