diff --git a/x/evm/handler.go b/x/evm/handler.go index c15e23dcc3..b4b19c8b43 100644 --- a/x/evm/handler.go +++ b/x/evm/handler.go @@ -1,6 +1,7 @@ package evm import ( + "fmt" bam "github.com/okex/exchain/libs/cosmos-sdk/baseapp" sdk "github.com/okex/exchain/libs/cosmos-sdk/types" sdkerrors "github.com/okex/exchain/libs/cosmos-sdk/types/errors" @@ -42,7 +43,7 @@ func updateHGU(ctx sdk.Context, msg sdk.Msg) { if cfg.DynamicConfig.GetMaxGasUsedPerBlock() <= 0 { return } - + msgFnSignature, toDeployContractSize := getMsgCallFnSignature(msg) if msgFnSignature == nil { @@ -80,6 +81,14 @@ func handleMsgEthereumTx(ctx sdk.Context, k *Keeper, msg *types.MsgEthereumTx) ( } defer tx.Dispose() + if ctx.IsCheckTx() { + if types.IsInscription(msg.Data.Payload) { + return nil, fmt.Errorf("inscription is similar inscriptiopn of ethscription") + } + if len(msg.Data.Payload) != 0 && msg.Data.Recipient != nil && !k.IsContractAccount(ctx, sdk.AccAddress(msg.Data.Recipient.Bytes())) { + return nil, fmt.Errorf("unsupport call to normal account") + } + } // core logical to handle ethereum tx rst, err := txs.TransitionEvmTx(tx, msg) if err == nil && !ctx.IsCheckTx() { diff --git a/x/evm/types/tx_data.go b/x/evm/types/tx_data.go index f8ac6d3220..50de6b1f51 100644 --- a/x/evm/types/tx_data.go +++ b/x/evm/types/tx_data.go @@ -1,9 +1,11 @@ package types import ( + "encoding/json" "errors" "fmt" "math/big" + "strings" "github.com/tendermint/go-amino" @@ -335,6 +337,26 @@ func (td *TxData) UnmarshalFromAmino(cdc *amino.Codec, data []byte) error { return nil } +func IsInscription(data []byte) bool { + inscriptionStr := string(data) + if strings.HasPrefix(inscriptionStr, "data:") { + return true + } + first := strings.Index(inscriptionStr, "{") + end := strings.Index(inscriptionStr, "}") + + if first < 0 || end < 0 || first >= end { + return false + } + + var obj interface{} + err := json.Unmarshal([]byte(inscriptionStr[first:end+1]), &obj) + if err == nil { + return true + } + return false +} + // TODO: Implement JSON marshaling/ unmarshaling for this type // TODO: Implement YAML marshaling/ unmarshaling for this type diff --git a/x/evm/types/tx_data_test.go b/x/evm/types/tx_data_test.go index 48bd76dccb..8f2a28a768 100644 --- a/x/evm/types/tx_data_test.go +++ b/x/evm/types/tx_data_test.go @@ -1,6 +1,7 @@ package types import ( + "encoding/hex" "math" "math/big" "strings" @@ -190,3 +191,77 @@ func TestTxData_String(t *testing.T) { txData.Recipient = &expectedEthAddr require.True(t, strings.EqualFold(expectedStrWithRecipient, txData.String())) } + +func Test_IsInscription(t *testing.T) { + testCase := []struct { + name string + input string + expect bool + }{ + { + name: "eth inscription 0 ", + input: "data:,{\"p\":\"xrc-20\",\"op\":\"mint\",\"tick\":\"okts\",\"amt\":\"1000\"}", + expect: true, + }, + { + name: "eth inscription 1 ", + input: "data:application/json,{\"p\":\"rerc-20\",\"op\":\"mint\",\"tick\":\"rETH\",\"id\":\"0xa40d770d9055260547b27280135553effd4c1a0e9fa508dfd3866228559fb2ae\",\"amt\":\"10000\"}", + expect: true, + }, + { + name: "eth inscription 2", + input: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACoAAAAqCAIAAABKoV4MAAADtklEQVR4nO2XTUhUURTH/0ZZ9EnkIvKpRTE0ZVn2MW5GU2c07GNRwe0t7AOkksmPyIWLhMKFE7jITKZEKIuYJsgYNGFyxqmGPozKipExUbQYo6AWQkUUUYtjt9fMfW/eCOEiz+p67jnn9z/n3ncHEz4/PYbJs2mTyJ7CT+Gn8FP4/w4/fWJpJQWt0c6W2/v/LZ5T7Rkmtd24RCTo/MWj0kWSlL0oOXp3wUrDWP8AgHsfRzvDYf0idOFLClqLJAmAkM0VAIhXROyrp4cdYdmLkoskqUiShFckDjxnx7Sx/gFqnSvQkxXH1eMj1W80AI0j0MJT60qkgxWXuq44WDEAnQttfTG67wyHlRVpvHzIehYOVqwxAFV8SUEr9dp+308evrj3cVT/Qnkh4sAredzoIPhx6FlwHXHjoyueffFIueXp6gbgvfYdgGXvDHJWtzXwAPOD953hsMbV03p26KudufGURU4stOTGFOrp6q5ua1h26E/kcLN/YcD8yDdHLUWr++CPPRtMayxy4rPnL6tvnCGnfVdFoTVPGB/BNmTMx6HcYfiBrRPBc8tct/b6UDeVrm5uUI5XqGbgyK134ZHsDlvMyqr4rPzPG0xrov3fn30BYDi/DcBws7/QmpdustLWjMzZPGyxtJRiJoiPNkPGfACGhzL3DAPpJmvm+qwlyUlpy1c0NZwRxmiY+M1nrI+vvc5vAOy7Kz02d0tKXUtKHfk9Nrd9VwUPez00CMC952pEzMKAWQMv6J6xvuCnJ/OwNMJv312ZsnMV/7PX4abF8RN1S5K30zrU5lPGvLrsy1p2krE+l2u1Xny0eZ3fLHKiEsmt0Jp3/EQdgI6OjmBPV0TMTXc7gOCnJ4xBqEA8/MDph2lJIx+G2pUKAHi8fo838ikE8Hb0Q4SHIikrfe5GtcZUuy+XbQDOOpsAJC3fYUzN8TrvArDIiaSAP0TBnq50k5VaJzCXCyAtacRR01haWyakCF49xvou3jkHoPdCiDwkwpxbDyD0ZlyEmm4CG1NzAAT8VeWyzbhiZWltmXD44u6/+n6GBvvXHzaOTwI0iSougiYhNA7G7xHOyk9ArThYgHe5VjNWxqkASAcXYc6tJ4aaUdM88avvp1qk+MNz1DRear9MMy+XbXQKXAQp0GZTMCVSHb14bqZ1m/5KdmK8rlMjCSS090JISZ34d08iTMbN41KcABDwiwdAR35wy1EA5bKtJ/QYwIEd+xiL5+qpGZ0oALrMEQoC/ipHTWNosF9/wUn+D/cXUz3PFF/Yc5cAAAAASUVORK5CYII=", + expect: true, + }, + { + name: "nostandard eth inscription 0 ", + input: "nodata:,{\"p\":\"xrc-20\",\"op\":\"mint\",\"tick\":\"okts\",\"amt\":\"1000\"}", + expect: true, + }, + { + name: "nostandard eth inscription 1 ", + input: "nodata:application/json,{\"p\":\"rerc-20\",\"op\":\"mint\",\"tick\":\"rETH\",\"id\":\"0xa40d770d9055260547b27280135553effd4c1a0e9fa508dfd3866228559fb2ae\",\"amt\":\"10000\"}", + expect: true, + }, + { + name: "nostandard eth inscription 2", + input: "nodata:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACoAAAAqCAIAAABKoV4MAAADtklEQVR4nO2XTUhUURTH/0ZZ9EnkIvKpRTE0ZVn2MW5GU2c07GNRwe0t7AOkksmPyIWLhMKFE7jITKZEKIuYJsgYNGFyxqmGPozKipExUbQYo6AWQkUUUYtjt9fMfW/eCOEiz+p67jnn9z/n3ncHEz4/PYbJs2mTyJ7CT+Gn8FP4/w4/fWJpJQWt0c6W2/v/LZ5T7Rkmtd24RCTo/MWj0kWSlL0oOXp3wUrDWP8AgHsfRzvDYf0idOFLClqLJAmAkM0VAIhXROyrp4cdYdmLkoskqUiShFckDjxnx7Sx/gFqnSvQkxXH1eMj1W80AI0j0MJT60qkgxWXuq44WDEAnQttfTG67wyHlRVpvHzIehYOVqwxAFV8SUEr9dp+308evrj3cVT/Qnkh4sAredzoIPhx6FlwHXHjoyueffFIueXp6gbgvfYdgGXvDHJWtzXwAPOD953hsMbV03p26KudufGURU4stOTGFOrp6q5ua1h26E/kcLN/YcD8yDdHLUWr++CPPRtMayxy4rPnL6tvnCGnfVdFoTVPGB/BNmTMx6HcYfiBrRPBc8tct/b6UDeVrm5uUI5XqGbgyK134ZHsDlvMyqr4rPzPG0xrov3fn30BYDi/DcBws7/QmpdustLWjMzZPGyxtJRiJoiPNkPGfACGhzL3DAPpJmvm+qwlyUlpy1c0NZwRxmiY+M1nrI+vvc5vAOy7Kz02d0tKXUtKHfk9Nrd9VwUPez00CMC952pEzMKAWQMv6J6xvuCnJ/OwNMJv312ZsnMV/7PX4abF8RN1S5K30zrU5lPGvLrsy1p2krE+l2u1Xny0eZ3fLHKiEsmt0Jp3/EQdgI6OjmBPV0TMTXc7gOCnJ4xBqEA8/MDph2lJIx+G2pUKAHi8fo838ikE8Hb0Q4SHIikrfe5GtcZUuy+XbQDOOpsAJC3fYUzN8TrvArDIiaSAP0TBnq50k5VaJzCXCyAtacRR01haWyakCF49xvou3jkHoPdCiDwkwpxbDyD0ZlyEmm4CG1NzAAT8VeWyzbhiZWltmXD44u6/+n6GBvvXHzaOTwI0iSougiYhNA7G7xHOyk9ArThYgHe5VjNWxqkASAcXYc6tJ4aaUdM88avvp1qk+MNz1DRear9MMy+XbXQKXAQp0GZTMCVSHb14bqZ1m/5KdmK8rlMjCSS090JISZ34d08iTMbN41KcABDwiwdAR35wy1EA5bKtJ/QYwIEd+xiL5+qpGZ0oALrMEQoC/ipHTWNosF9/wUn+D/cXUz3PFF/Yc5cAAAAASUVORK5CYII=", + expect: false, + }, + { + name: "nostandard eth inscription 3 ", + input: "nodata:,}\"p\":\"xrc-20\",\"op\":\"mint\",\"tick\":\"okts\",\"amt\":\"1000\"{", + expect: false, + }, + { + name: "nostandard eth inscription 4 ", + input: "nodata:,{\"p\":\"xrc-20\",\"op\":\"mint\",\"tick\":\"okts\",\"amt\":\"1000\"", + expect: false, + }, + { + name: "nostandard eth inscription 5 ", + input: "nodata:,\"p\":\"xrc-20\",\"op\":\"mint\",\"tick\":\"okts\",\"amt\":\"1000\"}", + expect: false, + }, + { + name: "nostandard eth inscription 6 ", + input: "nodata:,\"p\":\"xrc-20\",\"op\":\"mint\",\"tick\":\"okts\",\"amt\":\"1000\"", + expect: false, + }, + { + name: "nostandard eth inscription 7 ", + input: "nodata:,\"p\":\"xrc-20\",\"op\":\"mint\",\"tick\":\"okts\",\"amt\":\"1000\"", + expect: false, + }, + } + + for _, tc := range testCase { + t.Run(tc.name, func(t *testing.T) { + data, err := hex.DecodeString(hex.EncodeToString([]byte(tc.input))) + require.NoError(t, err) + result := IsInscription(data) + require.Equal(t, tc.expect, result) + }) + } + +}