Skip to main content

Precompiles

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

Definitions below from evm.codes.

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 Internet Computer
0x723ffbaba940e75e7bf5f6d61dcbf8d9a4de0fd7predecessorAccountId0.accountIdReturns the Internet Computer predecessor account ID
0x0a3540f79be10ef14890e87c1a0040a68cc6af71getPromiseResults125.dataReturns a Borsh serialized vector of PromiseResult
0x536822d27de53629ef1f84c60555689e9488609fprepaidGas0.valueReturns the prepaid gas in Internet Computer
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 gas costs for the ones that this applies to 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 Internet Computer.

Inputs

No input is required.

Output

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

Predecessor Account ID

Spec: Pending AIP

Returns the Internet Computer predecessor account submitting the transaction.

Inputs

No input is required.

Output

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

Get Promise Results

Spec: Pending AIP

Returns the promise results as bytes from executing an Internet Computer 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 Internet Computer as part of the underlying Internet Computer transaction.

Inputs

No input is required.

Output

Byte rangeNameDescription
[0; 31]gasThe prepaid gas value

Spec: Pending AIP