From: wz Date: Tue, 22 Oct 2019 07:02:45 +0000 (+0800) Subject: modify crossin transaction X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=92006481da0ed9f0f8bbf0afa3ad2ee1d4acefdc;p=bytom%2Fvapor.git modify crossin transaction --- diff --git a/api/nodeinfo.go b/api/nodeinfo.go index ac085ffa..8424647c 100644 --- a/api/nodeinfo.go +++ b/api/nodeinfo.go @@ -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 { diff --git a/blockchain/txbuilder/actions.go b/blockchain/txbuilder/actions.go index f5b40bc0..b88da89e 100644 --- a/blockchain/txbuilder/actions.go +++ b/blockchain/txbuilder/actions.go @@ -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/config/federation_test.go b/config/federation_test.go index 00e92ade..b8cce6f7 100644 --- a/config/federation_test.go +++ b/config/federation_test.go @@ -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) diff --git a/config/genesis.go b/config/genesis.go index a3b2f7e2..85ca145a 100644 --- a/config/genesis.go +++ b/config/genesis.go @@ -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, diff --git a/consensus/segwit/segwit.go b/consensus/segwit/segwit.go index 1477fdd8..3aa8e173 100644 --- a/consensus/segwit/segwit.go +++ b/consensus/segwit/segwit.go @@ -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,44 @@ func GetHashFromStandardProg(prog []byte) ([]byte, error) { return insts[1].Data, nil } + +func GetXpubsAndRequiredFromProg(prog []byte) ([]ed25519.PublicKey, int, error) { + // if program is P2PKH or P2SH script, convert it into actual executed program + if IsP2WPKHScript(prog) { + if witnessProg, err := ConvertP2PKHSigProgram(prog); err == nil { + prog = witnessProg + } + } else if IsP2WSHScript(prog) { + if witnessProg, err := ConvertP2SHProgram(prog); err == nil { + prog = witnessProg + } + } + + insts, err := vm.ParseProgram(prog) + if err != nil { + return nil, 0, err + } + + instsLen := len(insts) + + if insts[0].Op != vm.OP_TXSIGHASH || insts[instsLen-1].Op != vm.OP_CHECKMULTISIG { + return nil, 0, errors.New("instruction is error") + } + + 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++ { + pubs = append(pubs, insts[i].Data) + } + + return pubs, int(required), nil +} diff --git a/consensus/segwit/segwit_test.go b/consensus/segwit/segwit_test.go index 14ec13b6..6e081354 100644 --- a/consensus/segwit/segwit_test.go +++ b/consensus/segwit/segwit_test.go @@ -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,55 @@ func TestProgramType(t *testing.T) { } } } + +func TestGetXpubsAndRequiredFromProg(t *testing.T) { + xpubStr1 := "95a1fdf4d9c30a0daf3ef6ec475058ba09b62677ce1384e33a17d028c1755ede896ec9fd8abecf0fdef9d89bba8f0d7c2576a3e78120336584884e516e128354" + xpubStr2 := "bfc74caeb528064b056d7d1edd2913c9fb35a1bdd921087972effeb8ceb90f152b1e03199efbfc924fd7665107914309a6dcc12930256867a94b97855b392ff5" + + 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) + } + + cases := []struct { + desc string + program string + wantXpubs []ed25519.PublicKey + wantRequired int + }{ + { + desc: "one xpun", + program: "ae20f5f412c87794b137b9433ce7d1cbb147fe5d87ca03a81d28eaba4264d7a74fc65151ad", + wantXpubs: []ed25519.PublicKey{xpub1.PublicKey()}, + wantRequired: 1, + }, + { + desc: "two xpun", + program: "ae2099dbcf35be6b199e3183c7bbfe5a89d1d13978b5e1ceacbf7779507a998ba0e120ccbbbb7c72a7f8a77f227747bc8bc1f38a76ff112f395b5ff05c002e84ccd79e5152ad", + wantXpubs: []ed25519.PublicKey{xpub1.PublicKey(), xpub2.PublicKey()}, + wantRequired: 1, + }, + } + + 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) + + } + } +} diff --git a/node/node.go b/node/node.go index c160f17c..cdafc367 100644 --- a/node/node.go +++ b/node/node.go @@ -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 diff --git a/protocol/bc/bc.pb.go b/protocol/bc/bc.pb.go index b65b3b7f..d302d9bc 100644 --- a/protocol/bc/bc.pb.go +++ b/protocol/bc/bc.pb.go @@ -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 FileD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6d, 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, 0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e3, 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, } diff --git a/protocol/bc/bc.proto b/protocol/bc/bc.proto index 59190d4c..ddc90bdd 100644 --- a/protocol/bc/bc.proto +++ b/protocol/bc/bc.proto @@ -132,4 +132,5 @@ message CrossChainInput { AssetDefinition asset_definition = 4; repeated bytes witness_arguments = 5; uint64 ordinal = 6; + bytes rawDefinitionByte = 7; } diff --git a/protocol/bc/crosschain_input.go b/protocol/bc/crosschain_input.go index e9014c27..08a7cc76 100644 --- a/protocol/bc/crosschain_input.go +++ b/protocol/bc/crosschain_input.go @@ -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, } } diff --git a/protocol/bc/entry_test.go b/protocol/bc/entry_test.go index 34520be8..8ce9fbcb 100644 --- a/protocol/bc/entry_test.go +++ b/protocol/bc/entry_test.go @@ -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", }, diff --git a/protocol/bc/types/map.go b/protocol/bc/types/map.go index b75c9c6b..86fa1e83 100644 --- a/protocol/bc/types/map.go +++ b/protocol/bc/types/map.go @@ -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{ diff --git a/protocol/validation/tx.go b/protocol/validation/tx.go index 60532702..ccbe7f27 100644 --- a/protocol/validation/tx.go +++ b/protocol/validation/tx.go @@ -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 {