Skip to content

Commit

Permalink
adding my solution
Browse files Browse the repository at this point in the history
  • Loading branch information
partharora1610 committed May 19, 2024
0 parents commit aafaa1f
Show file tree
Hide file tree
Showing 8,167 changed files with 874,783 additions and 0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
37 changes: 37 additions & 0 deletions .github/workflows/classroom.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Autograding Tests
'on':
- push
- workflow_dispatch
- repository_dispatch
permissions:
checks: write
actions: read
contents: read
jobs:
run-autograding-tests:
runs-on: ubuntu-latest
if: github.actor != 'github-classroom[bot]'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download mempool
uses: GuillaumeFalourd/clone-github-repo-action@v2.3
with:
owner: 'SummerOfBitcoin'
repository: 'code-challenge-2024-mempool'
- name: Validate block
id: validate-block
uses: SummerOfBitcoin/code-challenge-2024-grader@v2.8
with:
test-name: 'Validate block '
command: chmod +x ./run.sh && ./run.sh
timeout: 10
max-fee: 20616923
max-score: 100
passing-score: 60
- name: Autograding Reporter
uses: SummerOfBitcoin/autograding-grading-reporter@v2.2
env:
VALIDATE-BLOCK_RESULTS: "${{steps.validate-block.outputs.result}}"
with:
runners: validate-block
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
66 changes: 66 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Summer of Bitcoin 2024: Mine your first block

## Overview
In this challenge, you are tasked with the simulation of mining process of a block, which includes validating and including transactions from a given set of transactions.
The repository contains a folder `mempool` which contains JSON files.
These files represent individual transactions, some of which may be invalid. Your goal is to successfully mine a block by including only the valid transactions, following the specific requirements outlined below.

## Objective
Your primary objective is to write a script that processes a series of transactions, validates them, and then mines them into a block. The output of your script should be a file named `output.txt` that follows a specific format.

## Requirements
### Input
- You are provided with a folder named `mempool` containing several JSON files. Each file represents a transaction that includes all necessary information for validation.
- Among these transactions, some are invalid. Your script should be able to discern valid transactions from invalid ones.

### Output
Your script must generate an output file named `output.txt` with the following structure:
- First line: The block header.
- Second line: The serialized coinbase transaction.
- Following lines: The transaction IDs (txids) of the transactions mined in the block, in order. The first txid should be that of the coinbase transaction

### Difficulty Target
The difficulty target is `0000ffff00000000000000000000000000000000000000000000000000000000`. This is the value that the block hash must be less than for the block to be successfully mined.

## Execution
- Create a file named `run.sh` that contains the command to execute your script. This file should ideally contain a single command like `python main.py` or `node index.js`.
- Your script should autonomously perform all tasks when `run.sh` is executed, without requiring any manual intervention.

## Evaluation Criteria
Your submission will be evaluated based on the following criteria:

- **Score**: Your code output will be scored bases on the fee collected and the amount of available block space utilised. **You must score at least 60 points to pass the challenge.**
- **Correctness**: The `output.txt` file must be correctly formatted in the manner described above.
- **Code Quality**: Your code should be well-organized, commented, and follow best practices.
- **Efficiency**: Your solution should process transactions and mine the block efficiently.

## Document your work

Apart from the code, you must also publish a `SOLUTION.md` file explaining your solution in the following format:
- **Design Approach:** Describe the approach you took to design your block construction program, explain all the key concepts of creating a valid block.
- **Implementation Details:** Provide pseudo code of your implementation, including sequence of logic, algorithms and variables used etc.
- **Results and Performance:** Present the results of your solution, and analyze the efficiency of your solution.
- **Conclusion:** Discuss any insights gained from solving the problem, and outline potential areas for future improvement or research. Include a list of references or resources consulted during the problem-solving process.

## What NOT to Do

In this challenge, it's crucial to understand and adhere to the following restrictions. These are put in place to ensure that you engage with the core concepts of bitcoin and apply your problem-solving skills to implement the solution from first principles.

