Skip to content

Commit

Permalink
Problem: require gas in RecvPacket is inaccurate when ReceiverChainIs…
Browse files Browse the repository at this point in the history
…Source (crypto-org-chain#1458)

* Problem: require gas in RecvPacket is inaccurate when ReceiverChainIsSource

* cleanup combo

* set relayer caller for hermes

* more users
  • Loading branch information
mmsqe committed May 28, 2024
1 parent ac56118 commit 0ef63b9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### State Machine Breaking

* [#1407](https://github.com/crypto-org-chain/cronos/pull/1407) Add end-to-end encryption module.
* [#1458](https://github.com/crypto-org-chain/cronos/pull/1458) Adjust require gas for recvPacket when ReceiverChainIsSource.

### Improvements

Expand Down
38 changes: 36 additions & 2 deletions x/cronos/keeper/precompiles/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"github.com/ethereum/go-ethereum/params"

authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
cronosevents "github.com/crypto-org-chain/cronos/v2/x/cronos/events"
"github.com/crypto-org-chain/cronos/v2/x/cronos/events/bindings/cosmos/precompile/relayer"
"github.com/crypto-org-chain/cronos/v2/x/cronos/types"
Expand Down Expand Up @@ -58,6 +60,10 @@ const (
UpdateClientAndAcknowledgement = "updateClientAndAcknowledgement"
UpdateClientAndTimeout = "updateClientAndTimeout"
UpdateClientAndTimeoutOnClose = "updateClientAndTimeoutOnClose"

GasForUpdateClient = 111894
GasWhenReceiverChainIsSource = 51705
GasWhenReceiverChainIsNotSource = 144025
)

func init() {
Expand Down Expand Up @@ -93,7 +99,7 @@ func init() {
case ChannelCloseConfirm:
relayerGasRequiredByMethod[methodID] = 31199
case RecvPacket:
relayerGasRequiredByMethod[methodID] = 144025
relayerGasRequiredByMethod[methodID] = GasWhenReceiverChainIsNotSource
case Acknowledgement:
relayerGasRequiredByMethod[methodID] = 61781
case Timeout:
Expand All @@ -107,7 +113,7 @@ func init() {
case UpdateClientAndChannelOpenConfirm:
relayerGasRequiredByMethod[methodID] = 132734
case UpdateClientAndRecvPacket:
relayerGasRequiredByMethod[methodID] = 257120
relayerGasRequiredByMethod[methodID] = GasForUpdateClient + GasWhenReceiverChainIsNotSource
case UpdateClientAndConnectionOpenInit:
relayerGasRequiredByMethod[methodID] = 131649
case UpdateClientAndConnectionOpenAck:
Expand Down Expand Up @@ -165,6 +171,34 @@ func (bc *RelayerContract) RequiredGas(input []byte) (gas uint64) {
var methodID [4]byte
copy(methodID[:], input[:4])
requiredGas, ok := relayerGasRequiredByMethod[methodID]
method, err := irelayerABI.MethodById(methodID[:])
if err != nil {
panic(err)
}
if method.Name == RecvPacket || method.Name == UpdateClientAndRecvPacket {
args, err := method.Inputs.Unpack(input[4:])
if err != nil {
panic(err)
}
i := args[0].([]byte)
if method.Name == UpdateClientAndRecvPacket {
i = args[1].([]byte)
}
var msg channeltypes.MsgRecvPacket
if err = bc.cdc.Unmarshal(i, &msg); err != nil {
panic(err)
}
var data ibctransfertypes.FungibleTokenPacketData
if err = ibctransfertypes.ModuleCdc.UnmarshalJSON(msg.Packet.GetData(), &data); err != nil {
panic(err)
}
if ibctransfertypes.ReceiverChainIsSource(msg.Packet.GetSourcePort(), msg.Packet.GetSourceChannel(), data.Denom) {
requiredGas = GasWhenReceiverChainIsSource
if method.Name == UpdateClientAndRecvPacket {
requiredGas += GasForUpdateClient
}
}
}
intrinsicGas, _ := core.IntrinsicGas(input, nil, false, bc.isHomestead, bc.isIstanbul, bc.isShanghai)
defer func() {
methodName := relayerMethodNamedByMethod[methodID]
Expand Down

0 comments on commit 0ef63b9

Please sign in to comment.