Skip to content

Commit

Permalink
chg: merge and solve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
marcello33 committed Jun 6, 2024
2 parents d1cb028 + ae5a160 commit bfb103e
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 13 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])
}
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 bfb103e

Please sign in to comment.