0) 准备
- 创建分支:
git switch -c upgrade/evm-v0.6。 - 确保升级前构建干净且测试通过。
- 为当前的 params/genesis 做快照,便于后续对比。
1) 依赖升级(go.mod)
- 将
github.com/cosmos/evm升级到 v0.6.0 并运行:
2) 应用接线变更
IBC Transfer 模块
v0.6.0 移除了自定义 IBC transfer keeper 覆盖,并改为直接使用官方 IBC-Go transfer keeper。这意味着无法通过 Cosmos IBC transfer 交易进行 ERC20 转换。这些转换现在仅在 ICS20 precompile 中处理,任何 ERC20 转账都必须通过那里发起。app.go 中所需的变更:
- 更新导入 - 用官方 IBC-Go 导入替换自定义 transfer 导入:
- 更新 TransferKeeper 初始化 - 移除 ERC20 keeper 参数:
- 更新模块注册 - 使用官方 transfer 模块:
- 更新 ICS20 precompile 接线 - 向 ICS20 precompile 传入 ERC20 keeper:
3) 破坏性 API 变更
StateDB 要求
v0.6.0 对事件追踪和状态管理引入了重大变更。所有 EVM 执行函数现在都需要显式传入stateDB 参数和 callFromPrecompile 标志,以便正确处理事件管理和状态转换。
**注意:**受影响的函数调用只有 CallEVM、CallEVMWithData、ApplyMessage 和 ApplyMessageWithConfig。这些函数通常用于常见的 precompile,以及从 SDK 回调进入 EVM 的逻辑。如果你的项目没有使用这些函数,那么这次升级无需执行额外步骤。
具体变更
以下函数的签名已更新:CallEVM
变更前(v0.5.x):
CallEVMWithData
变更前(v0.5.x):
ApplyMessage
变更前(v0.5.x):
ApplyMessageWithConfig
变更前(v0.5.x):
迁移步骤
对于非 Precompile 上下文
如果你是在 precompile 之外 调用 EVM 函数(例如在模块 keeper、message server 或 query handler 中):- 在调用 EVM 函数之前创建一个新的
stateDB - 为
callFromPrecompile参数传入false
对于 Precompile 上下文
如果你是在 precompile 内部 调用 EVM 函数:- 复用现有的
stateDB(不要创建新的) - 为
callFromPrecompile参数传入true - 现有的
stateDB通常可以作为 precompile 函数中的参数获得
重要说明
- 绝不要为
stateDB传入nil:这会返回ErrNilStateDB错误 - Precompile 中的 commit 行为:当
commit=true且callFromPrecompile=true时,状态变更会被刷新到 cache context,而不是被完全提交。这样可以避免在嵌套调用场景中压平缓存栈。
EVMKeeper 接口变更
如果你实现或 mock 了EVMKeeper 接口,请更新你的实现:
4) ERC20 Keeper 接口变更
ERC20Keeper 接口新增了以下方法:
5) 错误处理
新增了一种错误类型:nil 作为 stateDB 参数传给 EVM 函数时,会返回此错误。
6) 构建与测试
测试检查清单
迁移后,请验证:- 所有 EVM 调用都传入了有效的
stateDB - 非 precompile 调用使用
callFromPrecompile=false - precompile 调用复用了现有的
stateDB,并使用callFromPrecompile=true - 事件发射在成功和 revert 场景下都能正常工作
- 状态变更能够被正确提交或回滚
常见迁移示例
示例 1:模块 Keeper 查询
示例 2:Message Server 交易
示例 3:预编译内部调用
0) Prep
- Create a branch:
git switch -c upgrade/evm-v0.6. - Ensure a clean build + tests green pre-upgrade.
- Snapshot your current params/genesis for comparison later.
1) Dependency bumps (go.mod)
- Bump
github.com/cosmos/evmto v0.6.0 and run:
2) App Wiring Changes
IBC Transfer Module
v0.6.0 removes the custom IBC transfer keeper override and now uses the official IBC-Go transfer keeper directly. This means that ERC20 conversions via Cosmos IBC transfer transactions are not possible. These are now only handled in the ICS20 precompile, and any ERC20 transfer must be initiated through there. Changes required inapp.go:
- Update imports - Replace custom transfer imports with official IBC-Go imports:
- Update TransferKeeper initialization - Remove ERC20 keeper parameter:
- Update module registration - Use official transfer module:
- Update ICS20 precompile wiring - Pass ERC20 keeper to ICS20 precompile:
3) Breaking API Changes
StateDB Requirements
v0.6.0 introduces significant changes to event tracking and state management. All EVM execution functions now require an explicitstateDB parameter and a callFromPrecompile flag to properly handle event management and state transitions.
NOTE: The only function calls affected are CallEVM, CallEVMWithData, ApplyMessage, and ApplyMessageWithConfig. These are typically used in common precompiles and logic that calls back into the EVM from the SDK. If your project does not use these functions, then no steps need to be taken for the upgrade.
Advanced Changes
The following functions have updated signatures:CallEVM
Before (v0.5.x):
CallEVMWithData
Before (v0.5.x):
ApplyMessage
Before (v0.5.x):
ApplyMessageWithConfig
Before (v0.5.x):
Migration Steps
For Non-Precompile Contexts
If you’re calling EVM functions from outside a precompile (e.g., from a module keeper, message server, or query handler):- Create a new
stateDBbefore calling EVM functions - Pass
falsefor thecallFromPrecompileparameter
For Precompile Contexts
If you’re calling EVM functions from within a precompile:- Reuse the existing
stateDBfrom your precompile context (do not create a new one) - Pass
truefor thecallFromPrecompileparameter - The existing
stateDBis typically available as a parameter in your precompile function
Important Notes
- Never pass
nilforstateDB: This will returnErrNilStateDBerror - Commit behavior in precompiles: When
commit=trueandcallFromPrecompile=true, the state changes are flushed to the cache context rather than fully committed. This prevents collapsing the cache stack in nested call scenarios.
EVMKeeper Interface Changes
If you implement or mock theEVMKeeper interface, update your implementation:
4) ERC20 Keeper Interface Changes
TheERC20Keeper interface has new methods:
5) Error Handling
A new error type has been added:nil is passed as the stateDB parameter to EVM functions.
6) Build & Tests
Testing Checklist
After migration, verify:- All EVM calls pass a valid
stateDB - Non-precompile calls use
callFromPrecompile=false - Precompile calls reuse existing
stateDBand usecallFromPrecompile=true - Event emission works correctly in both success and revert scenarios
- State changes are properly committed or reverted