Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
plugin
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
link33
plugin
Commits
f9c75bbd
Commit
f9c75bbd
authored
Feb 26, 2021
by
madengji
Committed by
vipwzw
Sep 18, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add parse public input
parent
62e2139c
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
148 additions
and
51 deletions
+148
-51
testcase.sh
plugin/dapp/mix/cmd/build/testcase.sh
+0
-0
input.go
plugin/dapp/mix/cmd/gnark/circuit/transfer/input/input.go
+1
-1
input_test.go
...n/dapp/mix/cmd/gnark/circuit/transfer/input/input_test.go
+1
-1
output.go
plugin/dapp/mix/cmd/gnark/circuit/transfer/output/output.go
+1
-1
output_test.go
...dapp/mix/cmd/gnark/circuit/transfer/output/output_test.go
+1
-1
mix.go
plugin/dapp/mix/commands/mix.go
+72
-1
kv.go
plugin/dapp/mix/executor/kv.go
+2
-2
query.go
plugin/dapp/mix/executor/query.go
+1
-1
mix.proto
plugin/dapp/mix/proto/mix.proto
+2
-0
mix.pb.go
plugin/dapp/mix/types/mix.pb.go
+0
-0
mixbizdb.go
plugin/dapp/mix/wallet/mixbizdb.go
+3
-0
mixbiztable.go
plugin/dapp/mix/wallet/mixbiztable.go
+4
-1
txauth.go
plugin/dapp/mix/wallet/txauth.go
+2
-2
txdeposit.go
plugin/dapp/mix/wallet/txdeposit.go
+4
-4
txtransfer.go
plugin/dapp/mix/wallet/txtransfer.go
+7
-8
txwithdraw.go
plugin/dapp/mix/wallet/txwithdraw.go
+2
-2
util.go
plugin/dapp/mix/wallet/util.go
+30
-19
util_test.go
plugin/dapp/mix/wallet/util_test.go
+15
-7
No files found.
plugin/dapp/mix/cmd/build/testcase.sh
View file @
f9c75bbd
This diff is collapsed.
Click to expand it.
plugin/dapp/mix/cmd/gnark/circuit/transfer/input/
transferI
nput.go
→
plugin/dapp/mix/cmd/gnark/circuit/transfer/input/
i
nput.go
View file @
f9c75bbd
package
input
package
main
import
(
util
"github.com/33cn/plugin/plugin/dapp/mix/cmd/gnark/circuit"
...
...
plugin/dapp/mix/cmd/gnark/circuit/transfer/input/
transfer
input_test.go
→
plugin/dapp/mix/cmd/gnark/circuit/transfer/input/input_test.go
View file @
f9c75bbd
package
input
package
main
import
(
"testing"
...
...
plugin/dapp/mix/cmd/gnark/circuit/transfer/output/
transferO
utput.go
→
plugin/dapp/mix/cmd/gnark/circuit/transfer/output/
o
utput.go
View file @
f9c75bbd
package
output
package
main
import
(
util
"github.com/33cn/plugin/plugin/dapp/mix/cmd/gnark/circuit"
...
...
plugin/dapp/mix/cmd/gnark/circuit/transfer/output/
transferO
utput_test.go
→
plugin/dapp/mix/cmd/gnark/circuit/transfer/output/
o
utput_test.go
View file @
f9c75bbd
package
output
package
main
import
(
"testing"
...
...
plugin/dapp/mix/commands/mix.go
View file @
f9c75bbd
...
...
@@ -32,6 +32,7 @@ func MixCmd() *cobra.Command {
CreateTransferRawTxCmd
(),
CreateWithdrawRawTxCmd
(),
CreateAuthRawTxCmd
(),
CreateConfigCmd
(),
QueryCmd
(),
...
...
@@ -54,7 +55,7 @@ func CreateConfigCmd() *cobra.Command {
Short
:
"Proof parameters config to mix coin contract"
,
}
cmd
.
AddCommand
(
mixConfigVerifyKeyParaCmd
())
cmd
.
AddCommand
(
mixConfigAuthPubKeyParaCmd
())
//
cmd.AddCommand(mixConfigAuthPubKeyParaCmd())
cmd
.
AddCommand
(
mixConfigPaymentPubKeyParaCmd
())
return
cmd
...
...
@@ -589,10 +590,50 @@ func SecretCmd() *cobra.Command {
cmd
.
AddCommand
(
DecodeSecretDataCmd
())
cmd
.
AddCommand
(
EncryptSecretDataCmd
())
cmd
.
AddCommand
(
DecryptSecretDataCmd
())
cmd
.
AddCommand
(
DecodePubInputDataCmd
())
return
cmd
}
// DecodePublicInputDataCmd decode zk public data
func
DecodePubInputDataCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"parse"
,
Short
:
"parse zk public input data"
,
Run
:
decodePubInput
,
}
decodePubInputCmdFlags
(
cmd
)
return
cmd
}
func
decodePubInputCmdFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"data"
,
"d"
,
""
,
"public input data"
)
cmd
.
MarkFlagRequired
(
"data"
)
cmd
.
Flags
()
.
Int32P
(
"type"
,
"t"
,
0
,
"type 0:deposit,1:withdraw,2:transIn,3:transOut,4:auth"
)
cmd
.
MarkFlagRequired
(
"type"
)
}
func
decodePubInput
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
//rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
data
,
_
:=
cmd
.
Flags
()
.
GetString
(
"data"
)
ty
,
_
:=
cmd
.
Flags
()
.
GetInt32
(
"type"
)
v
,
err
:=
mixTy
.
DecodePubInput
(
mixTy
.
VerifyType
(
ty
),
data
)
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
err
)
return
}
rst
,
err
:=
json
.
MarshalIndent
(
v
,
""
,
" "
)
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
err
)
return
}
fmt
.
Println
(
string
(
rst
))
}
// EncodeSecretDataCmd get para chain status by height
func
DecodeSecretDataCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
...
...
@@ -750,6 +791,8 @@ func depositSecretCmdFlags(cmd *cobra.Command) {
cmd
.
Flags
()
.
StringP
(
"exec"
,
"e"
,
"coins"
,
"asset executor(coins, token, paracross), default coins"
)
cmd
.
Flags
()
.
StringP
(
"path"
,
"p"
,
""
,
"deposit circuit path "
)
cmd
.
Flags
()
.
Int32P
(
"privacy"
,
"w"
,
0
,
"get zk privacy data print, 1:print, default not"
)
cmd
.
Flags
()
.
Int32P
(
"verify"
,
"v"
,
0
,
"verify on chain:0 on local:1, default 0 "
)
}
...
...
@@ -764,6 +807,8 @@ func depositSecret(cmd *cobra.Command, args []string) {
token
,
_
:=
cmd
.
Flags
()
.
GetString
(
"token"
)
path
,
_
:=
cmd
.
Flags
()
.
GetString
(
"path"
)
privacy
,
_
:=
cmd
.
Flags
()
.
GetInt32
(
"privacy"
)
verify
,
_
:=
cmd
.
Flags
()
.
GetInt32
(
"verify"
)
deposit
:=
&
mixTy
.
DepositInfo
{
ReceiverAddrs
:
targets
,
...
...
@@ -783,6 +828,8 @@ func depositSecret(cmd *cobra.Command, args []string) {
AssetExec
:
assetExec
,
AssetToken
:
token
,
Title
:
paraName
,
Privacy
:
privacy
,
Verify
:
verify
,
}
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"mix.CreateRawTransaction"
,
params
,
nil
)
...
...
@@ -822,6 +869,9 @@ func transferSecretCmdFlags(cmd *cobra.Command) {
cmd
.
Flags
()
.
StringP
(
"outpath"
,
"o"
,
""
,
"output pk file "
)
cmd
.
MarkFlagRequired
(
"outpath"
)
cmd
.
Flags
()
.
Int32P
(
"privacy"
,
"w"
,
0
,
"get zk privacy data print, 1:print, default not"
)
cmd
.
Flags
()
.
Int32P
(
"verify"
,
"v"
,
0
,
"verify on chain:0 on local:1, default 0 "
)
}
func
transferSecret
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
...
...
@@ -839,6 +889,9 @@ func transferSecret(cmd *cobra.Command, args []string) {
assetExec
,
_
:=
cmd
.
Flags
()
.
GetString
(
"exec"
)
token
,
_
:=
cmd
.
Flags
()
.
GetString
(
"token"
)
privacy
,
_
:=
cmd
.
Flags
()
.
GetInt32
(
"privacy"
)
verify
,
_
:=
cmd
.
Flags
()
.
GetInt32
(
"verify"
)
input
:=
&
mixTy
.
TransferInputTxReq
{
NoteHashs
:
noteHash
,
ZkPath
:
inpath
,
...
...
@@ -867,6 +920,8 @@ func transferSecret(cmd *cobra.Command, args []string) {
AssetExec
:
assetExec
,
AssetToken
:
token
,
Title
:
paraName
,
Privacy
:
privacy
,
Verify
:
verify
,
}
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"mix.CreateRawTransaction"
,
params
,
nil
)
...
...
@@ -896,6 +951,10 @@ func withdrawSecretCmdFlags(cmd *cobra.Command) {
cmd
.
Flags
()
.
StringP
(
"path"
,
"p"
,
""
,
"withdraw pk file "
)
cmd
.
MarkFlagRequired
(
"path"
)
cmd
.
Flags
()
.
Int32P
(
"privacy"
,
"w"
,
0
,
"get zk privacy data print, 1:print, default not"
)
cmd
.
Flags
()
.
Int32P
(
"verify"
,
"v"
,
0
,
"verify on chain:0 on local:1, default 0 "
)
}
func
withdrawSecret
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
...
...
@@ -908,6 +967,8 @@ func withdrawSecret(cmd *cobra.Command, args []string) {
token
,
_
:=
cmd
.
Flags
()
.
GetString
(
"token"
)
path
,
_
:=
cmd
.
Flags
()
.
GetString
(
"path"
)
privacy
,
_
:=
cmd
.
Flags
()
.
GetInt32
(
"privacy"
)
verify
,
_
:=
cmd
.
Flags
()
.
GetInt32
(
"verify"
)
req
:=
&
mixTy
.
WithdrawTxReq
{
TotalAmount
:
amount
,
...
...
@@ -921,6 +982,8 @@ func withdrawSecret(cmd *cobra.Command, args []string) {
AssetExec
:
assetExec
,
AssetToken
:
token
,
Title
:
paraName
,
Privacy
:
privacy
,
Verify
:
verify
,
}
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"mix.CreateRawTransaction"
,
params
,
nil
)
...
...
@@ -951,6 +1014,9 @@ func authSecretCmdFlags(cmd *cobra.Command) {
cmd
.
Flags
()
.
StringP
(
"path"
,
"p"
,
""
,
"auth path file "
)
cmd
.
MarkFlagRequired
(
"path"
)
cmd
.
Flags
()
.
Int32P
(
"privacy"
,
"w"
,
0
,
"get zk privacy data print, 1:print, default not"
)
cmd
.
Flags
()
.
Int32P
(
"verify"
,
"v"
,
0
,
"verify on chain:0 on local:1, default 0 "
)
}
func
authSecret
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
...
...
@@ -964,6 +1030,9 @@ func authSecret(cmd *cobra.Command, args []string) {
path
,
_
:=
cmd
.
Flags
()
.
GetString
(
"path"
)
privacy
,
_
:=
cmd
.
Flags
()
.
GetInt32
(
"privacy"
)
verify
,
_
:=
cmd
.
Flags
()
.
GetInt32
(
"verify"
)
req
:=
&
mixTy
.
AuthTxReq
{
AuthorizeToAddr
:
toKey
,
NoteHash
:
noteHash
,
...
...
@@ -976,6 +1045,8 @@ func authSecret(cmd *cobra.Command, args []string) {
AssetExec
:
assetExec
,
AssetToken
:
token
,
Title
:
paraName
,
Privacy
:
privacy
,
Verify
:
verify
,
}
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"mix.CreateRawTransaction"
,
params
,
nil
)
...
...
plugin/dapp/mix/executor/kv.go
View file @
f9c75bbd
...
...
@@ -26,12 +26,12 @@ func setPrefix() {
authPubKeys
=
"mavl-mix-auth-pubkeys-"
paymentPubKey
=
"mavl-mix-payment-pubkey-"
commitTreeArchiveRoots
=
"mavl-mix-commitTree-roots-archive-"
commitTreeCurrentRoots
=
"mavl-mix-commitTree-
current-roots
"
commitTreeCurrentRoots
=
"mavl-mix-commitTree-
roots-current-
"
commitTreeCurrentLeaves
=
"mavl-mix-commitTree-current-leaves-"
commitTreeRootLeaves
=
"mavl-mix-commitTree-rootLeaves-"
authorizeHash
=
"mavl-mix-authorizeHash"
authorizeSpendHash
=
"mavl-mix-authorize
Hash-spend
-"
authorizeSpendHash
=
"mavl-mix-authorize
SpendHash
-"
nullifierHash
=
"mavl-mix-nullifierHash"
}
...
...
plugin/dapp/mix/executor/query.go
View file @
f9c75bbd
...
...
@@ -69,5 +69,5 @@ func (m *Mix) Query_PaymentPubKey(addr *types.ReqString) (types.Message, error)
// Query_PaymentPubKey 批量查询
func
(
m
*
Mix
)
Query_VerifyProof
(
req
*
mixTy
.
VerifyProofInfo
)
(
types
.
Message
,
error
)
{
return
nil
,
zkProofVerify
(
m
.
GetStateDB
(),
req
.
Proof
,
req
.
Ty
)
return
&
types
.
ReqNil
{}
,
zkProofVerify
(
m
.
GetStateDB
(),
req
.
Proof
,
req
.
Ty
)
}
plugin/dapp/mix/proto/mix.proto
View file @
f9c75bbd
...
...
@@ -385,6 +385,8 @@ message CreateRawTxReq{
string
assetExec
=
2
;
string
assetToken
=
3
;
string
title
=
6
;
//平行链名字
int32
privacy
=
7
;
//1:打印隐私数据
int32
verify
=
8
;
//0:链上验证,1:本地验证
}
...
...
plugin/dapp/mix/types/mix.pb.go
View file @
f9c75bbd
This diff is collapsed.
Click to expand it.
plugin/dapp/mix/wallet/mixbizdb.go
View file @
f9c75bbd
...
...
@@ -224,6 +224,9 @@ func (p *mixPolicy) listMixInfos(req *mixTy.WalletMixIndexReq) (types.Message, e
indexName
=
"authSpendHash"
}
else
if
len
(
req
.
Account
)
>
0
{
indexName
=
"account"
if
req
.
Status
>
0
{
indexName
=
"owner_status"
}
}
else
if
req
.
Status
>
0
{
indexName
=
"status"
}
...
...
plugin/dapp/mix/wallet/mixbiztable.go
View file @
f9c75bbd
...
...
@@ -25,7 +25,8 @@ var boardOpt = &table.Option{
"authHash"
,
"authSpendHash"
,
"account"
,
"status"
},
"status"
,
"owner_status"
},
}
//NewStageTable 新建表
...
...
@@ -79,6 +80,8 @@ func (r *MixRow) Get(key string) ([]byte, error) {
return
[]
byte
(
r
.
Info
.
Account
),
nil
case
"status"
:
return
[]
byte
(
fmt
.
Sprintf
(
"%2d"
,
r
.
Info
.
Status
)),
nil
case
"owner_status"
:
return
[]
byte
(
fmt
.
Sprintf
(
"%s_%2d"
,
r
.
Info
.
Account
,
r
.
Info
.
Status
)),
nil
default
:
return
nil
,
types
.
ErrNotFound
}
...
...
plugin/dapp/mix/wallet/txauth.go
View file @
f9c75bbd
...
...
@@ -134,12 +134,12 @@ func (p *mixPolicy) createAuthTx(req *mixTy.CreateRawTxReq) (*types.Transaction,
return
nil
,
err
}
proofInfo
,
err
:=
getZkProofKeys
(
auth
.
ZkPath
+
mixTy
.
AuthCircuit
,
auth
.
ZkPath
+
mixTy
.
AuthPk
,
*
input
)
proofInfo
,
err
:=
getZkProofKeys
(
auth
.
ZkPath
+
mixTy
.
AuthCircuit
,
auth
.
ZkPath
+
mixTy
.
AuthPk
,
*
input
,
req
.
Privacy
)
if
err
!=
nil
{
return
nil
,
errors
.
Wrapf
(
err
,
"getZkProofKeys note=%s"
,
auth
.
NoteHash
)
}
//verify
if
err
:=
p
.
verifyProofOnChain
(
mixTy
.
VerifyType_AUTHORIZE
,
proofInfo
,
auth
.
ZkPath
+
mixTy
.
AuthVk
);
err
!=
nil
{
if
err
:=
p
.
verifyProofOnChain
(
mixTy
.
VerifyType_AUTHORIZE
,
proofInfo
,
auth
.
ZkPath
+
mixTy
.
AuthVk
,
req
.
Verify
);
err
!=
nil
{
return
nil
,
errors
.
Wrapf
(
err
,
"verifyProof fail for note=%s"
,
auth
.
NoteHash
)
}
...
...
plugin/dapp/mix/wallet/txdeposit.go
View file @
f9c75bbd
...
...
@@ -128,7 +128,7 @@ func (p *mixPolicy) depositParams(receiver, returner, auth, amount string) (*mix
}
func
(
p
*
mixPolicy
)
getDepositProof
(
receiver
,
returner
,
auth
,
amount
,
zkPath
string
)
(
*
mixTy
.
ZkProofInfo
,
error
)
{
func
(
p
*
mixPolicy
)
getDepositProof
(
receiver
,
returner
,
auth
,
amount
,
zkPath
string
,
verifyOnChain
,
privacyPrint
int32
)
(
*
mixTy
.
ZkProofInfo
,
error
)
{
resp
,
err
:=
p
.
depositParams
(
receiver
,
returner
,
auth
,
amount
)
if
err
!=
nil
{
...
...
@@ -143,13 +143,13 @@ func (p *mixPolicy) getDepositProof(receiver, returner, auth, amount, zkPath str
input
.
ReturnPubKey
=
resp
.
Proof
.
ReturnKey
input
.
NoteRandom
=
resp
.
Proof
.
NoteRandom
proofInfo
,
err
:=
getZkProofKeys
(
zkPath
+
mixTy
.
DepositCircuit
,
zkPath
+
mixTy
.
DepositPk
,
input
)
proofInfo
,
err
:=
getZkProofKeys
(
zkPath
+
mixTy
.
DepositCircuit
,
zkPath
+
mixTy
.
DepositPk
,
input
,
privacyPrint
)
if
err
!=
nil
{
return
nil
,
err
}
//线上验证proof,失败的原因有可能circuit,Pk和线上vk不匹配,或不是一起产生的版本
if
err
:=
p
.
verifyProofOnChain
(
mixTy
.
VerifyType_DEPOSIT
,
proofInfo
,
zkPath
+
mixTy
.
DepositVk
);
err
!=
nil
{
if
err
:=
p
.
verifyProofOnChain
(
mixTy
.
VerifyType_DEPOSIT
,
proofInfo
,
zkPath
+
mixTy
.
DepositVk
,
verifyOnChain
);
err
!=
nil
{
return
nil
,
errors
.
Wrap
(
err
,
"verifyProof fail"
)
}
proofInfo
.
Secrets
=
resp
.
Secrets
...
...
@@ -180,7 +180,7 @@ func (p *mixPolicy) createDepositTx(req *mixTy.CreateRawTxReq) (*types.Transacti
var
proofs
[]
*
mixTy
.
ZkProofInfo
for
i
,
rcv
:=
range
receivers
{
p
,
err
:=
p
.
getDepositProof
(
rcv
,
deposit
.
Deposit
.
ReturnAddr
,
deposit
.
Deposit
.
AuthorizeAddr
,
amounts
[
i
],
deposit
.
ZkPath
)
p
,
err
:=
p
.
getDepositProof
(
rcv
,
deposit
.
Deposit
.
ReturnAddr
,
deposit
.
Deposit
.
AuthorizeAddr
,
amounts
[
i
],
deposit
.
ZkPath
,
req
.
Verify
,
req
.
Privacy
)
if
err
!=
nil
{
return
nil
,
errors
.
Wrapf
(
err
,
"get Deposit proof for=%s"
,
rcv
)
}
...
...
plugin/dapp/mix/wallet/txtransfer.go
View file @
f9c75bbd
...
...
@@ -93,7 +93,6 @@ type TransferOutput struct {
}
func
(
p
*
mixPolicy
)
getTransferInputPart
(
note
*
mixTy
.
WalletNoteInfo
)
(
*
TransferInput
,
error
)
{
//get spend privacy key
privacyKey
,
err
:=
p
.
getAccountPrivacyKey
(
note
.
Account
)
if
err
!=
nil
{
...
...
@@ -101,7 +100,7 @@ func (p *mixPolicy) getTransferInputPart(note *mixTy.WalletNoteInfo) (*TransferI
}
if
privacyKey
.
Privacy
.
PaymentKey
.
ReceiveKey
!=
note
.
Secret
.
ReceiverKey
&&
privacyKey
.
Privacy
.
PaymentKey
.
ReceiveKey
!=
note
.
Secret
.
ReturnKey
{
return
nil
,
errors
.
Wrapf
(
types
.
ErrInvalidParam
,
"
payment pubkey from note=%s not match from privacyK
ey=%s,for account =%s"
,
return
nil
,
errors
.
Wrapf
(
types
.
ErrInvalidParam
,
"
receiver key from note=%s not match from k
ey=%s,for account =%s"
,
note
.
Secret
.
ReceiverKey
,
privacyKey
.
Privacy
.
PaymentKey
.
ReceiveKey
,
note
.
Account
)
}
...
...
@@ -367,32 +366,32 @@ func (p *mixPolicy) createTransferTx(req *mixTy.CreateRawTxReq) (*types.Transact
//verify input
var
inputProofs
[]
*
mixTy
.
ZkProofInfo
for
i
,
input
:=
range
inputParts
{
inputProof
,
err
:=
getZkProofKeys
(
transfer
.
Input
.
ZkPath
+
mixTy
.
TransInputCircuit
,
transfer
.
Input
.
ZkPath
+
mixTy
.
TransInputPk
,
*
input
)
inputProof
,
err
:=
getZkProofKeys
(
transfer
.
Input
.
ZkPath
+
mixTy
.
TransInputCircuit
,
transfer
.
Input
.
ZkPath
+
mixTy
.
TransInputPk
,
*
input
,
req
.
Privacy
)
if
err
!=
nil
{
return
nil
,
errors
.
Wrapf
(
err
,
"verify.input getZkProofKeys,the i=%d"
,
i
)
}
if
err
:=
p
.
verifyProofOnChain
(
mixTy
.
VerifyType_TRANSFERINPUT
,
inputProof
,
transfer
.
Input
.
ZkPath
+
mixTy
.
TransInputVk
);
err
!=
nil
{
if
err
:=
p
.
verifyProofOnChain
(
mixTy
.
VerifyType_TRANSFERINPUT
,
inputProof
,
transfer
.
Input
.
ZkPath
+
mixTy
.
TransInputVk
,
req
.
Verify
);
err
!=
nil
{
return
nil
,
errors
.
Wrapf
(
err
,
"input verifyProof fail,the i=%d"
,
i
)
}
inputProofs
=
append
(
inputProofs
,
inputProof
)
}
//verify output
outputProof
,
err
:=
getZkProofKeys
(
transfer
.
Output
.
ZkPath
+
mixTy
.
TransOutputCircuit
,
transfer
.
Output
.
ZkPath
+
mixTy
.
TransOutputPk
,
*
outPart
)
outputProof
,
err
:=
getZkProofKeys
(
transfer
.
Output
.
ZkPath
+
mixTy
.
TransOutputCircuit
,
transfer
.
Output
.
ZkPath
+
mixTy
.
TransOutputPk
,
*
outPart
,
req
.
Privacy
)
if
err
!=
nil
{
return
nil
,
errors
.
Wrapf
(
err
,
"output getZkProofKeys"
)
}
if
err
:=
p
.
verifyProofOnChain
(
mixTy
.
VerifyType_TRANSFEROUTPUT
,
outputProof
,
transfer
.
Output
.
ZkPath
+
mixTy
.
TransOutputVk
);
err
!=
nil
{
if
err
:=
p
.
verifyProofOnChain
(
mixTy
.
VerifyType_TRANSFEROUTPUT
,
outputProof
,
transfer
.
Output
.
ZkPath
+
mixTy
.
TransOutputVk
,
req
.
Verify
);
err
!=
nil
{
return
nil
,
errors
.
Wrapf
(
err
,
"output verifyProof fail"
)
}
outputProof
.
Secrets
=
outDHSecret
//verify change
changeProof
,
err
:=
getZkProofKeys
(
transfer
.
Output
.
ZkPath
+
mixTy
.
TransOutputCircuit
,
transfer
.
Output
.
ZkPath
+
mixTy
.
TransOutputPk
,
*
changePart
)
changeProof
,
err
:=
getZkProofKeys
(
transfer
.
Output
.
ZkPath
+
mixTy
.
TransOutputCircuit
,
transfer
.
Output
.
ZkPath
+
mixTy
.
TransOutputPk
,
*
changePart
,
req
.
Privacy
)
if
err
!=
nil
{
return
nil
,
errors
.
Wrapf
(
err
,
"change getZkProofKeys"
)
}
if
err
:=
p
.
verifyProofOnChain
(
mixTy
.
VerifyType_TRANSFEROUTPUT
,
changeProof
,
transfer
.
Output
.
ZkPath
+
mixTy
.
TransOutputVk
);
err
!=
nil
{
if
err
:=
p
.
verifyProofOnChain
(
mixTy
.
VerifyType_TRANSFEROUTPUT
,
changeProof
,
transfer
.
Output
.
ZkPath
+
mixTy
.
TransOutputVk
,
req
.
Verify
);
err
!=
nil
{
return
nil
,
errors
.
Wrapf
(
err
,
"change verifyProof fail"
)
}
changeProof
.
Secrets
=
changeDHSecret
...
...
plugin/dapp/mix/wallet/txwithdraw.go
View file @
f9c75bbd
...
...
@@ -139,12 +139,12 @@ func (p *mixPolicy) createWithdrawTx(req *mixTy.CreateRawTxReq) (*types.Transact
return
nil
,
errors
.
Wrapf
(
err
,
"getWithdrawParams note=%s"
,
note
)
}
proofInfo
,
err
:=
getZkProofKeys
(
withdraw
.
ZkPath
+
mixTy
.
WithdrawCircuit
,
withdraw
.
ZkPath
+
mixTy
.
WithdrawPk
,
*
input
)
proofInfo
,
err
:=
getZkProofKeys
(
withdraw
.
ZkPath
+
mixTy
.
WithdrawCircuit
,
withdraw
.
ZkPath
+
mixTy
.
WithdrawPk
,
*
input
,
req
.
Privacy
)
if
err
!=
nil
{
return
nil
,
errors
.
Wrapf
(
err
,
"getZkProofKeys note=%s"
,
note
)
}
//verify
if
err
:=
p
.
verifyProofOnChain
(
mixTy
.
VerifyType_WITHDRAW
,
proofInfo
,
withdraw
.
ZkPath
+
mixTy
.
WithdrawVk
);
err
!=
nil
{
if
err
:=
p
.
verifyProofOnChain
(
mixTy
.
VerifyType_WITHDRAW
,
proofInfo
,
withdraw
.
ZkPath
+
mixTy
.
WithdrawVk
,
req
.
Verify
);
err
!=
nil
{
return
nil
,
errors
.
Wrapf
(
err
,
"verifyProof fail for note=%s"
,
note
)
}
...
...
plugin/dapp/mix/wallet/util.go
View file @
f9c75bbd
...
...
@@ -87,9 +87,9 @@ func decryptSecretData(req *mixTy.DecryptSecretData) (*mixTy.SecretData, error)
return
&
raw
,
nil
}
func
(
p
*
mixPolicy
)
verifyProofOnChain
(
ty
mixTy
.
VerifyType
,
proof
*
mixTy
.
ZkProofInfo
,
vkPath
string
)
error
{
func
(
p
*
mixPolicy
)
verifyProofOnChain
(
ty
mixTy
.
VerifyType
,
proof
*
mixTy
.
ZkProofInfo
,
vkPath
string
,
verifyOnChain
int32
)
error
{
//vkpath verify
if
len
(
vkPath
)
>
0
{
if
verifyOnChain
>
0
&&
len
(
vkPath
)
>
0
{
vk
,
err
:=
getVerifyKey
(
vkPath
)
if
err
!=
nil
{
return
errors
.
Wrapf
(
err
,
"getVerifyKey path=%s"
,
vkPath
)
...
...
@@ -111,11 +111,7 @@ func (p *mixPolicy) verifyProofOnChain(ty mixTy.VerifyType, proof *mixTy.ZkProof
Proof
:
proof
,
}
//onchain verify
_
,
err
:=
p
.
walletOperate
.
GetAPI
()
.
QueryChain
(
&
types
.
ChainExecutor
{
Driver
:
"mix"
,
FuncName
:
"VerifyProof"
,
Param
:
types
.
Encode
(
verify
),
})
_
,
err
:=
p
.
walletOperate
.
GetAPI
()
.
Query
(
mixTy
.
MixX
,
"VerifyProof"
,
verify
)
return
err
}
...
...
@@ -284,19 +280,34 @@ func updateTreePath(obj interface{}, treeProof *mixTy.TreePathProof) {
}
}
//func printObj(obj interface{}) {
// tv := reflect.ValueOf(obj)
// for i:=0;i<tv.NumField();i++{
// name := tv.Field(i).Elem()
// }
// for i, t := range treeProof.TreePath {
// tv.Elem().FieldByName("Path" + strconv.Itoa(i)).SetString(t)
// tv.Elem().FieldByName("Helper" + strconv.Itoa(i)).SetString(strconv.Itoa(int(treeProof.Helpers[i])))
// tv.Elem().FieldByName("Valid" + strconv.Itoa(i)).SetString("1")
// }
//}
func
printObj
(
obj
interface
{})
{
ty
:=
reflect
.
TypeOf
(
obj
)
tv
:=
reflect
.
ValueOf
(
obj
)
n
:=
ty
.
NumField
()
for
i
:=
0
;
i
<
n
;
i
++
{
name
:=
ty
.
Field
(
i
)
.
Name
v
,
ok
:=
ty
.
Field
(
i
)
.
Tag
.
Lookup
(
"tag"
)
if
!
ok
{
fmt
.
Println
(
"fieldname="
,
ty
.
Field
(
i
)
.
Name
,
"not set tag"
)
}
fmt
.
Println
(
"fieldname="
,
ty
.
Field
(
i
)
.
Name
,
"| value="
,
tv
.
FieldByName
(
name
)
.
Interface
(),
"| tag="
,
v
)
}
}
func
getZkProofKeys
(
circuitFile
,
pkFile
string
,
inputs
interface
{},
privacyPrint
int32
)
(
*
mixTy
.
ZkProofInfo
,
error
)
{
if
privacyPrint
>
0
{
fmt
.
Println
(
"--output zk parameters for circuit:"
,
circuitFile
)
rst
,
err
:=
json
.
MarshalIndent
(
inputs
,
""
,
" "
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
}
fmt
.
Println
(
string
(
rst
))
}
func
getZkProofKeys
(
circuitFile
,
pkFile
string
,
inputs
interface
{})
(
*
mixTy
.
ZkProofInfo
,
error
)
{
assignments
,
err
:=
getAssignments
(
inputs
)
if
err
!=
nil
{
return
nil
,
err
...
...
plugin/dapp/mix/wallet/util_test.go
View file @
f9c75bbd
...
...
@@ -2,6 +2,7 @@ package wallet
import
(
"encoding/hex"
"encoding/json"
"fmt"
"reflect"
"testing"
...
...
@@ -87,13 +88,20 @@ func TestGetAssignments(t *testing.T) {
_
,
ok
:=
reduceAssign
[
"ReceiverPubKey"
]
assert
.
Equal
(
t
,
ok
,
false
)
//tv := reflect.ValueOf(&deposit)
//tv.Elem().FieldByName("NoteHash").SetString("999")
////tv.FieldByName("NoteHash").Elem().SetString("999")
//assert.Equal(t,"999",deposit.NoteHash)
var
in
WithdrawInput
initTreePath
(
&
in
)
assert
.
Equal
(
t
,
"99"
,
in
.
Path1
)
tv
:=
reflect
.
ValueOf
(
&
deposit
)
tv
.
Elem
()
.
FieldByName
(
"NoteHash"
)
.
SetString
(
"999"
)
//tv.FieldByName("NoteHash").Elem().SetString("999")
assert
.
Equal
(
t
,
"999"
,
deposit
.
NoteHash
)
//var in WithdrawInput
//initTreePath(&in)
//assert.Equal(t, "99", in.Path1)
printObj
(
deposit
)
rst
,
err
:=
json
.
MarshalIndent
(
deposit
,
""
,
" "
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
return
}
fmt
.
Println
(
string
(
rst
))
}
func
TestVerifyProof
(
t
*
testing
.
T
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment