跳到主要内容

标准 EVM 预编译

OXN 实现标准以太坊预编译集,地址 0x010x090x0a(KZG point evaluation,随 EIP-4844 引入)不支持——OXN 没有 blob 交易。

支持矩阵

地址名称用途OXN基础 gas每 word gas
0x01ecrecover从签名恢复以太坊签名者3000
0x02sha256SHA-256 哈希6012
0x03ripemd160RIPEMD-160 哈希600120
0x04identity输入拷贝到输出153
0x05modexp模幂运算(EIP-198)复杂
0x06ecAddbn128(alt_bn128)上的椭圆曲线加法150
0x07ecMulbn128 上的椭圆曲线标量乘法6000
0x08ecPairingbn128 上的配对校验4500034000/pair
0x09blake2fBLAKE2b F 压缩函数复杂
0x0apointEvaluationKZG point evaluation(EIP-4844)

Gas 成本按当前 EVM 规范。

用法示例

ecrecover

从签名哈希恢复以太坊地址:

function recoverSigner(bytes32 hash, uint8 v, bytes32 r, bytes32 s)
external pure returns (address)
{
return ecrecover(hash, v, r, s);
}

用于 meta-transaction、EIP-712 typed 签名、链下签名验证。

sha256 / ripemd160

密码学哈希:

bytes memory input = "hello";
bytes32 shaResult = sha256(input);
bytes20 ripemdResult = ripemd160(input);

keccak256(地址 0x00,不是预编译)是标准以太坊哈希——除非你为了与外部系统兼容需要 SHA-256 或 RIPEMD-160,否则用它。

modexp

大数模幂——用于 RSA 验证和其他密码学协议:

function modexp(bytes memory base, bytes memory exp, bytes memory mod)
internal view returns (bytes memory)
{
(bool success, bytes memory result) = address(0x05).staticcall(
abi.encodePacked(base.length, exp.length, mod.length, base, exp, mod)
);
require(success);
return result;
}

bn128 曲线操作

用于 zkSNARK 验证(Groth16、Plonk)与其他基于配对的密码学:

// ecAdd: (x1, y1) + (x2, y2) 在 bn128 上
function ecAdd(uint256 x1, uint256 y1, uint256 x2, uint256 y2)
internal view returns (uint256, uint256)
{
(bool success, bytes memory result) = address(0x06).staticcall(
abi.encode(x1, y1, x2, y2)
);
require(success);
return abi.decode(result, (uint256, uint256));
}

不支持的原因

0x0a(pointEvaluation)——由 EIP-4844 为 blob 交易验证引入。OXN 没有 blob 交易,这个预编译在这里没有用途。

如果你的合约因为与 blob 无关的原因需要验证 KZG 承诺,只能在 Solidity 里实现(昂贵),或等待运行时升级加这个预编译。

下一步