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 for ica packet callback is not adjusted with ctx params #1251

Merged
merged 4 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Problem: require gas for ica packet callback is not adjusted with ctx…
… params
  • Loading branch information
mmsqe committed Dec 5, 2023
commit ef2e9ec17757e9bf34a4a826243dd2231d422d1b
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- [#1209](https://github.com/crypto-org-chain/cronos/pull/1209) Support accurate estimate gas in evm tx from relayer.
- [#1247](https://github.com/crypto-org-chain/cronos/pull/1247) Update ethermint to develop, go-ethereum to `v1.11.2`.
- [#1235](https://github.com/crypto-org-chain/cronos/pull/1235) Add channel detail in ica packet callback.
- [#1251](https://github.com/crypto-org-chain/cronos/pull/1251) Adjust require gas for submitMsgs in ica precompile.

### Improvements

Expand Down
6 changes: 3 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,11 +537,11 @@ func New(
tracer,
evmS,
[]evmkeeper.CustomContractFn{
func(rules ethparams.Rules) vm.PrecompiledContract {
func(_ sdk.Context, rules ethparams.Rules) vm.PrecompiledContract {
return cronosprecompiles.NewRelayerContract(app.IBCKeeper, appCodec, rules, app.Logger())
},
func(rules ethparams.Rules) vm.PrecompiledContract {
return cronosprecompiles.NewIcaContract(&app.ICAAuthKeeper, &app.CronosKeeper, appCodec, gasConfig)
func(ctx sdk.Context, rules ethparams.Rules) vm.PrecompiledContract {
return cronosprecompiles.NewIcaContract(ctx, &app.ICAAuthKeeper, &app.CronosKeeper, appCodec, gasConfig)
},
},
allKeys,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ replace (
// TODO: remove it: https://github.com/cosmos/cosmos-sdk/issues/13134
github.com/dgrijalva/jwt-go => github.com/golang-jwt/jwt/v4 v4.4.2
github.com/ethereum/go-ethereum => github.com/crypto-org-chain/go-ethereum v1.10.20-0.20231122021350-f905c2ec3570
github.com/evmos/ethermint => github.com/crypto-org-chain/ethermint v0.6.1-0.20231204041029-ccb83e2e0688
github.com/evmos/ethermint => github.com/crypto-org-chain/ethermint v0.6.1-0.20231205070424-9f62598bff76
// Fix upstream GHSA-h395-qcrw-5vmq and GHSA-3vp4-m3rf-835h vulnerabilities.
// TODO Remove it: https://github.com/cosmos/cosmos-sdk/issues/10409
github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.9.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,8 @@ github.com/crypto-org-chain/cometbft-db v0.0.0-20231011055109-57922ac52a63 h1:R1
github.com/crypto-org-chain/cometbft-db v0.0.0-20231011055109-57922ac52a63/go.mod h1:rocwIfnS+kA060x64gkSIRvWB9StSppIkJuo5MWzL24=
github.com/crypto-org-chain/cosmos-sdk v0.46.0-beta2.0.20231013072415-eec017435467 h1:m0/aHPIJAzi2MSP3TXzzbLTFf+koRFQiaYmerRZUtK4=
github.com/crypto-org-chain/cosmos-sdk v0.46.0-beta2.0.20231013072415-eec017435467/go.mod h1:G384omH7cXgm90xXR7xpHvsKG7vdBaDuz4To6GpTHUU=
github.com/crypto-org-chain/ethermint v0.6.1-0.20231204041029-ccb83e2e0688 h1:6bjEkpymCMWfhUEhTuVj8g46sGuYS1D5I6XPuSuUWm4=
github.com/crypto-org-chain/ethermint v0.6.1-0.20231204041029-ccb83e2e0688/go.mod h1:y8DDupItqxfGglMpak/ow8E7qvqXM2Vb7t6kdb6s96Q=
github.com/crypto-org-chain/ethermint v0.6.1-0.20231205070424-9f62598bff76 h1:mee01qkS0ZTfzOzVdwzKR60Xhixk40FXdjVV1NRems4=
github.com/crypto-org-chain/ethermint v0.6.1-0.20231205070424-9f62598bff76/go.mod h1:y8DDupItqxfGglMpak/ow8E7qvqXM2Vb7t6kdb6s96Q=
github.com/crypto-org-chain/go-ethereum v1.10.20-0.20231122021350-f905c2ec3570 h1:GukXF6eVCJZbK5pgTF+SHJoY9Wr0mPh95/LIOUQNMMM=
github.com/crypto-org-chain/go-ethereum v1.10.20-0.20231122021350-f905c2ec3570/go.mod h1:DuefStAgaxoaYGLR0FueVcVbehmn5n9QUcVrMCuOvuc=
github.com/crypto-org-chain/gravity-bridge/module/v2 v2.0.1-0.20230825054824-75403cd90c6e h1:rSTc35OBjjCBx47rHPWBCIHNGPbMnEj8f7fNcK2TjVI=
Expand Down
4 changes: 2 additions & 2 deletions gomod2nix.toml
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ schema = 3
hash = "sha256-1LRIM5dPmwjBxd57c9Y+2mZuBrbGWfMvEIlqYpdVBPA="
replaced = "github.com/crypto-org-chain/go-ethereum"
[mod."github.com/evmos/ethermint"]
version = "v0.6.1-0.20231204041029-ccb83e2e0688"
hash = "sha256-JluJj+FrL5gA3twvxt/IwiMxHcTKEs0ciz+MF+bHZFk="
version = "v0.6.1-0.20231205070424-9f62598bff76"
hash = "sha256-xRa8V6b9nVVtTq0L0e/Klz/2VPyNSaB6WvSUbopJlsE="
replaced = "github.com/crypto-org-chain/ethermint"
[mod."github.com/felixge/httpsnoop"]
version = "v1.0.2"
Expand Down
5 changes: 5 additions & 0 deletions integration_tests/configs/ibc.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ config {
},
genesis+: {
app_state+: {
cronos+: {
params+: {
max_callback_gas: 50000,
},
},
feemarket+: {
params+: {
no_base_fee: true,
Expand Down
9 changes: 8 additions & 1 deletion x/cronos/keeper/precompiles/ica.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var (
icaABI abi.ABI
icaCallbackABI abi.ABI
icaContractAddress = common.BytesToAddress([]byte{102})
icaMethodNamesByID = map[[4]byte]string{}
icaGasRequiredByMethod = map[[4]byte]uint64{}
)

Expand All @@ -58,6 +59,7 @@ func init() {
default:
icaGasRequiredByMethod[methodID] = 0
}
icaMethodNamesByID[methodID] = methodName
}
}

Expand All @@ -68,15 +70,17 @@ func OnPacketResultCallback(args ...interface{}) ([]byte, error) {
type IcaContract struct {
BaseContract

ctx sdk.Context
cdc codec.Codec
icaauthKeeper types.Icaauthkeeper
cronosKeeper types.CronosKeeper
kvGasConfig storetypes.GasConfig
}

func NewIcaContract(icaauthKeeper types.Icaauthkeeper, cronosKeeper types.CronosKeeper, cdc codec.Codec, kvGasConfig storetypes.GasConfig) vm.PrecompiledContract {
func NewIcaContract(ctx sdk.Context, icaauthKeeper types.Icaauthkeeper, cronosKeeper types.CronosKeeper, cdc codec.Codec, kvGasConfig storetypes.GasConfig) vm.PrecompiledContract {
return &IcaContract{
BaseContract: NewBaseContract(icaContractAddress),
ctx: ctx,
cdc: cdc,
icaauthKeeper: icaauthKeeper,
cronosKeeper: cronosKeeper,
Expand All @@ -95,6 +99,9 @@ func (ic *IcaContract) RequiredGas(input []byte) uint64 {
var methodID [4]byte
copy(methodID[:], input[:4])
requiredGas, ok := icaGasRequiredByMethod[methodID]
if icaMethodNamesByID[methodID] == SubmitMsgsMethodName {
requiredGas += ic.cronosKeeper.GetParams(ic.ctx).MaxCallbackGas
}
if ok {
return requiredGas + baseCost
}
Expand Down
3 changes: 1 addition & 2 deletions x/cronos/types/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
icaauthtypes "github.com/crypto-org-chain/cronos/v2/x/icaauth/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/params"
evmtypes "github.com/evmos/ethermint/x/evm/types"
Expand Down Expand Up @@ -92,7 +91,7 @@ type Icaauthkeeper interface {

// CronosKeeper defines the interface for cronos keeper
type CronosKeeper interface {
CallEVM(ctx sdk.Context, to *common.Address, data []byte, value *big.Int, gasLimit uint64) (*ethtypes.Message, *evmtypes.MsgEthereumTxResponse, error)
GetParams(ctx sdk.Context) (params Params)
}

// IbcKeeper defines the interface for ibc keeper
Expand Down