预编译(precompile)是在固定地址部署的智能合约接口,其实现以原生 Go 代码运行,而不是 EVM 字节码。在标准以太坊中,预编译通常是无状态的,用于处理签名验证、哈希等操作。在 Cosmos EVM 中,它们也可以是有状态的,即可读取和写入 EVM 之外的 Cosmos SDK 模块状态。 这正是它们强大的原因:智能合约可以调用 staking 预编译来委托代币,调用 governance 预编译来提交提案,或调用 IBC 预编译来发送跨链代币,而且全部通过标准 Solidity 接口完成,并且都可在一笔交易中执行。 预编译充当了通往 Cosmos SDK 的窗口:当调用预编译时,执行会从 EVM 路由到对应的 Cosmos SDK 模块,并将结果返回给 EVM 以继续执行。Gas 会在这两个环境中统一计量。
所有预编译合约都应使用以太坊标准的 18 位小数精度。尽管典型的 Cosmos 链通常使用 6 位小数精度,但 EVM 链应使用 18 位小数精度。 在与预编译交互之前,务必先确认你的链所使用的小数精度。

内置预编译

预编译地址用途参考
P2560x0000000000000000000000000000000000000100P-256 椭圆曲线签名验证详情
Bech320x0000000000000000000000000000000000000400以太坊十六进制地址与 Cosmos bech32 地址格式转换详情
Staking0x0000000000000000000000000000000000000800验证者操作、委托与质押奖励详情
Distribution0x0000000000000000000000000000000000000801质押奖励与社区资金池管理详情
ICS200x0000000000000000000000000000000000000802通过 IBC 进行跨链代币转移详情
Bank0x0000000000000000000000000000000000000804以 ERC20 风格访问原生 Cosmos SDK 代币详情
Governance0x0000000000000000000000000000000000000805链上治理提案与投票详情
Slashing0x0000000000000000000000000000000000000806验证者惩罚与监禁管理详情
ICS020x0000000000000000000000000000000000000807IBC 轻客户端查询源码
ERC20每个代币动态分配原生 Cosmos 代币的标准 ERC20 接口详情
WERC20每个代币动态分配原生代币的包装功能详情
链构建者可以控制哪些预编译处于启用状态,也可以添加自定义预编译。详情参见预编译配置指南。
Precompiles are smart contract interfaces deployed at fixed addresses where the implementation runs as native Go code rather than EVM bytecode. In standard Ethereum, precompiles are stateless and handle things like signature verification and hashing. In Cosmos EVM, they can also be stateful — reading from and writing to Cosmos SDK module state outside the EVM. This is what makes them powerful: a smart contract can call the staking precompile to delegate tokens, the governance precompile to submit a proposal, or the IBC precompile to send tokens cross-chain — all using a standard Solidity interface, all within a single transaction. Precompiles act as a window into the Cosmos SDK: when a precompile is invoked, execution routes from the EVM through the corresponding Cosmos SDK module and returns the result to the EVM for continued execution. Gas is metered across both environments.
All precompile contracts should use Ethereum’s standard 18 decimals.Although typical Cosmos chains use 6 decimals, EVM chains should use 18 decimals. Always check your chain’s decimal precision before interacting with a precompile.

Built-in Precompiles

PrecompileAddressPurposeReference
P2560x0000000000000000000000000000000000000100P-256 elliptic curve signature verificationDetails
Bech320x0000000000000000000000000000000000000400Address format conversion between Ethereum hex and Cosmos bech32Details
Staking0x0000000000000000000000000000000000000800Validator operations, delegation, and staking rewardsDetails
Distribution0x0000000000000000000000000000000000000801Staking rewards and community pool managementDetails
ICS200x0000000000000000000000000000000000000802Cross-chain token transfers via IBCDetails
Bank0x0000000000000000000000000000000000000804ERC20-style access to native Cosmos SDK tokensDetails
Governance0x0000000000000000000000000000000000000805On-chain governance proposals and votingDetails
Slashing0x0000000000000000000000000000000000000806Validator slashing and jail managementDetails
ICS020x0000000000000000000000000000000000000807IBC light client queriesSource
ERC20Dynamic per tokenStandard ERC20 interface for native Cosmos tokensDetails
WERC20Dynamic per tokenWrapped native token functionalityDetails
Chain builders can control which precompiles are active and add their own. See the Precompile Configuration guide for details.