Skip to content

Commit

Permalink
Merge pull request #54 from babylonchain/gai/bump-babylon-0.9.0-rc.3
Browse files Browse the repository at this point in the history
hotfix: Bump babylon and renamed magic bytes to tag
  • Loading branch information
gitferry authored Jul 16, 2024
2 parents 8ba711e + f472d66 commit 1320849
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 55 deletions.
20 changes: 10 additions & 10 deletions cmd/createStakingTxCmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
)

var (
FlagMagicBytes = "magic-bytes"
FlagTag = "tag"
FlagStakerPk = "staker-pk"
FlagStakingAmount = "staking-amount"
FlagStakingTime = "staking-time"
Expand Down Expand Up @@ -186,17 +186,17 @@ func parseTimeLock(timeBlocks int64) (uint16, error) {
return uint16(timeBlocks), nil
}

func parseMagicBytesFromHex(magicBytesHex string) ([]byte, error) {
magicBytes, err := hex.DecodeString(magicBytesHex)
func parseTagFromHex(tagHex string) ([]byte, error) {
tag, err := hex.DecodeString(tagHex)
if err != nil {
return nil, err
}

if len(magicBytes) != btcstaking.MagicBytesLen {
return nil, fmt.Errorf("magic bytes should be of length %d", btcstaking.MagicBytesLen)
if len(tag) != btcstaking.TagLen {
return nil, fmt.Errorf("tag should be of length %d", btcstaking.TagLen)
}

return magicBytes, nil
return tag, nil
}

func parsePosNum(num int64) (uint32, error) {
Expand All @@ -216,8 +216,8 @@ type CreateStakingTxResp struct {
}

func init() {
createStakingTxCmd.Flags().String(FlagMagicBytes, "", "magic bytes")
_ = createStakingTxCmd.MarkFlagRequired(FlagMagicBytes)
createStakingTxCmd.Flags().String(FlagTag, "", "tag")
_ = createStakingTxCmd.MarkFlagRequired(FlagTag)
createStakingTxCmd.Flags().String(FlagStakerPk, "", "staker pk")
_ = createStakingTxCmd.MarkFlagRequired(FlagStakerPk)
createStakingTxCmd.Flags().String(FlagFinalityProviderPk, "", "finality provider pk")
Expand Down Expand Up @@ -246,7 +246,7 @@ var createStakingTxCmd = &cobra.Command{
return err
}

magicBytes, err := parseMagicBytesFromHex(mustGetStringFlag(cmd, FlagMagicBytes))
tag, err := parseTagFromHex(mustGetStringFlag(cmd, FlagTag))

if err != nil {
return err
Expand Down Expand Up @@ -289,7 +289,7 @@ var createStakingTxCmd = &cobra.Command{
}

_, tx, err := btcstaking.BuildV0IdentifiableStakingOutputsAndTx(
magicBytes,
tag,
stakerPk,
finalityProviderPk,
covenantCommitteePks,
Expand Down
13 changes: 7 additions & 6 deletions cmd/createUnbondingTxCmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import (
"fmt"

"github.com/babylonchain/babylon/btcstaking"
"github.com/babylonchain/cli-tools/internal/btcclient"
"github.com/babylonchain/cli-tools/internal/config"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/wire"
"github.com/decred/dcrd/dcrec/secp256k1/v4"
"github.com/spf13/cobra"

"github.com/babylonchain/cli-tools/internal/btcclient"
"github.com/babylonchain/cli-tools/internal/config"
)

var (
Expand All @@ -31,8 +32,8 @@ func init() {
// parsing it wil fail
createUnbondingTxCmd.Flags().String(FlagStakingTxHex, "", "funded staking tx hex")
_ = createUnbondingTxCmd.MarkFlagRequired(FlagStakingTxHex)
createUnbondingTxCmd.Flags().String(FlagMagicBytes, "", "magic bytes")
_ = createUnbondingTxCmd.MarkFlagRequired(FlagMagicBytes)
createUnbondingTxCmd.Flags().String(FlagTag, "", "tag")
_ = createUnbondingTxCmd.MarkFlagRequired(FlagTag)
createUnbondingTxCmd.Flags().Int64(FlagUnbondingTime, 0, "unbonding time")
_ = createUnbondingTxCmd.MarkFlagRequired(FlagUnbondingTime)
createUnbondingTxCmd.Flags().Int64(FlagUnbondingTxFee, 0, "unbonding fee")
Expand Down Expand Up @@ -142,7 +143,7 @@ var createUnbondingTxCmd = &cobra.Command{
return err
}

magicBytes, err := parseMagicBytesFromHex(mustGetStringFlag(cmd, FlagMagicBytes))
tag, err := parseTagFromHex(mustGetStringFlag(cmd, FlagTag))

if err != nil {
return err
Expand Down Expand Up @@ -180,7 +181,7 @@ var createUnbondingTxCmd = &cobra.Command{

parsedStakingTx, err := btcstaking.ParseV0StakingTx(
stakingTx,
magicBytes,
tag,
covenantCommitteePks,
covenantQuorum,
btcParams,
Expand Down
13 changes: 7 additions & 6 deletions cmd/createWithdrawTxCmg.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"fmt"

"github.com/babylonchain/babylon/btcstaking"
"github.com/babylonchain/cli-tools/internal/btcclient"
"github.com/babylonchain/cli-tools/internal/config"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcd/wire"
"github.com/spf13/cobra"

"github.com/babylonchain/cli-tools/internal/btcclient"
"github.com/babylonchain/cli-tools/internal/config"
)

var (
Expand All @@ -24,8 +25,8 @@ func init() {
// parsing it wil fail
createWithdrawCmd.Flags().String(FlagStakingTxHex, "", "funded staking tx hex")
_ = createWithdrawCmd.MarkFlagRequired(FlagStakingTxHex)
createWithdrawCmd.Flags().String(FlagMagicBytes, "", "magic bytes")
_ = createWithdrawCmd.MarkFlagRequired(FlagMagicBytes)
createWithdrawCmd.Flags().String(FlagTag, "", "tag")
_ = createWithdrawCmd.MarkFlagRequired(FlagTag)
createWithdrawCmd.Flags().Int64(FlagWithdrawTxFee, 0, "withdraw fee")
_ = createWithdrawCmd.MarkFlagRequired(FlagWithdrawTxFee)
createWithdrawCmd.Flags().StringSlice(FlagCovenantCommitteePks, nil, "covenant committee pks")
Expand Down Expand Up @@ -74,7 +75,7 @@ var createWithdrawCmd = &cobra.Command{
return err
}

magicBytes, err := parseMagicBytesFromHex(mustGetStringFlag(cmd, FlagMagicBytes))
tag, err := parseTagFromHex(mustGetStringFlag(cmd, FlagTag))

if err != nil {
return err
Expand Down Expand Up @@ -118,7 +119,7 @@ var createWithdrawCmd = &cobra.Command{

parsedStakingTx, err := btcstaking.ParseV0StakingTx(
stakingTx,
magicBytes,
tag,
covenantCommitteePks,
covenantQuorum,
btcParams,
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ go 1.22.3
toolchain go1.22.4

require (
github.com/babylonchain/babylon v0.9.0-rc.1
github.com/babylonchain/babylon v0.9.0-rc.3
github.com/babylonchain/covenant-signer v0.2.6
github.com/babylonchain/networks/parameters v0.2.1
github.com/btcsuite/btcd v0.24.0
github.com/btcsuite/btcd v0.24.2
github.com/btcsuite/btcd/btcec/v2 v2.3.2
github.com/btcsuite/btcd/btcutil v1.1.5
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0
Expand Down Expand Up @@ -262,6 +262,7 @@ require (
github.com/sasha-s/go-deadlock v0.3.1 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/soheilhy/cmux v0.1.5 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/supranational/blst v0.3.11 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
github.com/tendermint/go-amino v0.16.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ github.com/aws/aws-sdk-go v1.44.122/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX
github.com/aws/aws-sdk-go v1.44.312 h1:llrElfzeqG/YOLFFKjg1xNpZCFJ2xraIi3PqSuP+95k=
github.com/aws/aws-sdk-go v1.44.312/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
github.com/babylonchain/babylon v0.9.0-rc.1 h1:mZYKQVHVKFUA2xaEAzJloB1kyePHvZECJPgm3p9TYas=
github.com/babylonchain/babylon v0.9.0-rc.1/go.mod h1:YFALTW+Kp/b5jSDoA7Z70RggJjAedlmQTrpdeU8c3hY=
github.com/babylonchain/babylon v0.9.0-rc.3 h1:Coaf37uqVvNBMpR0VR8nRcJsCx9FpAU4psRc5BGK1K8=
github.com/babylonchain/babylon v0.9.0-rc.3/go.mod h1:QTjpnEAEReQofIpZikCQXUZxSkdK0TrWAUbgxOSF9yA=
github.com/babylonchain/covenant-signer v0.2.6 h1:Dh72ounwl4WsPVd99IBY7uWlSv7zOXwWeMLOfkEx4+U=
github.com/babylonchain/covenant-signer v0.2.6/go.mod h1:67vSxNxAi/tfDp0WhVK2Sutj/f/ml1lJERY3asR3VuU=
github.com/babylonchain/networks/parameters v0.2.1 h1:OKHiCnwL/UdVN17cMwCrHz/bAjO/USauLiPyNlnVl6E=
Expand All @@ -304,8 +304,8 @@ github.com/btcsuite/btcd v0.22.0-beta.0.20220207191057-4dc4ff7963b4/go.mod h1:7a
github.com/btcsuite/btcd v0.23.1/go.mod h1:0QJIIN1wwIXF/3G/m87gIwGniDMDQqjVn4SZgnFpsYY=
github.com/btcsuite/btcd v0.23.3/go.mod h1:0QJIIN1wwIXF/3G/m87gIwGniDMDQqjVn4SZgnFpsYY=
github.com/btcsuite/btcd v0.23.5-0.20231215221805-96c9fd8078fd/go.mod h1:nm3Bko6zh6bWP60UxwoT5LzdGJsQJaPo6HjduXq9p6A=
github.com/btcsuite/btcd v0.24.0 h1:gL3uHE/IaFj6fcZSu03SvqPMSx7s/dPzfpG/atRwWdo=
github.com/btcsuite/btcd v0.24.0/go.mod h1:K4IDc1593s8jKXIF7yS7yCTSxrknB9z0STzc2j6XgE4=
github.com/btcsuite/btcd v0.24.2 h1:aLmxPguqxza+4ag8R1I2nnJjSu2iFn/kqtHTIImswcY=
github.com/btcsuite/btcd v0.24.2/go.mod h1:5C8ChTkl5ejr3WHj8tkQSCmydiMEPB0ZhQhehpq7Dgg=
github.com/btcsuite/btcd/btcec/v2 v2.1.0/go.mod h1:2VzYrv4Gm4apmbVVsSq5bqf1Ec8v56E48Vt0Y/umPgA=
github.com/btcsuite/btcd/btcec/v2 v2.1.3/go.mod h1:ctjw4H1kknNJmRN4iP1R7bTQ+v3GJkZBd6mui8ZsAZE=
github.com/btcsuite/btcd/btcec/v2 v2.3.2 h1:5n0X6hX0Zk+6omWcihdYvdAlGf2DfasC0GMf7DClJ3U=
Expand Down
2 changes: 1 addition & 1 deletion internal/services/expected_interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ type BtcSender interface {
type SystemParams struct {
CovenantPublicKeys []*btcec.PublicKey
CovenantQuorum uint32
MagicBytes []byte
Tag []byte
}

type ParamsRetriever interface {
Expand Down
2 changes: 1 addition & 1 deletion internal/services/global_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ func (g *VersionedParamsRetriever) ParamsByHeight(_ context.Context, height uint
return &SystemParams{
CovenantPublicKeys: versionedParams.CovenantPks,
CovenantQuorum: versionedParams.CovenantQuorum,
MagicBytes: versionedParams.Tag,
Tag: versionedParams.Tag,
}, nil
}
15 changes: 8 additions & 7 deletions internal/services/unbonding_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ import (

"github.com/babylonchain/babylon/btcstaking"
"github.com/babylonchain/babylon/types"
"github.com/babylonchain/cli-tools/internal/btcclient"
"github.com/babylonchain/cli-tools/internal/config"
"github.com/babylonchain/cli-tools/internal/db"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcec/v2/schnorr"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/prometheus/client_golang/prometheus/push"

"github.com/babylonchain/cli-tools/internal/btcclient"
"github.com/babylonchain/cli-tools/internal/config"
"github.com/babylonchain/cli-tools/internal/db"
)

var (
Expand Down Expand Up @@ -58,26 +59,26 @@ func pubKeyToStringCompressed(pubKey *btcec.PublicKey) string {
type SystemParamsRetriever struct {
CovenantPublicKeys []*btcec.PublicKey
CovenantQuorum uint32
MagicBytes []byte
Tag []byte
}

func NewSystemParamsRetriever(
quorum uint32,
pubKeys []*btcec.PublicKey,
magicBytes []byte,
tag []byte,
) *SystemParamsRetriever {
return &SystemParamsRetriever{
CovenantQuorum: quorum,
CovenantPublicKeys: pubKeys,
MagicBytes: magicBytes,
Tag: tag,
}
}

func (p *SystemParamsRetriever) GetParams() (*SystemParams, error) {
return &SystemParams{
CovenantQuorum: p.CovenantQuorum,
CovenantPublicKeys: p.CovenantPublicKeys,
MagicBytes: p.MagicBytes,
Tag: p.Tag,
}, nil
}

Expand Down
17 changes: 9 additions & 8 deletions internal/services/unbonding_pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ import (
"testing"

"github.com/babylonchain/babylon/btcstaking"
"github.com/babylonchain/cli-tools/internal/config"
"github.com/babylonchain/cli-tools/internal/logger"
"github.com/babylonchain/cli-tools/internal/mocks"
"github.com/babylonchain/cli-tools/internal/services"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcec/v2/schnorr"
"github.com/btcsuite/btcd/btcutil"
Expand All @@ -17,11 +13,16 @@ import (
"github.com/btcsuite/btcd/wire"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"

"github.com/babylonchain/cli-tools/internal/config"
"github.com/babylonchain/cli-tools/internal/logger"
"github.com/babylonchain/cli-tools/internal/mocks"
"github.com/babylonchain/cli-tools/internal/services"
)

var (
testParams = chaincfg.MainNetParams
magicBytes = []byte{0x00, 0x01, 0x02, 0x03}
tag = []byte{0x00, 0x01, 0x02, 0x03}
)

type MockedDependencies struct {
Expand Down Expand Up @@ -56,7 +57,7 @@ func NewUnbondingData(
fpKey, err := btcec.NewPrivateKey()
require.NoError(t, err)
stakingInfo, stakingTx, err := btcstaking.BuildV0IdentifiableStakingOutputsAndTx(
magicBytes,
tag,
stakerPubKey,
fpKey.PubKey(),
covenantInfo.GetCovenantPublicKeys(),
Expand Down Expand Up @@ -183,7 +184,7 @@ func TestValidSigningFlow(t *testing.T) {
deps.pr.EXPECT().ParamsByHeight(gomock.Any(), uint64(stakingTxHeight)).Return(&services.SystemParams{
CovenantPublicKeys: covenantMembers.GetCovenantPublicKeys(),
CovenantQuorum: covenantQuorum,
MagicBytes: magicBytes,
Tag: tag,
}, nil)
deps.cs.EXPECT().SignUnbondingTransaction(gomock.Any()).Return(covenantSignatures[0], nil)
deps.bs.EXPECT().CheckTxOutSpendable(
Expand Down Expand Up @@ -229,7 +230,7 @@ func TestInvalidSignatureHandling(t *testing.T) {
deps.pr.EXPECT().ParamsByHeight(gomock.Any(), uint64(stakingTxHeight)).Return(&services.SystemParams{
CovenantPublicKeys: covenantMembers.GetCovenantPublicKeys(),
CovenantQuorum: covenantQuorum,
MagicBytes: magicBytes,
Tag: tag,
}, nil)

// tamper signature so it is invalid
Expand Down
2 changes: 1 addition & 1 deletion internal/services/witness_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func CreateUnbondingPathSpendInfo(
net *chaincfg.Params,
) (*wire.TxOut, *staking.SpendInfo, error) {
info, err := staking.BuildV0IdentifiableStakingOutputs(
params.MagicBytes,
params.Tag,
stakingInfo.StakerPk,
stakingInfo.FinalityProviderPk,
params.CovenantPublicKeys,
Expand Down
Loading

0 comments on commit 1320849

Please sign in to comment.