1. 引言
Zcash中的hash函式主要有:
- BLAKE2 Hash Function
- Group Hash into Jubjub
- Pedersen Hash Function
- Mixing Pedersen Hash Function
- Merkle Tree Hash Function
- C R H i v k CRH^{ivk} CRHivk Hash Function
- D i v e r s i f y H a s h S a p l i n g DiversifyHash^{Sapling} DiversifyHashSapling Hash Function
2. BLAKE2 Hash Function
BLAKE2 定義在 [ANWW2013-BLAKE2: simpler, smaller, fast as MD5] 中,BLAKE2比MD5、SHA-1、SHA-2和SHA-3的速度都快, 但是其安全性與當前最新的standard SHA-3安全性相當,
BLAKE2 主要有2個分支:
- BLAKE2b (或直接簡稱為BLAKE2) :針對64-bit平臺(含NEON-enabled ARM平臺)進行了優化,輸出的digest長度為1byte 到 64bytes,
- BLAKE2s:針對8-bit或32-bit 平臺進行了優化,輸出的digest長度為1byte 到32 bytest,

Zcash使用了 BLAKE2b 和 BLAKE2s 的變種:
-
B
L
A
K
E
2
b
?
l
(
p
,
x
)
BLAKE2b-l(p,x)
BLAKE2b?l(p,x):為unkeyed
B
L
A
K
E
2
b
?
l
:
B
Y
[
16
]
×
B
Y
[
N
]
→
B
Y
[
l
/
8
]
BLAKE2b-l: \mathbb{B}^{\mathbb{Y}^{[16]}}\times \mathbb{B}^{\mathbb{Y}^{[\mathbb{N}]}}\rightarrow \mathbb{B}^{\mathbb{Y}^{[l/8]}}
BLAKE2b?l:BY[16]×BY[N]→BY[l/8] in sequential mode,其中
p
p
p為16-byte personalization string,
x
x
x為input,輸出的digest length為
l
/
8
l/8
l/8 bytes,
BLAKE2b已用于 i S i g C R H , E q u i h a h s G e n , P R F e x p a n d , P R F o c k S a p l i n g , K D F S a p l i n g iSigCRH, EquihahsGen,PRF^{expand},PRF^{ockSapling}, KDF^{Sapling} iSigCRH,EquihahsGen,PRFexpand,PRFockSapling,KDFSapling 以及 RedJubjub signature scheme中的 S p e n d A u t h S i g S a p l i n g SpendAuthSig^{Sapling} SpendAuthSigSapling 和 B i n d i n g S i g S a p l i n g BindingSig^{Sapling} BindingSigSapling, -
B
L
A
K
E
2
s
?
l
(
p
,
x
)
BLAKE2s-l(p,x)
BLAKE2s?l(p,x):為unkeyed
B
L
A
K
E
2
s
?
l
:
B
Y
[
8
]
×
B
Y
[
N
]
→
B
Y
[
l
/
8
]
BLAKE2s-l: \mathbb{B}^{\mathbb{Y}^{[8]}}\times \mathbb{B}^{\mathbb{Y}^{[\mathbb{N}]}}\rightarrow \mathbb{B}^{\mathbb{Y}^{[l/8]}}
BLAKE2s?l:BY[8]×BY[N]→BY[l/8] in sequential mode,其中
p
p
p為8-byte personalization string,
x
x
x為input,輸出的digest length為
l
/
8
l/8
l/8 bytes,
BLAKE2s已用于 P R F n f S a p l i n g , C R H i v k , G r o u p H a s h J ( r ) ? PRF^{nfSapling},CRH^{ivk}, GroupHash^{\mathbb{J}^{(r)*}} PRFnfSapling,CRHivk,GroupHashJ(r)? ,
3. Group Hash into Jubjub
- U R S URS URS:為MPC randomness beacon,
- G r o u p H a s h J ( r ) ? . I n p u t = B Y [ 8 ] × B Y [ N ] GroupHash^{\mathbb{J}^{(r)*}}.Input=\mathbb{B}^{\mathbb{Y}^{[8]}}\times \mathbb{B}^{\mathbb{Y}^{[\mathbb{N}]}} GroupHashJ(r)?.Input=BY[8]×BY[N],其中的 B Y [ 8 ] \mathbb{B}^{\mathbb{Y}^{[8]}} BY[8]是“personalization”引數,用于區分不同用途的group hash,
- D : B Y [ 8 ] D:\mathbb{B}^{\mathbb{Y}^{[8]}} D:BY[8]:為8-byte domain separator,
- M : B Y [ N ] M:\mathbb{B}^{\mathbb{Y}^{[\mathbb{N}]}} M:BY[N]:為 hash input,
G
r
o
p
H
a
s
h
U
R
S
J
(
r
)
?
(
D
,
M
)
:
J
(
r
)
?
GropHash_{URS}^{\mathbb{J}^{(r)*}}(D,M):\mathbb{J}^{(r)*}
GropHashURSJ(r)??(D,M):J(r)? hash運算程序為:
1)
H
=
B
L
A
K
E
2
s
?
256
(
D
,
U
R
S
∣
∣
M
)
H=BLAKE2s-256(D,URS||M)
H=BLAKE2s?256(D,URS∣∣M),
2)
P
=
a
b
s
t
J
(
L
E
O
S
2
B
S
P
256
(
H
)
)
P=abst_{\mathbb{J}}(LEOS2BSP_{256}(H))
P=abstJ?(LEOS2BSP256?(H)),若
P
=
⊥
P=\perp
P=⊥,則回傳
⊥
\perp
⊥,
3)
Q
=
[
h
J
]
P
Q=[h_{\mathbb{J}}]P
Q=[hJ?]P,若
Q
=
O
J
Q=\mathcal{O}_{\mathbb{J}}
Q=OJ?,則回傳
⊥
\perp
⊥,否則回傳
Q
Q
Q,
F
i
n
d
G
r
o
u
p
H
a
s
h
J
(
r
)
?
(
D
,
M
)
FindGroupHash^{\mathbb{J}^{(r)*}}(D,M)
FindGroupHashJ(r)?(D,M) 通過 引入byte
i
i
i,使得回傳的為有效的prime group point:

