预编译合约 - 支持的预编译合约

预编译合约是在EVM中使用的一种折中方案,用于提供更复杂的库函数(通常用于复杂的操作,如加密、哈希等),这些函数不适合使用opcode编写。 它们适用于简单但频繁调用的合约,或者逻辑上固定但计算密集的合约。预编译合约在客户端上通过客户端代码实现,因为它们不需要EVM, 所以运行速度快。对于开发人员来说,使用预编译合约的成本也比直接在EVM中运行函数低。

MAP预编译合约

为了简化轻客户端的开发,所有种类的密码学原语都在区块链层面上得到支持,并通过预编译合约暴露给EVM。

MAP中继链将实现预编译合约以支持:

bn256

bn256AddIstanbul

  • Address 0x0000000000000000000000000000000000000006

    bn256Add implements a native elliptic curve point addition conforming to Istanbul consensus rules.

package example

func (c *bn256AddIstanbul) Run(evm *EVM, contract *Contract, input []byte) ([]byte, error) {
	return runBn256Add(input)
}

bn256ScalarMulIstanbul

  • Address 0x0000000000000000000000000000000000000007

    bn256ScalarMulIstanbul implements a native elliptic curve scalar multiplication conforming to Istanbul consensus rules.

bn256PairingIstanbul

  • Address 0x0000000000000000000000000000000000000008

    bn256PairingIstanbul implements a pairing pre-compile for the bn256 curve conforming to Istanbul consensus rules.

bls

BLS12_G1ADD

  • Address 0x000000000000000000000000000000000000000a

    Implements EIP-2537 G1Add precompile.

    > G1 addition call expects 256 bytes as an input that is interpreted as byte concatenation of two G1 points (128 bytes each).

    > Output is an encoding of addition operation result - single G1 point (128 bytes).

BLS12_G1MUL

  • Address 0x000000000000000000000000000000000000000b

    Implements EIP-2537 G1Mul precompile.

    > G1 multiplication call expects 160 bytes as an input that is interpreted as byte concatenation of encoding of G1 point (128 bytes) and encoding of a scalar value (32 bytes).

    > Output is an encoding of multiplication operation result - single G1 point(128 bytes).

BLS12_G1MULTIEXP

  • Address 0x000000000000000000000000000000000000000c

    Implements EIP-2537 G1MultiExp precompile.

    G1 multiplication call expects 160*k bytes as an input that is interpreted as byte concatenation of k slices each of them being a byte concatenation of encoding of G1 point (128 bytes) and encoding of a scalar value (32 bytes).

    Output is an encoding of multiexponentiation operation result - single G1 point (128 bytes).

BLS12_G2ADD

  • Address 0x000000000000000000000000000000000000000d

    Implements EIP-2537 G2Add precompile.

    > G2 addition call expects 512 bytes as an input that is interpreted as byte concatenation of two G2 points (256 bytes each).

    > Output is an encoding of addition operation result - single G2 point (256 bytes).

BLS12_G2MUL

  • Address 0x000000000000000000000000000000000000000e

    Implements EIP-2537 G2MUL precompile logic.

    > G2 multiplication call expects 288 bytes as an input that is interpreted as byte concatenation of encoding of G2 point (256 bytes) and encoding of a scalar value (32 bytes).

    > Output is an encoding of multiplication operation result - single G2 point (256 bytes).

BLS12_G2MULTIEXP

  • Address 0x000000000000000000000000000000000000000f

    Implements EIP-2537 G2MultiExp precompile logic

    > G2 multiplication call expects 288*k bytes as an input that is interpreted as byte concatenation of k slices each of them being a byte concatenation of encoding of G2 point (256 bytes) and encoding of a scalar value (32 bytes).

    > Output is an encoding of multiexponentiation operation result - single G2 point (256 bytes).

BLS12_PAIRING

  • Address 0x0000000000000000000000000000000000000010

    Implements EIP-2537 Pairing precompile logic.

    > Pairing call expects 384*k bytes as an inputs that is interpreted as byte concatenation of k slices. Each slice has the following structure:

    > - 128 bytes of G1 point encoding

    > - 256 bytes of G2 point encoding

    > Output is a 32 bytes where last single byte is 0x01 if pairing result is equal to multiplicative identity in a pairing target field and 0x00 otherwise

    > (which is equivalent of Big Endian encoding of Solidity values uint256(1) and uin256(0) respectively).

BLS12_MAP_FP_TO_G1

  • Address 0x0000000000000000000000000000000000000011

Implements EIP-2537 Map_To_G1 precompile.

> Field-to-curve call expects 64 bytes an an input that is interpreted as a an element of the base field.

> Output of this call is 128 bytes and is G1 point following respective encoding rules.

BLS12_MAP_FP2_TO_G2

  • Address 0x0000000000000000000000000000000000000012

    Implements EIP-2537 Map_FP2_TO_G2 precompile logic.

    > Field-to-curve call expects 128 bytes an an input that is interpreted as a an element of the quadratic extension field.

    > Output of this call is 256 bytes and is G2 point following respective encoding rules.

istanbul consensus

proofOfPossession

  • Address 0x00000000000000000000000000000000000000fb

    verify validator`s address 、publicKey、g1publickey、signature

getValidator

  • Address 0x00000000000000000000000000000000000000fa

    Return the validators that are required to sign the given, possibly unsealed, block number. If this block is the last in an epoch, note that that may mean one or more of those validators may no longer be elected for subsequent blocks. WARNING: Validator set is always constructed from the canonical chain, therefore this precompile is undefined if the engine is aware of a chain with higher total difficulty.

numberValidators

  • Address 0x00000000000000000000000000000000000000f9

    Return the number of validators that are required to sign this current, possibly unsealed, block. If this block is the last in an epoch, note that that may mean one or more of those validators may no longer be elected for subsequent blocks.

epochSize

  • Address 0x00000000000000000000000000000000000000f8

    return the epochSize

blockNumberFromHeader

  • Address 0x00000000000000000000000000000000000000f7

    return the blockNumber from header

hashHeader

  • Address 0x00000000000000000000000000000000000000f6

    return the hashHeader from header

getParentSealBitmap

  • Address 0x00000000000000000000000000000000000000F5

    Return the signer bitmap from the parent seal of a past block in the chain. Requested parent seal must have occurred within 4 epochs of the current block number.

getVerifiedSealBitmap

  • Address 0x00000000000000000000000000000000000000F4

    rerurn the extra.AggregatedSeal.Bitmap from header

light client verify

store

  • Address 0x000068656164657273746F726541646472657373

    execute atlas header store contract

verify

  • Address 0x0000000000747856657269667941646472657373

    RunTxVerify execute atlas tx verify contract

eth2VerifyLightClient

  • Address 0x000000000000000000000000000

other

ecrecover

  • Address 0x0000000000000000000000000000000000000001

    ecrecover implemented as a native contract.

sha256hash

  • Address 0x0000000000000000000000000000000000000002

    SHA256 implemented as a native contract.

dataCopy

  • Address 0x0000000000000000000000000000000000000004

data copy implemented as a native contract.

bigModExp

  • Address 0x0000000000000000000000000000000000000005

    bigModExp implements a native big integer exponential modular operation.

transfer

  • Address 0x00000000000000000000000000000000000000fd

    Native transfer contract to make Atlas Gold ERC20 compatible.

fractionMulExp

  • Address 0x00000000000000000000000000000000000000fc

    computes a * (b ^ exponent) to decimals places of precision, where a and b are fractions

ed25519Verify

  • Address 0x00000000000000000000000000000000000000f3

    ed25519Verify implements a native Ed25519 signature verification.

Last updated