Skip to content

Commit

Permalink
Merge pull request #1160 from maticnetwork/dependabot/go_modules/gola…
Browse files Browse the repository at this point in the history
…ng.org/x/net-0.23.0

Bump golang.org/x/net from 0.17.0 to 0.23.0
  • Loading branch information
pratikspatil024 committed May 3, 2024
2 parents 3721597 + d29eb2f commit 08e0e44
Show file tree
Hide file tree
Showing 16 changed files with 67 additions and 22 deletions.
6 changes: 5 additions & 1 deletion bridge/setu/listener/rootchain_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ func (rl *RootChainListener) handleStakedLog(vLog types.Log, selectedEvent *abi.
rl.Logger.Error("Error while parsing event", "name", selectedEvent.Name, "error", err)
}

if !util.IsPubKeyFirstByteValid(pubkey[0:1]) {
rl.Logger.Error("public key first byte mismatch", "expected", "0x04", "received", pubkey[0:1])
}

if bytes.Equal(event.SignerPubkey, pubkey[1:]) {
// topup has to be processed first before validator join. so adding delay.
delay := util.TaskDelayBetweenEachVal
Expand Down Expand Up @@ -106,7 +110,7 @@ func (rl *RootChainListener) handleSignerChangeLog(vLog types.Log, selectedEvent
rl.Logger.Error("Error while parsing event", "name", selectedEvent.Name, "error", err)
}

if bytes.Equal(event.SignerPubkey, pubkey[1:]) {
if bytes.Equal(event.SignerPubkey, pubkey[1:]) && util.IsPubKeyFirstByteValid(pubkey[0:1]) {
rl.SendTaskWithDelay("sendSignerChangeToHeimdall", selectedEvent.Name, logBytes, 0, event)
} else if isCurrentValidator, delay := util.CalculateTaskDelay(rl.cliCtx, event); isCurrentValidator {
rl.SendTaskWithDelay("sendSignerChangeToHeimdall", selectedEvent.Name, logBytes, delay, event)
Expand Down
9 changes: 9 additions & 0 deletions bridge/setu/util/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -703,3 +703,12 @@ func LogElapsedTimeForStateSyncedEvent(event interface{}, functionName string, s
"stateSyncId", typedEvent.Id,
"timeElapsed", timeElapsed)
}

// IsPubKeyFirstByteValid checks the validity of the first byte of the public key.
// It must be 0x04 for uncompressed public keys
func IsPubKeyFirstByteValid(pubKey []byte) bool {
prefix := make([]byte, 1)
prefix[0] = byte(0x04)

return bytes.Equal(prefix, pubKey[0:1])
}
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,10 @@ require (
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.19.0
go.opentelemetry.io/otel/sdk v1.24.0
go.opentelemetry.io/otel/trace v1.24.0
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/oauth2 v0.16.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/api v0.155.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2229,8 +2229,8 @@ golang.org/x/crypto v0.10.0/go.mod h1:o4eNf7Ede1fv+hwOwZsTHl9EsPFO6q6ZvYR8vYfY45
golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio=
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc=
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
Expand Down Expand Up @@ -2393,8 +2393,8 @@ golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ=
golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down Expand Up @@ -2594,8 +2594,8 @@ golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
Expand Down
11 changes: 11 additions & 0 deletions helper/tx.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package helper

import (
"bytes"
"context"
"encoding/hex"
"errors"
"fmt"
"math/big"
"strings"
Expand Down Expand Up @@ -155,6 +157,15 @@ func (c *ContractCaller) SendTick(signedData []byte, sigs []byte, slashManagerAd
// StakeFor stakes for a validator
func (c *ContractCaller) StakeFor(val common.Address, stakeAmount *big.Int, feeAmount *big.Int, acceptDelegation bool, stakeManagerAddress common.Address, stakeManagerInstance *stakemanager.Stakemanager) error {
signerPubkey := GetPubKey()

prefix := make([]byte, 1)
prefix[0] = byte(0x04)

if !bytes.Equal(prefix, signerPubkey[0:1]) {
Logger.Error("public key first byte mismatch", "expected", "0x04", "received", signerPubkey[0:1])
return errors.New("public key first byte mismatch")
}

signerPubkeyBytes := signerPubkey[1:] // remove 04 prefix

// pack data based on method definition
Expand Down
4 changes: 2 additions & 2 deletions packaging/deb/heimdalld/DEBIAN/control
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ Section: develop
Priority: Testing
Maintainer: Polygon <team@polygon.technology>
Build-Depends: debhelper-compat (= 13)
Standards-Version: v1.0.3-amoy-2
Standards-Version: v1.0.5
Homepage: https://polygon.technology
Rules-Requires-Root: no
Package: heimdalld
Version: 1.0.3-amoy-2
Version: 1.0.5
Architecture: amd64
Multi-Arch: foreign
Depends:
Expand Down
2 changes: 1 addition & 1 deletion packaging/templates/package_scripts/control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Source: heimdalld
Version: 1.0.3-amoy-2
Version: 1.0.5
Section: develop
Priority: standard
Maintainer: Polygon <release-team@polygon.technology>
Expand Down
2 changes: 1 addition & 1 deletion packaging/templates/package_scripts/control.arm64
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Source: heimdalld
Version: 1.0.3-amoy-2
Version: 1.0.5
Section: develop
Priority: standard
Maintainer: Polygon <release-team@polygon.technology>
Expand Down
2 changes: 1 addition & 1 deletion packaging/templates/package_scripts/control.profile.amd64
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Source: heimdalld-profile
Version: 1.0.3-amoy-2
Version: 1.0.5
Section: develop
Priority: standard
Maintainer: Polygon <release-team@polygon.technology>
Expand Down
2 changes: 1 addition & 1 deletion packaging/templates/package_scripts/control.profile.arm64
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Source: heimdalld-profile
Version: 1.0.3-amoy-2
Version: 1.0.5
Section: develop
Priority: standard
Maintainer: Polygon <release-team@polygon.technology>
Expand Down
4 changes: 2 additions & 2 deletions packaging/templates/package_scripts/control.validator
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ Section: develop
Priority: Testing
Maintainer: Polygon <team@polygon.technology>
Build-Depends: debhelper-compat (= 13)
Standards-Version: v1.0.3-amoy-2
Standards-Version: v1.0.5
Homepage: https://polygon.technology
Rules-Requires-Root: no
Package: heimdalld-profile
Version: 1.0.3-amoy-2
Version: 1.0.5
Architecture: amd64
Multi-Arch: foreign
Depends: rabbitmq-server
Expand Down
4 changes: 2 additions & 2 deletions packaging/templates/package_scripts/control.validator.arm64
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ Section: develop
Priority: Testing
Maintainer: Polygon <team@polygon.technology>
Build-Depends: debhelper-compat (= 13)
Standards-Version: v1.0.3-amoy-2
Standards-Version: v1.0.5
Homepage: https://polygon.technology
Rules-Requires-Root: no
Package: heimdalld-profile
Version: 1.0.3-amoy-2
Version: 1.0.5
Architecture: arm64
Multi-Arch: foreign
Depends: rabbitmq-server
Expand Down
8 changes: 8 additions & 0 deletions staking/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ func SendValidatorJoinTx(cdc *codec.Codec) *cobra.Command {
return fmt.Errorf("Invalid tx for validator join")
}

if !util.IsPubKeyFirstByteValid(pubkey.Bytes()[0:1]) {
return fmt.Errorf("public key first byte mismatch")
}

if !bytes.Equal(event.SignerPubkey, pubkey.Bytes()[1:]) {
return fmt.Errorf("Public key mismatch with event log")
}
Expand Down Expand Up @@ -276,6 +280,10 @@ func SendValidatorUpdateTx(cdc *codec.Codec) *cobra.Command {
}
pubkey := hmTypes.NewPubKey(pubkeyBytes)

if !util.IsPubKeyFirstByteValid(pubkey.Bytes()[0:1]) {
return fmt.Errorf("public key first byte mismatch")
}

txhash := viper.GetString(FlagTxHash)
if txhash == "" {
return fmt.Errorf("transaction hash has to be supplied")
Expand Down
11 changes: 11 additions & 0 deletions staking/side_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"

authTypes "github.com/maticnetwork/heimdall/auth/types"
"github.com/maticnetwork/heimdall/bridge/setu/util"
"github.com/maticnetwork/heimdall/common"
hmCommon "github.com/maticnetwork/heimdall/common"
"github.com/maticnetwork/heimdall/helper"
Expand Down Expand Up @@ -88,6 +89,11 @@ func SideHandleMsgValidatorJoin(ctx sdk.Context, msg types.MsgValidatorJoin, k K
pubkey := msg.SignerPubKey
signer := pubkey.Address()

if !util.IsPubKeyFirstByteValid(pubkey[0:1]) {
k.Logger(ctx).Error("public key first byte mismatch", "expected", "0x04", "received", pubkey[0:1])
return hmCommon.ErrorSideTx(k.Codespace(), common.CodeInvalidMsg)
}

// check signer pubkey in message corresponds
if !bytes.Equal(pubkey.Bytes()[1:], eventLog.SignerPubkey) {
k.Logger(ctx).Error(
Expand Down Expand Up @@ -237,6 +243,11 @@ func SideHandleMsgSignerUpdate(ctx sdk.Context, msg types.MsgSignerUpdate, k Kee
return hmCommon.ErrorSideTx(k.Codespace(), common.CodeInvalidMsg)
}

if !util.IsPubKeyFirstByteValid(newPubKey.Bytes()[0:1]) {
k.Logger(ctx).Error("public key first byte mismatch", "expected", "0x04", "received", newPubKey.Bytes()[0:1])
return hmCommon.ErrorSideTx(k.Codespace(), common.CodeInvalidMsg)
}

if !bytes.Equal(eventLog.SignerPubkey, newPubKey.Bytes()[1:]) {
k.Logger(ctx).Error("Newsigner pubkey in txhash and msg dont match", "msgPubKey", newPubKey.String(), "pubkeyTx", hmTypes.NewPubKey(eventLog.SignerPubkey[:]).String())
return hmCommon.ErrorSideTx(k.Codespace(), common.CodeInvalidMsg)
Expand Down
3 changes: 2 additions & 1 deletion staking/side_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
ethTypes "github.com/ethereum/go-ethereum/core/types"

"github.com/maticnetwork/heimdall/app"
"github.com/maticnetwork/heimdall/bridge/setu/util"
chSim "github.com/maticnetwork/heimdall/checkpoint/simulation"
"github.com/maticnetwork/heimdall/common"
errs "github.com/maticnetwork/heimdall/common"
Expand Down Expand Up @@ -89,7 +90,7 @@ func (suite *SideHandlerTestSuite) TestSideHandleMsgValidatorJoin() {
amount, _ := big.NewInt(0).SetString("1000000000000000000", 10)

privKey1 := secp256k1.GenPrivKey()
pubkey := hmTypes.NewPubKey(privKey1.PubKey().Bytes())
pubkey := hmTypes.NewPubKey(util.AppendPrefix(privKey1.PubKey().Bytes()))
address := pubkey.Address()

chainParams := app.ChainKeeper.GetParams(ctx)
Expand Down
3 changes: 2 additions & 1 deletion staking/simulation/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"crypto/rand"
"math/big"

"github.com/maticnetwork/heimdall/bridge/setu/util"
"github.com/maticnetwork/heimdall/types"
"github.com/tendermint/tendermint/crypto/secp256k1"
)
Expand All @@ -12,7 +13,7 @@ import (
func GenRandomVal(count int, startBlock uint64, power int64, timeAlive uint64, randomise bool, startID uint64) (validators []types.Validator) {
for i := 0; i < count; i++ {
privKey1 := secp256k1.GenPrivKey()
pubkey := types.NewPubKey(privKey1.PubKey().Bytes())
pubkey := types.NewPubKey(util.AppendPrefix(privKey1.PubKey().Bytes()))

if randomise {
startBlock = generateRandNumber(10)
Expand Down

0 comments on commit 08e0e44

Please sign in to comment.