In this fifth week you will:
- Create two wallets on regtest:
MinerandAlice. - Fund the wallets by:
- Mining blocks to credit Miner.
- Sending some BTC from Miner to Alice.
- Confirm the funding transaction and assert that Alice’s balance is positive.
- Build a refund transaction from Alice back to Miner for 10 BTC, with a relative timelock of 10 blocks (i.e. set the input’s nSequence appropriately).
- Attempt to broadcast the refund transaction immediately, and report in your terminal what error or behavior you observe.
- Mine 10 more blocks.
- Broadcast the refund transaction, then mine one additional block to confirm it.
- Output the refund transaction ID to
out.txt. - Target Locations for the solution code for each languages are given below:
- Bash: solution.sh
- Javascript: index.js
- Python: main.py
- Rust: main.rs
Relative timelocks are used to make input-specific locks. Using relative timelock, a transaction can be locked up to a certain number of blocks since the block in which the input it is referring to has been mined.
The exercise below demonstrates using a relative timelock spend.
Implement the following tasks in exactly one of the language-specific directories (bash, javascript, python, or rust):
- Create two wallets:
Miner,Alice. - Fund the wallets by generating some blocks for
Minerand sending some coins toAlice. - Confirm the transaction and assert that
Alicehas a positive balance. - Create a refund transaction where
Alicepays 10 BTC back toMiner, but with a relative timelock of 10 blocks. - Report in the terminal output what happens when you try to broadcast the refund transaction.
- Generate 10 more blocks.
- Broadcast the refund transaction. Confirm it by generating one more block.
- Report Balance of
Alice.
Output the txid of the refund transaction to out.txt. The file should contain the following structure:
<txid_refund>- Write your solution in
solution.sh. Make sure to include comments explaining each step of your code. - Commit your changes and push to the main branch:
- Add your changes by running
git add solution.sh. - Commit the changes by running
git commit -m "Solution". - Push the changes by running
git push origin main.
- Add your changes by running
- The autograder will run your script against a test script to verify the functionality.
- Check the status of the autograder on the Github Classroom portal to see if it passed successfully or failed. Once you pass the autograder with a score of 100, you have successfully completed the challenge.
- You can submit multiple times before the deadline. The last submission before the deadline will be considered your final submission.
- You will lose access to the repository after the deadline.
| Language | Prerequisite packages |
|---|---|
| Bash | jq, curl, wget, tar |
| JavaScript | Node.js ≥ 20, npm |
| Python | Python ≥ 3.9 |
| Rust | Rust stable toolchain |
- Install
jqtool for parsing JSON data if you don't have it installed. - Install Node.js and npm to run the test script.
- Node version 20 or higher is recommended. You can install Node.js using the following command:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash source ~/.nvm/nvm.sh nvm install --lts - Install the required npm packages by running
npm install.
It's a good idea to run the whole test locally to ensure your code is working properly.
- Uncomment the specific line in run.sh corresponding to your language of choice.
- Grant execution permission to test.sh, by running
chmod +x ./test.sh. - Execute
./test.sh. - The test script will run your script and verify the output. If the test script passes, you have successfully completed the challenge and are ready to submit your solution.
Note: There is a pre-cooked setup script available here to download and start bitcoind. You may use that script for all local testing purposes.
- Your submission should not stop the Bitcoin Core daemon at any point.
- Linux and MacOS are the recommended operating systems for this challenge. If you are using Windows, you may face compatibility issues.
- The autograder will run the test script on an Ubuntu 22.04 environment. Make sure your script is compatible with this environment.
- If you are unable to run the test script locally, you can submit your solution and check the results on the Github.
- Commit all code inside the appropriate language directory and the modified
run.sh.git add . git commit -m "Week 2 solution" - Push to the main branch:
git push origin main - The autograder will run your script against a test script to verify the functionality.
- Check the status of the autograder on the Github Classroom portal to see if it passed successfully or failed. Once you pass the autograder with a score of 100, you have successfully completed the challenge.
- You can submit multiple times before the deadline. The latest submission before the deadline will be considered your final submission.
- You will lose access to the repository after the deadline.
- Useful bash script examples: https://linuxhint.com/30_bash_script_examples/
- Useful
jqexamples: https://www.baeldung.com/linux/jq-command-json - Use
jqto create JSON: https://spin.atomicobject.com/2021/06/08/jq-creating-updating-json/
Your submission will be evaluated based on:
- Autograder: Your code must pass the autograder test script.
- Explainer Comments: Include comments explaining each step of your code.
- Code Quality: Your code should be well-organized, commented, and adhere to best practices.
Our plagiarism detection checker thoroughly identifies any instances of copying or cheating. Participants are required to publish their solutions in the designated repository, which is private and accessible only to the individual and the administrator. Solutions should not be shared publicly or with peers. In case of plagiarism, both parties involved will be directly disqualified to maintain fairness and integrity.
You may use AI tools like ChatGPT to gather information and explore alternative approaches, but avoid relying solely on AI for complete solutions. Verify and validate any insights obtained and maintain a balance between AI assistance and independent problem-solving.
These rules are designed to enhance your understanding of the technical aspects of Bitcoin. By completing this assignment, you gain practical experience with the technology that secures and maintains the trustlessness of Bitcoin. This challenge not only tests your ability to develop functional Bitcoin applications but also encourages deep engagement with the core elements of Bitcoin technology.