OSDN Git Service

Merge branch 'mov' into mov_crossin_tx
authorwz <mars@bytom.io>
Wed, 23 Oct 2019 11:02:09 +0000 (19:02 +0800)
committerGitHub <noreply@github.com>
Wed, 23 Oct 2019 11:02:09 +0000 (19:02 +0800)
14 files changed:
api/nodeinfo.go
blockchain/txbuilder/actions.go
common/crossin_asset.go [new file with mode: 0644]
config/federation_test.go
config/genesis.go
consensus/segwit/segwit.go
consensus/segwit/segwit_test.go
node/node.go
protocol/bc/bc.pb.go
protocol/bc/bc.proto
protocol/bc/crosschain_input.go
protocol/bc/entry_test.go
protocol/bc/types/map.go
protocol/validation/tx.go

index ac085ff..8424647 100644 (file)
@@ -40,7 +40,7 @@ type NetInfo struct {
 func (a *API) GetNodeInfo() *NetInfo {
        nodeXPub := cfg.CommonConfig.PrivateKey().XPub()
 
-       signScript := cfg.FederationPMultiSigScript(cfg.CommonConfig)
+       signScript := cfg.FederationPMultiSigScript(cfg.CommonConfig.Federation)
        scriptHash := crypto.Sha256(signScript)
        address, err := common.NewAddressWitnessScriptHash(scriptHash, consensus.BytomMainNetParams(&consensus.ActiveNetParams))
        if err != nil {
index f5b40bc..b88da89 100644 (file)
@@ -10,6 +10,7 @@ import (
        "github.com/vapor/common"
        cfg "github.com/vapor/config"
        "github.com/vapor/consensus"
+       "github.com/vapor/crypto/ed25519/chainkd"
        "github.com/vapor/encoding/json"
        "github.com/vapor/protocol/bc"
        "github.com/vapor/protocol/bc/types"
@@ -262,22 +263,24 @@ func DecodeCrossInAction(data []byte) (Action, error) {
 
 type crossInAction struct {
        bc.AssetAmount
-       SourceID          bc.Hash       `json:"source_id"`
-       SourcePos         uint64        `json:"source_pos"`
-       VMVersion         uint64        `json:"vm_version"`
-       RawDefinitionByte json.HexBytes `json:"raw_definition_byte"`
-       IssuanceProgram   json.HexBytes `json:"issuance_program"`
+       SourceID            bc.Hash        `json:"source_id"`
+       SourcePos           uint64         `json:"source_pos"`
+       VMVersion           uint64         `json:"vm_version"`
+       RawDefinitionByte   json.HexBytes  `json:"raw_definition_byte"`
+       IssuanceProgram     json.HexBytes  `json:"issuance_program"`
+       OpenFederationXpubs []chainkd.XPub `json:"open_federation_xpubs"`
+       Quorum              int            `json:"quorum"`
 }
 
-func (a *crossInAction) Build(ctx context.Context, builder *TemplateBuilder) error {
+func (c *crossInAction) Build(ctx context.Context, builder *TemplateBuilder) error {
        var missing []string
-       if a.SourceID.IsZero() {
+       if c.SourceID.IsZero() {
                missing = append(missing, "source_id")
        }
-       if a.AssetId.IsZero() {
+       if c.AssetId.IsZero() {
                missing = append(missing, "asset_id")
        }
-       if a.Amount == 0 {
+       if c.Amount == 0 {
                missing = append(missing, "amount")
        }
 
@@ -285,20 +288,30 @@ func (a *crossInAction) Build(ctx context.Context, builder *TemplateBuilder) err
                return MissingFieldsError(missing...)
        }
 
-       if err := a.checkAssetID(); err != nil {
+       if err := c.checkAssetID(); err != nil {
                return err
        }
 
        // arguments will be set when materializeWitnesses
-       txin := types.NewCrossChainInput(nil, a.SourceID, *a.AssetId, a.Amount, a.SourcePos, a.VMVersion, a.RawDefinitionByte, a.IssuanceProgram)
+       txin := types.NewCrossChainInput(nil, c.SourceID, *c.AssetId, c.Amount, c.SourcePos, c.VMVersion, c.RawDefinitionByte, c.IssuanceProgram)
        tplIn := &SigningInstruction{}
        fed := cfg.CommonConfig.Federation
+       isCrossChain, err := common.IsCrossChainAssetOfNoBytom(c.RawDefinitionByte)
+       if err != nil {
+               return err
+       }
+
+       if isCrossChain {
+               fed.Xpubs = c.OpenFederationXpubs
+               fed.Quorum = c.Quorum
+       }
+
        tplIn.AddRawWitnessKeys(fed.Xpubs, cfg.FedAddressPath, fed.Quorum)
-       tplIn.AddDataWitness(cfg.FederationPMultiSigScript(cfg.CommonConfig))
+       tplIn.AddDataWitness(cfg.FederationPMultiSigScript(fed))
        return builder.AddInput(txin, tplIn)
 }
 
-func (a *crossInAction) ActionType() string {
+func (c *crossInAction) ActionType() string {
        return "cross_chain_in"
 }
 
diff --git a/common/crossin_asset.go b/common/crossin_asset.go
new file mode 100644 (file)
index 0000000..7fd182d
--- /dev/null
@@ -0,0 +1,28 @@
+package common
+
+import (
+       "encoding/json"
+       "errors"
+)
+
+func IsCrossChainAssetOfNoBytom(rawDefinitionByte []byte) (bool, error) {
+       var defMap map[string]interface{}
+       if err := json.Unmarshal(rawDefinitionByte, &defMap); err != nil {
+               return false, err
+       }
+
+       description, ok := defMap["description"].(map[string]interface{})
+       if !ok {
+               return false, nil
+       }
+
+       issueAssetAction, ok := description["issue_asset_action"].(string)
+       if !ok {
+               return false, nil
+       }
+
+       if issueAssetAction != "cross_chain" {
+               return false, errors.New("issueAssetAction is error")
+       }
+       return true, nil
+}
index 00e92ad..b8cce6f 100644 (file)
@@ -9,7 +9,6 @@ import (
 )
 
 func TestFederation(t *testing.T) {
-
        tmpDir, err := ioutil.TempDir(".", "")
        if err != nil {
                t.Fatalf("failed to create temporary data folder: %v", err)
index a3b2f7e..85ca145 100644 (file)
@@ -7,6 +7,7 @@ import (
 
        "github.com/vapor/consensus"
        "github.com/vapor/crypto"
+       "github.com/vapor/crypto/ed25519"
        "github.com/vapor/crypto/ed25519/chainkd"
        "github.com/vapor/protocol/bc"
        "github.com/vapor/protocol/bc/types"
@@ -22,10 +23,10 @@ var FedAddressPath = [][]byte{
        []byte{0x01, 0x00, 0x00, 0x00},
 }
 
-func FederationPMultiSigScript(c *Config) []byte {
-       xpubs := c.Federation.Xpubs
+func FederationPMultiSigScript(c *FederationConfig) []byte {
+       xpubs := c.Xpubs
        derivedXPubs := chainkd.DeriveXPubs(xpubs, FedAddressPath)
-       program, err := vmutil.P2SPMultiSigProgram(chainkd.XPubKeys(derivedXPubs), c.Federation.Quorum)
+       program, err := vmutil.P2SPMultiSigProgram(chainkd.XPubKeys(derivedXPubs), c.Quorum)
        if err != nil {
                log.Panicf("fail to generate federation scirpt for federation: %v", err)
        }
@@ -33,7 +34,7 @@ func FederationPMultiSigScript(c *Config) []byte {
        return program
 }
 
-func FederationWScript(c *Config) []byte {
+func FederationWScript(c *FederationConfig) []byte {
        script := FederationPMultiSigScript(c)
        scriptHash := crypto.Sha256(script)
        wscript, err := vmutil.P2WSHProgram(scriptHash)
@@ -44,13 +45,28 @@ func FederationWScript(c *Config) []byte {
        return wscript
 }
 
+func FederationWScriptFromPubs(pubkeys []ed25519.PublicKey, quorum int) []byte {
+       program, err := vmutil.P2SPMultiSigProgram(pubkeys, quorum)
+       if err != nil {
+               log.Panicf("fail to generate federation scirpt for federation: %v", err)
+       }
+
+       scriptHash := crypto.Sha256(program)
+       wscript, err := vmutil.P2WSHProgram(scriptHash)
+       if err != nil {
+               log.Panicf("Fail converts scriptHash to witness: %v", err)
+       }
+
+       return wscript
+}
+
 func GenesisTx() *types.Tx {
        contract, err := hex.DecodeString("00148c9d063ff74ee6d9ffa88d83aeb038068366c4c4")
        if err != nil {
                log.Panicf("fail on decode genesis tx output control program")
        }
 
-       coinbaseInput := FederationWScript(CommonConfig)
+       coinbaseInput := FederationWScript(CommonConfig.Federation)
 
        txData := types.TxData{
                Version: 1,
index 1477fdd..2607087 100644 (file)
@@ -4,6 +4,7 @@ import (
        "errors"
 
        "github.com/vapor/consensus"
+       "github.com/vapor/crypto/ed25519"
        "github.com/vapor/protocol/bc"
        "github.com/vapor/protocol/vm"
        "github.com/vapor/protocol/vm/vmutil"
@@ -160,3 +161,45 @@ func GetHashFromStandardProg(prog []byte) ([]byte, error) {
 
        return insts[1].Data, nil
 }
+
+func GetXpubsAndRequiredFromProg(prog []byte) ([]ed25519.PublicKey, int, error) {
+       insts, err := vm.ParseProgram(prog)
+       if err != nil {
+               return nil, 0, err
+       }
+
+       instsLen := len(insts)
+
+       if instsLen < 5 {
+               return nil, 0, errors.New("bad length of instruction for issuance program")
+       }
+
+       if insts[0].Op != vm.OP_TXSIGHASH || insts[instsLen-1].Op != vm.OP_CHECKMULTISIG {
+               return nil, 0, errors.New("bad op of instruction for issuance program")
+       }
+
+       if !(insts[instsLen-2].IsPushdata() && insts[instsLen-3].IsPushdata()) {
+               return nil, 0, errors.New("bad pushdata in instruction for issuance program")
+       }
+
+       required, err := vm.AsInt64(insts[instsLen-3].Data)
+       if err != nil {
+               return nil, 0, err
+       }
+
+       xpubsNum, err := vm.AsInt64(insts[instsLen-2].Data)
+       if err != nil {
+               return nil, 0, err
+       }
+
+       var pubs []ed25519.PublicKey
+       for i := 1; i < int(xpubsNum+1); i++ {
+               if insts[i].Op != vm.OP_DATA_32 || len(insts[i].Data) != 32 {
+                       return nil, 0, errors.New("bad publicKey in instruction for issuance program")
+               }
+
+               pubs = append(pubs, insts[i].Data)
+       }
+
+       return pubs, int(required), nil
+}
index 14ec13b..97716c6 100644 (file)
@@ -3,6 +3,10 @@ package segwit
 import (
        "encoding/hex"
        "testing"
+
+       "github.com/vapor/crypto/ed25519"
+       "github.com/vapor/crypto/ed25519/chainkd"
+       "github.com/vapor/testutil"
 )
 
 func TestConvertProgram(t *testing.T) {
@@ -119,3 +123,67 @@ func TestProgramType(t *testing.T) {
                }
        }
 }
+
+func TestGetXpubsAndRequiredFromProg(t *testing.T) {
+       xpubStr1 := "95a1fdf4d9c30a0daf3ef6ec475058ba09b62677ce1384e33a17d028c1755ede896ec9fd8abecf0fdef9d89bba8f0d7c2576a3e78120336584884e516e128354"
+       xpubStr2 := "bfc74caeb528064b056d7d1edd2913c9fb35a1bdd921087972effeb8ceb90f152b1e03199efbfc924fd7665107914309a6dcc12930256867a94b97855b392ff5"
+       xpubStr3 := "5624b832e0276af2811c8c8dbb6ed9f603201e8a4236aaac7880d6ee1a746abe91e21f290f47d867aaa7bf8e0c8a69ab383c41966e5c960371b2d2cd219c11ac"
+
+       xpub1 := &chainkd.XPub{}
+       if err := xpub1.UnmarshalText([]byte(xpubStr1)); err != nil {
+               t.Fatal(err)
+       }
+
+       xpub2 := &chainkd.XPub{}
+       if err := xpub2.UnmarshalText([]byte(xpubStr2)); err != nil {
+               t.Fatal(err)
+       }
+
+       xpub3 := &chainkd.XPub{}
+       if err := xpub3.UnmarshalText([]byte(xpubStr3)); err != nil {
+               t.Fatal(err)
+       }
+
+       cases := []struct {
+               desc         string
+               program      string
+               wantXpubs    []ed25519.PublicKey
+               wantRequired int
+       }{
+               {
+                       desc:         "one xpub",
+                       program:      "ae20f5f412c87794b137b9433ce7d1cbb147fe5d87ca03a81d28eaba4264d7a74fc65151ad",
+                       wantXpubs:    []ed25519.PublicKey{xpub1.PublicKey()},
+                       wantRequired: 1,
+               },
+               {
+                       desc:         "two xpub",
+                       program:      "ae2099dbcf35be6b199e3183c7bbfe5a89d1d13978b5e1ceacbf7779507a998ba0e120ccbbbb7c72a7f8a77f227747bc8bc1f38a76ff112f395b5ff05c002e84ccd79e5152ad",
+                       wantXpubs:    []ed25519.PublicKey{xpub1.PublicKey(), xpub2.PublicKey()},
+                       wantRequired: 1,
+               },
+               {
+                       desc:         "three xpub",
+                       program:      "ae209ab9179c0266ca64abca8fd7703081cf4911dab8d7e44cef921414dd31109ff320ce889516b82f9367a54d146b0c20c995dead34f0bf7c393f6a23ec5367dbbd782043f5fcdecfacb24dc1a61a750dec71065657d028695650d6c73c878e963448155253ad",
+                       wantXpubs:    []ed25519.PublicKey{xpub1.PublicKey(), xpub2.PublicKey(), xpub3.PublicKey()},
+                       wantRequired: 2,
+               },
+       }
+
+       for i, c := range cases {
+               progBytes, err := hex.DecodeString(c.program)
+               if err != nil {
+                       t.Fatal(err)
+               }
+
+               gotXpus, gotRequired, err := GetXpubsAndRequiredFromProg(progBytes)
+               if err != nil {
+                       t.Fatal(err)
+               }
+
+               if gotRequired != c.wantRequired || testutil.DeepEqual(gotXpus, c.wantXpubs) {
+                       t.Errorf("case #%d (%s) got xpubs: %v, Required: %d, expect xpubs: %v,  Required: %d", i, c.desc, gotXpus, gotRequired, c.wantXpubs, c.wantRequired)
+
+               }
+       }
+}
index c160f17..cdafc36 100644 (file)
@@ -66,8 +66,8 @@ func NewNode(config *cfg.Config) *Node {
                cmn.Exit(cmn.Fmt("Failed to load federated information:[%s]", err.Error()))
        }
 
-       if err:=vaporLog.InitLogFile(config);err!=nil{
-               log.WithField("err",err).Fatalln("InitLogFile failed")
+       if err := vaporLog.InitLogFile(config); err != nil {
+               log.WithField("err", err).Fatalln("InitLogFile failed")
        }
 
        log.WithFields(log.Fields{
@@ -75,7 +75,7 @@ func NewNode(config *cfg.Config) *Node {
                "pubkey":             config.PrivateKey().XPub(),
                "fed_xpubs":          config.Federation.Xpubs,
                "fed_quorum":         config.Federation.Quorum,
-               "fed_controlprogram": hex.EncodeToString(cfg.FederationWScript(config)),
+               "fed_controlprogram": hex.EncodeToString(cfg.FederationWScript(config.Federation)),
        }).Info()
 
        if err := consensus.InitActiveNetParams(config.ChainID); err != nil {
@@ -169,7 +169,7 @@ func NewNode(config *cfg.Config) *Node {
 
 // find whether config xpubs equal genesis block xpubs
 func checkConfig(chain *protocol.Chain, config *cfg.Config) error {
-       fedpegScript := cfg.FederationWScript(config)
+       fedpegScript := cfg.FederationWScript(config.Federation)
        genesisBlock, err := chain.GetBlockByHeight(0)
        if err != nil {
                return err
index b65b3b7..d302d9b 100644 (file)
@@ -698,6 +698,7 @@ type CrossChainInput struct {
        AssetDefinition    *AssetDefinition  `protobuf:"bytes,4,opt,name=asset_definition,json=assetDefinition" json:"asset_definition,omitempty"`
        WitnessArguments   [][]byte          `protobuf:"bytes,5,rep,name=witness_arguments,json=witnessArguments,proto3" json:"witness_arguments,omitempty"`
        Ordinal            uint64            `protobuf:"varint,6,opt,name=ordinal" json:"ordinal,omitempty"`
+       RawDefinitionByte  []byte            `protobuf:"bytes,7,opt,name=rawDefinitionByte,proto3" json:"rawDefinitionByte,omitempty"`
 }
 
 func (m *CrossChainInput) Reset()                    { *m = CrossChainInput{} }
@@ -747,6 +748,13 @@ func (m *CrossChainInput) GetOrdinal() uint64 {
        return 0
 }
 
+func (m *CrossChainInput) GetRawDefinitionByte() []byte {
+       if m != nil {
+               return m.RawDefinitionByte
+       }
+       return nil
+}
+
 func init() {
        proto.RegisterType((*Hash)(nil), "bc.Hash")
        proto.RegisterType((*Program)(nil), "bc.Program")
@@ -773,65 +781,66 @@ func init() {
 func init() { proto.RegisterFile("bc.proto", fileDescriptor0) }
 
 var fileDescriptor0 = []byte{
-       // 951 bytes of a gzipped FileDescriptorProto
-       0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xd4, 0x56, 0x5f, 0x6f, 0x23, 0x35,
-       0x10, 0x57, 0x36, 0xdb, 0x24, 0x9d, 0xf4, 0x9a, 0xc4, 0xbd, 0x83, 0xd5, 0xe9, 0x10, 0xd5, 0x4a,
-       0x47, 0x0f, 0x21, 0x55, 0xfd, 0x73, 0xfc, 0x79, 0x40, 0x88, 0xd2, 0x72, 0x5c, 0x1e, 0x4e, 0x87,
-       0xdc, 0x2a, 0xaf, 0x2b, 0x67, 0xd7, 0x49, 0x2c, 0x92, 0x75, 0xb0, 0xbd, 0xa1, 0xd7, 0xaf, 0xc0,
-       0x33, 0x0f, 0x7c, 0x22, 0x1e, 0x10, 0xe2, 0x23, 0x81, 0x3c, 0xeb, 0x4d, 0x36, 0x7f, 0xda, 0x82,
-       0x00, 0x01, 0x6f, 0x3b, 0xe3, 0xf1, 0x6f, 0x7e, 0xf3, 0xf3, 0x8c, 0xd7, 0xd0, 0xe8, 0xc7, 0x87,
-       0x53, 0x25, 0x8d, 0x24, 0x5e, 0x3f, 0x0e, 0x5f, 0x80, 0xff, 0x92, 0xe9, 0x11, 0xd9, 0x05, 0x6f,
-       0x76, 0x14, 0x54, 0xf6, 0x2b, 0xcf, 0x6a, 0xd4, 0x9b, 0x1d, 0xa1, 0x7d, 0x1c, 0x78, 0xce, 0x3e,
-       0x46, 0xfb, 0x24, 0xa8, 0x3a, 0xfb, 0x04, 0xed, 0xd3, 0xc0, 0x77, 0xf6, 0x69, 0xf8, 0x29, 0xd4,
-       0xbf, 0x56, 0x72, 0xa8, 0xd8, 0x84, 0xbc, 0x03, 0x30, 0x9b, 0x44, 0x33, 0xae, 0xb4, 0x90, 0x29,
-       0x42, 0xfa, 0x74, 0x7b, 0x36, 0xe9, 0xe5, 0x0e, 0x42, 0xc0, 0x8f, 0x65, 0xc2, 0x11, 0x7b, 0x87,
-       0xe2, 0x77, 0xd8, 0x85, 0xfa, 0x99, 0xd6, 0xdc, 0x74, 0x2f, 0xfe, 0x32, 0x91, 0x57, 0xd0, 0x44,
-       0xa8, 0xb3, 0x89, 0xcc, 0x52, 0x43, 0xde, 0x83, 0x06, 0xb3, 0x66, 0x24, 0x12, 0x04, 0x6d, 0x9e,
-       0x34, 0x0f, 0xfb, 0xf1, 0xa1, 0xcb, 0x46, 0xeb, 0xb8, 0xd8, 0x4d, 0xc8, 0x5b, 0x50, 0x63, 0xb8,
-       0x03, 0x53, 0xf9, 0xd4, 0x59, 0xe1, 0x10, 0x5a, 0x18, 0x7b, 0xc1, 0x07, 0x22, 0x15, 0xc6, 0x16,
-       0xf0, 0x11, 0xb4, 0x85, 0xd6, 0x19, 0x4b, 0x63, 0x1e, 0x4d, 0xf3, 0x9a, 0xcb, 0xd0, 0x4e, 0x06,
-       0xda, 0x2a, 0x82, 0x0a, 0x5d, 0x9e, 0x80, 0x9f, 0x30, 0xc3, 0x30, 0x41, 0xf3, 0xa4, 0x61, 0x63,
-       0xad, 0xf4, 0x14, 0xbd, 0xe1, 0x18, 0x9a, 0x3d, 0x36, 0xce, 0xf8, 0xa5, 0xcc, 0x54, 0xcc, 0xc9,
-       0x63, 0xa8, 0x2a, 0x3e, 0x70, 0xb8, 0x8b, 0x58, 0xeb, 0x24, 0x4f, 0x61, 0x6b, 0x66, 0x43, 0x1d,
-       0x52, 0x6b, 0x5e, 0x50, 0x5e, 0x33, 0xcd, 0x57, 0xc9, 0x63, 0x68, 0x4c, 0xa5, 0x46, 0xce, 0xa8,
-       0x97, 0x4f, 0xe7, 0x76, 0xf8, 0x2d, 0xb4, 0x31, 0xdb, 0x05, 0xd7, 0x46, 0xa4, 0x0c, 0xeb, 0xfa,
-       0x87, 0x53, 0xfe, 0xe6, 0x41, 0xf3, 0x8b, 0xb1, 0x8c, 0xbf, 0x79, 0xc9, 0x59, 0xc2, 0x15, 0x09,
-       0xa0, 0xbe, 0xdc, 0x23, 0x85, 0x69, 0xcf, 0x62, 0xc4, 0xc5, 0x70, 0x34, 0x3f, 0x8b, 0xdc, 0x22,
-       0xcf, 0xa1, 0x33, 0x55, 0x7c, 0x26, 0x64, 0xa6, 0xa3, 0xbe, 0x45, 0xb2, 0x87, 0x5a, 0x5d, 0xa1,
-       0xdb, 0x2a, 0x42, 0x30, 0x57, 0x37, 0x21, 0x4f, 0x60, 0xdb, 0x88, 0x09, 0xd7, 0x86, 0x4d, 0xa6,
-       0xd8, 0x27, 0x3e, 0x5d, 0x38, 0xc8, 0x87, 0xd0, 0x31, 0x8a, 0xa5, 0x9a, 0xc5, 0x96, 0xa4, 0x8e,
-       0x94, 0x94, 0x26, 0xd8, 0x5a, 0xc1, 0x6c, 0x97, 0x43, 0xa8, 0x94, 0x86, 0x7c, 0x0e, 0x6f, 0x97,
-       0x7c, 0x91, 0x36, 0xcc, 0x64, 0x3a, 0x1a, 0x31, 0x3d, 0x0a, 0x6a, 0x2b, 0x9b, 0x1f, 0x95, 0x02,
-       0x2f, 0x31, 0x0e, 0x07, 0xee, 0x02, 0xc8, 0x3a, 0x42, 0x50, 0xc7, 0xcd, 0x8f, 0xec, 0xe6, 0xab,
-       0xd5, 0x6d, 0xb4, 0xb3, 0x86, 0x44, 0x3e, 0x80, 0xce, 0x77, 0xc2, 0xa4, 0x5c, 0xeb, 0x88, 0xa9,
-       0x61, 0x36, 0xe1, 0xa9, 0xd1, 0x41, 0x63, 0xbf, 0xfa, 0x6c, 0x87, 0xb6, 0xdd, 0xc2, 0x59, 0xe1,
-       0x0f, 0x7f, 0xa8, 0x40, 0xe3, 0xea, 0xfa, 0x5e, 0xf9, 0x0f, 0xa0, 0xa5, 0xb9, 0x12, 0x6c, 0x2c,
-       0x6e, 0x78, 0x12, 0x69, 0x71, 0xc3, 0xdd, 0x39, 0xec, 0x2e, 0xdc, 0x97, 0xe2, 0x86, 0xdb, 0x41,
-       0xb7, 0x42, 0x46, 0x8a, 0xa5, 0x43, 0xee, 0xce, 0x1b, 0xa5, 0xa5, 0xd6, 0x41, 0x0e, 0x00, 0x14,
-       0xd7, 0xd9, 0xd8, 0xce, 0x9e, 0x0e, 0xfc, 0xfd, 0xea, 0x92, 0x2c, 0xdb, 0xf9, 0x5a, 0x37, 0xd1,
-       0xe1, 0x31, 0xec, 0x5e, 0x5d, 0xf7, 0xb8, 0x12, 0x83, 0x37, 0x14, 0x9d, 0xe4, 0x5d, 0x68, 0x3a,
-       0x49, 0x07, 0x4c, 0x8c, 0x91, 0x60, 0x83, 0x42, 0xee, 0x7a, 0xc1, 0xc4, 0x38, 0x1c, 0x40, 0x67,
-       0x4d, 0x9f, 0x3b, 0x4a, 0xfa, 0x18, 0x1e, 0xcc, 0x10, 0xbf, 0xd0, 0xd9, 0x43, 0x36, 0x04, 0x75,
-       0x5e, 0x4a, 0x4d, 0x77, 0xf2, 0xc0, 0x1c, 0x32, 0xfc, 0xa5, 0x02, 0xd5, 0x57, 0xd9, 0x35, 0x79,
-       0x1f, 0xea, 0x1a, 0x07, 0x53, 0x07, 0x15, 0xdc, 0x8a, 0x13, 0x50, 0x1a, 0x58, 0x5a, 0xac, 0x93,
-       0xa7, 0x50, 0x2f, 0x6e, 0x05, 0x6f, 0xfd, 0x56, 0x28, 0xd6, 0xc8, 0x57, 0xf0, 0xb0, 0x38, 0xb9,
-       0x64, 0x31, 0x84, 0x3a, 0xa8, 0x22, 0xfc, 0xc3, 0x39, 0x7c, 0x69, 0x42, 0xe9, 0x9e, 0xdb, 0x51,
-       0xf2, 0xdd, 0xd2, 0x02, 0xfe, 0x2d, 0x2d, 0x20, 0xa1, 0x71, 0x2e, 0x45, 0xda, 0x67, 0x9a, 0x93,
-       0x2f, 0x61, 0x6f, 0x03, 0x03, 0x37, 0xff, 0x9b, 0x09, 0x90, 0x75, 0x02, 0x76, 0xbe, 0x98, 0xea,
-       0x0b, 0xa3, 0x98, 0x7a, 0xe3, 0x2e, 0xf5, 0x85, 0x23, 0xfc, 0xbe, 0x02, 0xed, 0x6e, 0x6a, 0x14,
-       0x3b, 0x1f, 0x31, 0x91, 0xbe, 0xce, 0xcc, 0x34, 0x33, 0xe4, 0x00, 0x6a, 0xb9, 0x5a, 0x2e, 0xd9,
-       0x9a, 0x98, 0x6e, 0x99, 0x3c, 0x87, 0x56, 0x2c, 0x53, 0xa3, 0xe4, 0x38, 0xba, 0x43, 0xd3, 0x5d,
-       0x17, 0x53, 0x5c, 0xb4, 0x01, 0xd4, 0xa5, 0x4a, 0x44, 0xca, 0xc6, 0xae, 0x29, 0x0b, 0x13, 0xd9,
-       0x9c, 0x2b, 0xa9, 0xf5, 0x7f, 0x82, 0xcd, 0x8f, 0x15, 0x80, 0x9e, 0x34, 0xfc, 0x5f, 0xe6, 0x61,
-       0xff, 0xc8, 0x33, 0x69, 0x38, 0x5e, 0x8e, 0x3b, 0x14, 0xbf, 0xc3, 0x9f, 0x2b, 0xb0, 0xdd, 0xe3,
-       0x46, 0x76, 0x53, 0x4b, 0xed, 0x08, 0x5a, 0x7a, 0xca, 0x53, 0x13, 0x49, 0xa4, 0xba, 0xf8, 0x99,
-       0x2e, 0xe6, 0xf9, 0x01, 0x06, 0xe4, 0xa5, 0x74, 0x93, 0xdb, 0x9a, 0xcb, 0xfb, 0x93, 0xcd, 0xb5,
-       0xb1, 0xb9, 0xab, 0x9b, 0x9b, 0xbb, 0x5c, 0xa1, 0xbf, 0xac, 0xf4, 0x6b, 0x00, 0xca, 0x8d, 0x50,
-       0xdc, 0x06, 0xfe, 0x71, 0xa1, 0x4b, 0x80, 0xde, 0x32, 0xe0, 0x4f, 0x15, 0xd8, 0xba, 0x9c, 0xf2,
-       0x34, 0xf9, 0xdf, 0x4b, 0xf3, 0xab, 0x07, 0xad, 0xc5, 0x48, 0xe4, 0xc7, 0xfd, 0x09, 0xec, 0x4d,
-       0x98, 0x48, 0x63, 0xeb, 0xb9, 0xa3, 0xae, 0xce, 0x3c, 0xe8, 0xef, 0xae, 0x6d, 0x43, 0x87, 0x57,
-       0xef, 0xef, 0xf0, 0xcf, 0xa0, 0x9d, 0xbf, 0xf5, 0x92, 0xf9, 0x63, 0x0d, 0xab, 0x6d, 0x9e, 0xec,
-       0xcd, 0xdf, 0x2b, 0x8b, 0x77, 0x1c, 0x6d, 0xb1, 0x95, 0x87, 0xdd, 0x46, 0x45, 0xb7, 0xee, 0x57,
-       0xb4, 0xb6, 0xa4, 0x68, 0xbf, 0x86, 0xaf, 0xeb, 0xd3, 0xdf, 0x03, 0x00, 0x00, 0xff, 0xff, 0x20,
-       0xd9, 0x30, 0x59, 0x69, 0x0b, 0x00, 0x00,
+       // 967 bytes of a gzipped FileDescriptorProto
+       0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xd4, 0x56, 0x4b, 0x6f, 0x23, 0x45,
+       0x10, 0x96, 0xc7, 0x13, 0xdb, 0x29, 0x7b, 0x63, 0xbb, 0xb3, 0x0b, 0xa3, 0xd5, 0x22, 0xa2, 0x91,
+       0x96, 0x2c, 0x02, 0x45, 0x89, 0xb3, 0x3c, 0x0e, 0x08, 0x91, 0x4d, 0x58, 0xd6, 0x87, 0xd5, 0xa2,
+       0x4e, 0xe4, 0xeb, 0xa8, 0x3d, 0xd3, 0xb6, 0x5b, 0xd8, 0xd3, 0xa6, 0xbb, 0xc7, 0x79, 0xfc, 0x05,
+       0xce, 0x1c, 0xf8, 0x45, 0x1c, 0x10, 0x3f, 0x09, 0x81, 0xba, 0x66, 0xc6, 0xe3, 0x57, 0x12, 0x10,
+       0x20, 0xd8, 0xdb, 0xd4, 0xa3, 0xbf, 0xaa, 0xfa, 0xaa, 0xaa, 0xa7, 0xa1, 0xd6, 0x0f, 0x0f, 0xa6,
+       0x4a, 0x1a, 0x49, 0x9c, 0x7e, 0xe8, 0xbf, 0x04, 0xf7, 0x15, 0xd3, 0x23, 0xb2, 0x03, 0xce, 0xec,
+       0xd0, 0x2b, 0xed, 0x95, 0x9e, 0x55, 0xa8, 0x33, 0x3b, 0x44, 0xf9, 0xc8, 0x73, 0x32, 0xf9, 0x08,
+       0xe5, 0x8e, 0x57, 0xce, 0xe4, 0x0e, 0xca, 0xc7, 0x9e, 0x9b, 0xc9, 0xc7, 0xfe, 0x17, 0x50, 0xfd,
+       0x56, 0xc9, 0xa1, 0x62, 0x13, 0xf2, 0x1e, 0xc0, 0x6c, 0x12, 0xcc, 0xb8, 0xd2, 0x42, 0xc6, 0x08,
+       0xe9, 0xd2, 0xed, 0xd9, 0xa4, 0x97, 0x2a, 0x08, 0x01, 0x37, 0x94, 0x11, 0x47, 0xec, 0x06, 0xc5,
+       0x6f, 0xbf, 0x0b, 0xd5, 0x13, 0xad, 0xb9, 0xe9, 0x9e, 0xfd, 0xed, 0x44, 0x5e, 0x43, 0x1d, 0xa1,
+       0x4e, 0x26, 0x32, 0x89, 0x0d, 0xf9, 0x00, 0x6a, 0xcc, 0x8a, 0x81, 0x88, 0x10, 0xb4, 0xde, 0xa9,
+       0x1f, 0xf4, 0xc3, 0x83, 0x2c, 0x1a, 0xad, 0xa2, 0xb1, 0x1b, 0x91, 0x77, 0xa0, 0xc2, 0xf0, 0x04,
+       0x86, 0x72, 0x69, 0x26, 0xf9, 0x43, 0x68, 0xa2, 0xef, 0x19, 0x1f, 0x88, 0x58, 0x18, 0x5b, 0xc0,
+       0xa7, 0xd0, 0x12, 0x5a, 0x27, 0x2c, 0x0e, 0x79, 0x30, 0x4d, 0x6b, 0x5e, 0x84, 0xce, 0x68, 0xa0,
+       0xcd, 0xdc, 0x29, 0xe7, 0xe5, 0x09, 0xb8, 0x11, 0x33, 0x0c, 0x03, 0xd4, 0x3b, 0x35, 0xeb, 0x6b,
+       0xa9, 0xa7, 0xa8, 0xf5, 0xc7, 0x50, 0xef, 0xb1, 0x71, 0xc2, 0xcf, 0x65, 0xa2, 0x42, 0x4e, 0x1e,
+       0x43, 0x59, 0xf1, 0x41, 0x86, 0x5b, 0xf8, 0x5a, 0x25, 0x79, 0x0a, 0x5b, 0x33, 0xeb, 0x9a, 0x21,
+       0x35, 0xe7, 0x05, 0xa5, 0x35, 0xd3, 0xd4, 0x4a, 0x1e, 0x43, 0x6d, 0x2a, 0x35, 0xe6, 0x8c, 0x7c,
+       0xb9, 0x74, 0x2e, 0xfb, 0xdf, 0x43, 0x0b, 0xa3, 0x9d, 0x71, 0x6d, 0x44, 0xcc, 0xb0, 0xae, 0x7f,
+       0x39, 0xe4, 0xef, 0x0e, 0xd4, 0x5f, 0x8c, 0x65, 0xf8, 0xdd, 0x2b, 0xce, 0x22, 0xae, 0x88, 0x07,
+       0xd5, 0xe5, 0x19, 0xc9, 0x45, 0xdb, 0x8b, 0x11, 0x17, 0xc3, 0xd1, 0xbc, 0x17, 0xa9, 0x44, 0x9e,
+       0x43, 0x7b, 0xaa, 0xf8, 0x4c, 0xc8, 0x44, 0x07, 0x7d, 0x8b, 0x64, 0x9b, 0x5a, 0x5e, 0x49, 0xb7,
+       0x99, 0xbb, 0x60, 0xac, 0x6e, 0x44, 0x9e, 0xc0, 0xb6, 0x11, 0x13, 0xae, 0x0d, 0x9b, 0x4c, 0x71,
+       0x4e, 0x5c, 0x5a, 0x28, 0xc8, 0x27, 0xd0, 0x36, 0x8a, 0xc5, 0x9a, 0x85, 0x36, 0x49, 0x1d, 0x28,
+       0x29, 0x8d, 0xb7, 0xb5, 0x82, 0xd9, 0x5a, 0x74, 0xa1, 0x52, 0x1a, 0xf2, 0x15, 0xbc, 0xbb, 0xa0,
+       0x0b, 0xb4, 0x61, 0x26, 0xd1, 0xc1, 0x88, 0xe9, 0x91, 0x57, 0x59, 0x39, 0xfc, 0x68, 0xc1, 0xf1,
+       0x1c, 0xfd, 0x70, 0xe1, 0xce, 0x80, 0xac, 0x23, 0x78, 0x55, 0x3c, 0xfc, 0xc8, 0x1e, 0xbe, 0x58,
+       0x3d, 0x46, 0xdb, 0x6b, 0x48, 0xe4, 0x23, 0x68, 0x5f, 0x0a, 0x13, 0x73, 0xad, 0x03, 0xa6, 0x86,
+       0xc9, 0x84, 0xc7, 0x46, 0x7b, 0xb5, 0xbd, 0xf2, 0xb3, 0x06, 0x6d, 0x65, 0x86, 0x93, 0x5c, 0xef,
+       0xff, 0x58, 0x82, 0xda, 0xc5, 0xd5, 0xbd, 0xf4, 0xef, 0x43, 0x53, 0x73, 0x25, 0xd8, 0x58, 0xdc,
+       0xf0, 0x28, 0xd0, 0xe2, 0x86, 0x67, 0x7d, 0xd8, 0x29, 0xd4, 0xe7, 0xe2, 0x86, 0xdb, 0x45, 0xb7,
+       0x44, 0x06, 0x8a, 0xc5, 0x43, 0x9e, 0xf5, 0x1b, 0xa9, 0xa5, 0x56, 0x41, 0xf6, 0x01, 0x14, 0xd7,
+       0xc9, 0xd8, 0xee, 0x9e, 0xf6, 0xdc, 0xbd, 0xf2, 0x12, 0x2d, 0xdb, 0xa9, 0xad, 0x1b, 0x69, 0xff,
+       0x08, 0x76, 0x2e, 0xae, 0x7a, 0x5c, 0x89, 0xc1, 0x35, 0x45, 0x25, 0x79, 0x1f, 0xea, 0x19, 0xa5,
+       0x03, 0x26, 0xc6, 0x98, 0x60, 0x8d, 0x42, 0xaa, 0x7a, 0xc9, 0xc4, 0xd8, 0x1f, 0x40, 0x7b, 0x8d,
+       0x9f, 0x3b, 0x4a, 0xfa, 0x0c, 0x1e, 0xcc, 0x10, 0x3f, 0xe7, 0xd9, 0xc1, 0x6c, 0x08, 0xf2, 0xbc,
+       0x14, 0x9a, 0x36, 0x52, 0xc7, 0x14, 0xd2, 0xff, 0xb5, 0x04, 0xe5, 0xd7, 0xc9, 0x15, 0xf9, 0x10,
+       0xaa, 0x1a, 0x17, 0x53, 0x7b, 0x25, 0x3c, 0x8a, 0x1b, 0xb0, 0xb0, 0xb0, 0x34, 0xb7, 0x93, 0xa7,
+       0x50, 0xcd, 0x6f, 0x05, 0x67, 0xfd, 0x56, 0xc8, 0x6d, 0xe4, 0x1b, 0x78, 0x98, 0x77, 0x2e, 0x2a,
+       0x96, 0x50, 0x7b, 0x65, 0x84, 0x7f, 0x38, 0x87, 0x5f, 0xd8, 0x50, 0xba, 0x9b, 0x9d, 0x58, 0xd0,
+       0xdd, 0x32, 0x02, 0xee, 0x2d, 0x23, 0x20, 0xa1, 0x76, 0x2a, 0x45, 0xdc, 0x67, 0x9a, 0x93, 0xaf,
+       0x61, 0x77, 0x43, 0x06, 0xd9, 0xfe, 0x6f, 0x4e, 0x80, 0xac, 0x27, 0x60, 0xf7, 0x8b, 0xa9, 0xbe,
+       0x30, 0x8a, 0xa9, 0xeb, 0xec, 0x52, 0x2f, 0x14, 0xfe, 0x0f, 0x25, 0x68, 0x75, 0x63, 0xa3, 0xd8,
+       0xe9, 0x88, 0x89, 0xf8, 0x4d, 0x62, 0xa6, 0x89, 0x21, 0xfb, 0x50, 0x49, 0xd9, 0xca, 0x82, 0xad,
+       0x91, 0x99, 0x99, 0xc9, 0x73, 0x68, 0x86, 0x32, 0x36, 0x4a, 0x8e, 0x83, 0x3b, 0x38, 0xdd, 0xc9,
+       0x7c, 0xf2, 0x8b, 0xd6, 0x83, 0xaa, 0x54, 0x91, 0x88, 0xd9, 0x38, 0x1b, 0xca, 0x5c, 0xc4, 0x6c,
+       0x4e, 0x95, 0xd4, 0xfa, 0x7f, 0x91, 0xcd, 0x4f, 0x25, 0x80, 0x9e, 0x34, 0xfc, 0x3f, 0xce, 0xc3,
+       0xfe, 0x91, 0x67, 0xd2, 0x70, 0xbc, 0x1c, 0x1b, 0x14, 0xbf, 0xfd, 0x5f, 0x4a, 0xb0, 0xdd, 0xe3,
+       0x46, 0x76, 0x63, 0x9b, 0xda, 0x21, 0x34, 0xf5, 0x94, 0xc7, 0x26, 0x90, 0x98, 0x6a, 0xf1, 0x33,
+       0x2d, 0xf6, 0xf9, 0x01, 0x3a, 0xa4, 0xa5, 0x74, 0xa3, 0xdb, 0x86, 0xcb, 0xf9, 0x8b, 0xc3, 0xb5,
+       0x71, 0xb8, 0xcb, 0x9b, 0x87, 0x7b, 0xb1, 0x42, 0x77, 0x99, 0xe9, 0x37, 0x00, 0x94, 0x1b, 0xa1,
+       0xb8, 0x75, 0xfc, 0xf3, 0x44, 0x2f, 0x00, 0x3a, 0xcb, 0x80, 0x3f, 0x97, 0x60, 0xeb, 0x7c, 0xca,
+       0xe3, 0xe8, 0xad, 0xa7, 0xe6, 0x37, 0x07, 0x9a, 0xc5, 0x4a, 0xa4, 0xed, 0xfe, 0x1c, 0x76, 0x27,
+       0x4c, 0xc4, 0xa1, 0xd5, 0xdc, 0x51, 0x57, 0x7b, 0xee, 0xf4, 0x4f, 0xd7, 0xb6, 0x61, 0xc2, 0xcb,
+       0xf7, 0x4f, 0xf8, 0x97, 0xd0, 0x4a, 0xdf, 0x7a, 0xd1, 0xfc, 0xb1, 0x86, 0xd5, 0xd6, 0x3b, 0xbb,
+       0xf3, 0xf7, 0x4a, 0xf1, 0x8e, 0xa3, 0x4d, 0xb6, 0xf2, 0xb0, 0xdb, 0xc8, 0xe8, 0xd6, 0xfd, 0x8c,
+       0x56, 0x96, 0xd7, 0xe9, 0x63, 0x68, 0x2b, 0x76, 0x59, 0xe0, 0xbe, 0xb8, 0x36, 0x1c, 0x7f, 0xec,
+       0x0d, 0xba, 0x6e, 0xe8, 0x57, 0xf0, 0x2d, 0x7e, 0xfc, 0x47, 0x00, 0x00, 0x00, 0xff, 0xff, 0x2a,
+       0xe9, 0x2b, 0xb1, 0x97, 0x0b, 0x00, 0x00,
 }
index 59190d4..ddc90bd 100644 (file)
@@ -132,4 +132,5 @@ message CrossChainInput {
   AssetDefinition  asset_definition          = 4;
   repeated bytes   witness_arguments         = 5;
   uint64           ordinal                   = 6;
+  bytes            rawDefinitionByte         = 7;
 }
index e9014c2..08a7cc7 100644 (file)
@@ -22,11 +22,12 @@ func (cci *CrossChainInput) SetDestination(id *Hash, val *AssetAmount, pos uint6
 }
 
 // NewCrossChainInput creates a new CrossChainInput.
-func NewCrossChainInput(mainchainOutputID *Hash, prog *Program, ordinal uint64, assetDef *AssetDefinition) *CrossChainInput {
+func NewCrossChainInput(mainchainOutputID *Hash, prog *Program, ordinal uint64, assetDef *AssetDefinition, rawDefinitionByte []byte) *CrossChainInput {
        return &CrossChainInput{
                MainchainOutputId: mainchainOutputID,
                Ordinal:           ordinal,
                ControlProgram:    prog,
                AssetDefinition:   assetDef,
+               RawDefinitionByte: rawDefinitionByte,
        }
 }
index 34520be..8ce9fbc 100644 (file)
@@ -76,6 +76,7 @@ func TestEntryID(t *testing.T) {
                                        IssuanceProgram: &Program{VmVersion: 1, Code: []byte{1, 2, 3, 4}},
                                        Data:            &Hash{V0: 0, V1: 1, V2: 2, V3: 3},
                                },
+                               []byte{},
                        ),
                        expectEntryID: "14bb3f6e68f37d037b1f1539a21ab41e182b8d59d703a1af6c426d52cfc775d9",
                },
index b75c9c6..86fa1e8 100644 (file)
@@ -163,7 +163,7 @@ func mapTx(tx *TxData) (headerID bc.Hash, hdr *bc.TxHeader, entryMap map[bc.Hash
                                },
                        }
 
-                       crossIn := bc.NewCrossChainInput(&mainchainOutputID, prog, uint64(i), assetDef)
+                       crossIn := bc.NewCrossChainInput(&mainchainOutputID, prog, uint64(i), assetDef, inp.AssetDefinition)
                        crossIn.WitnessArguments = inp.Arguments
                        crossInID := addEntry(crossIn)
                        muxSources[i] = &bc.ValueSource{
index 6053270..ccbe7f2 100644 (file)
@@ -5,8 +5,10 @@ import (
        "math"
        "sync"
 
+       "github.com/vapor/common"
        "github.com/vapor/config"
        "github.com/vapor/consensus"
+       "github.com/vapor/consensus/segwit"
        "github.com/vapor/errors"
        "github.com/vapor/math/checked"
        "github.com/vapor/protocol/bc"
@@ -277,9 +279,24 @@ func checkValid(vs *validationState, e bc.Entry) (err error) {
                        return errors.New("incorrect asset_id while checking CrossChainInput")
                }
 
+               code := config.FederationWScript(config.CommonConfig.Federation)
+
+               isCrossChainOfNoBytom, err := common.IsCrossChainAssetOfNoBytom(e.RawDefinitionByte)
+               if err != nil {
+                       return err
+               }
+
+               if isCrossChainOfNoBytom {
+                       pubs, required, err := segwit.GetXpubsAndRequiredFromProg(e.AssetDefinition.IssuanceProgram.Code)
+                       if err != nil {
+                               return err
+                       }
+                       code = config.FederationWScriptFromPubs(pubs, required)
+               }
+
                prog := &bc.Program{
                        VmVersion: e.ControlProgram.VmVersion,
-                       Code:      config.FederationWScript(config.CommonConfig),
+                       Code:      code,
                }
 
                if _, err := vm.Verify(NewTxVMContext(vs, e, prog, e.WitnessArguments), consensus.ActiveNetParams.DefaultGasCredit); err != nil {