Pebble Coding

ソフトウェアエンジニアによるIT技術、数学の備忘録

grin のトランザクションフローのメモ

こちらにgrinのトランザクションフローについての図が上がっていたので、テキストに落としておく。
まだソースを追っているところだったが、このフロー図で理解が進みやすくなる気がする。
この図はどこから入手したんだろ。

MimblewimbleとGrinのトランザクションフロー - Develop with pleasure!

なお、2018年10月10日時点のマスターブランチの状態のようなので、最新ではない。

Current Grin Transaction Workflow
Accurate as of Oct 10, 2018 - Master branch only

変数の接頭辞について
x: 秘匿するべき値(private)
o: オフセット値
k: ナンス値
s: シュノア署名
S: 送信者(sender)
R: 受信者(receipient)

Round 1, 送信者の処理

1: Create Transaction UUID (for reference and maintaining corrent state)
2: Set lock_height for transaction kernel (current chain height)
3: Select inputs using desired selection strategy
4: Calculate sum inputs blinding factors xI
5: Create change_output
6: Select blinding factor xC for change_output
7: Create lock function sF that locks inputs and stores change_output in wallet
and identifying wallet transaction log entry TS linking inputs + outputs
(Not executed at this point)
8: Calculate tx_weight: MAX( -1 * num_inputs + 4 * (num_change_outputs + 1), 1)
(+1 covers a single output on the receiver's side)
9: Calculate fee: tx_weight * 1_000_000 nG
10: Calculate total blinding execess sum for all inputs and outputs xS1 = xC - xI (private scalar)
11: Select a random nonce kS (private scalar)
12: Subtract random kernel offset oS from xS1. Calculate xS = xS1 - oS
13: Multiply xS and kS by generator G to create public curve points xSG and kSG
14. Add values to Slate for passing to other participants: UUID, inputs, change_outputs,
fee, amount, lock_height, kSG, xSG, oS

送信者は Slate の内容を受信者に直接送る.
MimbleWimble にはビットコインのように、アドレスという概念が存在しないので、トランザクションを作成する際には送信者と
受信者が通信できる状態でなければならない。
ただし、直接送受信するとプライバシーの問題が生じるので、ここには別の技術が使われているが、
長くなるので省略する。

Round 2, 受信者の処理

1: Check fee against number of inputs, change_outputs + 1 * receiver_output
2: Create receiver_output
3: Choose random blinding factor for receiver_output xR (private scalar)
4: Calculate message M= fee | lock_height
5: Choose random nonce kR (private scalar)
6: Multiply xR and kR by generator G to create public curve points xRG and kRG
7: Compute Schnorr challenge e = SHA256(kRG + kSG|xRG + xSG|M)
8: Compute Recipient Schnorr signature sR = kR + e * xR
9: Add sR, xRG, kRG to Slate
10: Create wallet output function rF that stores receiver_output in wallet with status "Unconfirmed"
and identifying transaction log entry TR linking receiver_output with transaction.

受信者は Slate の内容を送信者に送り返す.

Finalize Transaction, 送信者の処理

1: Calculate message M = fee|lock_height
2: Compute Schnorr challenge e = SHA256(kRG + kSG|xRG + xSG|M)
3: Verify sR by verifying kRG + e * xRG = sRG
4: Compute Sender Schnorr signature sS = kS + e * xS
5: Calculate final signature s = (kSG + kRG, sS + sR)
6: Calculate public key for s: xG = xRG + xSG
7: Verify s against execess values in final transaction using xG
8: Create Transaction Kernel Containing:
Excess signature s
Public excess xG
fee
lock_height

9: Create final transaction tx from Slate
10: Post tx to grin node mempool

Grin Node 以降の処理

1: Grin Node send "Ok" to recipient
2: recipient send "Ok" UUID to sender
3: sender execute wallet lock function sF
4: recipient send "Confirm reciver_output" to grin node
5: recipient change status of receiver_output to "Confirmed"
6: sender send "Confirm change_output" to grin node
7: sender change status of inputs to "Spent"
8: sender change status of change_output to "Confirmed"

grinに期待する理由

完全な余談になるが、私がgrinに期待している理由をあげておく。
1. ビットコインのソースへのコミット者が多い、Blockstream社のエンジニアによるプロジェクトである。
2. ビットコインの問題点を解決しようとしている。
3. 最初からrustで書かれている。