Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: require gas in RecvPacket is inaccurate when ReceiverChainIsSource (backport #1458) #1460

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
"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 @@
UpdateClientAndAcknowledgement = "updateClientAndAcknowledgement"
UpdateClientAndTimeout = "updateClientAndTimeout"
UpdateClientAndTimeoutOnClose = "updateClientAndTimeoutOnClose"

GasForUpdateClient = 111894
GasWhenReceiverChainIsSource = 51705
GasWhenReceiverChainIsNotSource = 144025
)

func init() {
Expand Down Expand Up @@ -93,7 +99,7 @@
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 @@
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 @@
var methodID [4]byte
copy(methodID[:], input[:4])
requiredGas, ok := relayerGasRequiredByMethod[methodID]
method, err := irelayerABI.MethodById(methodID[:])
if err != nil {
panic(err)

Check warning on line 176 in x/cronos/keeper/precompiles/relayer.go

View check run for this annotation

Codecov / codecov/patch

x/cronos/keeper/precompiles/relayer.go#L174-L176

Added lines #L174 - L176 were not covered by tests
}
if method.Name == RecvPacket || method.Name == UpdateClientAndRecvPacket {
args, err := method.Inputs.Unpack(input[4:])
if err != nil {
panic(err)

Check warning on line 181 in x/cronos/keeper/precompiles/relayer.go

View check run for this annotation

Codecov / codecov/patch

x/cronos/keeper/precompiles/relayer.go#L178-L181

Added lines #L178 - L181 were not covered by tests
}
i := args[0].([]byte)
if method.Name == UpdateClientAndRecvPacket {
i = args[1].([]byte)

Check warning on line 185 in x/cronos/keeper/precompiles/relayer.go

View check run for this annotation

Codecov / codecov/patch

x/cronos/keeper/precompiles/relayer.go#L183-L185

Added lines #L183 - L185 were not covered by tests
}
var msg channeltypes.MsgRecvPacket
if err = bc.cdc.Unmarshal(i, &msg); err != nil {
panic(err)

Check warning on line 189 in x/cronos/keeper/precompiles/relayer.go

View check run for this annotation

Codecov / codecov/patch

x/cronos/keeper/precompiles/relayer.go#L187-L189

Added lines #L187 - L189 were not covered by tests
}
var data ibctransfertypes.FungibleTokenPacketData
if err = ibctransfertypes.ModuleCdc.UnmarshalJSON(msg.Packet.GetData(), &data); err != nil {
panic(err)

Check warning on line 193 in x/cronos/keeper/precompiles/relayer.go

View check run for this annotation

Codecov / codecov/patch

x/cronos/keeper/precompiles/relayer.go#L191-L193

Added lines #L191 - L193 were not covered by tests
}
if ibctransfertypes.ReceiverChainIsSource(msg.Packet.GetSourcePort(), msg.Packet.GetSourceChannel(), data.Denom) {
requiredGas = GasWhenReceiverChainIsSource
if method.Name == UpdateClientAndRecvPacket {
requiredGas += GasForUpdateClient

Check warning on line 198 in x/cronos/keeper/precompiles/relayer.go

View check run for this annotation

Codecov / codecov/patch

x/cronos/keeper/precompiles/relayer.go#L195-L198

Added lines #L195 - L198 were not covered by tests
}
}
}
intrinsicGas, _ := core.IntrinsicGas(input, nil, false, bc.isHomestead, bc.isIstanbul, bc.isShanghai)
defer func() {
methodName := relayerMethodNamedByMethod[methodID]
Expand Down
Loading