owned this note
owned this note
Published
Linked with GitHub
# Make your own signet w/ Josie
###### tags: `tutorials` `signet`
## Main goals
* Run bitcoin core
* Run the tests
* make changes, test them and run it on a custom signet
## Ideas
* Everyone should be mining or able to mine, so should therefore generate a private key to be a signer
* Can we automate this all in a single script?
* Can people join in as "miners"?
* Go through chaincode seminars and for each topics add some exercies which you could do on signet
* You can change consensus-critial and non-consensus critial bitcoind stuff, recompile and see how it works on your signet:
...
* Remove DNS seeds, then hardcoded seeds, then use -connect
* Own activation heights for stuff
* Disabling segwit/taproot, change coin prefixes
* Change interblock time, observe orphan blocks re-orgs
* Change block size, soft or hard fork [Vitalik has a way](https://www.reddit.com/r/btc/comments/428tjl/softforking_the_block_time_to_2_min_my_primarily/)
* Eclipse attack someone
* Re-introduce [coin age priority](https://github.com/bitcoin/bitcoin/blob/7fcf53f7b4524572d1d0c9a5fdc388e87eb02416/doc/release-notes/release-notes-0.15.0.md#removal-of-coin-age-priority)
Other ideas
* Could they create P2P messenger
* Or build your own node from scratch, no-wallet, or choose which BIPs you want to implement
* Try to DoS attack someone else's node, flood mempool etc.
* change any and all policy parameters and observer their effect on the network, i.e everyone run in blocks only mode, change mempool min relay fees, etc
- [x] Make a repo for signet chaincode seminar exercises/question banks
https://github.com/learn-me-a-signet/signet-ex
## TODO:
- [x] Run a signet
- [x] Familiarise with the scripts
- [x] Check if anyone can join as a miner later, if not generate 50 keys to distribute, k of n 1 or 50
- [ ] Can we use taproot multisig (MuSig/MuSig2)
- [x] Check if I can mine blocks on my own
- [ ] Can we implment regular re-orgs using
- [ ] Can we automate people joining the signet
- [x] Org Learn-me-a-signet: for signet questions
## Notes
### Generate keys using regtest
Start bitcoind in regtest mode and create a non-descriptor wallet (so we can use `dumpprivkey` on it).
```bash
bitcoind -regtest
bitcoin-cli -regtest -named createwallet wallet_name="test" descriptors=false
```
Next generate a few keys, e.g. in bash:
```bash
ADDR=$(bitcoin-cli -regtest -rpcwallet="test" getnewaddress)
PK=$(bitcoin-cli -regtest -rpcwallet="test" dumpprivkey)
bitcoin-cli -regtest -rpcwallet="test" getaddressinfo $ADDR | grep pubkey | cut -d \" -f4
```
Fish script to generate `n` keys:
```fish
function gen-regtest-keys
set num $argv[1]
for i in (seq $num)
set ADDR (bitcoin-cli -regtest -rpcwallet="test" getnewaddress)
set PRIVKEY (bitcoin-cli -regtest -rpcwallet="test" dumpprivkey $ADDR)
set PUBKEY (bitcoin-cli -regtest -rpcwallet="test" getaddressinfo $ADDR | grep pubkey | cut -d \" -f4)
echo "---------------------------------"
echo $PRIVKEY
echo $PUBKEY
end
echo "---------------------------------"
end
```
then
```shell=
gen-regtest-keys 10
```
This will output privkeys & pubkeys e.g.:
```text
---------------------------------
cPu7ZGY3Hs5WdNB73M7ok3VBH1nV7MRwJ8V6vJqyKGwFv5H5f9bC
02e240f3e2e2a4ef79e03fbd0e3afb999997ddbce14c250e73d2f6b7af97f941f7
---------------------------------
cQHXC3dKXLVRVMfeMv35YNvmsVHxViEiJsH5EAgJHz7VKEanfGrQ
038c761f9fa1b29191011ef95acf76328355bc086b8706f79bce931e55075bd978
---------------------------------
cR1L5F4vv3FPc3LNuKkVoYNzD6fjvt88s8H95KXcfj4WQUbz7qwM
0274fac0536a8e7f384dea2b1e209893d3a043c53d835389b80082a8fbf8d5401d
---------------------------------
cUVVjKcib4aRMKq5iemTABDprh433b1vq4GRFNv8dTizVJmfXujF
0353e6b2589f6c5872b0a9cd424af60923f73ac5c081fc30ea99f6e5f188f3ad65
---------------------------------
```
Multisig script for 1-of-4 will resemble:
```text
OP_PUSHNUM_1 OP_PUSHBYTES_33 02e240f3e2e2a4ef79e03fbd0e3afb999997ddbce14c250e73d2f6b7af97f941f7 OP_PUSHBYTES_33 038c761f9fa1b29191011ef95acf76328355bc086b8706f79bce931e55075bd978 OP_PUSHBYTES_33 0274fac0536a8e7f384dea2b1e209893d3a043c53d835389b80082a8fbf8d5401d OP_PUSHBYTES_33 0353e6b2589f6c5872b0a9cd424af60923f73ac5c081fc30ea99f6e5f188f3ad65 OP_PUSHNUM_4 OP_CHECKMULTISIG
```
We can use `createmultisig` from Bitcoin Core with e.g.:
```shell
bitcoin-cli -regtest -rpcwallet="test" createmultisig 1 "[\"02e240f3e2e2a4ef79e03fbd0e3afb999997ddbce14c250e73d2f6b7af97f941f7\",\"038c761f9fa1b29191011ef95acf76328355bc086b8706f79bce931e55075bd978\",\"0274fac0536a8e7f384dea2b1e209893d3a043c53d835389b80082a8fbf8d5401d\",\"0353e6b2589f6c5872b0a9cd424af60923f73ac5c081fc30ea99f6e5f188f3ad65\"]"
```
We will be returned a fully-formed multisig address, redeem script and descriptor:
```shell
{
"address": "2N7W7xJ31SGTiYkh3hpmtkFNXqnJV2xzdYX",
"redeemScript": "512102e240f3e2e2a4ef79e03fbd0e3afb999997ddbce14c250e73d2f6b7af97f941f721038c761f9fa1b29191011ef95acf76328355bc086b8706f79bce931e55075bd978210274fac0536a8e7f384dea2b1e209893d3a043c53d835389b80082a8fbf8d5401d210353e6b2589f6c5872b0a9cd424af60923f73ac5c081fc30ea99f6e5f188f3ad6554ae",
"descriptor": "sh(multi(1,02e240f3e2e2a4ef79e03fbd0e3afb999997ddbce14c250e73d2f6b7af97f941f7,038c761f9fa1b29191011ef95acf76328355bc086b8706f79bce931e55075bd978,0274fac0536a8e7f384dea2b1e209893d3a043c53d835389b80082a8fbf8d5401d,0353e6b2589f6c5872b0a9cd424af60923f73ac5c081fc30ea99f6e5f188f3ad65))#fa4q073s"
}
```
We can use the redeem script as the `signetchallenge` for the signet.
### Start mining on signet
First we want to fire up a node on our custom signet.
Start by editing `bitcoin.conf`:
```text
daemon=1
signet=1
# The redeem script for the multisig
signetchallenge=512102e240f3e2e2a4ef79e03fbd0e3afb999997ddbce14c250e73d2f6b7af97f941f721038c761f9fa1b29191011ef95acf76328355bc086b8706f79bce931e55075bd978210274fac0536a8e7f384dea2b1e209893d3a043c53d835389b80082a8fbf8d5401d210353e6b2589f6c5872b0a9cd424af60923f73ac5c081fc30ea99f6e5f188f3ad6554ae
```
Start bitcoind from the new conf (reccomend `-datadir` over `-conf` for cleanliness) and test to see that we're running.
```bash
bitcoind -datadir=$HOME/signet/1/
bitcoin-cli -datadir=$HOME/signet/1 -getinfo
```
Create a wallet and import one of the privkeys used to create the multisig into it:
```bash=
bitcoin-cli -datadir=$HOME/signet/1 -named createwallet wallet_name="test" descriptors=false
bitcoin-cli -datadir=$HOME/signet/1 importprivkey cPu7ZGY3Hs5WdNB73M7ok3VBH1nV7MRwJ8V6vJqyKGwFv5H5f9bC
```
**WARNING**: Need to use the mining script from master, since there is a bug which has been fixed by [24553](https://github.com/bitcoin/bitcoin/pull/24553).
Follow the guide to mining from the [Signet Readme](https://github.com/bitcoin/bitcoin/blob/v23.0rc2/contrib/signet/README.md#miner) (in bitcoin source dir):
```bash
cd src/
MINER="../contrib/signet/miner"
GRIND="./bitcoin-util grind"
$MINER calibrate --grind-cmd="$GRIND"
nbits=1e00f403 for 25s average mining time
```
To mine the first block in the custom chain run:
```bash
CLI="./bitcoin-cli -datadir=$HOME/signet/1"
ADDR=$($CLI -signet getnewaddress)
NBITS=1e00f403
$MINER --cli="$CLI" generate --grind-cmd="$GRIND" --address="$ADDR" --nbits=$NBITS
```
To mine continuously:
```bash=
$MINER --cli="$CLI" generate --grind-cmd="$GRIND" --address="$ADDR" --nbits=$NBITS --ongoing --multiminer=1/4
```
Using the --multiminer parameter allows mining to be distributed amongst multiple miners. For example, if you have 3 miners and want to share blocks between them, specify --multiminer=1/3 on one, --multiminer=2/3 on another, and --multiminer=3/3 on the last one. If you want one to do 10% of blocks and two others to do 45% each, --multiminer=1-10/100 on the first, and --multiminer=11-55 and --multiminer=56-100 on the others. Note that which miner mines which block is determined by the previous block hash, so occasional runs of one miner doing many blocks in a row is to be expected.
When --multiminer is used, if a miner is down and does not mine a block within five minutes of when it is due, the other miners will automatically act as redundant backups ensuring the chain does not halt. The --backup-delay parameter can be used to change how long a given miner waits, allowing one to be the primary backup (after five minutes) and another to be the secondary backup (after six minutes, eg).
The --standby-delay parameter can be used to make a backup miner that only mines if a block doesn't arrive on time. This can be combined with --multiminer if desired. Setting --standby-delay also prevents the first block from being mined immediately.
## Misc
[min.sc policy](https://min.sc/#c=A%20%3D%2002e240f3e2e2a4ef79e03fbd0e3afb999997ddbce14c250e73d2f6b7af97f941f7%3B%0AB%20%3D%20038c761f9fa1b29191011ef95acf76328355bc086b8706f79bce931e55075bd978%3B%0AC%20%3D%200274fac0536a8e7f384dea2b1e209893d3a043c53d835389b80082a8fbf8d5401d%3B%0AD%20%3D%200353e6b2589f6c5872b0a9cd424af60923f73ac5c081fc30ea99f6e5f188f3ad65%3B%0A%0A1%20of%20%5B%20pk%28A%29%2C%20pk%28B%29%2C%20pk%28C%29%2C%20pk%28D%29%20%5D)