Skip to main content

Precompiles

The Aurora EVM supports all Ethereum precompiles as well as extra precompiles designed to interact with the NEAR blockchain. The ones denoted in bold are extra.

Definitions below from evm.codes.

info

exitToNear and exitToEthereum precompiles can only be invoked from Aurora EVM self-deployed NEP-141 mapped ERC-20 contract. These ERC-20 contracts are deployed by invoking the deploy_erc20_token function.

AddressNameMinimum GasInputOutputDescription
0x01ecRecover3000hash, v, r, spublicAddressElliptic curve digital signature algorithm (ECDSA) public key recovery function
0x02SHA2-25660datahashHash function
0x03RIPEMD-160600datahashHash function
0x04identity15datadataReturns the input
0x05modexp200Bsize, Esize, Msize, B, E, MvalueArbitrary-precision exponentiation under modulo
0x06ecAdd150x1, y1, x2, y2x, yPoint addition (ADD) on the elliptic curve alt_bn128
0x07ecMul6000x1, y1, sx, yScalar multiplication (MUL) on the elliptic curve alt_bn128
0x08ecPairing45000x1, y1, x2, y2, ..., xk, yksuccessBilinear function on groups on the elliptic curve alt_bn128
0x09blake2f0rounds, h, m, t, fhCompression function F used in the BLAKE2 cryptographic hashing algorithm
0xc104f4840573bed437190daf5d2898c2bdf928acrandomSeed0.hashReturns a hash from a per block entropy source from NEAR
0x723ffbaba940e75e7bf5f6d61dcbf8d9a4de0fd7predecessorAccountId0.accountIdReturns the NEAR predecessor account ID
0x0a3540f79be10ef14890e87c1a0040a68cc6af71getPromiseResults125.dataReturns a Borsh serialized vector of PromiseResult
0x536822d27de53629ef1f84c60555689e9488609fprepaidGas0.valueReturns the prepaid gas in NEAR
0xe9217bc70b7ed1f598ddd3199e80b093fa71124fexitToNear0flag, <amount>, nearAccountId.Used in exiting from Aurora to the NEAR ecosystem as NEP-141 fungible tokens
0xb0bd02f6a392af548bdf1cfaee5dfa0eefcc8eabexitToEthereum0flag, <amount>, ethAddress.Used in exiting from Aurora to Ethereum over the Rainbow bridge
note

Some precompiles currently have a gas value of 0. This is temporary as it is difficult to determine an exact gas value. However, the ones that this applies to the gas cost are generally negligible.

ECRecover

Spec: Ethereum yellow paper, appendix F

More information about ECDSA can be found here.

Inputs

