Skip to content

Commit f34b37f

Browse files
authored
Merge pull request #112 from ChrisSon15/main
reorg of documentation and concept. delet of 'renderedForWeb' directory, uses pandoc --katex in github actions to deploy the md-files as html files to github pages.
2 parents 81d2415 + 1928bcd commit f34b37f

30 files changed

Lines changed: 320 additions & 17805 deletions

.github/workflows/deploy-pages.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Deploy MD to GitHub Pages
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: read
10+
pages: write
11+
id-token: write
12+
13+
concurrency:
14+
group: "pages"
15+
cancel-in-progress: false
16+
17+
jobs:
18+
deploy:
19+
environment:
20+
name: github-pages
21+
url: ${{ steps.deployment.outputs.page_url }}
22+
runs-on: ubuntu-latest
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v4
26+
27+
- name: Install pandoc and katex
28+
run: |
29+
sudo apt-get update && sudo apt-get install -y pandoc
30+
npm install katex
31+
32+
- name: Setup Pages
33+
uses: actions/configure-pages@v4
34+
35+
- name: Build HTML from MD
36+
run: |
37+
mkdir -p public
38+
# Find all .md files and convert them
39+
find . -name "*.md" -not -path "./target/*" -not -path "./.github/*" | while read md_file; do
40+
# Create the same directory structure in public/
41+
relative_path=$(realpath --relative-to="." "$md_file")
42+
html_file="public/${relative_path%.md}.md.html"
43+
mkdir -p "$(dirname "$html_file")"
44+
45+
echo "Converting $md_file to $html_file"
46+
pandoc "$md_file" -s -o "$html_file" --metadata title="${relative_path%.md}" --lua-filter="$GITHUB_WORKSPACE/concept/pandoc/convert_links.lua" --css="$GITHUB_WORKSPACE/concept/pandoc/fullwidth.css" --embed-resources --standalone --katex="node_modules/katex/dist/"
47+
done
48+
49+
# Copy other assets like images, and existing HTML files
50+
# We use -n to not overwrite the HTML files we just generated from MD
51+
find . -type f \( -name "*.png" -o -name "*.jpg" -o -name "*.jpeg" -o -name "*.gif" -o -name "*.svg" -o -name "*.html" -o -name "*.css" -o -name "*.js" \) -not -path "./target/*" -not -path "./.github/*" -not -path "./public/*" | while read asset; do
52+
relative_path=$(realpath --relative-to="." "$asset")
53+
dest="public/$relative_path"
54+
mkdir -p "$(dirname "$dest")"
55+
cp -n "$asset" "$dest"
56+
done
57+
58+
# Create an index.html
59+
cp public/README.md.html public/index.html
60+
61+
- name: Upload artifact
62+
uses: actions/upload-pages-artifact@v3
63+
with:
64+
path: './public'
65+
66+
- name: Deploy to GitHub Pages
67+
id: deployment
68+
uses: actions/deploy-pages@v4

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
target
22
.idea
3-
/concept/tmp/
43
.classpath
54
.project
65
.settings
6+
/concept/pandoc/output/

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# bisq MuSig2 Protocol
1+
# Bisq MuSig2 Protocol
22

33
This is module inside Bisq2. it implements a new Multisig protocol for Bisq2, this protocol is similar to the protocol used in Bisq1.
44
It enables to buy/sell bitcoin from other peers without needing any trust in the other peer or into any coordinator or any third party. Since there is no intermediary to
@@ -13,12 +13,15 @@ Main changes to the Bisq1 protocol are:
1313

1414
## overview
1515

16-
This project is the handling the cryptographic part of the overall protocol. Even though it is the centerpiece there are more pieces necessary to pull this off.
16+
This project is the handling the cryptographic part of the overall protocol. Even though it is the centerpiece
17+
there are more pieces necessary to pull this off.
1718
Here is an Overview drawing:
18-
![modules](concept/renderedForWeb/bisq-musig-modules.png)
19+
20+
![modules](concept/bisq-musig-modules.png)
1921

2022
## docs
2123

24+
Detailed docs are in the [Concepts](concept/README.md) section.
2225
To get a more indepth understanding of what this module is doing, please read [SingleTxOverview](./concept/SingleTxOverview.md)
2326
This module's programming language is Rust.
2427
Technologies include:
@@ -77,5 +80,5 @@ cargo test --package protocol --lib --tests -- --nocapture
7780
## reading the Markdown files
7881

7982
Some of the markdown files have LaTeX included, you can best view them using RustRover.
80-
Github sucks at displaying LaTeX. I also keep an html-export of the markdown files
81-
in the directory 'renderedForWeb', so you can view them without RustRover.
83+
Github sucks at displaying LaTeX. There is also an html export on the github pages of the project
84+
at [github pages](https://chrisson15.github.io/bisq-musig/)

concept/MuSig2adaptor-rust.md

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,20 @@ of a 2of2 multisig such that when Alice uses it, she must reveal $t$ to Bob.
1212

1313
Let
1414

15-
$$T=t \cdot G$$
16-
17-
where \
18-
$t$ is secret adaptor, the secret which will be revealed\
19-
$T$ is public adaptor\
20-
$G$ is the Generator point of secp256k1\
21-
$m$ (the message) is the serialisation of a transaction which spends the output of the 2of2 Multisig.
15+
$$T=t \cdot G $$
16+
$$\begin{aligned}
17+
\text{where}& \hspace{1000pt} \\
18+
t & \text{ is secret adaptor, the secret which will be revealed} \\
19+
T &\text{ is public adaptor} \\
20+
G &\text{ is the Generator point of secp256k1} \\
21+
m &\text{ (the message) is the serialisation of a transaction which spends the output of the 2of2 Multisig.}
22+
\end{aligned}
23+
$$
2224

2325
The function $H_{tagged}(x_1,...,x_n)$ is a hash function where the name 'tagged' is used as literal to init the hash
2426
and if $x_i$ is a Curvepoint then we use the compressed x-key instead. Operator '||' stands for concatenation.
2527

26-
$$H_{tagged}(x_1,...,x_n):=sha256(sha256(sha256('tagged')||sha256('tagged'))||x_1||...||x_n)$$
28+
$$H_{tagged}(x_1,...,x_n):=sha256(sha256(sha256('tagged')~||~sha256('tagged'))||x_1||...||x_n)$$
2729

2830
## key aggregation
2931

@@ -37,11 +39,13 @@ Alice does the Key Aggregation in MuSig2
3739

3840
$$(1) \hspace{5pt} P = a_a \cdot P_a + a_b \cdot P_b$$
3941

40-
$ \begin{eqnarray}
41-
where \\ \hspace{5pt} a_a &=& H_{agg}(sha256(P_a,P_b),P_a) \\
42-
a_b &=& 1 \\
43-
P_a &\ne& P_b
44-
\end{eqnarray}$
42+
$$\begin{aligned}
43+
\text{where}& \\
44+
a_a &= H_{agg}(sha256(P_a,P_b),P_a) \hspace{1000pt} \\
45+
a_b &= 1 \\
46+
P_a &\ne P_b \\
47+
\end{aligned}
48+
$$
4549

4650
by calling `KeyAggContext::new([P_a,P_b])` with the pubkeys of all participants.
4751
$a_i$ is called the coefficients.
@@ -58,12 +62,12 @@ Up to here, its independent of the message and can be precalculated.
5862

5963
From collected Nonce the aggregated Nonce $R$ is calculated:
6064

61-
$\hspace{100pt}\begin{eqnarray*}
62-
(2)\hspace{5pt} R_1 &=& R_{a,1} + R_{b,1} \\
63-
R_2 &=& R_{a,2} + R_{b,2} \\
64-
b &=& H_{non}(R_1 , R_2, P, m) \\
65-
(3)\hspace{5pt} R &=& R_1 + b \cdot R_2 + T
66-
\end{eqnarray*}$
65+
$$\begin{aligned}
66+
(2)~~ R_1 &= R_{a,1} + R_{b,1} \\
67+
R_2 &= R_{a,2} + R_{b,2} \\
68+
b &= H_{non}(R_1 , R_2, P, m) \\
69+
(3)~~ R &= R_1 + b \cdot R_2 + T
70+
\end{aligned}$$
6771

6872
Note that the $T$ is added to $R$, this seperates normal MuSig2 from adaptive MuSig2.
6973
This is done via `AggNonce::sum()` and `musig2::adaptor::sign_partial(T)`. This is split into 2 methods, the aggregated Nounce is in `musig2`
@@ -100,21 +104,21 @@ pre-signature, not a valid signature.
100104
We can prove that this pre-signature is indeed a valid adaptor signature by multiplying with $G$ and
101105
setting $e:=H_{sig}(R,P,m)$:
102106

103-
$\begin{eqnarray}
104-
s\cdot G &=& s_a\cdot G+s_b\cdot G ;| \hspace{3pt} with (4) \\
105-
&=&(r_{a,1} + b \cdot r_{a,2} + a_a \cdot e \cdot p_a)\cdot G + (r_{b,1}+b \cdot r_{b,2} + a_b \cdot e \cdot p_b)\cdot G \\
106-
&=&R_{a,1}+b\cdot R_{a,2} + a_a\cdot e \cdot P_a + R_{b,1}+b\cdot R_{b,2} + a_b\cdot e \cdot P_b;| \hspace{3pt} with (2) \\
107-
&=& R_1 + b \cdot R_2 + a_a \cdot e \cdot P_a + a_b \cdot e \cdot P_b;| \hspace{3pt} with (1) \\
108-
&=& R_1 + b \cdot R_2 + e \cdot P;| \hspace{3pt} with (3) \\
109-
&=& R - T + e \cdot P
110-
\end{eqnarray}$
107+
$$\begin{aligned}
108+
s\cdot G &= s_a\cdot G+s_b\cdot G ;| ~~ with (4) \\
109+
&=(r_{a,1} + b \cdot r_{a,2} + a_a \cdot e \cdot p_a)\cdot G + (r_{b,1}+b \cdot r_{b,2} + a_b \cdot e \cdot p_b)\cdot G \\
110+
&=R_{a,1}+b\cdot R_{a,2} + a_a\cdot e \cdot P_a + R_{b,1}+b\cdot R_{b,2} + a_b\cdot e \cdot P_b;| ~~ with (2) \\
111+
&= R_1 + b \cdot R_2 + a_a \cdot e \cdot P_a + a_b \cdot e \cdot P_b;| ~~ with (1) \\
112+
&= R_1 + b \cdot R_2 + e \cdot P;| ~~ with (3) \\
113+
&= R - T + e \cdot P
114+
\end{aligned}$$
111115

112116
that means
113117

114-
$$\begin{eqnarray}
115-
s \cdot G + T &=& R+e \cdot P \\
116-
\Leftrightarrow (s + t) \cdot G &=& R + e \cdot P
117-
\end{eqnarray}$$
118+
$$\begin{aligned}
119+
s \cdot G + T &= R+e \cdot P \\
120+
\Leftrightarrow (s + t) \cdot G &= R + e \cdot P
121+
\end{aligned}$$
118122

119123
so with the discrete logarithm (DLOG) of $T$, which is $t$, we would have a valid signature.
120124

concept/ProtocolSubStates.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ substates of it. It is intended that this state maschine will be implemented in
88
Bisq2 using the FSM.
99

1010
![StateMachine.drawio.png](StateMachine.drawio.png)
11+
1112
1. signing of Txs
1213
this is already implemented in rust, basically the running test link serves as a rust
1314
implementation of what needs to be implemented in Java with FSM. Please see the [test-case here](https://github.com/bisq-network/bisq-musig/blob/main/protocol/src/lib.rs#L23).
@@ -19,29 +20,29 @@ Bisq2 using the FSM.
1920
-no substates-
2021

2122
3. Seller broadcasts SwapTx
22-
3.1. Seller broadcasts SwapTx has no additional state fpr the seller
23-
3.2. Buyer gets informed of chain-services that SwapTx is being detected, then continue with 6.
23+
1. Seller broadcasts SwapTx has no additional state for the seller
24+
2. Buyer gets informed of chain-services that SwapTx is being detected, then continue with 6.
2425

25-
4. Traders exchange secret keys for P'
26-
4.1. Seller sends hie partial key to Buyer
27-
4.2. Buyer receives a partial key from Seller
28-
4.3. continue with 7.
26+
4. Traders exchange secret keys for P'\
27+
1. Seller sends hie partial key to Buyer\
28+
1. Buyer receives a partial key from Seller
29+
1. continue with 7.
2930

30-
5. Seller or Buyer broadcast WarningTx
31+
5. Seller or Buyer broadcast WarningTx.
3132
Note that there are two (slightly) different WarningTxs for seller and buyer
32-
5.1. S or B presses the button to broadcast WarningTx
33-
5.2. B or S sees that WarningTx is confirmed on blockchain (seeing in mempool is not enough)
34-
5.3. continue with 8.
33+
1. S or B presses the button to broadcast WarningTx
34+
2. B or S sees that WarningTx is confirmed on blockchain (seeing in mempool is not enough)
35+
3. continue with 8.
3536

3637
6. No additional substates (will be one call to the rust code)
3738

3839
7. Traders exchange secret keys for Q'
39-
7.1. Buyer send private key for Q' to seller
40-
7.2. Users (Buyer and seller) get informed that the trade is over and funds can be spend.
40+
1. Buyer send private key for Q' to seller
41+
2. Users (Buyer and seller) get informed that the trade is over and funds can be spend.
4142

42-
8.+9. can be made into one state API-call for the java code.
43+
8. +9. can be made into one state API-call for the java code.
4344
Something like checkWarningKeysExchanged(...) could be called and returns true iff keys were present and funds have been transafered to wallet.
44-
9.1. Users need to be informed about funds being transferred.
45+
1. Users need to be informed about funds being transferred.
4546

4647
10. t1 expired
4748
time trigger should go off if other trader broadcasted the WarningTx and t1 expired. no substates

concept/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Concept of the Protocol Bisq-MuSig
2+
3+
## Initial idea
4+
5+
- [SingleTxOverview.md](SingleTxOverview.md)
6+
- [MuSig2adaptor-rust.md](MuSig2adaptor-rust.md)
7+
8+
## Updates to the initial idea
9+
10+
- [update.md](update.md)
11+
- [ProtocolUpdate2.md](ProtocolUpdate2.md)
12+
13+
## Different aspects in detail
14+
15+
- [OverviewWatchTowers.md](watchtower/OverviewWatchTowers.md)
16+
- [partialTransaction.md](partialTransaction.md)
17+
- [ProtocolSubStates.md](ProtocolSubStates.md)
18+
- [tradefeepayment.md](tradefees/tradefeepayment.md)
19+
- [SilentPayment.md](silentpayment/SilentPayment.md)
20+
- [SPDepositTx.md](silentpayment/SPDepositTx.md)
21+
22+
## API
23+
24+
- [API.md](API.md)

0 commit comments

Comments
 (0)