Commit 62e2139c authored by madengji's avatar madengji Committed by vipwzw

test pass

parent 9b794a19
......@@ -47,11 +47,12 @@ function run_dapp() {
mv docker-compose-metrics.yml docker-compose-paracross.yml
app="paracross"
else
rm -rf "${app}"-ci && mkdir -p "${app}"-ci && cp ./"${app}"/* ./"${app}"-ci && echo $?
rm -rf "${app}"-ci && mkdir -p "${app}"-ci && cp -r ./"${app}"/* ./"${app}"-ci && echo $?
cp -n ./* ./"${app}"-ci/ && echo $?
if [ "$app" == "paracross" ]; then
cp -r dapptest/ "${app}"-ci/ && echo $?
fi
cd "${app}"-ci/ && pwd
fi
......
all:
chmod +x ./build.sh
./build.sh $(OUT) $(FLAG)
\ No newline at end of file
#!/usr/bin/env bash
strpwd=$(pwd)
strcmd=${strpwd##*dapp/}
strapp=${strcmd%/cmd*}
OUT_DIR="${1}/$strapp"
mkdir -p "${OUT_DIR}"/gnark
# shellcheck disable=SC2086
cp ./build/* "${OUT_DIR}"
cp -r ./gnark/circuit "${OUT_DIR}"/gnark
OUT_TESTDIR="${1}/dapptest/$strapp"
mkdir -p "${OUT_TESTDIR}"
cp ./test/* "${OUT_TESTDIR}"
FROM ubuntu:16.04
WORKDIR /root
COPY chain33 chain33
COPY chain33-cli chain33-cli
COPY chain33.toml chain33*.toml ./
ADD gnark gnark/
CMD ["/root/chain33", "-f", "/root/chain33.toml"]
This diff is collapsed.
......@@ -17,7 +17,6 @@ func main() {
/*
public:
treeRootHash
authorizePubKey
authorizeHash(=hash(authpubkey+noterandom))
authorizeSpendHash(=hash(spendpub+value+noterandom))
......@@ -25,6 +24,7 @@ private:
amount
receiverPubKey
returnPubKey
authorizePubKey
authorizePriKey
spendFlag
noteRandom
......@@ -47,7 +47,7 @@ func NewAuth() *frontend.R1CS {
authorizePriKey := circuit.SECRET_INPUT("AuthorizePriKey")
noteRandom := circuit.SECRET_INPUT("NoteRandom")
authPubKey := circuit.PUBLIC_INPUT("AuthorizePubKey")
authPubKey := circuit.SECRET_INPUT("AuthorizePubKey")
authorizeHash := circuit.PUBLIC_INPUT("AuthorizeHash")
// hash function
......
public, TreeRootHash,10531321614990797034921282585661869614556487056951485265320464926630499341310
public, AuthorizePubKey,13519883267141251871527102103999205179714486518503885909948192364772977661583
public, AuthorizeHash,1267825436937766239630340333349685320927256968591056373125946583184548355070
public, AuthorizeSpendHash,14468512365438613046028281588661351435476168610934165547900473609197783547663
......@@ -7,6 +6,7 @@ public, AuthorizeSpendHash,14468512365438613046028281588661351435476168610934165
secret, Amount,28242048
secret, ReceiverPubKey,13735985067536865723202617343666111332145536963656464451727087263423649028705
secret, ReturnPubKey,16067249407809359746114321133992130903102335882983385972747813693681808870497
public, AuthorizePubKey,13519883267141251871527102103999205179714486518503885909948192364772977661583
secret, AuthorizePriKey,17822967620457187568904804290291537271142779717280482398091401115827760898835
secret, SpendFlag,1
secret, NoteRandom,2824204835
......
package main
package input
import (
util "github.com/33cn/plugin/plugin/dapp/mix/cmd/gnark/circuit"
......
package main
package output
import (
util "github.com/33cn/plugin/plugin/dapp/mix/cmd/gnark/circuit"
......
......@@ -72,6 +72,11 @@ func NewWithdraw() *frontend.R1CS {
targetAuthHash := circuit.SELECT(authFlag, calcAuthHash, nullValue)
circuit.MUSTBE_EQ(authHash, targetAuthHash)
//need check in database if not null
nullifierHash := circuit.PUBLIC_INPUT("NullifierHash")
calcNullifierHash := mimc.Hash(&circuit, noteRandom)
circuit.MUSTBE_EQ(nullifierHash, calcNullifierHash)
//通过merkle tree保证noteHash存在,即便return,auth都是null也是存在的,则可以不经过授权即可消费
//preImage=hash(spendPubkey, returnPubkey,AuthPubkey,spendValue,noteRandom)
noteHash := circuit.SECRET_INPUT("NoteHash")
......
......@@ -160,23 +160,27 @@ func mixConfigPaymentPubKeyParaCmd() *cobra.Command {
}
func addPayPubKeyConfigFlags(cmd *cobra.Command) {
cmd.Flags().StringP("addr", "a", "", "register for addr ")
cmd.MarkFlagRequired("addr")
cmd.Flags().StringP("receiver", "r", "", "receiver key")
cmd.MarkFlagRequired("receiver")
cmd.Flags().StringP("encryptKey", "a", "", "encrypt key for secret")
cmd.Flags().StringP("encryptKey", "e", "", "encrypt key for secret")
cmd.MarkFlagRequired("encryptKey")
}
func createConfigPayPubKey(cmd *cobra.Command, args []string) {
paraName, _ := cmd.Flags().GetString("paraName")
addr, _ := cmd.Flags().GetString("addr")
receiver, _ := cmd.Flags().GetString("receiver")
encryptKey, _ := cmd.Flags().GetString("encryptKey")
payload := &mixTy.MixConfigAction{}
payload.Ty = mixTy.MixConfigType_Payment
payload.Value = &mixTy.MixConfigAction_PaymentKey{PaymentKey: &mixTy.PaymentKey{ReceiverKey: receiver, EncryptKey: encryptKey}}
payload.Value = &mixTy.MixConfigAction_PaymentKey{PaymentKey: &mixTy.PaymentKey{Addr: addr, ReceiverKey: receiver, EncryptKey: encryptKey}}
params := &rpctypes.CreateTxIn{
Execer: getRealExecName(paraName, mixTy.MixX),
......@@ -362,8 +366,8 @@ func showMixTxs(cmd *cobra.Command, args []string) {
// ShowProposalBoardCmd 显示提案查询信息
func ShowPaymentPubKeyCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "rcvkey",
Short: "show peer addr receive key info",
Use: "peer",
Short: "get peer addr receive key info",
Run: showPayment,
}
addShowPaymentflags(cmd)
......@@ -411,7 +415,7 @@ func WalletCmd() *cobra.Command {
func ShowAccountPrivacyInfo() *cobra.Command {
cmd := &cobra.Command{
Use: "keys",
Short: "show account note privacy keys",
Short: "get account privacy keys for mix note",
Run: accountPrivacy,
}
accountPrivacyCmdFlags(cmd)
......@@ -421,9 +425,9 @@ func ShowAccountPrivacyInfo() *cobra.Command {
func accountPrivacyCmdFlags(cmd *cobra.Command) {
cmd.Flags().StringP("addr", "a", "", "user wallet addr")
cmd.Flags().StringP("priv", "p", "", "user wallet privacy key,option")
cmd.Flags().StringP("priv", "p", "", "user wallet addr's privacy key,option")
cmd.Flags().Uint32P("detail", "d", 0, "if get payment priv keys,option")
cmd.Flags().Uint32P("detail", "d", 0, "if get keys' privacy keys,option")
}
......@@ -589,49 +593,6 @@ func SecretCmd() *cobra.Command {
return cmd
}
//// EncodeSecretDataCmd get para chain status by height
//func EncodeSecretDataCmd() *cobra.Command {
// cmd := &cobra.Command{
// Use: "raw",
// Short: "raw secret data",
// Run: encodeSecret,
// }
// encodeSecretCmdFlags(cmd)
// return cmd
//}
//
//func encodeSecretCmdFlags(cmd *cobra.Command) {
// cmd.Flags().StringP("receiver", "p", "", "receiver key")
// cmd.MarkFlagRequired("receiver")
//
// cmd.Flags().StringP("return", "r", "", "return key")
//
// cmd.Flags().StringP("authorize", "a", "", "authorize key")
//
// cmd.Flags().StringP("amount", "m", "", "amount")
// cmd.MarkFlagRequired("amount")
//
//}
//func encodeSecret(cmd *cobra.Command, args []string) {
// rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
// receiver, _ := cmd.Flags().GetString("receiver")
// returnKey, _ := cmd.Flags().GetString("return")
// authorize, _ := cmd.Flags().GetString("authorize")
// amount, _ := cmd.Flags().GetString("amount")
//
// req := mixTy.SecretData{
// ReceiverKey: receiver,
// ReturnKey: returnKey,
// AuthorizeKey: authorize,
// Amount: amount,
// }
//
// var res mixTy.EncodedSecretData
// ctx := jsonclient.NewRPCCtx(rpcLaddr, "mix.EncodeSecretData", req, &res)
// ctx.Run()
//}
// EncodeSecretDataCmd get para chain status by height
func DecodeSecretDataCmd() *cobra.Command {
cmd := &cobra.Command{
......
......@@ -28,25 +28,25 @@ func (a *action) authParamCheck(input *mixTy.AuthorizePublicInput) error {
return errors.Wrapf(mixTy.ErrAuthorizeHashExist, "auth=%s", input.AuthorizeHash)
}
if !isNotFound(err) {
return errors.Wrapf(err, "auth=%s", input.AuthorizeHash)
return errors.Wrapf(err, "get auth=%s", input.AuthorizeHash)
}
authPubKeys, err := a.getAuthKeys()
if err != nil {
return errors.Wrap(err, "get AuthPubkey")
}
//authorize pubkey hash should be configured already
var found bool
for _, k := range authPubKeys.Keys {
if input.AuthorizePubKey == k {
found = true
break
}
}
if !found {
return errors.Wrapf(types.ErrNotFound, "authPubkey=%s", input.AuthorizePubKey)
}
//authPubKeys, err := a.getAuthKeys()
//if err != nil {
// return errors.Wrap(err, "get AuthPubkey")
//}
//
////authorize pubkey hash should be configured already
//var found bool
//for _, k := range authPubKeys.Keys {
// if input.AuthorizePubKey == k {
// found = true
// break
// }
//}
//if !found {
// return errors.Wrapf(types.ErrNotFound, "authPubkey=%s", input.AuthorizePubKey)
//}
return nil
}
......
......@@ -187,9 +187,13 @@ func GetPaymentPubKey(db dbm.KV, addr string) (*mixTy.PaymentKey, error) {
}
func (a *action) ConfigPaymentPubKey(paykey *mixTy.PaymentKey) (*types.Receipt, error) {
if paykey == nil || len(paykey.ReceiverKey) == 0 || len(paykey.EncryptKey) == 0 {
if paykey == nil || len(paykey.ReceiverKey) == 0 || len(paykey.EncryptKey) == 0 || len(paykey.Addr) == 0 {
return nil, errors.Wrapf(types.ErrInvalidParam, "pubkey=%v", paykey)
}
//检查用户使用对应的addr的key,但不能确保key就是对应addr
if paykey.Addr != a.fromaddr {
return nil, errors.Wrapf(types.ErrInvalidParam, "register addr=%s not match with sign=%s", paykey.Addr, a.fromaddr)
}
//直接覆盖
return makeConfigPaymentKeyReceipt(&mixTy.PaymentKey{
Addr: a.fromaddr,
......
......@@ -5,3 +5,6 @@
1. 转账,私对私,花费某个支票,转账给目标账户,多出部分找零给自己,目标账户和金额全隐藏
1. 提款,私对公,花费某些支票,统一转出给签名地址,转账金额公开(验证),签名地址和支票账户不一定对应,也就是任何知道支票密码的人都可以提款
##授权
1. 授权账户可以是任意账户,不需要注册公共授权账户,存款方需要自己保证授权地址ok,否则接收方和返回方都不能花费
......@@ -23,7 +23,6 @@ import (
//}
func (g *channelClient) GetRescanStatus(ctx context.Context, in *types.ReqNil) (*types.ReqString, error) {
log.Info("GetRescanStatus in")
data, err := g.ExecWalletFunc(mixTy.MixX, "GetRescanStatus", in)
if err != nil {
return nil, err
......@@ -34,7 +33,6 @@ func (g *channelClient) GetRescanStatus(ctx context.Context, in *types.ReqNil) (
//
//// 扫描UTXO以及获取扫描UTXO后的状态
func (g *channelClient) RescanNotes(ctx context.Context, in *types.ReqNil) (*types.ReqString, error) {
log.Info("RescanNotes in")
data, err := g.ExecWalletFunc(mixTy.MixX, "RescanNotes", in)
if err != nil {
return nil, err
......@@ -52,8 +50,7 @@ func (g *channelClient) EnablePrivacy(ctx context.Context, in *types.ReqAddrs) (
}
// ShowPrivacyAccountInfo display privacy account information for json rpc
func (c *Jrpc) ShowAccountPrivacyInfo(in *types.ReqString, result *json.RawMessage) error {
log.Info("ShowAccountPrivacyInfo jrpc in")
func (c *Jrpc) ShowAccountPrivacyInfo(in *mixTy.PaymentKeysReq, result *json.RawMessage) error {
reply, err := c.cli.ExecWalletFunc(mixTy.MixX, "ShowAccountPrivacyInfo", in)
if err != nil {
return err
......
......@@ -35,13 +35,15 @@ func newPrivacyKey(rootPrivKey []byte) *mixTy.AccountPrivacyKey {
payPrivKey := key.([32]byte)
//payPrivKey := mimcHashByte([][]byte{rootPrivKey})
//payPrivKey 可能超出fr的模,spendKey是payPrivKey对fr取的模,有可能和payPrivKey不相等,这里用spendKey取hash
//mimcHashByte 会对输入参数对fr取模,在电路上不会影响ReceiveKey
paymentKey := &mixTy.PaymentKeyPair{}
paymentKey.SpendKey = mixTy.Byte2Str(payPrivKey[:])
paymentKey.ReceiveKey = mixTy.Byte2Str(mimcHashByte([][]byte{payPrivKey[:]}))
paymentKey.ReceiveKey = mixTy.Byte2Str(mimcHashByte([][]byte{mixTy.Str2Byte(paymentKey.SpendKey)}))
encryptKeyPair := &mixTy.EncryptKeyPair{}
pubkey := ecdh.PublicKey(payPrivKey)
//需要Hex编码,不要使用fr.string, 模范围不同
//加解密是在x25519域,需要Hex编码,不要使用fr.string, 模范围不同
encryptKeyPair.PrivKey = hex.EncodeToString(payPrivKey[:])
pubData := pubkey.([32]byte)
encryptKeyPair.PubKey = hex.EncodeToString(pubData[:])
......@@ -396,7 +398,10 @@ func (p *mixPolicy) enablePrivacy(addrs []string) (*mixTy.ReqEnablePrivacyRst, e
func (p *mixPolicy) showAccountNoteInfo(req *mixTy.WalletMixIndexReq) (*mixTy.WalletNoteResp, error) {
resp, err := p.listMixInfos(req)
return resp.(*mixTy.WalletNoteResp), err
if err != nil {
return nil, err
}
return resp.(*mixTy.WalletNoteResp), nil
}
func (p *mixPolicy) createRawTx(req *mixTy.CreateRawTxReq) (*types.Transaction, error) {
......
......@@ -364,18 +364,17 @@ func (p *mixPolicy) decodeSecret(noteHash string, secretData string, privacyKeys
//decrypted, save database
var info mixTy.WalletNoteInfo
info.NoteHash = noteHash
info.Nullifier = hex.EncodeToString(mimcHashString([]string{rawData.NoteRandom}))
info.Nullifier = mixTy.Byte2Str(mimcHashString([]string{rawData.NoteRandom}))
//如果自己是spender,则记录有关spenderAuthHash,如果是returner,则记录returnerAuthHash
//如果授权为spenderAuthHash,则根据授权hash索引到本地数据库,spender更新本地为VALID,returner侧不变仍为FROZEN,花费后,两端都变为USED
//如果授权为returnerAuthHash,则returner更新本地为VALID,spender侧仍为FROZEN,
info.AuthorizeSpendHash = "0"
if len(rawData.AuthorizeKey) > LENNULLKEY {
switch key.Privacy.PaymentKey.ReceiveKey {
case rawData.ReceiverKey:
case rawData.ReturnKey:
info.AuthorizeSpendHash = hex.EncodeToString(mimcHashString([]string{key.Privacy.PaymentKey.ReceiveKey, rawData.Amount, rawData.NoteRandom}))
case rawData.ReceiverKey, rawData.ReturnKey:
info.AuthorizeSpendHash = mixTy.Byte2Str(mimcHashString([]string{key.Privacy.PaymentKey.ReceiveKey, rawData.Amount, rawData.NoteRandom}))
case rawData.AuthorizeKey:
info.AuthorizeHash = hex.EncodeToString(mimcHashString([]string{rawData.AuthorizeKey, rawData.NoteRandom}))
info.AuthorizeHash = mixTy.Byte2Str(mimcHashString([]string{rawData.AuthorizeKey, rawData.NoteRandom}))
}
}
......
......@@ -2,6 +2,7 @@ package wallet
import (
"encoding/hex"
"math/big"
"testing"
"github.com/33cn/chain33/common"
......@@ -106,3 +107,28 @@ func TestEncodeSecretData(t *testing.T) {
types.Decode(rawData, &rawSecret)
assert.Equal(t, rawSecret.ReceiverKey, secret.ReceiverKey)
}
func TestMimcHashPriKey(t *testing.T) {
//frModValue := "21888242871839275222246405745257275088548364400416034343698204186575808495617"
a := "11888242871839275222246405745257275088548364400416034343698204186575808495617"
b := "31888242871839275222246405745257275088548364400416034343698204186575808495617"
var bigVal, lessVal big.Int
lessVal.SetString(a, 10)
bigVal.SetString(b, 10)
//测试大值
prikey := bigVal.Bytes()
//prikey对modValue取了模,spendkey 不一定和Prikey相等了, lessval相等,bigVal不相等
spendKey := mixTy.Byte2Str(prikey[:])
t.Log("prikey ori", hex.EncodeToString(prikey), "prikey spendkey", hex.EncodeToString(mixTy.Str2Byte(spendKey)))
//mimcHash 会对每个val取模,这样又相等了
rcvSpenPri := mimcHashByte([][]byte{mixTy.Str2Byte(spendKey)})
//payPrivKey 可能超出fr的模,spendKey是payPrivKey对fr取的模,有可能和payPrivKey不相等,这里需要用spendKey取hash
rcvKeyPri := mimcHashByte([][]byte{prikey})
receiveKeyBig := mimcHashByte([][]byte{mixTy.Str2Byte(b)})
t.Log("spendPri", hex.EncodeToString(rcvSpenPri), "prikey", hex.EncodeToString(rcvKeyPri), "big", hex.EncodeToString(receiveKeyBig))
assert.Equal(t, rcvSpenPri, rcvKeyPri)
}
......@@ -18,13 +18,13 @@ import (
type AuthorizeInput struct {
//public
TreeRootHash string `tag:"public"`
AuthorizePubKey string `tag:"public"`
AuthorizeHash string `tag:"public"`
AuthorizeSpendHash string `tag:"public"`
//secret
ReceiverPubKey string `tag:"secret"`
ReturnPubKey string `tag:"secret"`
AuthorizePubKey string `tag:"secret"`
AuthorizePriKey string `tag:"secret"`
NoteRandom string `tag:"secret"`
......@@ -106,7 +106,7 @@ func (p *mixPolicy) getAuthParms(req *mixTy.AuthTxReq) (*AuthorizeInput, error)
//default auto to receiver
input.SpendFlag = "1"
if input.ReturnPubKey != "0" && input.ReturnPubKey != req.AuthorizeToAddr {
if input.ReturnPubKey != "0" && input.ReturnPubKey == req.AuthorizeToAddr {
//auth to returner
input.SpendFlag = "0"
}
......
......@@ -33,7 +33,7 @@ type DepositInput struct {
}
func (p *mixPolicy) depositParams(receiver, returner, auth, amount string) (*mixTy.DepositProofResp, error) {
if receiver == returner || receiver == auth || returner == auth {
if len(receiver) > 0 && len(returner) > 0 && (receiver == returner || receiver == auth || returner == auth) {
return nil, errors.Wrapf(types.ErrInvalidParam, "addrs should not be same to receiver=%s,return=%s,auth=%s",
receiver, returner, auth)
}
......
......@@ -403,8 +403,8 @@ func (p *mixPolicy) createTransferTx(req *mixTy.CreateRawTxReq) (*types.Transact
func (p *mixPolicy) getTransferTx(execName string, inputProofs []*mixTy.ZkProofInfo, proofs ...*mixTy.ZkProofInfo) (*types.Transaction, error) {
payload := &mixTy.MixTransferAction{}
payload.Inputs = inputProofs
payload.Output = proofs[1]
payload.Change = proofs[2]
payload.Output = proofs[0]
payload.Change = proofs[1]
cfg := p.getWalletOperate().GetAPI().GetConfig()
action := &mixTy.MixAction{
......
......@@ -284,6 +284,18 @@ 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 getZkProofKeys(circuitFile, pkFile string, inputs interface{}) (*mixTy.ZkProofInfo, error) {
assignments, err := getAssignments(inputs)
if err != nil {
......
......@@ -95,9 +95,13 @@ function para_set_toml() {
function para_set_wallet() {
echo "=========== # para set wallet ============="
#1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4
para_import_wallet "${PARA_CLI}" "0x6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b" "paraAuthAccount"
#1JRNjdEqp4LJ5fqycUBm9ayCKSeeskgMKR
para_import_wallet "${PARA_CLI2}" "0x19c069234f9d3e61135fefbeb7791b149cdf6af536f26bebb310d4cd22c3fee4" "paraAuthAccount"
#1NLHPEcbTWWxxU3dGUZBhayjrCHD3psX7k
para_import_wallet "${PARA_CLI1}" "0x7a80a1f75d7360c6123c32a78ecf978c1ac55636f87892df38d8b85a9aeff115" "paraAuthAccount"
#1MCftFynyvG2F4ED5mdHYgziDxx6vDrScs
para_import_wallet "${PARA_CLI4}" "0xcacb1f5d51700aea07fca2246ab43b0917d70405c65edea9b5063d72eb5c6b71" "paraAuthAccount"
#14KEKbYtKKQm4wMthSK9J4La4nAiidGozt
......
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