Skip to content

Commit

Permalink
Merge pull request maticnetwork#1016 from maticnetwork/vaibhav/Heimda…
Browse files Browse the repository at this point in the history
…llSyncIssue

Fix:SignBytes representation of empty string data field in the event-…
  • Loading branch information
VAIBHAVJINDAL3012 authored Jul 22, 2023
2 parents d2cac96 + ad15687 commit 329efab
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
20 changes: 17 additions & 3 deletions auth/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func NewAnteHandler(
stdSigs := stdTx.GetSignatures()

// check signature, return account with incremented nonce
signBytes := GetSignBytes(newCtx.ChainID(), stdTx, signerAcc, isGenesis)
signBytes := GetSignBytes(ctx, newCtx.ChainID(), stdTx, signerAcc, isGenesis)

signerAcc, res = processSig(newCtx, signerAcc, stdSigs[0], signBytes, simulate, params, sigGasConsumer)
if !res.IsOK() {
Expand Down Expand Up @@ -313,11 +313,25 @@ func SetGasMeter(simulate bool, ctx sdk.Context, gasLimit uint64) sdk.Context {

// GetSignBytes returns a slice of bytes to sign over for a given transaction
// and an account.
func GetSignBytes(chainID string, stdTx authTypes.StdTx, acc authTypes.Account, genesis bool) []byte {
func GetSignBytes(ctx sdk.Context, chainID string, stdTx authTypes.StdTx, acc authTypes.Account, genesis bool) []byte {
var accNum uint64
if !genesis {
accNum = acc.GetAccountNumber()
}

return authTypes.StdSignBytes(chainID, accNum, acc.GetSequence(), stdTx.Msg, stdTx.Memo)
signBytes := authTypes.StdSignBytes(chainID, accNum, acc.GetSequence(), stdTx.Msg, stdTx.Memo)

if ctx.BlockHeight() > helper.GetNewHexToStringAlgoHeight() {
return signBytes
}

const newData = ",\"data\":\"0x\","

const oldData = ",\"data\":\"0x0\","

if bytes.Contains(signBytes, []byte(newData)) {
signBytes = bytes.Replace(signBytes, []byte(newData), []byte(oldData), 1)
}

return signBytes
}
11 changes: 11 additions & 0 deletions helper/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ var newSelectionAlgoHeight int64 = 0

var spanOverrideHeight int64 = 0

var newHexToStringAlgoHeight int64 = 0

type ChainManagerAddressMigration struct {
MaticTokenAddress hmTypes.HeimdallAddress
RootChainAddress hmTypes.HeimdallAddress
Expand Down Expand Up @@ -371,12 +373,16 @@ func InitHeimdallConfigWith(homeDir string, heimdallConfigFileFromFLag string) {
case MainChain:
newSelectionAlgoHeight = 375300
spanOverrideHeight = 8664000
newHexToStringAlgoHeight = 9266260

case MumbaiChain:
newSelectionAlgoHeight = 282500
spanOverrideHeight = 10205000
newHexToStringAlgoHeight = 10630672
default:
newSelectionAlgoHeight = 0
spanOverrideHeight = 0
newHexToStringAlgoHeight = 0
}
}

Expand Down Expand Up @@ -495,6 +501,11 @@ func GetSpanOverrideHeight() int64 {
return spanOverrideHeight
}

// GetNewHexToStringAlgoHeight returns newHexToStringAlgoHeight
func GetNewHexToStringAlgoHeight() int64 {
return newHexToStringAlgoHeight
}

func GetChainManagerAddressMigration(blockNum int64) (ChainManagerAddressMigration, bool) {
chainMigration := chainManagerAddressMigrations[conf.Chain]
if chainMigration == nil {
Expand Down

0 comments on commit 329efab

Please sign in to comment.