diff --git a/submission/01.sh b/submission/01.sh index 574e268..7135066 100755 --- a/submission/01.sh +++ b/submission/01.sh @@ -1 +1,2 @@ # Create a wallet with the name "btrustwallet". +bitcoin-cli -regtest createwallet "btrustwallet" \ No newline at end of file diff --git a/submission/02.sh b/submission/02.sh index e8dfb18..cbb6138 100755 --- a/submission/02.sh +++ b/submission/02.sh @@ -1 +1,14 @@ # Create a native segwit address and get the public key from the address. +# submission/02.sh +#!/bin/bash + +# Generate a new bech32 (SegWit) address +ADDRESS=$(bitcoin-cli -regtest -rpcwallet=btrustwallet getnewaddress "" bech32) + +# Get the public key associated with the address +PUB_KEY=$(bitcoin-cli -regtest -rpcwallet=btrustwallet getaddressinfo "$ADDRESS" | jq -r '.pubkey') + +# Output the public key +echo "$PUB_KEY" + + diff --git a/submission/03.sh b/submission/03.sh index ea91ece..c735a2d 100755 --- a/submission/03.sh +++ b/submission/03.sh @@ -1,2 +1,18 @@ # Create a 1-of-4 P2SH multisig address from the public keys in the four inputs of this raw tx: # transaction="02000000000104b5f641e80e9065f09b12f3e373072518885d1bd1ddd9298e5b9840de515edac90000000000feffffffd54f8986afbb6ff18572acaee58fa3ad64446dd770ffe9b6a04f798becdafb440000000000feffffff475e3062b1c3ee87544c29d723866da2b65a1b1a42e6ea4a4fd48d79f83c26c50000000000feffffffa56387352ecc93dfd37648e6ebd4d9effb37ffefcad02eb7b85860c9097cf8090000000000feffffff02fa440f00000000001600148070ec3954ecdcbfc210d0117e8d28a19eb8467270947d0000000000160014b5fe46c647353ec9c06374655502094095f0289c0247304402200dd758801b40393f68dad8ab57558803efcd2b681ee31eb44fb3cfa9666d2bf90220254d34fa4990e23652bf669053c5e16fd2fbb816bed2eeb44c1f1e6e54143e3e012102bbb4ba3f39b5f3258f0014d5e4eab5a6990009e3e1dba6e8eaff10b3832394f70247304402201694761a5749b6a84f71459c04a44cf9d34a36ae8c9044c3af7a3a5514ef2e64022058f61feb92d6d54b71fdea47e7dfcd20f6a5c12e2fbcb15bc44fe95c73f2e808012103aaf17b1a7b4108f7e5bc4f7d59c20f7fb1a72dbc74a9a3d6d1f8488df159c76002473044022014b65c60f65e62d9dac893e404c8de2a007c7c6b74dbac18e454d8374e159759022012453f69112adadf9495fd3fe288aa5ed9e3d836340da06fa1e82c8e09adef57012103a6d919c76d9117c23570a767450013edf31cf6be7d3b5a881c06a9aa1f2c24ce0247304402203d3b02390803c1d673fa49bd64d4a26fbeb29e3fc152af8f844d776c9409e41302206903a011a04e00a7f4ec606da4320226d2d393f565702cc58cfcef6dca67f84c01210383d12258e3e294a6d7754336f6b4baef992ec4b91694d3460bcb022b11da8cd2817e0c00" +#!/bin/bash + +# Define public keys +Npublic1="02bbb4ba3f39b5f3258f0014d5e4eab5a6990009e3e1dba6e8eaff10b3832394f7" +Npublic2="03aaf17b1a7b4108f7e5bc4f7d59c20f7fb1a72dbc74a9a3d6d1f8488df159c760" +Npublic3="03a6d919c76d9117c23570a767450013edf31cf6be7d3b5a881c06a9aa1f2c24ce" +Npublic4="0383d12258e3e294a6d7754336f6b4baef992ec4b91694d3460bcb022b11da8cd2" + +# Generate P2SH multisig address +MULTISIG_OUTPUT=$(bitcoin-cli -regtest createmultisig 1 "[\"$Npublic1\", \"$Npublic2\", \"$Npublic3\", \"$Npublic4\"]") + +# Extract only the address from the JSON output +P2SH_ADDRESS=$(echo "$MULTISIG_OUTPUT" | jq -r '.address') + +# Output the address +echo "$P2SH_ADDRESS" diff --git a/submission/04.sh b/submission/04.sh index 21873c5..94b8f31 100755 --- a/submission/04.sh +++ b/submission/04.sh @@ -3,3 +3,20 @@ # 024bc198a88b69316952414af34105613c3617561a433a229100a0966cd631dd3d # 035e11024a7fa1e0ca537e0e76b15c1631486f6611c7d8187aea8f6c1ae5d30617 # 03ce11c7b563c3d7fae916351f234eac5089ad2e42fa9e29a94ee944e00c880c66 +#!/bin/bash + +# Define public keys +zpublic1="024bc198a88b69316952414af34105613c3617561a433a229100a0966cd631dd3d" +zpublic2="035e11024a7fa1e0ca537e0e76b15c1631486f6611c7d8187aea8f6c1ae5d30617" +zpublic3="03ce11c7b563c3d7fae916351f234eac5089ad2e42fa9e29a94ee944e00c880c66" + +# Generate P2SH multisig address +MULTISIG_OUTPUT=$(bitcoin-cli -regtest createmultisig 2 "[\"$zpublic1\", \"$zpublic2\", \"$zpublic3\"]") + +# Extract only the address from the JSON output +P2SH_ADDRESS=$(echo "$MULTISIG_OUTPUT" | jq -r '.address') + +# Output the address +echo "$P2SH_ADDRESS" + + diff --git a/submission/05.sh b/submission/05.sh index c5ebb72..72e3d91 100644 --- a/submission/05.sh +++ b/submission/05.sh @@ -3,3 +3,60 @@ # Amount of 20,000,000 satoshis to this address: 2MvLcssW49n9atmksjwg2ZCMsEMsoj3pzUP # Use the UTXOs from the transaction below # transaction="01000000000101c8b0928edebbec5e698d5f86d0474595d9f6a5b2e4e3772cd9d1005f23bdef772500000000ffffffff0276b4fa0000000000160014f848fe5267491a8a5d32423de4b0a24d1065c6030e9c6e000000000016001434d14a23d2ba08d3e3edee9172f0c97f046266fb0247304402205fee57960883f6d69acf283192785f1147a3e11b97cf01a210cf7e9916500c040220483de1c51af5027440565caead6c1064bac92cb477b536e060f004c733c45128012102d12b6b907c5a1ef025d0924a29e354f6d7b1b11b5a7ddff94710d6f0042f3da800000000" + +#!/bin/bash + +WALLET_NAME="btrustwallet" + +# Ensure Bitcoin Core is running +if ! bitcoin-cli -regtest getblockchaininfo >/dev/null 2>&1; then + bitcoind -regtest -daemon + sleep 5 # Wait for Bitcoin Core to start +fi + +# Check if wallet exists, otherwise load it +if ! bitcoin-cli -regtest listwallets | grep -q "$WALLET_NAME"; then + echo "⚠️ Loading wallet..." + bitcoin-cli -regtest loadwallet "$WALLET_NAME" || bitcoin-cli -regtest createwallet "$WALLET_NAME" +fi + +# Set wallet flag to use fallback fee +bitcoin-cli -regtest -rpcwallet="$WALLET_NAME" settxfee 0.00001 >/dev/null 2>&1 + +# Check balance +BALANCE=$(bitcoin-cli -regtest -rpcwallet="$WALLET_NAME" getbalance) +if (( $(echo "$BALANCE < 1" | bc -l) )); then + echo "⚠️ Insufficient funds! Mining blocks and funding wallet..." + MINER_ADDR=$(bitcoin-cli -regtest getnewaddress) + bitcoin-cli -regtest generatetoaddress 101 "$MINER_ADDR" + RECEIVER=$(bitcoin-cli -regtest -rpcwallet="$WALLET_NAME" getnewaddress) + bitcoin-cli -regtest sendtoaddress "$RECEIVER" 1 + bitcoin-cli -regtest generatetoaddress 1 "$MINER_ADDR" +fi + +# Fetch an available UTXO +UTXO=$(bitcoin-cli -regtest -rpcwallet="$WALLET_NAME" listunspent | jq -r '.[0]') +if [ "$UTXO" == "null" ]; then + echo "❌ Error: No available UTXOs!" + exit 1 +fi +txid=$(echo "$UTXO" | jq -r '.txid') +vout=$(echo "$UTXO" | jq -r '.vout') + +# Destination address +destination_address="2MvLcssW49n9atmksjwg2ZCMsEMsoj3pzUP" + +# Create raw transaction +rawtx=$(bitcoin-cli -regtest -rpcwallet="$WALLET_NAME" createrawtransaction \ + '[{"txid": "'"$txid"'", "vout": '"$vout"'}]' \ + '[{"'"$destination_address"'": 0.2}]') + +echo "Raw Transaction: $rawtx" + +# Create PSBT with fallback fee +psbt=$(bitcoin-cli -regtest -rpcwallet="$WALLET_NAME" walletcreatefundedpsbt \ + '[]' '[{"'"$destination_address"'": 0.2}]' \ + 0 '{"subtractFeeFromOutputs":[0], "replaceable":true, "fee_rate": 10, "includeWatching": true}') + +echo "Partially Signed Transaction: $psbt" + diff --git a/submission/06.sh b/submission/06.sh index 6339466..c9f69d9 100644 --- a/submission/06.sh +++ b/submission/06.sh @@ -1,2 +1,4 @@ # What is the hash of this partially signed transaction? # transaction=cHNidP8BAHsCAAAAAhuVpgVRdOxkuC7wW2rvw4800OVxl+QCgezYKHtCYN7GAQAAAAD/////HPTH9wFgyf4iQ2xw4DIDP8t9IjCePWDjhqgs8fXvSIcAAAAAAP////8BigIAAAAAAAAWABTHctb5VULhHvEejvx8emmDCtOKBQAAAAAAAAAA +bitcoin-cli -regtest decodepsbt cHNidP8BAHsCAAAAAhuVpgVRdOxkuC7wW2rvw4800OVxl+QCgezYKHtCYN7GAQAAAAD/////HPTH9wFgyf4iQ2xw4DIDP8t9IjCePWDjhqgs8fXvSIcAAAAAAP////8BigIAAAAAAAAWABTHctb5VULhHvEejvx8emmDCtOKBQAAAAAAAAAA +#ea73a631b456d2b041ed73bf5767946408c6ff067716929a68ecda2e3e4de6d3 diff --git a/submission/07.sh b/submission/07.sh index 81c5ad2..5c6950a 100644 --- a/submission/07.sh +++ b/submission/07.sh @@ -1,2 +1,4 @@ # What is the receiver's address in this partially signed transaction? # transaction=cHNidP8BAHsCAAAAAhuVpgVRdOxkuC7wW2rvw4800OVxl+QCgezYKHtCYN7GAQAAAAD/////HPTH9wFgyf4iQ2xw4DIDP8t9IjCePWDjhqgs8fXvSIcAAAAAAP////8BigIAAAAAAAAWABTHctb5VULhHvEejvx8emmDCtOKBQAAAAAAAAAA +bitcoin-cli -regtest decodepsbt cHNidP8BAHsCAAAAAhuVpgVRdOxkuC7wW2rvw4800OVxl+QCgezYKHtCYN7GAQAAAAD/////HPTH9wFgyf4iQ2xw4DIDP8t9IjCePWDjhqgs8fXvSIcAAAAAAP////8BigIAAAAAAAAWABTHctb5VULhHvEejvx8emmDCtOKBQAAAAAAAAAA +#bcrt1qcaedd724gts3aug73m78c7nfsv9d8zs9znw8py