Byte rangeNameDescription
[0; 31] (32 bytes)hashKeccak-256 hash of the transaction
[32; 63] (32 bytes)vRecovery identifier, expected to be either 27 or 28
[64; 95] (32 bytes)rx-value, expected to be in the range ]0; secp256k1n[
[96; 127] (32 bytes)sExpected to be in the range ]0; secp256k1n[

Output

Byte rangeNameDescription
[0; 31] (32 bytes)publicAddressThe recovered 20-byte address right aligned to 32 bytes

If an address cannot be recovered, or not enough gas was given, then there is no return data. Please note, that the return is the address that issued the signature but it won't verify the signature.

SHA2-256

Spec: Ethereum yellow paper, appendix E. Precompiled Contracts

More information about SHA2 can be found here.

Inputs

Byte rangeNameDescription
[0; length]dataData to hash with SHA2-256

Output

Byte rangeNameDescription
[0; 31] (32 bytes)hashThe result hash

If not enough gas was given, then there is no return data.

RIPEMD-160

Spec: Ethereum yellow paper, appendix E. Precompiled Contracts

More information can be found here.

Inputs

Byte rangeNameDescription
[0; length]dataData to hash with RIPEMD-160

Output

Byte rangeNameDescription
[0; 31] (32 bytes)hashThe result 20-byte hash right aligned to 32 bytes

If not enough gas was given, then there is no return data.

Identity

Spec: Ethereum yellow paper, appendix E. Precompiled Contracts

The identity function is typically used to copy a chunk of memory.

Inputs

Byte rangeNameDescription
[0; length]dataData to return

Output

Byte rangeNameDescription
[0; length]dataData from input

If not enough gas was given, then there is no return data.

ModExp

Spec: Ethereum yellow paper, appendix E. Precompiled Contracts

Arbitrary-precision exponentiation under modulo.

Inputs

Byte rangeNameDescription
[0; 31] (32 bytes)BsizeByte size of B
[32; 63] (32 bytes)EsizeByte size of E
[64; 95] (32 bytes)MsizeByte size of M
[96; 96 + Bsize]BBase as unsigned integer
[96 + Bsize; 96 + Bsize + Esize]EExponent as unsigned integer, if zero, then B ** E will be one
[96 + Bsize + Esize; 96 + Bsize + Esize + Msize]MModulo as unsigned integer, if zero, then returns zero

Output

Byte rangeNameDescription
[0; mSize]valueResult of the computation, with the same number of bytes as M

If not enough gas was given, then there is no return data.

BN256 Add

Spec: Ethereum yellow paper, appendix E.1 zkSNARK Related Precompiled Contract

The point at infinity is encoded with both fields x and y at 0.

Inputs

Byte rangeNameDescription
[0; 31] (32 bytes)x1X coordinate of the first point on the elliptic curve 'alt_bn128'
[32; 63] (32 bytes)y1Y coordinate of the first point on the elliptic curve 'alt_bn128'
[64; 95] (32 bytes)x2X coordinate of the second point on the elliptic curve 'alt_bn128'
[96; 127] (32 bytes)y2Y coordinate of the second point on the elliptic curve 'alt_bn128'

Output

Byte rangeNameDescription
[0; 31] (32 bytes)xX coordinate of the result point on the elliptic curve 'alt_bn128'
[32; 63] (32 bytes)yY coordinate of the result point on the elliptic curve 'alt_bn128'

If the input is not valid, or if not enough gas was given, then there is no return data.

BN256 Multiply

Spec: Ethereum yellow paper, appendix E.1 zkSNARK Related Precompiled Contract

The point at infinity is encoded with both fields x and y at 0.

Inputs

Byte rangeNameDescription
[0; 31] (32 bytes)x1X coordinate of the first point on the elliptic curve 'alt_bn128'
[32; 63] (32 bytes)y1Y coordinate of the first point on the elliptic curve 'alt_bn128'
[64; 95] (32 bytes)sScalar to use for the multiplication

Output

Byte rangeNameDescription
[0; 31] (32 bytes)xX coordinate of the result point on the elliptic curve 'alt_bn128'
[32; 63] (32 bytes)yY coordinate of the result point on the elliptic curve 'alt_bn128'

If the input is not valid, or if not enough gas was given, then there is no return data.

BN256 Pairing

Spec: Ethereum yellow paper, appendix E.1 zkSNARK Related Precompiled Contract

The point at infinity is encoded with both fields x and y at 0.

Inputs

The input must always be a multiple of 6 32-byte values. 0 inputs are valid and return 1. One set of inputs are defined as follows:

Byte rangeNameDescription
[0; 31] (32 bytes)x1
[32; 63] (32 bytes)y1
[64; 95] (32 bytes)x3
[96; 127] (32 bytes)x2
[128; 159] (32 bytes)y3
[160; 191] (32 bytes)y2

Output

Byte rangeNameDescription
[0; 31] (32 bytes)success1 if the pairing was a success, 0 otherwise

If the input is not valid, or if not enough gas was given, then there is no return data.

Blake2 F

Spec: Ethereum yellow paper, appendix E.2. BLAKE2 Precompiled Contract

The Blake2 F compression algorithm is defined in this RFC, section 3.2.

Inputs

Byte rangeNameDescription
[0; 3] (4 bytes)roundsNumber of rounds (big-endian unsigned integer)
[4; 67] (64 bytes)hState vector (8 8-byte little-endian unsigned integer)
[68; 195] (128 bytes)mMessage block vector (16 8-byte little-endian unsigned integer)
[196; 211] (16 bytes)tOffset counters (2 8-byte little-endian integer)
[212; 212] (1 byte)fFinal block indicator flag (0 or 1)

Output

Byte rangeNameDescription
[0; 63] (64 bytes)hState vector (8 8-byte little-endian unsigned integer)

If the input is not valid, or if not enough gas was given, then there is no return data.

Random Seed

Spec: Pending AIP

A random seed generated per block from NEAR.

Inputs

No input is required.

Output

Byte rangeNameDescription
[0; 31] (32 bytes)hashRandom seed bytes

Predecessor Account ID

Spec: Pending AIP

Returns the NEAR predecessor account submitting the transaction.

Inputs

No input is required.

Output

Byte rangeNameDescription
[0; length] (32 bytes)account idNEAR predecessor account ID

Get Promise Results

Spec: Pending AIP

Returns the promise results as bytes from executing a NEAR promise.

Inputs

No input is required.

Output

Byte rangeNameDescription
borsh([0; length])promisesBorsh encoded promises

Prepaid Gas

Spec: Pending AIP

Returns the prepaid gas denoted in NEAR as part of the underlying NEAR transaction.

Inputs

No input is required.

Output

Byte rangeNameDescription
[0; 31]gasThe prepaid gas value

Exit to NEAR

Spec: Pending AIP

Transfers either ETH or a NEP-141 mapped ERC-20 token from the Aurora EVM to Near as NEP-141.

This can only be invoked through Engine self-deployed NEP-141 mapped ERC-20 contracts using the deploy_erc20_token method on the EVM.

note

For completeness, the details are included anyways even though you can not directly interface with this precompile.

Inputs

There are two kinds of inputs depending on if you are withdrawing ETH or ERC-20 from a NEP-141 mapped ERC-20 contract.

ETH withdraw

Byte rangeNameDescription
[0] (1 byte)flagThe flag must be set as 0x0 for ETH transfer
[1; length]account_idThe NEAR recipient account which will receive ETH tokens as NEP-141 tokens

ERC-20 withdraw

Byte rangeNameDescription
[0] (1 byte)flagThe flag must be set as 0x1 for ERC-20 transfer
[1; 32] (32 bytes)amountThe amount value which is required only for ERC-20 transfers
[33; length]account_idThe NEAR recipient account which will receive ERC-20 tokens as NEP-141 tokens

Output

There is no output except for log emissions which will trigger the transfer of NEP-141 tokens.

Exit to Ethereum

Spec: Pending AIP

Transfers either ETH or a NEP-141 mapped ERC-20 token from the Aurora EVM to Ethereum over the Rainbow Bridge.

This can only be invoked through Engine self-deployed NEP-141 mapped ERC-20 contracts using the deploy_erc20_token method on the EVM.

note

For completeness, the details are included anyways even though you can not directly interface with this precompile.

Inputs

There are two kinds of inputs depending on if you are withdrawing ETH or ERC-20 from a NEP-141 mapped ERC-20 contract.

ETH withdraw

Byte rangeNameDescription
[0] (1 byte)flagThe flag must be set as 0x0 for ETH transfer
[1; 20] (20 bytes)eth_addressThe ETH recipient address which will receive ETH tokens on Ethereum

ERC-20 withdraw

Byte rangeNameDescription
[0] (1 byte)flagThe flag must be set as 0x1 for ERC-20 transfer
[1; 32] (32 bytes)amountThe amount value which is required only for ERC-20 transfers
[33; 52] (20 bytes)eth_addressThe ETH recipient address which will receive ERC-20 tokens on Ethereum

Output

There is no output except for log emissions which will trigger the transfer from Aurora EVM to the Ethereum blockchain.