4. Pedersen Hash Function
P
e
d
e
r
s
e
n
H
a
s
h
PedersenHash
PedersenHash 基于的安全假設為:
the hardness of the Discrete Logarithm Problem on the Jubjub curve,
P e d e r s e n H a s h PedersenHash PedersenHash 具有collision resistance (for fixed input length),【注意對于variable-length inputs不具有collision-resistant,】
P e d e r s e n H a s h PedersenHash PedersenHash 已用于:
- Pedersen commitment —— Windowed Pedersen commitment,
- Pedersen hash for the Sapling incremental Merkle tree —— M e r k l e C R H S a p l i n g MerkleCRH^{Sapling} MerkleCRHSapling Hash Function,

5. Mixing Pedersen Hash Function
Mixing Pedersen hash 用于 根據
c
m
cm
cm和
p
o
s
pos
pos 計算
ρ
\rho
ρ,

6. Merkle Tree Hash Function
Merkle Tree Hash Function M e r k l e C R H S a p l i n g MerkleCRH^{Sapling} MerkleCRHSapling 用于對note commitment tree進行hash,其中:
- prefix l l l 用于區分inputs所在的layer,
- M e r k l e D e p t h S a p l i n g = 32 MerkleDepth^{Sapling}=32 MerkleDepthSapling=32
- l M e r k l e S a p l i n g = 255 l_{Merkle}^{Sapling}=255 lMerkleSapling?=255

7. C R H i v k CRH^{ivk} CRHivk Hash Function
C
R
H
i
v
k
CRH^{ivk}
CRHivk 用于派生 incoming viewing key
i
v
k
ivk
ivk for a Sapling shielded payment address,
其中:
- l i v k S a p l i n g = 251 l_{ivk}^{Sapling}=251 livkSapling?=251

8. D i v e r s i f y H a s h S a p l i n g DiversifyHash^{Sapling} DiversifyHashSapling Hash Function
D
i
v
e
r
s
i
f
y
H
a
s
h
S
a
p
l
i
n
g
DiversifyHash^{Sapling}
DiversifyHashSapling 用于根據diversifier
d
d
d 派生a diversified base
g
d
g_d
gd?,基于該
g
d
g_d
gd?構建shielded payment address中的transmission key
p
k
d
=
i
v
k
?
g
d
pk_d=ivk\cdot g_d
pkd?=ivk?gd?,應滿足unlinkable屬性,即已知兩個來自不同主題的shielded payment address,無法區分新來的shielded payment address與其中的哪個主體是一樣的,

參考資料
[1] Zcash Protocol Specification
[2] BLAKE2 hash函式
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/277091.html
標籤:區塊鏈
上一篇:chia 相關參考資料
下一篇:你的迷惑,Chia大佬來親自解開
