feat: upgrade cosmos/evm from v0.3.2 to v0.4.0#239
Open
AryaLanjewar3005 wants to merge 5 commits into
Open
Conversation
…ions for evm v0.4.0 signature change
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
All changes are in
push-chain/and were required by breaking API changes inevm/introduced during the upgrade from
cosmos/evm v0.3.2→v0.4.0.1.
go.mod— Dependency updatesFile:
go.modChange
Why
go-ethereum version bump: The evm fork was upgraded to include go-ethereum 1.16 (upstream PR
#315).The replace directive was bumped from the old
v1.15.11-cosmos-0tag to the new timestamped commitv0.0.0-20250806193535-2fc7571efa91. Using the old tag causes missinggo.sumentries and typeincompatibilities with code that was written against the 1.16 API (e.g.
vm.PrecompiledContractsPraguewhich does not exist in 1.15).
2.
app/precompiles.go— Full rewriteFile:
app/precompiles.goThe entire file was rewritten. The old file had a flat function with hardcoded precompile constructors
using the v0.3.2 API. The new file adds an
Optionalsstruct with address codecs and updates everyconstructor call to match the v0.4.0 signatures.
2a. Evidence precompile removed
Why (evm change): The evidence precompile (
precompiles/evidence/) was entirely deleted fromcosmos/evmin upstream PR#305. The package no longer exists in v0.4.0, so any import of itcauses a compilation error. The parameter
evidenceKeeper evidencekeeper.Keeperwas dropped fromNewAvailableStaticPrecompilesas a result.2b. Staking precompile —
bankKeeperreplaced withAddressCodecWhy (evm change): The staking precompile constructor was refactored in v0.4.0 as part of the
address codec injection pattern.
bankKeeperwas removed from the constructor signature; theprecompile now takes an
address.Codecfor address encoding/decoding instead.2c. Distribution precompile —
bankKeeperremoved,AddressCodecadded, argument order changedWhy (evm change): The distribution precompile constructor was refactored.
bankKeeperwas removed(it was not actually used in the distribution logic) and
address.Codecwas added as the finalargument for address encoding. The order of
stakingKeeperandevmKeeperwas also shifted.2d. ICS-20 precompile —
bankKeepermoved to first parameterWhy (evm change): The ICS-20 precompile constructor argument order changed in v0.4.0.
bankKeeperwas moved from the second position to the first to align with the pattern used across other precompiles.
Calling with the old order compiles (both are keeper types) but produces a runtime panic when the
precompile tries to use the wrong keeper.
2e. Gov precompile —
bankKeeperreplaced withAddressCodecWhy (evm change): The gov precompile constructor was refactored to remove
bankKeeperand injectan
address.Codecinstead. The argument order ofappCodecand the new codec also changed.2f. Slashing precompile —
bankKeeperreplaced with two addr codecsWhy (evm change): The slashing precompile now requires separate validator and consensus address
codecs for correctly encoding/decoding validator and consensus addresses.
bankKeeperwas removedentirely.
2g.
Optionalspattern addedWhy (evm change): v0.4.0 introduced a functional options pattern for precompile constructors.
Address codecs are now passed in instead of being hardcoded inside each precompile, making the
precompiles chain-agnostic. The
NewAvailableStaticPrecompilesfunction now acceptsopts ...Optionvariadic arguments and merges them over the defaults.
2h.
vm.PrecompiledContractsBerlin→vm.PrecompiledContractsPragueWhy (evm change): The go-ethereum 1.16 upgrade (upstream PR
#315) added Prague EVM precompiles.vm.PrecompiledContractsPragueis the new correct baseline and includes all precompiles up throughthe Prague hard fork. Using the old
PrecompiledContractsBerlinconstant still compiles but resultsin a stale precompile set that is missing newer EIP precompiles.
3.
app/app.go— Evidence keeper removed fromNewAvailableStaticPrecompilescallFile:
app/app.goChange
corePrecompiles := NewAvailableStaticPrecompiles( *app.StakingKeeper, app.DistrKeeper, app.BankKeeper, app.Erc20Keeper, app.TransferKeeper, app.IBCKeeper.ChannelKeeper, app.EVMKeeper, app.GovKeeper, app.SlashingKeeper, - app.EvidenceKeeper, appCodec, )Why (evm change): Follows directly from the evidence precompile removal (upstream PR
#305).The
evidenceKeeperparameter was dropped fromNewAvailableStaticPrecompiles, so the call sitein
app.gomust pass one fewer argument.4.
app/app.go—SetClientCtxandRegisterPendingTxListeneraddedFile:
app/app.goChange
New fields added to the
ChainAppstruct:New import:
"github.com/ethereum/go-ethereum/common"New methods:
Why (evm change): v0.4.0 introduced the
evmserver.Applicationinterface inevm/server/start.go:The EVM server calls
evmApp.SetClientCtx(clientCtx)during node startup to inject the Cosmos clientcontext (needed for JSON-RPC and pending tx streaming).
RegisterPendingTxListenerenables the EVMmempool to notify the JSON-RPC WebSocket layer when a pending transaction arrives.
ChainAppmustimplement both methods to satisfy this interface, which is checked at compile time by
cosmosevmserver.NewDefaultStartOptions.5.
cmd/pchaind/commands.go—newAppreturn type and SDK wrapperFile:
cmd/pchaind/commands.goChange
newAppreturn type updated:func newApp( logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts servertypes.AppOptions, - ) servertypes.Application { + ) cosmosevmserver.Application {New SDK wrapper added for
pruning.Cmdandsnapshot.Cmd:Why (evm change):
cosmosevmserver.NewDefaultStartOptionswas changed in v0.4.0 to acceptevmserver.AppCreator(a function returningevmserver.Application) instead ofservertypes.AppCreator. SinceChainAppnow implementsevmserver.Application(via the newmethods above),
newAppcan return that richer type. However,pruning.Cmdandsnapshot.Cmdin the Cosmos SDK still expect
servertypes.Application, so a thin wrapper (sdkAppCreator) isrequired to satisfy both call sites without changing the Cosmos SDK types.
6.
x/uexecutor/types/expected_keepers.go—CallEVMinterface updatedFile:
x/uexecutor/types/expected_keepers.goChange
type EVMKeeper interface { CallEVM( ctx sdk.Context, abi abi.ABI, from, contract common.Address, commit bool, + gasCap *big.Int, method string, args ...interface{}, ) (*types.MsgEthereumTxResponse, error)Why (evm change): The
CallEVMfunction inx/vm/keeper/call_evm.gogained a newgasCap *big.Intparameter in v0.4.0:This allows callers to impose a custom gas cap on EVM calls. Pass
nilto use the default(
config.DefaultGasCap). The interface inexpected_keepers.gomust mirror the real signatureexactly, otherwise the
EVMKeepermock used in tests and the keeper wiring inkeeper.goproducea compile error.
7.
x/uexecutor/keeper/evm.go— AllCallEVMcall sites updatedFile:
x/uexecutor/keeper/evm.goChange
niladded as thegasCapargument (betweencommit boolandmethod string) at everyCallEVMcall site. Example:Functions updated:
CallFactoryToGetUEAAddressForOrigin→getUEAForOriginCallFactoryGetOriginForUEA→getOriginForUEACallUEADomainSeparator→domainSeparatorGetGasPriceByChain→gasPriceByChainNamespaceGetL1GasFeeByChain→l1GasFeeByChainNamespaceGetTssFundMigrationGasLimitByChain→tssFundMigrationGasLimitByChainNamespaceGetUniversalCoreQuoterAddress→uniswapV3QuoterGetUniversalCoreWPCAddress→WPCGetDefaultFeeTierForToken→defaultFeeTierGetSwapQuote→quoteExactInputSingleWhy (evm change): Directly follows from the
CallEVMsignature change described in item 6.All existing callers pass
nilto preserve the previous default gas cap behaviour.8.
x/uexecutor/keeper/gas_fee.go—CallEVMcall site updatedFile:
x/uexecutor/keeper/gas_fee.goChange
Why (evm change): Same
CallEVMsignature change as item 6. This call site is in a separatefile (
gas_fee.go) from the rest of the evm.go call sites; updated independently.9.
test/utils/contracts_setup.go— AllCallEVMcall sites updatedFile:
test/utils/contracts_setup.goChange
niladded as thegasCapargument at all test-utility call sites. Example:Call sites updated:
setupHandlerContractinitializesetupFactoryContractowner(×2),initialize,setUEAProxyImplementationsetupPrc20ContractupdateHandlerContractregisterEVMChainAndUEAregisterNewChain,registerUEA,getUEAWhy (evm change): Same
CallEVMsignature change as item 6. Test utilities callapp.EVMKeeperdirectly (not through the
EVMKeeperinterface), so they must match the concrete keeper signature.Bonus: evm-side change made to accommodate push-chain
evm/mempool/check_tx.gomoved toevm/mempool/checktx/check_tx.goWhat changed in evm:
NewCheckTxHandlerwas added in v0.4.0, relying ontypes.CheckTxHandlerand
types.RunTxfrom cosmos-sdkv0.53.4.Problem: push-chain pins cosmos-sdk to
v0.50.10(via areplacedirective). When push-chaincompiled the
evm/mempoolpackage (transitively viaevm/ante), the build failed becausetypes.CheckTxHandlerdoes not exist in cosmos-sdkv0.50.10.Fix:
check_tx.gowas moved from themempoolpackage into a newmempool/checktxsub-package. This means importing
github.com/cosmos/evm/mempool(used byante/evm/09_increment_sequence.goforErrNonceGap) no longer transitively compilescheck_tx.go, which requires the newer SDK types.evmd/app.go(the only caller ofNewCheckTxHandler) was updated to import from the newsub-package path:
This change lives in
evm/, not inpush-chain/, but it was made specifically to unblock thepush-chain build.
Test File changes
1.
x/uexecutor/mocks/mock_evmkeeper.go— UpdatedCallEVMmock signatureFailing test: Build failure in
x/uexecutor/keeper— mock no longer matched theEVMKeeperinterface.Root cause: v0.4.0 added a
gasCap *big.Intparameter toCallEVMbetweencommit boolandmethod string. The hand-maintained mock was still using the old 7-parameter signature.Fix: Added
gasCap *big.Intto both the mock method and the mock recorder:2.
x/uexecutor/keeper/msg_server_test.go— UpdatedCallEVMmock expectationsFailing test:
TestMsgServer_ExecutePayload/Fail:_CallFactoryToComputeUEAAddressRoot cause: Two
EXPECT().CallEVM(...)calls used 7gomock.Any()matchers matching the old signature. After the mock was updated with the new 8-parameter signature, the expectations had a mismatch ("Got: 8, want: 7").Fix: Added one
gomock.Any()to both expectations (thegasCapposition):3. Integration test files —
nilgasCap inCallEVMcallsFailing tests: Build failures across all
test/integration/packages.Root cause: Same v0.4.0
CallEVMsignature change. All call sites passed arguments positionally without the newgasCap *big.Intparameter, causing compile errors.Files fixed and pattern applied:
test/integration/uexecutor/inbound_solana_test.gotest/integration/uexecutor/vote_chain_meta_test.gotest/integration/uexecutor/inbound_synthetic_bridge_test.gotest/integration/uexecutor/inbound_cea_gas_and_payload_test.gotest/integration/uexecutor/inbound_cea_payload_test.gotest/integration/uexecutor/inbound_cea_smart_contract_test.gotest/integration/utss/fund_migration_test.goPattern (both single-line and multi-line forms):
Pre-existing Failure (Not Fixed)
TestSimulateBSC_FetchVaultFromGatewayinuniversalClient/chains/evm/tx_builder_test.goThis test makes a live RPC call to BSC mainnet (
vault()method on a gateway contract). It fails due to a network/contract revert, not related to the upgrade. The test predates this upgrade work and was failing before it began.References
Changes
Testing
go test ./...Checklist