- **Do Not Use Bitcoin Libraries for Transaction Validation:** You must not use any Bitcoin-specific libraries or frameworks that automate transaction validation processes. The intent of this challenge is for you to understand and implement the validation logic manually.
- **Permissible Libraries:** The use of standard cryptographic libraries, such as secp256k1 for elliptic curve cryptography, and standard hashing libraries (e.g., for SHA-256) is allowed and encouraged. These libraries are essential for implementing the cryptographic underpinnings of bitcoin without reinventing the wheel.
- **Implement the Mining Algorithm Yourself:** You are required to implement the mining algorithm on your own. This includes creating a way to correctly form a block header, calculate the hash, and meet the challenge of finding a hash below a certain target.

### Plagiarism Policy:
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.

### AI Usage Disclaimer:
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.

## Why These Restrictions?
These restrictions are designed to deepen your understanding of bitcoin technicals.
By completing this assignment, you will gain hands-on experience with the technology that make bitcoin secure and trustless.
Remember, the goal of this challenge is not just to produce a working solution but to engage critically with the fundamental components of bitcoin. This is an opportunity to showcase your problem-solving skills and your ability to implement complex algorithms from scratch.

## Additional Information
- This challenge is designed to test your understanding of bitcoin fundamentals, including transaction validation and block mining processes.
- While the challenge focuses on the simulation of these processes, you are encouraged to implement your solution in a way that demonstrates depth of understanding and creativity.
Binary file added image-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"version": 2,
"locktime": 0,
"vin": [
{
"txid": "64ca1941edef34b690dd6672c7d395c60882067f7f3fc396e64d88e39c1da5b4",
"vout": 0,
"prevout": {
"scriptpubkey": "0014d5bfb7a6d05d44c1e14443919b30d284c0c0a10a",
"scriptpubkey_asm": "OP_0 OP_PUSHBYTES_20 d5bfb7a6d05d44c1e14443919b30d284c0c0a10a",
"scriptpubkey_type": "v0_p2wpkh",
"scriptpubkey_address": "bc1q6klm0fkst4zvrc2ygwgekvxjsnqvpgg2jjfurm",
"value": 10740
},
"scriptsig": "",
"scriptsig_asm": "",
"witness": [
"3044022100884219ecbb54a6ec4d09597ca6aca49692ded3c2ffb13d1858ca5b70e59fabb4021f2de73021471a01d8f03a71a923b662f00120d181d0f7fa8e06faa1bb750e8f01",
"0271d4e7a84804c075017593271c370e8983f704f123d22aa747cd321268981cba"
],
"is_coinbase": false,
"sequence": 4294967293
}
],
"vout": [
{
"scriptpubkey": "a91450feb99697a4901d3fe082eca341204fb6711b9487",
"scriptpubkey_asm": "OP_HASH160 OP_PUSHBYTES_20 50feb99697a4901d3fe082eca341204fb6711b94 OP_EQUAL",
"scriptpubkey_type": "p2sh",
"scriptpubkey_address": "395H8VPYPtAoZWa2bx5SRyN2VojXrsb7j3",
"value": 9520
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"version": 2,
"locktime": 0,
"vin": [
{
"txid": "79593e210f4e7c61be57dfb6c33541ab39513a3bb964737c8e8c988bd395986e",
"vout": 1,
"prevout": {
"scriptpubkey": "5120f6dcb2b44ee298462ffc8dd9d7b969d660ddedd98ff31dd3be803b699aea9416",
"scriptpubkey_asm": "OP_PUSHNUM_1 OP_PUSHBYTES_32 f6dcb2b44ee298462ffc8dd9d7b969d660ddedd98ff31dd3be803b699aea9416",
"scriptpubkey_type": "v1_p2tr",
"scriptpubkey_address": "bc1p7mwt9dzwu2vyvtlu3hva0wtf6esdmmwe3le3m5a7sqaknxh2jstq3vztqn",
"value": 593313
},
"scriptsig": "",
"scriptsig_asm": "",
"witness": [
"7c6982626a43525e568d328824702b3743b112e40e75293b3162b182c41e7754d481e911839b211cb7547f266814afa911eea85676f69722c1f268410a75f864"
],
"is_coinbase": false,
"sequence": 4294967295
},
{
"txid": "dd006a4a306b45dab04fb249be9449caae04df24269b60afd443238729260d56",
"vout": 1,
"prevout": {
"scriptpubkey": "5120f6dcb2b44ee298462ffc8dd9d7b969d660ddedd98ff31dd3be803b699aea9416",
"scriptpubkey_asm": "OP_PUSHNUM_1 OP_PUSHBYTES_32 f6dcb2b44ee298462ffc8dd9d7b969d660ddedd98ff31dd3be803b699aea9416",
"scriptpubkey_type": "v1_p2tr",
"scriptpubkey_address": "bc1p7mwt9dzwu2vyvtlu3hva0wtf6esdmmwe3le3m5a7sqaknxh2jstq3vztqn",
"value": 10704
},
"scriptsig": "",
"scriptsig_asm": "",
"witness": [
"c2ed1bd63aa5e6e7d094210615d01cfcd74d87ffeb2232fb909f34dc661300e1ada70e6deda0cf3a05d390820a89b247d2115a59502eb82f1ed619ec929a2acd"
],
"is_coinbase": false,
"sequence": 4294967295
}
],
"vout": [
{
"scriptpubkey": "a914bf98ba19c45f75bb76b50afce91fb5bb7276bd7787",
"scriptpubkey_asm": "OP_HASH160 OP_PUSHBYTES_20 bf98ba19c45f75bb76b50afce91fb5bb7276bd77 OP_EQUAL",
"scriptpubkey_type": "p2sh",
"scriptpubkey_address": "3KA5wqaDxNSkEWKdmsnx6jxJBKtQXuhM7u",
"value": 600107
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"version": 2,
"locktime": 834637,
"vin": [
{
"txid": "4bc8a6bbd9f01b7c20fb59adc81352ff087ff7dbc52efb3cc55f188edebf47d8",
"vout": 1,
"prevout": {
"scriptpubkey": "00145017ec1e0f2e6fd64561aa072931bcd261797559",
"scriptpubkey_asm": "OP_0 OP_PUSHBYTES_20 5017ec1e0f2e6fd64561aa072931bcd261797559",
"scriptpubkey_type": "v0_p2wpkh",
"scriptpubkey_address": "bc1q2qt7c8s09ehav3tp4grjjvdu6fshja2e49rqzq",
"value": 259893968
},
"scriptsig": "",
"scriptsig_asm": "",
"witness": [
"304402206cb268614ab72910e5a975893e7cd2cb84aa58ac4f318cf84547dd3a9562761a0220455f61baeb45533265180d07a6dab52a4034ec0ffb5d7cb85757c562936509ea01",
"030b512819670cf864aa7605c7bfb32e37002db4f30c9d03a8b8aa1976049105aa"
],
"is_coinbase": false,
"sequence": 4294967294
}
],
"vout": [
{
"scriptpubkey": "0014b9c1c402d4a435ba726f52e31c71e254af33ee0e",
"scriptpubkey_asm": "OP_0 OP_PUSHBYTES_20 b9c1c402d4a435ba726f52e31c71e254af33ee0e",
"scriptpubkey_type": "v0_p2wpkh",
"scriptpubkey_address": "bc1qh8qugqk55s6m5un02t33cu0z2jhn8msw8rv8mr",
"value": 257963288
},
{
"scriptpubkey": "a914348fed75d9648cad589e072b1098cb674873c69087",
"scriptpubkey_asm": "OP_HASH160 OP_PUSHBYTES_20 348fed75d9648cad589e072b1098cb674873c690 OP_EQUAL",
"scriptpubkey_type": "p2sh",
"scriptpubkey_address": "36UwUnLVs27P4FmsAFvT26tt1zwwa1FRvQ",
"value": 1927200
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"version": 1,
"locktime": 0,
"vin": [
{
"txid": "aa6109f3cea8a458438de069af49cf8bde43db9f746f78fd5d4cac8e94b46e3c",
"vout": 1,
"prevout": {
"scriptpubkey": "0014421b8f0182ae2ab26e9297718f92f82805a48ba2",
"scriptpubkey_asm": "OP_0 OP_PUSHBYTES_20 421b8f0182ae2ab26e9297718f92f82805a48ba2",
"scriptpubkey_type": "v0_p2wpkh",
"scriptpubkey_address": "bc1qggdc7qvz4c4tym5jjacclyhc9qz6fzazsqje0d",
"value": 2993846
},
"scriptsig": "",
"scriptsig_asm": "",
"witness": [
"3045022100da9befe31774321233b2315e9c5077679131274b9900966e45e8ac0c1c0391970220355144dcc40269048bb704c46d9864e47f631792f0b9e28ff380075a52818a5c01",
"02ddde52e4b72358ff888c056b2c0d7c3e47361e82e79d9202b1b011141d417192"
],
"is_coinbase": false,
"sequence": 4294967295
}
],
"vout": [
{
"scriptpubkey": "00148e56a5479728f7786a6a8fc7cc0f3535cea91b52",
"scriptpubkey_asm": "OP_0 OP_PUSHBYTES_20 8e56a5479728f7786a6a8fc7cc0f3535cea91b52",
"scriptpubkey_type": "v0_p2wpkh",
"scriptpubkey_address": "bc1q3et223uh9rmhs6n23lrucre4xh82jx6jnukpcl",
"value": 83000
},
{
"scriptpubkey": "0014421b8f0182ae2ab26e9297718f92f82805a48ba2",
"scriptpubkey_asm": "OP_0 OP_PUSHBYTES_20 421b8f0182ae2ab26e9297718f92f82805a48ba2",
"scriptpubkey_type": "v0_p2wpkh",
"scriptpubkey_address": "bc1qggdc7qvz4c4tym5jjacclyhc9qz6fzazsqje0d",
"value": 2896746
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"version": 2,
"locktime": 0,
"vin": [
{
"txid": "e3acb27a9fb6593822a4d8bbb8be9f9516e33123f196a41fc2801a9cae278ba4",
"vout": 0,
"prevout": {
"scriptpubkey": "5120d7b0161160dc8ce46dfbf55c602ffeef5ed4ebcadebbe077918819b0aa1b73e6",
"scriptpubkey_asm": "OP_PUSHNUM_1 OP_PUSHBYTES_32 d7b0161160dc8ce46dfbf55c602ffeef5ed4ebcadebbe077918819b0aa1b73e6",
"scriptpubkey_type": "v1_p2tr",
"scriptpubkey_address": "bc1p67cpvytqmjxwgm0m74wxqtl7aa0df672m6a7qau33qvmp2smw0nqrgxc8d",
"value": 546
},
"scriptsig": "",
"scriptsig_asm": "",
"witness": [
"265f6c3128efad948b8e1d11e1cd165c457e9e5da32f0e4093d81221aa6ecd6ec9bebbda812f4aa8c2caabf50575d22b551cd95d27ec015031950589869b5d26"
],
"is_coinbase": false,
"sequence": 2147483649
},
{
"txid": "ef575d36c46466f419678345bd0fc17d65cc1a5741a47ac272d9e329dab7c0c9",
"vout": 1,
"prevout": {
"scriptpubkey": "5120d7b0161160dc8ce46dfbf55c602ffeef5ed4ebcadebbe077918819b0aa1b73e6",
"scriptpubkey_asm": "OP_PUSHNUM_1 OP_PUSHBYTES_32 d7b0161160dc8ce46dfbf55c602ffeef5ed4ebcadebbe077918819b0aa1b73e6",
"scriptpubkey_type": "v1_p2tr",
"scriptpubkey_address": "bc1p67cpvytqmjxwgm0m74wxqtl7aa0df672m6a7qau33qvmp2smw0nqrgxc8d",
"value": 1811712
},
"scriptsig": "",
"scriptsig_asm": "",
"witness": [
"8b8b8a72ac3d38c85fb59b0ba462d6a4ef39b73bd86a3ac8a300e5ab52033729ecd442e2b0eb5aba0ba9111ad0bccbdb4d24483caf482ebe6d2b819825f27731"
],
"is_coinbase": false,
"sequence": 2147483649
}
],
"vout": [
{
"scriptpubkey": "5120d7b0161160dc8ce46dfbf55c602ffeef5ed4ebcadebbe077918819b0aa1b73e6",
"scriptpubkey_asm": "OP_PUSHNUM_1 OP_PUSHBYTES_32 d7b0161160dc8ce46dfbf55c602ffeef5ed4ebcadebbe077918819b0aa1b73e6",
"scriptpubkey_type": "v1_p2tr",
"scriptpubkey_address": "bc1p67cpvytqmjxwgm0m74wxqtl7aa0df672m6a7qau33qvmp2smw0nqrgxc8d",
"value": 546
},
{
"scriptpubkey": "5120d7b0161160dc8ce46dfbf55c602ffeef5ed4ebcadebbe077918819b0aa1b73e6",
"scriptpubkey_asm": "OP_PUSHNUM_1 OP_PUSHBYTES_32 d7b0161160dc8ce46dfbf55c602ffeef5ed4ebcadebbe077918819b0aa1b73e6",
"scriptpubkey_type": "v1_p2tr",
"scriptpubkey_address": "bc1p67cpvytqmjxwgm0m74wxqtl7aa0df672m6a7qau33qvmp2smw0nqrgxc8d",
"value": 1809391
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"version": 2,
"locktime": 0,
"vin": [
{
"txid": "a74026e81488bc8ed65781b5904edb3fd401d40e8892fa7c6d91a1cc66f02170",
"vout": 7,
"prevout": {
"scriptpubkey": "51202691567e31e951fc72a28ebace6fd5ab716dd455e7b150eadfcadd03a9e37b0e",
"scriptpubkey_asm": "OP_PUSHNUM_1 OP_PUSHBYTES_32 2691567e31e951fc72a28ebace6fd5ab716dd455e7b150eadfcadd03a9e37b0e",
"scriptpubkey_type": "v1_p2tr",
"scriptpubkey_address": "bc1py6g4vl33a9glcu4z36avum744dckm4z4u7c4p6kletws820r0v8qh8nknh",
"value": 1962
},
"scriptsig": "",
"scriptsig_asm": "",
"witness": [
"937d2bbbde729857003c7c48bec4613141e42b8a12c8e7a9f065ace973b3bc4ed5f7c49beb362cd22c16fd0002ee19422dabfc3027682dccfdb52a8ac44862c1",
"20abf657ab0c1aabaa24896a8ab10adde8612397f1eb7067bdcd5d9371d70c2febac0063036f7264010118746578742f706c61696e3b636861727365743d7574662d3800367b2270223a226272632d3230222c226f70223a226d696e74222c227469636b223a2261616161222c22616d74223a223130303030227d68",
"c1abf657ab0c1aabaa24896a8ab10adde8612397f1eb7067bdcd5d9371d70c2feb"
],
"is_coinbase": false,
"sequence": 4294967293
}
],
"vout": [
{
"scriptpubkey": "0014606aea6bcae8843bfa542b3231f709d8e8c47366",
"scriptpubkey_asm": "OP_0 OP_PUSHBYTES_20 606aea6bcae8843bfa542b3231f709d8e8c47366",
"scriptpubkey_type": "v0_p2wpkh",
"scriptpubkey_address": "bc1qvp4w5672azzrh7j59verracfmr5vgumxtld8pd",
"value": 294
}
]
}
Loading

0 comments on commit aafaa1f

Please sign in to comment.