Skip to content

Commit

Permalink
fix: add sorting of EIP712 msg types
Browse files Browse the repository at this point in the history
  • Loading branch information
pythonberg1997 committed Jun 8, 2023
1 parent d38a12d commit 5fdc2d1
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions x/auth/tx/eip712.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth/signing"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/cosmos/gogoproto/jsonpb"
"sort"
)

var domain = &apitypes.TypedDataDomain{
Expand Down Expand Up @@ -148,12 +149,12 @@ func GetMsgTypes(signerData signing.SignerData, tx sdk.Tx, typedChainID *big.Int
"Fee": {
{Name: "amount", Type: "Coin[]"},
{Name: "gas_limit", Type: "uint256"},
{Name: "payer", Type: "string"},
{Name: "granter", Type: "string"},
{Name: "payer", Type: "string"},
},
"Coin": {
{Name: "denom", Type: "string"},
{Name: "amount", Type: "uint256"},
{Name: "denom", Type: "string"},
},
}
for i, msg := range protoTx.GetMsgs() {
Expand Down Expand Up @@ -233,6 +234,13 @@ func WrapTxToTypedData(
}
delete(txData, "msgs")

// sort the msg types
for _, val := range msgTypes {
sort.Slice(val, func(i, j int) bool {
return val[i].Name < val[j].Name
})
}

tempDomain := *domain
tempDomain.ChainId = math.NewHexOrDecimal256(int64(chainID))
typedData := apitypes.TypedData{
Expand Down

0 comments on commit 5fdc2d1

Please sign in to comment.