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
25cf36cb
Commit
25cf36cb
authored
Jan 20, 2021
by
madengji
Committed by
vipwzw
Sep 18, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add proof
parent
0ccc4d97
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
261 additions
and
165 deletions
+261
-165
authorize.go
plugin/dapp/mix/cmd/gnark/circuit/authorize/authorize.go
+4
-0
authorize_test.go
...in/dapp/mix/cmd/gnark/circuit/authorize/authorize_test.go
+1
-1
deposit.go
plugin/dapp/mix/cmd/gnark/circuit/deposit/deposit.go
+3
-3
withdraw.go
plugin/dapp/mix/cmd/gnark/circuit/withdraw/withdraw.go
+1
-0
mix.go
plugin/dapp/mix/commands/mix.go
+0
-0
committree.go
plugin/dapp/mix/executor/committree.go
+2
-6
config.go
plugin/dapp/mix/executor/config.go
+55
-33
deposit.go
plugin/dapp/mix/executor/deposit.go
+10
-12
kv.go
plugin/dapp/mix/executor/kv.go
+9
-3
mix.go
plugin/dapp/mix/executor/mix.go
+21
-0
query.go
plugin/dapp/mix/executor/query.go
+7
-1
mix.proto
plugin/dapp/mix/proto/mix.proto
+76
-19
rpc.go
plugin/dapp/mix/rpc/rpc.go
+45
-0
mix.go
plugin/dapp/mix/types/mix.go
+1
-0
mix.pb.go
plugin/dapp/mix/types/mix.pb.go
+0
-0
exec.go
plugin/dapp/mix/wallet/exec.go
+8
-0
mix.go
plugin/dapp/mix/wallet/mix.go
+10
-72
mixbizdb.go
plugin/dapp/mix/wallet/mixbizdb.go
+8
-12
mixbiztable.go
plugin/dapp/mix/wallet/mixbiztable.go
+0
-3
No files found.
plugin/dapp/mix/cmd/gnark/circuit/authorize/authorize.go
View file @
25cf36cb
...
@@ -29,6 +29,7 @@ private:
...
@@ -29,6 +29,7 @@ private:
authorizePriKey
authorizePriKey
spendFlag
spendFlag
noteRandom
noteRandom
noteHash
path...
path...
helper...
helper...
...
@@ -69,6 +70,9 @@ func NewAuth() *frontend.R1CS {
...
@@ -69,6 +70,9 @@ func NewAuth() *frontend.R1CS {
//通过merkle tree保证noteHash存在,即便return,auth都是null也是存在的,则可以不经过授权即可消费
//通过merkle tree保证noteHash存在,即便return,auth都是null也是存在的,则可以不经过授权即可消费
// specify note hash constraint
// specify note hash constraint
preImage
:=
mimc
.
Hash
(
&
circuit
,
spendPubKey
,
returnPubKey
,
authPubKey
,
spendAmount
,
noteRandom
)
preImage
:=
mimc
.
Hash
(
&
circuit
,
spendPubKey
,
returnPubKey
,
authPubKey
,
spendAmount
,
noteRandom
)
noteHash
:=
circuit
.
SECRET_INPUT
(
"noteHash"
)
circuit
.
MUSTBE_EQ
(
noteHash
,
preImage
)
util
.
MerkelPathPart
(
&
circuit
,
mimc
,
preImage
)
util
.
MerkelPathPart
(
&
circuit
,
mimc
,
preImage
)
r1cs
:=
circuit
.
ToR1CS
()
r1cs
:=
circuit
.
ToR1CS
()
...
...
plugin/dapp/mix/cmd/gnark/circuit/authorize/authorize_test.go
View file @
25cf36cb
...
@@ -47,8 +47,8 @@ func TestAuthorizeSpend(t *testing.T) {
...
@@ -47,8 +47,8 @@ func TestAuthorizeSpend(t *testing.T) {
good
.
Assign
(
backend
.
Secret
,
"authorizePriKey"
,
"17822967620457187568904804290291537271142779717280482398091401115827760898835"
)
good
.
Assign
(
backend
.
Secret
,
"authorizePriKey"
,
"17822967620457187568904804290291537271142779717280482398091401115827760898835"
)
good
.
Assign
(
backend
.
Secret
,
"spendFlag"
,
"1"
)
good
.
Assign
(
backend
.
Secret
,
"spendFlag"
,
"1"
)
good
.
Assign
(
backend
.
Secret
,
"noteRandom"
,
"2824204835"
)
good
.
Assign
(
backend
.
Secret
,
"noteRandom"
,
"2824204835"
)
good
.
Assign
(
backend
.
Secret
,
"noteHash"
,
"16308793397024662832064523892418908145900866571524124093537199035808550255649"
)
//nodehash="16308793397024662832064523892418908145900866571524124093537199035808550255649"
good
.
Assign
(
backend
.
Secret
,
"path1"
,
"19561523370160677851616596032513161448778901506614020103852017946679781620105"
)
good
.
Assign
(
backend
.
Secret
,
"path1"
,
"19561523370160677851616596032513161448778901506614020103852017946679781620105"
)
good
.
Assign
(
backend
.
Secret
,
"path2"
,
"13898857070666440684265042188056372750257678232709763835292910585848522658637"
)
good
.
Assign
(
backend
.
Secret
,
"path2"
,
"13898857070666440684265042188056372750257678232709763835292910585848522658637"
)
good
.
Assign
(
backend
.
Secret
,
"path3"
,
"15019169196974879571470243100379529757970866395477207575033769902587972032431"
)
good
.
Assign
(
backend
.
Secret
,
"path3"
,
"15019169196974879571470243100379529757970866395477207575033769902587972032431"
)
...
...
plugin/dapp/mix/cmd/gnark/circuit/deposit/deposit.go
View file @
25cf36cb
...
@@ -15,7 +15,7 @@ func main() {
...
@@ -15,7 +15,7 @@ func main() {
//spend commit hash the circuit implementing
//spend commit hash the circuit implementing
/*
/*
public:
public:
no
d
eHash
no
t
eHash
amount
amount
private:
private:
...
@@ -31,7 +31,7 @@ func NewDeposit() *frontend.R1CS {
...
@@ -31,7 +31,7 @@ func NewDeposit() *frontend.R1CS {
circuit
:=
frontend
.
New
()
circuit
:=
frontend
.
New
()
//公共输入以验证
//公共输入以验证
spendValue
:=
circuit
.
PUBLIC_INPUT
(
"amount"
)
amount
:=
circuit
.
PUBLIC_INPUT
(
"amount"
)
//spend pubkey
//spend pubkey
spendPubkey
:=
circuit
.
SECRET_INPUT
(
"spendPubKey"
)
spendPubkey
:=
circuit
.
SECRET_INPUT
(
"spendPubKey"
)
...
@@ -48,7 +48,7 @@ func NewDeposit() *frontend.R1CS {
...
@@ -48,7 +48,7 @@ func NewDeposit() *frontend.R1CS {
//preImage=hash(spendPubkey, returnPubkey,AuthPubkey,spendValue,noteRandom)
//preImage=hash(spendPubkey, returnPubkey,AuthPubkey,spendValue,noteRandom)
noteHash
:=
circuit
.
PUBLIC_INPUT
(
"noteHash"
)
noteHash
:=
circuit
.
PUBLIC_INPUT
(
"noteHash"
)
// specify note hash constraint
// specify note hash constraint
preImage
:=
mimc
.
Hash
(
&
circuit
,
spendPubkey
,
returnPubkey
,
authPubkey
,
spendValue
,
noteRandom
)
preImage
:=
mimc
.
Hash
(
&
circuit
,
spendPubkey
,
returnPubkey
,
authPubkey
,
amount
,
noteRandom
)
circuit
.
MUSTBE_EQ
(
noteHash
,
preImage
)
circuit
.
MUSTBE_EQ
(
noteHash
,
preImage
)
r1cs
:=
circuit
.
ToR1CS
()
r1cs
:=
circuit
.
ToR1CS
()
...
...
plugin/dapp/mix/cmd/gnark/circuit/withdraw/withdraw.go
View file @
25cf36cb
...
@@ -29,6 +29,7 @@ private:
...
@@ -29,6 +29,7 @@ private:
spendFlag
spendFlag
authorizeFlag
authorizeFlag
noteRandom
noteRandom
noteHash
path...
path...
helper...
helper...
...
...
plugin/dapp/mix/commands/mix.go
View file @
25cf36cb
This diff is collapsed.
Click to expand it.
plugin/dapp/mix/executor/committree.go
View file @
25cf36cb
...
@@ -6,9 +6,6 @@ package executor
...
@@ -6,9 +6,6 @@ package executor
import
(
import
(
"bytes"
"bytes"
"strconv"
"strings"
dbm
"github.com/33cn/chain33/common/db"
dbm
"github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/types"
"github.com/33cn/plugin/plugin/dapp/mix/executor/merkletree"
"github.com/33cn/plugin/plugin/dapp/mix/executor/merkletree"
...
@@ -235,11 +232,10 @@ func getProveData(targetLeaf []byte, leaves [][]byte) (*mixTy.CommitTreeProve, e
...
@@ -235,11 +232,10 @@ func getProveData(targetLeaf []byte, leaves [][]byte) (*mixTy.CommitTreeProve, e
}
}
helpers
:=
merkletree
.
GenerateProofHelper
(
proofSet
,
proofIndex
,
num
)
helpers
:=
merkletree
.
GenerateProofHelper
(
proofSet
,
proofIndex
,
num
)
var
helpStr
[]
string
for
_
,
i
:=
range
helpers
{
for
_
,
i
:=
range
helpers
{
helpStr
=
append
(
helpStr
,
strconv
.
Itoa
(
i
))
prove
.
Helpers
=
append
(
prove
.
Helpers
,
uint32
(
i
))
}
}
prove
.
Helpers
=
strings
.
Join
(
helpStr
,
","
)
return
&
prove
,
nil
return
&
prove
,
nil
...
...
plugin/dapp/mix/executor/config.go
View file @
25cf36cb
...
@@ -31,24 +31,22 @@ func (a *action) Config(config *mixTy.MixConfigAction) (*types.Receipt, error) {
...
@@ -31,24 +31,22 @@ func (a *action) Config(config *mixTy.MixConfigAction) (*types.Receipt, error) {
}
}
switch
config
.
Ty
{
switch
config
.
Ty
{
case
mixTy
.
MixConfigType_VerifyKey
:
case
mixTy
.
MixConfigType_VerifyKey
:
if
config
.
Action
==
mixTy
.
MixConfigAct_Add
{
return
a
.
ConfigAddVerifyKey
(
config
.
GetVerifyKey
())
return
a
.
ConfigAddVerifyKey
(
config
.
GetVerifyKey
())
}
else
{
return
a
.
ConfigDeleteVerifyKey
(
config
.
GetVerifyKey
())
}
case
mixTy
.
MixConfigType_AuthPubKey
:
case
mixTy
.
MixConfigType_AuthPubKey
:
if
config
.
Action
==
mixTy
.
MixConfigAct_Add
{
if
config
.
Action
==
mixTy
.
MixConfigAct_Add
{
return
a
.
ConfigAddAuthPubKey
(
config
.
GetAuthPk
())
return
a
.
ConfigAddAuthPubKey
(
config
.
GetAuthPk
())
}
else
{
}
else
{
return
a
.
ConfigDeleteAuthPubKey
(
config
.
GetAuthPk
())
return
a
.
ConfigDeleteAuthPubKey
(
config
.
GetAuthPk
())
}
}
case
mixTy
.
MixConfigType_PaymentPubKey
:
return
a
.
ConfigPaymentPubKey
(
config
.
GetPaymentKey
())
}
}
return
nil
,
types
.
ErrNotFound
return
nil
,
errors
.
Wrapf
(
types
.
ErrNotFound
,
"ty=%d"
,
config
.
Ty
)
}
}
func
makeConfigVerifyKeyReceipt
(
data
*
mixTy
.
ZkVerifyKeys
)
*
types
.
Receipt
{
func
makeConfigVerifyKeyReceipt
(
data
*
mixTy
.
ZkVerifyKeys
,
ty
int32
)
*
types
.
Receipt
{
key
:=
getVerifyKeysKey
()
key
:=
getVerifyKeysKey
(
ty
)
return
&
types
.
Receipt
{
return
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
Ty
:
types
.
ExecOk
,
KV
:
[]
*
types
.
KeyValue
{
KV
:
[]
*
types
.
KeyValue
{
...
@@ -61,8 +59,8 @@ func makeConfigVerifyKeyReceipt(data *mixTy.ZkVerifyKeys) *types.Receipt {
...
@@ -61,8 +59,8 @@ func makeConfigVerifyKeyReceipt(data *mixTy.ZkVerifyKeys) *types.Receipt {
}
}
func
getVerifyKeys
(
db
dbm
.
KV
)
(
*
mixTy
.
ZkVerifyKeys
,
error
)
{
func
getVerifyKeys
(
db
dbm
.
KV
,
ty
int32
)
(
*
mixTy
.
ZkVerifyKeys
,
error
)
{
key
:=
getVerifyKeysKey
()
key
:=
getVerifyKeysKey
(
ty
)
v
,
err
:=
db
.
Get
(
key
)
v
,
err
:=
db
.
Get
(
key
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
errors
.
Wrapf
(
err
,
"get db verify key"
)
return
nil
,
errors
.
Wrapf
(
err
,
"get db verify key"
)
...
@@ -77,36 +75,19 @@ func getVerifyKeys(db dbm.KV) (*mixTy.ZkVerifyKeys, error) {
...
@@ -77,36 +75,19 @@ func getVerifyKeys(db dbm.KV) (*mixTy.ZkVerifyKeys, error) {
}
}
func
(
a
*
action
)
ConfigAddVerifyKey
(
newKey
*
mixTy
.
ZkVerifyKey
)
(
*
types
.
Receipt
,
error
)
{
func
(
a
*
action
)
ConfigAddVerifyKey
(
newKey
*
mixTy
.
ZkVerifyKey
)
(
*
types
.
Receipt
,
error
)
{
keys
,
err
:=
getVerifyKeys
(
a
.
db
)
keys
,
err
:=
getVerifyKeys
(
a
.
db
,
int32
(
newKey
.
Type
)
)
if
isNotFound
(
errors
.
Cause
(
err
))
{
if
isNotFound
(
errors
.
Cause
(
err
))
{
keys
:=
&
mixTy
.
ZkVerifyKeys
{}
keys
:=
&
mixTy
.
ZkVerifyKeys
{}
keys
.
Data
=
append
(
keys
.
Data
,
newKey
)
keys
.
Data
=
append
(
keys
.
Data
,
newKey
)
return
makeConfigVerifyKeyReceipt
(
keys
),
nil
return
makeConfigVerifyKeyReceipt
(
keys
,
int32
(
newKey
.
Type
)
),
nil
}
}
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
errors
.
Wrapf
(
err
,
"AddVerifyKey,ty=%d"
,
newKey
.
Type
)
}
keys
.
Data
=
append
(
keys
.
Data
,
newKey
)
return
makeConfigVerifyKeyReceipt
(
keys
),
nil
}
func
(
a
*
action
)
ConfigDeleteVerifyKey
(
config
*
mixTy
.
ZkVerifyKey
)
(
*
types
.
Receipt
,
error
)
{
keys
,
err
:=
getVerifyKeys
(
a
.
db
)
if
err
!=
nil
{
return
nil
,
err
}
}
//逆序保存keys,保证新的key先遍历到
keys
.
Data
=
[]
*
mixTy
.
ZkVerifyKey
{
newKey
,
keys
.
Data
[
0
]}
return
makeConfigVerifyKeyReceipt
(
keys
,
int32
(
newKey
.
Type
)),
nil
var
newKeys
mixTy
.
ZkVerifyKeys
for
_
,
v
:=
range
keys
.
Data
{
//不同类型的vk 肯定不同,
if
v
.
CurveId
==
config
.
CurveId
&&
v
.
Value
==
config
.
Value
{
continue
}
newKeys
.
Data
=
append
(
newKeys
.
Data
,
v
)
}
return
makeConfigVerifyKeyReceipt
(
&
newKeys
),
nil
}
}
func
makeConfigAuthKeyReceipt
(
data
*
mixTy
.
AuthPubKeys
)
*
types
.
Receipt
{
func
makeConfigAuthKeyReceipt
(
data
*
mixTy
.
AuthPubKeys
)
*
types
.
Receipt
{
...
@@ -169,3 +150,44 @@ func (a *action) ConfigDeleteAuthPubKey(key string) (*types.Receipt, error) {
...
@@ -169,3 +150,44 @@ func (a *action) ConfigDeleteAuthPubKey(key string) (*types.Receipt, error) {
return
makeConfigAuthKeyReceipt
(
&
newKeys
),
nil
return
makeConfigAuthKeyReceipt
(
&
newKeys
),
nil
}
}
func
makeConfigPaymentKeyReceipt
(
data
*
mixTy
.
PaymentKey
)
*
types
.
Receipt
{
key
:=
getPaymentPubKey
(
data
.
Addr
)
return
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
[]
*
types
.
KeyValue
{
{
Key
:
key
,
Value
:
types
.
Encode
(
data
)},
},
Logs
:
[]
*
types
.
ReceiptLog
{
{
Ty
:
mixTy
.
TyLogMixConfigPaymentKey
,
Log
:
types
.
Encode
(
data
)},
},
}
}
func
GetPaymentPubKey
(
db
dbm
.
KV
,
addr
string
)
(
*
mixTy
.
PaymentKey
,
error
)
{
key
:=
getPaymentPubKey
(
addr
)
v
,
err
:=
db
.
Get
(
key
)
if
err
!=
nil
{
return
nil
,
errors
.
Wrapf
(
err
,
"get db"
)
}
var
keys
mixTy
.
PaymentKey
err
=
types
.
Decode
(
v
,
&
keys
)
if
err
!=
nil
{
return
nil
,
errors
.
Wrapf
(
err
,
"decode db key"
)
}
return
&
keys
,
nil
}
func
(
a
*
action
)
ConfigPaymentPubKey
(
paykey
*
mixTy
.
PaymentKey
)
(
*
types
.
Receipt
,
error
)
{
if
paykey
==
nil
||
len
(
paykey
.
PayingKey
)
==
0
||
len
(
paykey
.
ReceivingKey
.
X
)
==
0
||
len
(
paykey
.
ReceivingKey
.
Y
)
==
0
{
return
nil
,
errors
.
Wrapf
(
types
.
ErrInvalidParam
,
"pubkey=%v"
,
paykey
)
}
//直接覆盖
return
makeConfigPaymentKeyReceipt
(
&
mixTy
.
PaymentKey
{
Addr
:
a
.
fromaddr
,
PayingKey
:
paykey
.
PayingKey
,
ReceivingKey
:
paykey
.
ReceivingKey
}),
nil
}
plugin/dapp/mix/executor/deposit.go
View file @
25cf36cb
...
@@ -24,25 +24,23 @@ func makeNullifierSetReceipt(hash string, data proto.Message) *types.Receipt {
...
@@ -24,25 +24,23 @@ func makeNullifierSetReceipt(hash string, data proto.Message) *types.Receipt {
}
}
func
zkProofVerify
(
db
dbm
.
KV
,
proof
*
mixTy
.
ZkProofInfo
,
verifyT
y
mixTy
.
VerifyType
)
error
{
func
zkProofVerify
(
db
dbm
.
KV
,
proof
*
mixTy
.
ZkProofInfo
,
t
y
mixTy
.
VerifyType
)
error
{
keys
,
err
:=
getVerifyKeys
(
db
)
keys
,
err
:=
getVerifyKeys
(
db
,
int32
(
ty
)
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
var
pass
bool
var
pass
bool
for
_
,
verifyKey
:=
range
keys
.
Data
{
for
_
,
verifyKey
:=
range
keys
.
Data
{
if
verifyKey
.
Type
==
verifyTy
{
ok
,
err
:=
zksnark
.
Verify
(
verifyKey
.
Value
,
proof
.
Proof
,
proof
.
PublicInput
)
ok
,
err
:=
zksnark
.
Verify
(
verifyKey
.
Value
,
proof
.
Proof
,
proof
.
PublicInput
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
if
!
ok
{
if
!
ok
{
continue
continue
}
pass
=
true
break
}
}
pass
=
true
break
}
}
if
!
pass
{
if
!
pass
{
return
errors
.
Wrap
(
mixTy
.
ErrZkVerifyFail
,
"verify"
)
return
errors
.
Wrap
(
mixTy
.
ErrZkVerifyFail
,
"verify"
)
...
...
plugin/dapp/mix/executor/kv.go
View file @
25cf36cb
...
@@ -11,6 +11,7 @@ import (
...
@@ -11,6 +11,7 @@ import (
var
(
var
(
verifyKeys
string
verifyKeys
string
authPubKeys
string
authPubKeys
string
paymentPubKey
string
commitTreeArchiveRoots
string
commitTreeArchiveRoots
string
commitTreeCurrentRoots
string
commitTreeCurrentRoots
string
commitTreeCurrentLeaves
string
commitTreeCurrentLeaves
string
...
@@ -23,6 +24,7 @@ var (
...
@@ -23,6 +24,7 @@ var (
func
setPrefix
()
{
func
setPrefix
()
{
verifyKeys
=
"mavl-mix-verify-keys-"
verifyKeys
=
"mavl-mix-verify-keys-"
authPubKeys
=
"mavl-mix-auth-pubkeys-"
authPubKeys
=
"mavl-mix-auth-pubkeys-"
paymentPubKey
=
"mavl-mix-payment-pubkey-"
commitTreeArchiveRoots
=
"mavl-mix-commitTree-roots-archive-"
commitTreeArchiveRoots
=
"mavl-mix-commitTree-roots-archive-"
commitTreeCurrentRoots
=
"mavl-mix-commitTree-current-roots"
commitTreeCurrentRoots
=
"mavl-mix-commitTree-current-roots"
commitTreeCurrentLeaves
=
"mavl-mix-commitTree-current-leaves-"
commitTreeCurrentLeaves
=
"mavl-mix-commitTree-current-leaves-"
...
@@ -35,14 +37,18 @@ func setPrefix() {
...
@@ -35,14 +37,18 @@ func setPrefix() {
}
}
//support multi version verify parameter setting
//support multi version verify parameter setting
func
getVerifyKeysKey
()
[]
byte
{
func
getVerifyKeysKey
(
ty
int32
)
[]
byte
{
return
[]
byte
(
fmt
.
Sprintf
(
verifyKeys
))
return
[]
byte
(
fmt
.
Sprintf
(
verifyKeys
+
"%d"
,
ty
))
}
}
func
getAuthPubKeysKey
()
[]
byte
{
func
getAuthPubKeysKey
()
[]
byte
{
return
[]
byte
(
fmt
.
Sprintf
(
authPubKeys
))
return
[]
byte
(
fmt
.
Sprintf
(
authPubKeys
))
}
}
func
getPaymentPubKey
(
addr
string
)
[]
byte
{
return
[]
byte
(
fmt
.
Sprintf
(
paymentPubKey
+
"%s"
,
addr
))
}
func
calcCommitTreeArchiveRootsKey
()
[]
byte
{
func
calcCommitTreeArchiveRootsKey
()
[]
byte
{
return
[]
byte
(
fmt
.
Sprintf
(
commitTreeArchiveRoots
))
return
[]
byte
(
fmt
.
Sprintf
(
commitTreeArchiveRoots
))
}
}
...
@@ -56,7 +62,7 @@ func calcCurrentCommitLeavesKey() []byte {
...
@@ -56,7 +62,7 @@ func calcCurrentCommitLeavesKey() []byte {
}
}
func
calcCommitTreeRootLeaves
(
rootHash
string
)
[]
byte
{
func
calcCommitTreeRootLeaves
(
rootHash
string
)
[]
byte
{
return
[]
byte
(
fmt
.
Sprintf
(
commitTreeRootLeaves
+
"s"
,
rootHash
))
return
[]
byte
(
fmt
.
Sprintf
(
commitTreeRootLeaves
+
"
%
s"
,
rootHash
))
}
}
func
calcAuthorizeHashKey
(
hash
string
)
[]
byte
{
func
calcAuthorizeHashKey
(
hash
string
)
[]
byte
{
...
...
plugin/dapp/mix/executor/mix.go
View file @
25cf36cb
...
@@ -71,3 +71,24 @@ func (m *Mix) CheckTx(tx *types.Transaction, index int) error {
...
@@ -71,3 +71,24 @@ func (m *Mix) CheckTx(tx *types.Transaction, index int) error {
return
nil
return
nil
}
}
// CheckTx check transaction
func
(
m
*
Mix
)
CheckTx
(
tx
*
types
.
Transaction
,
index
int
)
error
{
action
:=
new
(
mixTy
.
MixAction
)
if
err
:=
types
.
Decode
(
tx
.
Payload
,
action
);
err
!=
nil
{
mlog
.
Error
(
"CheckTx decode"
,
"err"
,
err
)
return
err
}
if
action
.
Ty
!=
mixTy
.
MixActionTransfer
{
// mix隐私交易,只私对私需要特殊签名验证
return
m
.
DriverBase
.
CheckTx
(
tx
,
index
)
}
_
,
_
,
err
:=
MixTransferInfoVerify
(
m
.
GetStateDB
(),
action
.
GetTransfer
())
if
err
!=
nil
{
mlog
.
Error
(
"checkTx"
,
"err"
,
err
)
return
err
}
return
nil
}
plugin/dapp/mix/executor/query.go
View file @
25cf36cb
...
@@ -10,7 +10,7 @@ import (
...
@@ -10,7 +10,7 @@ import (
mixTy
"github.com/33cn/plugin/plugin/dapp/mix/types"
mixTy
"github.com/33cn/plugin/plugin/dapp/mix/types"
)
)
// Query_GetT
itle query paracross title
// Query_GetT
reePath 根据leaf获取path 证明和roothash
func
(
m
*
Mix
)
Query_GetTreePath
(
in
*
mixTy
.
TreeInfoReq
)
(
types
.
Message
,
error
)
{
func
(
m
*
Mix
)
Query_GetTreePath
(
in
*
mixTy
.
TreeInfoReq
)
(
types
.
Message
,
error
)
{
if
in
==
nil
{
if
in
==
nil
{
return
nil
,
types
.
ErrInvalidParam
return
nil
,
types
.
ErrInvalidParam
...
@@ -60,3 +60,9 @@ func (m *Mix) Query_GetRootList(in *types.ReqNil) (types.Message, error) {
...
@@ -60,3 +60,9 @@ func (m *Mix) Query_GetRootList(in *types.ReqNil) (types.Message, error) {
func
(
m
*
Mix
)
Query_ListMixTxs
(
in
*
mixTy
.
MixTxListReq
)
(
types
.
Message
,
error
)
{
func
(
m
*
Mix
)
Query_ListMixTxs
(
in
*
mixTy
.
MixTxListReq
)
(
types
.
Message
,
error
)
{
return
m
.
listMixInfos
(
in
)
return
m
.
listMixInfos
(
in
)
}
}
// Query_PaymentPubKey 批量查询
func
(
m
*
Mix
)
Query_PaymentPubKey
(
addr
*
types
.
ReqString
)
(
types
.
Message
,
error
)
{
return
GetPaymentPubKey
(
m
.
GetStateDB
(),
addr
.
Data
)
}
plugin/dapp/mix/proto/mix.proto
View file @
25cf36cb
...
@@ -15,18 +15,11 @@ enum VerifyType{
...
@@ -15,18 +15,11 @@ enum VerifyType{
AUTHORIZE
=
4
;
AUTHORIZE
=
4
;
}
}
//区分zk 所选取的曲线,需要和gnark保持一致
enum
ZkCurveId
{
UNKNOWN
=
0
;
BLS377
=
1
;
BLS381
=
2
;
BN256
=
3
;
}
message
ZkVerifyKey
{
message
ZkVerifyKey
{
ZkCurveId
curveId
=
1
;
VerifyType
type
=
1
;
VerifyType
typ
e
=
2
;
string
valu
e
=
2
;
string
value
=
3
;
}
}
message
ZkVerifyKeys
{
message
ZkVerifyKeys
{
...
@@ -37,11 +30,18 @@ message AuthPubKeys{
...
@@ -37,11 +30,18 @@ message AuthPubKeys{
repeated
string
data
=
1
;
repeated
string
data
=
1
;
}
}
message
PaymentKey
{
string
addr
=
1
;
string
payingKey
=
2
;
PubKey
receivingKey
=
3
;
}
enum
MixConfigType
{
enum
MixConfigType
{
VerifyKey
=
0
;
VerifyKey
=
0
;
//register unify authorize pubkey
//register unify authorize pubkey
AuthPubKey
=
1
;
AuthPubKey
=
1
;
//for spender's pay pubkey register,DH secret
//for spender's pay pubkey register,DH secret
//spender注册自己的payment公钥, 用来生成DiffHellman秘钥
PaymentPubKey
=
2
;
PaymentPubKey
=
2
;
}
}
...
@@ -60,7 +60,7 @@ message MixConfigAction {
...
@@ -60,7 +60,7 @@ message MixConfigAction {
oneof
value
{
oneof
value
{
ZkVerifyKey
verifyKey
=
3
;
ZkVerifyKey
verifyKey
=
3
;
string
authPk
=
4
;
string
authPk
=
4
;
P
ubKey
paymentPk
=
5
;
P
aymentKey
paymentKey
=
5
;
}
}
}
}
...
@@ -72,7 +72,7 @@ message DHSecret{
...
@@ -72,7 +72,7 @@ message DHSecret{
//Diff-Helman 加密group, for spender, returner, authorizer to decrypt
//Diff-Helman 加密group, for spender, returner, authorizer to decrypt
message
DHSecretGroup
{
message
DHSecretGroup
{
DHSecret
spender
=
1
;
DHSecret
payment
=
1
;
DHSecret
returner
=
2
;
DHSecret
returner
=
2
;
DHSecret
authorize
=
3
;
DHSecret
authorize
=
3
;
}
}
...
@@ -184,7 +184,7 @@ message CommitTreeProve {
...
@@ -184,7 +184,7 @@ message CommitTreeProve {
repeated
string
proofSet
=
2
;
repeated
string
proofSet
=
2
;
uint32
proofIndex
=
3
;
uint32
proofIndex
=
3
;
uint32
numLeaves
=
4
;
uint32
numLeaves
=
4
;
string
helpers
=
5
;
repeated
uint32
helpers
=
5
;
}
}
message
TreeInfoReq
{
message
TreeInfoReq
{
...
@@ -259,18 +259,76 @@ message DecryptSecretData{
...
@@ -259,18 +259,76 @@ message DecryptSecretData{
}
}
//一键式获取加密数据
message
DepositProofReq
{
string
paymentAddr
=
1
;
string
returnAddr
=
2
;
string
authorizeAddr
=
3
;
string
amount
=
4
;
}
message
DepositProofResp
{
string
noteHash
=
1
;
SecretData
proof
=
2
;
DHSecretGroup
secrets
=
3
;
}
message
TreePathProof
{
string
treeRootHash
=
1
;
repeated
string
treePath
=
2
;
repeated
uint32
helpers
=
3
;
repeated
uint32
validPath
=
4
;
}
message
WithdrawProofReq
{
string
noteHash
=
1
;
}
message
WithdrawProofResp
{
SecretData
proof
=
1
;
string
nullifierHash
=
2
;
string
authSpendHash
=
3
;
string
noteHash
=
4
;
string
spendPrivKey
=
5
;
uint32
spendFlag
=
6
;
uint32
authFlag
=
7
;
TreePathProof
treeProof
=
8
;
}
message
AuthProofReq
{
string
noteHash
=
1
;
uint32
authReturn
=
2
;
}
message
AuthProofResp
{
SecretData
proof
=
1
;
string
authPubKey
=
2
;
string
authPrivKey
=
3
;
string
authHash
=
4
;
string
authSpendHash
=
5
;
string
noteHash
=
6
;
uint32
spendFlag
=
7
;
TreePathProof
treeProof
=
8
;
}
enum
NoteStatus
{
enum
NoteStatus
{
UNDEF
=
0
;
UNDEF
=
0
;
FROZEN
=
1
;
//未授权
FROZEN
=
1
;
//未授权
OPEN
=
2
;
//已授权可使用
VALID
=
2
;
//已授权可使用
CLOSE
=
3
;
//已使用
INVALID
=
3
;
//已使用
}
}
message
WalletIndexInfo
{
message
WalletIndexInfo
{
string
noteHash
=
1
;
string
noteHash
=
1
;
string
nullifier
=
2
;
string
nullifier
=
2
;
string
authSpendHash
=
3
;
string
authSpendHash
=
3
;
string
spender
=
4
;
bool
isReturner
=
4
;
string
account
=
5
;
//账户地址
string
account
=
5
;
//账户地址
NoteStatus
status
=
6
;
NoteStatus
status
=
6
;
SecretData
secret
=
7
;
SecretData
secret
=
7
;
...
@@ -287,7 +345,6 @@ message WalletMixIndexReq {
...
@@ -287,7 +345,6 @@ message WalletMixIndexReq {
string
noteHash
=
1
;
string
noteHash
=
1
;
string
nullifier
=
2
;
string
nullifier
=
2
;
string
authSpendHash
=
3
;
string
authSpendHash
=
3
;
string
spender
=
4
;
string
account
=
5
;
string
account
=
5
;
int32
status
=
6
;
int32
status
=
6
;
int32
count
=
7
;
int32
count
=
7
;
...
...
plugin/dapp/mix/rpc/rpc.go
View file @
25cf36cb
...
@@ -132,3 +132,48 @@ func (c *Jrpc) DecryptSecretData(in *mixTy.DecryptSecretData, result *json.RawMe
...
@@ -132,3 +132,48 @@ func (c *Jrpc) DecryptSecretData(in *mixTy.DecryptSecretData, result *json.RawMe
*
result
,
err
=
types
.
PBToJSON
(
reply
)
*
result
,
err
=
types
.
PBToJSON
(
reply
)
return
err
return
err
}
}
func
(
c
*
Jrpc
)
DepositProof
(
in
*
mixTy
.
DepositProofReq
,
result
*
json
.
RawMessage
)
error
{
reply
,
err
:=
c
.
cli
.
ExecWalletFunc
(
mixTy
.
MixX
,
"DepositProof"
,
in
)
if
err
!=
nil
{
return
err
}
*
result
,
err
=
types
.
PBToJSON
(
reply
)
return
err
}
func
(
c
*
Jrpc
)
AuthProof
(
in
*
mixTy
.
DepositProofReq
,
result
*
json
.
RawMessage
)
error
{
reply
,
err
:=
c
.
cli
.
ExecWalletFunc
(
mixTy
.
MixX
,
"AuthProof"
,
in
)
if
err
!=
nil
{
return
err
}
*
result
,
err
=
types
.
PBToJSON
(
reply
)
return
err
}
func
(
c
*
Jrpc
)
PayInProof
(
in
*
mixTy
.
DepositProofReq
,
result
*
json
.
RawMessage
)
error
{
reply
,
err
:=
c
.
cli
.
ExecWalletFunc
(
mixTy
.
MixX
,
"PayInProof"
,
in
)
if
err
!=
nil
{
return
err
}
*
result
,
err
=
types
.
PBToJSON
(
reply
)
return
err
}
func
(
c
*
Jrpc
)
PayOutProof
(
in
*
mixTy
.
DepositProofReq
,
result
*
json
.
RawMessage
)
error
{
reply
,
err
:=
c
.
cli
.
ExecWalletFunc
(
mixTy
.
MixX
,
"PayOutProof"
,
in
)
if
err
!=
nil
{
return
err
}
*
result
,
err
=
types
.
PBToJSON
(
reply
)
return
err
}
func
(
c
*
Jrpc
)
WithdrawProof
(
in
*
mixTy
.
WithdrawProofReq
,
result
*
json
.
RawMessage
)
error
{
reply
,
err
:=
c
.
cli
.
ExecWalletFunc
(
mixTy
.
MixX
,
"WithdrawProof"
,
in
)
if
err
!=
nil
{
return
err
}
*
result
,
err
=
types
.
PBToJSON
(
reply
)
return
err
}
plugin/dapp/mix/types/mix.go
View file @
25cf36cb
...
@@ -28,6 +28,7 @@ const (
...
@@ -28,6 +28,7 @@ const (
TyLogNulliferSet
=
760
TyLogNulliferSet
=
760
TyLogAuthorizeSet
=
761
TyLogAuthorizeSet
=
761
TyLogAuthorizeSpendSet
=
762
TyLogAuthorizeSpendSet
=
762
TyLogMixConfigPaymentKey
=
763
)
)
//action type
//action type
...
...
plugin/dapp/mix/types/mix.pb.go
View file @
25cf36cb
This diff is collapsed.
Click to expand it.
plugin/dapp/mix/wallet/exec.go
View file @
25cf36cb
...
@@ -46,3 +46,11 @@ func (policy *mixPolicy) On_EncryptSecretData(req *mixTy.EncryptSecretData) (typ
...
@@ -46,3 +46,11 @@ func (policy *mixPolicy) On_EncryptSecretData(req *mixTy.EncryptSecretData) (typ
func
(
policy
*
mixPolicy
)
On_DecryptSecretData
(
req
*
mixTy
.
DecryptSecretData
)
(
types
.
Message
,
error
)
{
func
(
policy
*
mixPolicy
)
On_DecryptSecretData
(
req
*
mixTy
.
DecryptSecretData
)
(
types
.
Message
,
error
)
{
return
decryptSecretData
(
req
)
return
decryptSecretData
(
req
)
}
}
func
(
policy
*
mixPolicy
)
On_DepositProof
(
req
*
mixTy
.
DepositProofReq
)
(
types
.
Message
,
error
)
{
return
policy
.
depositProof
(
req
)
}
func
(
policy
*
mixPolicy
)
On_WithdrawProof
(
req
*
mixTy
.
WithdrawProofReq
)
(
types
.
Message
,
error
)
{
return
policy
.
withdrawProof
(
req
)
}
plugin/dapp/mix/wallet/mix.go
View file @
25cf36cb
...
@@ -7,8 +7,6 @@ package wallet
...
@@ -7,8 +7,6 @@ package wallet
import
(
import
(
"bytes"
"bytes"
"fmt"
"fmt"
"math/big"
"github.com/33cn/chain33/system/dapp"
"github.com/33cn/chain33/system/dapp"
"github.com/pkg/errors"
"github.com/pkg/errors"
...
@@ -26,10 +24,10 @@ import (
...
@@ -26,10 +24,10 @@ import (
//payment, payPrivKey=hash(privkey), payPubkey=hash(payPrivKey)
//payment, payPrivKey=hash(privkey), payPubkey=hash(payPrivKey)
//DH crypt key, prikey=payPrikey, pubKey=payPrikey*G
//DH crypt key, prikey=payPrikey, pubKey=payPrikey*G
func
newPrivacyWithPrivKey
(
privKey
[]
byte
)
(
*
mixTy
.
AccountPrivacyKey
,
error
)
{
func
newPrivacyWithPrivKey
(
privKey
[]
byte
)
(
*
mixTy
.
AccountPrivacyKey
,
error
)
{
payPrivacyKey
:=
M
imcHashByte
([][]
byte
{
privKey
})
payPrivacyKey
:=
m
imcHashByte
([][]
byte
{
privKey
})
paymentKey
:=
&
mixTy
.
PaymentKeyPair
{}
paymentKey
:=
&
mixTy
.
PaymentKeyPair
{}
paymentKey
.
SpendKey
=
getFrString
(
payPrivacyKey
)
paymentKey
.
SpendKey
=
getFrString
(
payPrivacyKey
)
paymentKey
.
PayKey
=
getFrString
(
M
imcHashByte
([][]
byte
{
payPrivacyKey
}))
paymentKey
.
PayKey
=
getFrString
(
m
imcHashByte
([][]
byte
{
payPrivacyKey
}))
shareSecretKey
:=
&
mixTy
.
ShareSecretKeyPair
{}
shareSecretKey
:=
&
mixTy
.
ShareSecretKeyPair
{}
ecdh
:=
NewCurveBn256ECDH
()
ecdh
:=
NewCurveBn256ECDH
()
...
@@ -71,13 +69,14 @@ func encryptDataWithPadding(password, data []byte) []byte {
...
@@ -71,13 +69,14 @@ func encryptDataWithPadding(password, data []byte) []byte {
return
wcom
.
CBCEncrypterPrivkey
(
password
,
paddingText
)
return
wcom
.
CBCEncrypterPrivkey
(
password
,
paddingText
)
}
}
func
encryptData
(
receiverPubKey
*
mixTy
.
PubKey
,
data
[]
byte
)
(
*
mixTy
.
PubKey
,
[]
byte
,
error
)
{
func
encryptData
(
receiverPubKey
*
mixTy
.
PubKey
,
data
[]
byte
)
*
mixTy
.
DHSecret
{
ecdh
:=
NewCurveBn256ECDH
()
ecdh
:=
NewCurveBn256ECDH
()
//generate ephemeral priv/pub key
//generate ephemeral priv/pub key
ephPriv
,
ephPub
:=
ecdh
.
GenerateKey
(
nil
)
ephPriv
,
ephPub
:=
ecdh
.
GenerateKey
(
nil
)
password
,
_
:=
ecdh
.
GenerateSharedSecret
(
ephPriv
,
receiverPubKey
)
password
,
_
:=
ecdh
.
GenerateSharedSecret
(
ephPriv
,
receiverPubKey
)
encrypt
:=
encryptDataWithPadding
(
password
,
data
)
return
ephPub
,
encryptDataWithPadding
(
password
,
data
),
nil
return
&
mixTy
.
DHSecret
{
Epk
:
ephPub
,
Secret
:
common
.
ToHex
(
encrypt
)}
}
}
...
@@ -104,25 +103,25 @@ func getFrString(v []byte) string {
...
@@ -104,25 +103,25 @@ func getFrString(v []byte) string {
return
f
.
String
()
return
f
.
String
()
}
}
func
M
imcHashString
(
params
[]
string
)
[]
byte
{
func
m
imcHashString
(
params
[]
string
)
[]
byte
{
var
sum
[]
byte
var
sum
[]
byte
for
_
,
k
:=
range
params
{
for
_
,
k
:=
range
params
{
fmt
.
Println
(
"input:"
,
k
)
//
fmt.Println("input:", k)
sum
=
append
(
sum
,
getByte
(
k
)
...
)
sum
=
append
(
sum
,
getByte
(
k
)
...
)
}
}
hash
:=
mimcHashCalc
(
sum
)
hash
:=
mimcHashCalc
(
sum
)
fmt
.
Println
(
"hash="
,
getFrString
(
hash
))
//
fmt.Println("hash=", getFrString(hash))
return
hash
return
hash
}
}
func
M
imcHashByte
(
params
[][]
byte
)
[]
byte
{
func
m
imcHashByte
(
params
[][]
byte
)
[]
byte
{
var
sum
[]
byte
var
sum
[]
byte
for
_
,
k
:=
range
params
{
for
_
,
k
:=
range
params
{
sum
=
append
(
sum
,
k
...
)
sum
=
append
(
sum
,
k
...
)
}
}
hash
:=
mimcHashCalc
(
sum
)
hash
:=
mimcHashCalc
(
sum
)
fmt
.
Println
(
"hash="
,
getFrString
(
hash
))
//
fmt.Println("hash=", getFrString(hash))
return
hash
return
hash
}
}
...
@@ -387,64 +386,3 @@ func (policy *mixPolicy) showAccountNoteInfo(addrs []string) (*mixTy.WalletIndex
...
@@ -387,64 +386,3 @@ func (policy *mixPolicy) showAccountNoteInfo(addrs []string) (*mixTy.WalletIndex
}
}
return
&
resps
,
nil
return
&
resps
,
nil
}
}
//对secretData 编码为string,同时增加随机值
func
encodeSecretData
(
secret
*
mixTy
.
SecretData
)
(
*
mixTy
.
EncodedSecretData
,
error
)
{
if
secret
==
nil
{
return
nil
,
errors
.
Wrap
(
types
.
ErrInvalidParam
,
"para is nil"
)
}
if
len
(
secret
.
PaymentPubKey
)
<=
0
{
return
nil
,
errors
.
Wrap
(
types
.
ErrInvalidParam
,
"spendPubKey is nil"
)
}
var
val
big
.
Int
ret
,
succ
:=
val
.
SetString
(
secret
.
Amount
,
10
)
if
!
succ
{
return
nil
,
errors
.
Wrapf
(
types
.
ErrInvalidParam
,
"wrong amount = %s"
,
secret
.
Amount
)
}
if
ret
.
Sign
()
<=
0
{
return
nil
,
errors
.
Wrapf
(
types
.
ErrInvalidParam
,
"amount = %s, need bigger than 0"
,
secret
.
Amount
)
}
//获取随机值
var
fr
fr_bn256
.
Element
fr
.
SetRandom
()
secret
.
NoteRandom
=
fr
.
String
()
code
:=
types
.
Encode
(
secret
)
var
resp
mixTy
.
EncodedSecretData
resp
.
Encoded
=
common
.
ToHex
(
code
)
resp
.
RawData
=
secret
return
&
resp
,
nil
}
//产生随机秘钥和receivingPk对data DH加密,返回随机秘钥的公钥
func
encryptSecretData
(
req
*
mixTy
.
EncryptSecretData
)
(
*
mixTy
.
DHSecret
,
error
)
{
secret
,
err
:=
common
.
FromHex
(
req
.
Secret
)
if
err
!=
nil
{
return
nil
,
errors
.
Wrap
(
err
,
"decode secret"
)
}
epk
,
crypt
,
err
:=
encryptData
(
req
.
ReceivingPk
,
secret
)
if
err
!=
nil
{
return
nil
,
errors
.
Wrap
(
err
,
"encrypt"
)
}
return
&
mixTy
.
DHSecret
{
Epk
:
epk
,
Secret
:
common
.
ToHex
(
crypt
)},
nil
}
func
decryptSecretData
(
req
*
mixTy
.
DecryptSecretData
)
(
*
mixTy
.
SecretData
,
error
)
{
secret
,
err
:=
common
.
FromHex
(
req
.
Secret
)
if
err
!=
nil
{
return
nil
,
errors
.
Wrap
(
err
,
"decode req.secret"
)
}
decrypt
,
err
:=
decryptData
(
req
.
ReceivingPriKey
,
req
.
Epk
,
secret
)
if
err
!=
nil
{
return
nil
,
errors
.
Wrap
(
err
,
"decrypt secret"
)
}
var
raw
mixTy
.
SecretData
err
=
types
.
Decode
(
decrypt
,
&
raw
)
if
err
!=
nil
{
return
nil
,
errors
.
Wrap
(
mixTy
.
ErrDecryptDataFail
,
"decode decrypt.secret"
)
}
return
&
raw
,
nil
}
plugin/dapp/mix/wallet/mixbizdb.go
View file @
25cf36cb
...
@@ -158,7 +158,7 @@ func updateNullifier(ldb *table.Table, nullifier string) error {
...
@@ -158,7 +158,7 @@ func updateNullifier(ldb *table.Table, nullifier string) error {
return
nil
return
nil
}
}
u
.
Info
.
Status
=
mixTy
.
NoteStatus_
CLOSE
u
.
Info
.
Status
=
mixTy
.
NoteStatus_
INVALID
return
ldb
.
Update
([]
byte
(
u
.
TxIndex
),
u
)
return
ldb
.
Update
([]
byte
(
u
.
TxIndex
),
u
)
}
}
...
@@ -174,7 +174,7 @@ func updateAuthSpend(ldb *table.Table, authSpend string) error {
...
@@ -174,7 +174,7 @@ func updateAuthSpend(ldb *table.Table, authSpend string) error {
return
nil
return
nil
}
}
u
.
Info
.
Status
=
mixTy
.
NoteStatus_
OPEN
u
.
Info
.
Status
=
mixTy
.
NoteStatus_
VALID
return
ldb
.
Update
([]
byte
(
u
.
TxIndex
),
u
)
return
ldb
.
Update
([]
byte
(
u
.
TxIndex
),
u
)
}
}
...
@@ -193,8 +193,6 @@ func (e *mixPolicy) listMixInfos(req *mixTy.WalletMixIndexReq) (types.Message, e
...
@@ -193,8 +193,6 @@ func (e *mixPolicy) listMixInfos(req *mixTy.WalletMixIndexReq) (types.Message, e
indexName
=
"nullifier"
indexName
=
"nullifier"
}
else
if
len
(
req
.
AuthSpendHash
)
>
0
{
}
else
if
len
(
req
.
AuthSpendHash
)
>
0
{
indexName
=
"authSpendHash"
indexName
=
"authSpendHash"
}
else
if
len
(
req
.
Spender
)
>
0
{
indexName
=
"spender"
}
else
if
len
(
req
.
Account
)
>
0
{
}
else
if
len
(
req
.
Account
)
>
0
{
indexName
=
"account"
indexName
=
"account"
}
else
if
req
.
Status
>
0
{
}
else
if
req
.
Status
>
0
{
...
@@ -206,7 +204,6 @@ func (e *mixPolicy) listMixInfos(req *mixTy.WalletMixIndexReq) (types.Message, e
...
@@ -206,7 +204,6 @@ func (e *mixPolicy) listMixInfos(req *mixTy.WalletMixIndexReq) (types.Message, e
NoteHash
:
req
.
NoteHash
,
NoteHash
:
req
.
NoteHash
,
Nullifier
:
req
.
Nullifier
,
Nullifier
:
req
.
Nullifier
,
AuthSpendHash
:
req
.
AuthSpendHash
,
AuthSpendHash
:
req
.
AuthSpendHash
,
Spender
:
req
.
Spender
,
Account
:
req
.
Account
,
Account
:
req
.
Account
,
Status
:
mixTy
.
NoteStatus
(
req
.
Status
),
Status
:
mixTy
.
NoteStatus
(
req
.
Status
),
}},
}},
...
@@ -271,7 +268,7 @@ func (p *mixPolicy) processSecretGroup(noteHash string, secretGroup *mixTy.DHSec
...
@@ -271,7 +268,7 @@ func (p *mixPolicy) processSecretGroup(noteHash string, secretGroup *mixTy.DHSec
}
}
//可能自己账户里面既有spender,也有returner 或authorize,都要解一遍
//可能自己账户里面既有spender,也有returner 或authorize,都要解一遍
info
,
err
:=
p
.
decodeSecret
(
noteHash
,
secretGroup
.
Spender
,
privacyKeys
)
info
,
err
:=
p
.
decodeSecret
(
noteHash
,
secretGroup
.
Payment
,
privacyKeys
)
if
err
!=
nil
{
if
err
!=
nil
{
bizlog
.
Error
(
"processSecretGroup.spender"
,
"err"
,
err
)
bizlog
.
Error
(
"processSecretGroup.spender"
,
"err"
,
err
)
}
}
...
@@ -324,18 +321,17 @@ func (p *mixPolicy) decodeSecret(noteHash string, dhSecret *mixTy.DHSecret, priv
...
@@ -324,18 +321,17 @@ func (p *mixPolicy) decodeSecret(noteHash string, dhSecret *mixTy.DHSecret, priv
//decrypted, save database
//decrypted, save database
var
info
mixTy
.
WalletIndexInfo
var
info
mixTy
.
WalletIndexInfo
info
.
NoteHash
=
noteHash
info
.
NoteHash
=
noteHash
info
.
Nullifier
=
getFrString
(
M
imcHashString
([]
string
{
rawData
.
NoteRandom
}))
info
.
Nullifier
=
getFrString
(
m
imcHashString
([]
string
{
rawData
.
NoteRandom
}))
//如果自己是spender,则记录有关spenderAuthHash,如果是returner,则记录returnerAuthHash
//如果自己是spender,则记录有关spenderAuthHash,如果是returner,则记录returnerAuthHash
//如果授权为spenderAuthHash,则spender更新本地为OPEN,returner侧仍为FROZEN,花费后,两端都变为USED
//如果授权为spenderAuthHash,则spender更新本地为OPEN,returner侧仍为FROZEN,花费后,两端都变为USED
//如果授权为returnerAuthHash,则returner更新本地为OPEN,spender侧仍为FROZEN,
//如果授权为returnerAuthHash,则returner更新本地为OPEN,spender侧仍为FROZEN,
if
rawData
.
PaymentPubKey
==
key
.
Privacy
.
PaymentKey
.
PayKey
{
if
rawData
.
PaymentPubKey
==
key
.
Privacy
.
PaymentKey
.
PayKey
{
info
.
Spender
=
rawData
.
PaymentPubKey
info
.
AuthSpendHash
=
getFrString
(
mimcHashString
([]
string
{
rawData
.
PaymentPubKey
,
rawData
.
Amount
,
rawData
.
NoteRandom
}))
info
.
AuthSpendHash
=
getFrString
(
MimcHashString
([]
string
{
rawData
.
PaymentPubKey
,
rawData
.
Amount
,
rawData
.
NoteRandom
}))
}
else
if
rawData
.
ReturnPubKey
==
key
.
Privacy
.
PaymentKey
.
PayKey
{
}
else
if
rawData
.
ReturnPubKey
==
key
.
Privacy
.
PaymentKey
.
PayKey
{
info
.
Spender
=
rawData
.
ReturnPubKey
info
.
IsReturner
=
true
info
.
AuthSpendHash
=
getFrString
(
M
imcHashString
([]
string
{
rawData
.
ReturnPubKey
,
rawData
.
Amount
,
rawData
.
NoteRandom
}))
info
.
AuthSpendHash
=
getFrString
(
m
imcHashString
([]
string
{
rawData
.
ReturnPubKey
,
rawData
.
Amount
,
rawData
.
NoteRandom
}))
}
}
info
.
Status
=
mixTy
.
NoteStatus_
OPEN
info
.
Status
=
mixTy
.
NoteStatus_
VALID
if
len
(
rawData
.
AuthorizePubKey
)
>
0
{
if
len
(
rawData
.
AuthorizePubKey
)
>
0
{
info
.
Status
=
mixTy
.
NoteStatus_FROZEN
info
.
Status
=
mixTy
.
NoteStatus_FROZEN
}
}
...
...
plugin/dapp/mix/wallet/mixbiztable.go
View file @
25cf36cb
...
@@ -23,7 +23,6 @@ var boardOpt = &table.Option{
...
@@ -23,7 +23,6 @@ var boardOpt = &table.Option{
"noteHash"
,
"noteHash"
,
"nullifier"
,
"nullifier"
,
"authSpendHash"
,
"authSpendHash"
,
"spender"
,
"account"
,
"account"
,
"status"
},
"status"
},
}
}
...
@@ -73,8 +72,6 @@ func (r *MixRow) Get(key string) ([]byte, error) {
...
@@ -73,8 +72,6 @@ func (r *MixRow) Get(key string) ([]byte, error) {
return
[]
byte
(
r
.
Info
.
Nullifier
),
nil
return
[]
byte
(
r
.
Info
.
Nullifier
),
nil
case
"authSpendHash"
:
case
"authSpendHash"
:
return
[]
byte
(
r
.
Info
.
AuthSpendHash
),
nil
return
[]
byte
(
r
.
Info
.
AuthSpendHash
),
nil
case
"spender"
:
return
[]
byte
(
r
.
Info
.
Spender
),
nil
case
"account"
:
case
"account"
:
return
[]
byte
(
r
.
Info
.
Account
),
nil
return
[]
byte
(
r
.
Info
.
Account
),
nil
case
"status"
:
case
"status"
:
...
...
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