Commit 25cf36cb authored by madengji's avatar madengji Committed by vipwzw

add proof

parent 0ccc4d97
......@@ -29,6 +29,7 @@ private:
authorizePriKey
spendFlag
noteRandom
noteHash
path...
helper...
......@@ -69,6 +70,9 @@ func NewAuth() *frontend.R1CS {
//通过merkle tree保证noteHash存在,即便return,auth都是null也是存在的,则可以不经过授权即可消费
// specify note hash constraint
preImage := mimc.Hash(&circuit, spendPubKey, returnPubKey, authPubKey, spendAmount, noteRandom)
noteHash := circuit.SECRET_INPUT("noteHash")
circuit.MUSTBE_EQ(noteHash, preImage)
util.MerkelPathPart(&circuit, mimc, preImage)
r1cs := circuit.ToR1CS()
......
......@@ -47,8 +47,8 @@ func TestAuthorizeSpend(t *testing.T) {
good.Assign(backend.Secret, "authorizePriKey", "17822967620457187568904804290291537271142779717280482398091401115827760898835")
good.Assign(backend.Secret, "spendFlag", "1")
good.Assign(backend.Secret, "noteRandom", "2824204835")
good.Assign(backend.Secret, "noteHash", "16308793397024662832064523892418908145900866571524124093537199035808550255649")
//nodehash="16308793397024662832064523892418908145900866571524124093537199035808550255649"
good.Assign(backend.Secret, "path1", "19561523370160677851616596032513161448778901506614020103852017946679781620105")
good.Assign(backend.Secret, "path2", "13898857070666440684265042188056372750257678232709763835292910585848522658637")
good.Assign(backend.Secret, "path3", "15019169196974879571470243100379529757970866395477207575033769902587972032431")
......
......@@ -15,7 +15,7 @@ func main() {
//spend commit hash the circuit implementing
/*
public:
nodeHash
noteHash
amount
private:
......@@ -31,7 +31,7 @@ func NewDeposit() *frontend.R1CS {
circuit := frontend.New()
//公共输入以验证
spendValue := circuit.PUBLIC_INPUT("amount")
amount := circuit.PUBLIC_INPUT("amount")
//spend pubkey
spendPubkey := circuit.SECRET_INPUT("spendPubKey")
......@@ -48,7 +48,7 @@ func NewDeposit() *frontend.R1CS {
//preImage=hash(spendPubkey, returnPubkey,AuthPubkey,spendValue,noteRandom)
noteHash := circuit.PUBLIC_INPUT("noteHash")
// 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)
r1cs := circuit.ToR1CS()
......
......@@ -29,6 +29,7 @@ private:
spendFlag
authorizeFlag
noteRandom
noteHash
path...
helper...
......
This diff is collapsed.
......@@ -6,9 +6,6 @@ package executor
import (
"bytes"
"strconv"
"strings"
dbm "github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/types"
"github.com/33cn/plugin/plugin/dapp/mix/executor/merkletree"
......@@ -235,11 +232,10 @@ func getProveData(targetLeaf []byte, leaves [][]byte) (*mixTy.CommitTreeProve, e
}
helpers := merkletree.GenerateProofHelper(proofSet, proofIndex, num)
var helpStr []string
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
......
......@@ -31,24 +31,22 @@ func (a *action) Config(config *mixTy.MixConfigAction) (*types.Receipt, error) {
}
switch config.Ty {
case mixTy.MixConfigType_VerifyKey:
if config.Action == mixTy.MixConfigAct_Add {
return a.ConfigAddVerifyKey(config.GetVerifyKey())
} else {
return a.ConfigDeleteVerifyKey(config.GetVerifyKey())
}
return a.ConfigAddVerifyKey(config.GetVerifyKey())
case mixTy.MixConfigType_AuthPubKey:
if config.Action == mixTy.MixConfigAct_Add {
return a.ConfigAddAuthPubKey(config.GetAuthPk())
} else {
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 {
key := getVerifyKeysKey()
func makeConfigVerifyKeyReceipt(data *mixTy.ZkVerifyKeys, ty int32) *types.Receipt {
key := getVerifyKeysKey(ty)
return &types.Receipt{
Ty: types.ExecOk,
KV: []*types.KeyValue{
......@@ -61,8 +59,8 @@ func makeConfigVerifyKeyReceipt(data *mixTy.ZkVerifyKeys) *types.Receipt {
}
func getVerifyKeys(db dbm.KV) (*mixTy.ZkVerifyKeys, error) {
key := getVerifyKeysKey()
func getVerifyKeys(db dbm.KV, ty int32) (*mixTy.ZkVerifyKeys, error) {
key := getVerifyKeysKey(ty)
v, err := db.Get(key)
if err != nil {
return nil, errors.Wrapf(err, "get db verify key")
......@@ -77,36 +75,19 @@ func getVerifyKeys(db dbm.KV) (*mixTy.ZkVerifyKeys, 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)) {
keys := &mixTy.ZkVerifyKeys{}
keys.Data = append(keys.Data, newKey)
return makeConfigVerifyKeyReceipt(keys), nil
return makeConfigVerifyKeyReceipt(keys, int32(newKey.Type)), nil
}
if err != nil {
return nil, err
}
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
return nil, errors.Wrapf(err, "AddVerifyKey,ty=%d", newKey.Type)
}
//逆序保存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 {
......@@ -169,3 +150,44 @@ func (a *action) ConfigDeleteAuthPubKey(key string) (*types.Receipt, error) {
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
}
......@@ -24,25 +24,23 @@ func makeNullifierSetReceipt(hash string, data proto.Message) *types.Receipt {
}
func zkProofVerify(db dbm.KV, proof *mixTy.ZkProofInfo, verifyTy mixTy.VerifyType) error {
keys, err := getVerifyKeys(db)
func zkProofVerify(db dbm.KV, proof *mixTy.ZkProofInfo, ty mixTy.VerifyType) error {
keys, err := getVerifyKeys(db, int32(ty))
if err != nil {
return err
}
var pass bool
for _, verifyKey := range keys.Data {
if verifyKey.Type == verifyTy {
ok, err := zksnark.Verify(verifyKey.Value, proof.Proof, proof.PublicInput)
if err != nil {
return err
}
if !ok {
continue
}
pass = true
break
ok, err := zksnark.Verify(verifyKey.Value, proof.Proof, proof.PublicInput)
if err != nil {
return err
}
if !ok {
continue
}
pass = true
break
}
if !pass {
return errors.Wrap(mixTy.ErrZkVerifyFail, "verify")
......
......@@ -11,6 +11,7 @@ import (
var (
verifyKeys string
authPubKeys string
paymentPubKey string
commitTreeArchiveRoots string
commitTreeCurrentRoots string
commitTreeCurrentLeaves string
......@@ -23,6 +24,7 @@ var (
func setPrefix() {
verifyKeys = "mavl-mix-verify-keys-"
authPubKeys = "mavl-mix-auth-pubkeys-"
paymentPubKey = "mavl-mix-payment-pubkey-"
commitTreeArchiveRoots = "mavl-mix-commitTree-roots-archive-"
commitTreeCurrentRoots = "mavl-mix-commitTree-current-roots"
commitTreeCurrentLeaves = "mavl-mix-commitTree-current-leaves-"
......@@ -35,14 +37,18 @@ func setPrefix() {
}
//support multi version verify parameter setting
func getVerifyKeysKey() []byte {
return []byte(fmt.Sprintf(verifyKeys))
func getVerifyKeysKey(ty int32) []byte {
return []byte(fmt.Sprintf(verifyKeys+"%d", ty))
}
func getAuthPubKeysKey() []byte {
return []byte(fmt.Sprintf(authPubKeys))
}
func getPaymentPubKey(addr string) []byte {
return []byte(fmt.Sprintf(paymentPubKey+"%s", addr))
}
func calcCommitTreeArchiveRootsKey() []byte {
return []byte(fmt.Sprintf(commitTreeArchiveRoots))
}
......@@ -56,7 +62,7 @@ func calcCurrentCommitLeavesKey() []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 {
......
......@@ -71,3 +71,24 @@ func (m *Mix) CheckTx(tx *types.Transaction, index int) error {
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
}
......@@ -10,7 +10,7 @@ import (
mixTy "github.com/33cn/plugin/plugin/dapp/mix/types"
)
// Query_GetTitle query paracross title
// Query_GetTreePath 根据leaf获取path 证明和roothash
func (m *Mix) Query_GetTreePath(in *mixTy.TreeInfoReq) (types.Message, error) {
if in == nil {
return nil, types.ErrInvalidParam
......@@ -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) {
return m.listMixInfos(in)
}
// Query_PaymentPubKey 批量查询
func (m *Mix) Query_PaymentPubKey(addr *types.ReqString) (types.Message, error) {
return GetPaymentPubKey(m.GetStateDB(), addr.Data)
}
......@@ -15,18 +15,11 @@ enum VerifyType{
AUTHORIZE = 4;
}
//区分zk 所选取的曲线,需要和gnark保持一致
enum ZkCurveId{
UNKNOWN = 0;
BLS377 = 1;
BLS381 = 2;
BN256 = 3;
}
message ZkVerifyKey {
ZkCurveId curveId = 1;
VerifyType type = 2;
string value = 3;
VerifyType type = 1;
string value = 2;
}
message ZkVerifyKeys{
......@@ -37,11 +30,18 @@ message AuthPubKeys{
repeated string data = 1;
}
message PaymentKey{
string addr = 1;
string payingKey = 2;
PubKey receivingKey = 3;
}
enum MixConfigType{
VerifyKey = 0;
//register unify authorize pubkey
AuthPubKey = 1;
//for spender's pay pubkey register,DH secret
//spender注册自己的payment公钥, 用来生成DiffHellman秘钥
PaymentPubKey = 2;
}
......@@ -60,7 +60,7 @@ message MixConfigAction {
oneof value {
ZkVerifyKey verifyKey = 3;
string authPk = 4;
PubKey paymentPk = 5;
PaymentKey paymentKey = 5;
}
}
......@@ -72,7 +72,7 @@ message DHSecret{
//Diff-Helman 加密group, for spender, returner, authorizer to decrypt
message DHSecretGroup{
DHSecret spender = 1;
DHSecret payment = 1;
DHSecret returner = 2;
DHSecret authorize = 3;
}
......@@ -184,7 +184,7 @@ message CommitTreeProve {
repeated string proofSet = 2;
uint32 proofIndex = 3;
uint32 numLeaves = 4;
string helpers = 5;
repeated uint32 helpers = 5;
}
message TreeInfoReq{
......@@ -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{
UNDEF = 0;
FROZEN = 1; //未授权
OPEN = 2; //已授权可使用
CLOSE = 3; //已使用
UNDEF = 0;
FROZEN = 1; //未授权
VALID = 2; //已授权可使用
INVALID = 3; //已使用
}
message WalletIndexInfo {
string noteHash = 1;
string nullifier = 2;
string authSpendHash = 3;
string spender = 4;
bool isReturner = 4;
string account = 5; //账户地址
NoteStatus status = 6;
SecretData secret = 7;
......@@ -287,7 +345,6 @@ message WalletMixIndexReq {
string noteHash = 1;
string nullifier = 2;
string authSpendHash = 3;
string spender = 4;
string account = 5;
int32 status = 6;
int32 count = 7;
......
......@@ -132,3 +132,48 @@ func (c *Jrpc) DecryptSecretData(in *mixTy.DecryptSecretData, result *json.RawMe
*result, err = types.PBToJSON(reply)
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
}
......@@ -28,6 +28,7 @@ const (
TyLogNulliferSet = 760
TyLogAuthorizeSet = 761
TyLogAuthorizeSpendSet = 762
TyLogMixConfigPaymentKey = 763
)
//action type
......
This diff is collapsed.
......@@ -46,3 +46,11 @@ func (policy *mixPolicy) On_EncryptSecretData(req *mixTy.EncryptSecretData) (typ
func (policy *mixPolicy) On_DecryptSecretData(req *mixTy.DecryptSecretData) (types.Message, error) {
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)
}
......@@ -7,8 +7,6 @@ package wallet
import (
"bytes"
"fmt"
"math/big"
"github.com/33cn/chain33/system/dapp"
"github.com/pkg/errors"
......@@ -26,10 +24,10 @@ import (
//payment, payPrivKey=hash(privkey), payPubkey=hash(payPrivKey)
//DH crypt key, prikey=payPrikey, pubKey=payPrikey*G
func newPrivacyWithPrivKey(privKey []byte) (*mixTy.AccountPrivacyKey, error) {
payPrivacyKey := MimcHashByte([][]byte{privKey})
payPrivacyKey := mimcHashByte([][]byte{privKey})
paymentKey := &mixTy.PaymentKeyPair{}
paymentKey.SpendKey = getFrString(payPrivacyKey)
paymentKey.PayKey = getFrString(MimcHashByte([][]byte{payPrivacyKey}))
paymentKey.PayKey = getFrString(mimcHashByte([][]byte{payPrivacyKey}))
shareSecretKey := &mixTy.ShareSecretKeyPair{}
ecdh := NewCurveBn256ECDH()
......@@ -71,13 +69,14 @@ func encryptDataWithPadding(password, data []byte) []byte {
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()
//generate ephemeral priv/pub key
ephPriv, ephPub := ecdh.GenerateKey(nil)
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 {
return f.String()
}
func MimcHashString(params []string) []byte {
func mimcHashString(params []string) []byte {
var sum []byte
for _, k := range params {
fmt.Println("input:", k)
//fmt.Println("input:", k)
sum = append(sum, getByte(k)...)
}
hash := mimcHashCalc(sum)
fmt.Println("hash=", getFrString(hash))
//fmt.Println("hash=", getFrString(hash))
return hash
}
func MimcHashByte(params [][]byte) []byte {
func mimcHashByte(params [][]byte) []byte {
var sum []byte
for _, k := range params {
sum = append(sum, k...)
}
hash := mimcHashCalc(sum)
fmt.Println("hash=", getFrString(hash))
//fmt.Println("hash=", getFrString(hash))
return hash
}
......@@ -387,64 +386,3 @@ func (policy *mixPolicy) showAccountNoteInfo(addrs []string) (*mixTy.WalletIndex
}
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
}
......@@ -158,7 +158,7 @@ func updateNullifier(ldb *table.Table, nullifier string) error {
return nil
}
u.Info.Status = mixTy.NoteStatus_CLOSE
u.Info.Status = mixTy.NoteStatus_INVALID
return ldb.Update([]byte(u.TxIndex), u)
}
......@@ -174,7 +174,7 @@ func updateAuthSpend(ldb *table.Table, authSpend string) error {
return nil
}
u.Info.Status = mixTy.NoteStatus_OPEN
u.Info.Status = mixTy.NoteStatus_VALID
return ldb.Update([]byte(u.TxIndex), u)
}
......@@ -193,8 +193,6 @@ func (e *mixPolicy) listMixInfos(req *mixTy.WalletMixIndexReq) (types.Message, e
indexName = "nullifier"
} else if len(req.AuthSpendHash) > 0 {
indexName = "authSpendHash"
} else if len(req.Spender) > 0 {
indexName = "spender"
} else if len(req.Account) > 0 {
indexName = "account"
} else if req.Status > 0 {
......@@ -206,7 +204,6 @@ func (e *mixPolicy) listMixInfos(req *mixTy.WalletMixIndexReq) (types.Message, e
NoteHash: req.NoteHash,
Nullifier: req.Nullifier,
AuthSpendHash: req.AuthSpendHash,
Spender: req.Spender,
Account: req.Account,
Status: mixTy.NoteStatus(req.Status),
}},
......@@ -271,7 +268,7 @@ func (p *mixPolicy) processSecretGroup(noteHash string, secretGroup *mixTy.DHSec
}
//可能自己账户里面既有spender,也有returner 或authorize,都要解一遍
info, err := p.decodeSecret(noteHash, secretGroup.Spender, privacyKeys)
info, err := p.decodeSecret(noteHash, secretGroup.Payment, privacyKeys)
if err != nil {
bizlog.Error("processSecretGroup.spender", "err", err)
}
......@@ -324,18 +321,17 @@ func (p *mixPolicy) decodeSecret(noteHash string, dhSecret *mixTy.DHSecret, priv
//decrypted, save database
var info mixTy.WalletIndexInfo
info.NoteHash = noteHash
info.Nullifier = getFrString(MimcHashString([]string{rawData.NoteRandom}))
info.Nullifier = getFrString(mimcHashString([]string{rawData.NoteRandom}))
//如果自己是spender,则记录有关spenderAuthHash,如果是returner,则记录returnerAuthHash
//如果授权为spenderAuthHash,则spender更新本地为OPEN,returner侧仍为FROZEN,花费后,两端都变为USED
//如果授权为returnerAuthHash,则returner更新本地为OPEN,spender侧仍为FROZEN,
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 {
info.Spender = rawData.ReturnPubKey
info.AuthSpendHash = getFrString(MimcHashString([]string{rawData.ReturnPubKey, rawData.Amount, rawData.NoteRandom}))
info.IsReturner = true
info.AuthSpendHash = getFrString(mimcHashString([]string{rawData.ReturnPubKey, rawData.Amount, rawData.NoteRandom}))
}
info.Status = mixTy.NoteStatus_OPEN
info.Status = mixTy.NoteStatus_VALID
if len(rawData.AuthorizePubKey) > 0 {
info.Status = mixTy.NoteStatus_FROZEN
}
......
......@@ -23,7 +23,6 @@ var boardOpt = &table.Option{
"noteHash",
"nullifier",
"authSpendHash",
"spender",
"account",
"status"},
}
......@@ -73,8 +72,6 @@ func (r *MixRow) Get(key string) ([]byte, error) {
return []byte(r.Info.Nullifier), nil
case "authSpendHash":
return []byte(r.Info.AuthSpendHash), nil
case "spender":
return []byte(r.Info.Spender), nil
case "account":
return []byte(r.Info.Account), nil
case "status":
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment