The Bifrost Network supports the standard precompiled contract installed on the Ethereum mainnet. The following is the table of addresses of the implemented precompiled contracts.
ECRECOVER
It returns the signer address of the ecdsa signature (v, r, s) if the signature is valid. It can be called directly in Solidity code.
Also known as datacopy, this function serves as a cost-efficient way to copy data in memory. Since the Solidity compiler does not support this function, this function must be called by assembly as follows.
This function calculates the remainder when an integer b(base) is raised to the e-th power(the exponent) and is divided by a positive integer m(the modulus). Since the Solidity compiler does not support this function, this function must be called by assembly as follows.
// contract address: 0x0000000000000000000000000000000000000005contract ModularCheck {uintpublic checkResult;// Function to Verify ModExp Resultfunctionverify( uint_base,uint_exp,uint_modulus) public { checkResult =modExp(_base, _exp, _modulus); }functionmodExp(uint256_b,uint256_e,uint256_m) publicreturns (uint256 result) {assembly {// Free memory pointerlet pointer :=mload(0x40)// Define length of base, exponent and modulus. 0x20 == 32 bytesmstore(pointer,0x20)mstore(add(pointer,0x20),0x20)mstore(add(pointer,0x40),0x20)// Define variables base, exponent and modulusmstore(add(pointer,0x60), _b)mstore(add(pointer,0x80), _e)mstore(add(pointer,0xa0), _m)// Store the resultlet value :=mload(0xc0)// Call the precompiled contract 0x05 = bigModExpifiszero(call(not(0),0x05,0, pointer,0xc0, value,0x20)) {revert(0,0) } result :=mload(value) } }}
BN128Add
The BN128Add precompiled contract implements a native elliptic curve point addition. It returns an elliptic curve point representing (ax, ay) + (bx, by) such that (ax, ay) and (bx, by) are valid points on the curve BN256. Since the Solidity compiler does not support this function, this function must be called by assembly as follows.
The BN128Mul precompiled contract implements a native elliptic curve multiplication with a scalar value. It returns an elliptic curve point representing scalar * (x, y) such that (x, y) is a valid curve point on the curve BN256. Since the Solidity compiler does not support this function, this function must be called by assembly as follows.
The BN128Pairing precompile implements elliptic curve paring operation to perform zkSNARK verification. For more information, check out the EIP-197 standard. Since the Solidity compiler does not support this function, this function must be called by assembly as follows.
// contract address: 0x0000000000000000000000000000000000000008contract Precompiles {functioncallBn256Pairing(bytesmemory input) publicreturns (bytes32 result) {// input is a serialized bytes stream of (a1, b1, a2, b2, ..., ak, bk) from (G_1 x G_2)^kuint256 len = input.length;require(len % 192==0);assembly {let memPtr :=mload(0x40)let success :=call(gas,0x08,0,add(input,0x20), len, memPtr,0x20) switch success case 0 {revert(0,0) } default { result :=mload(memPtr) } } }}
Blake2F
This EIP will enable the BLAKE2b hash function and other higher-round 64-bit BLAKE2 variants to run cost-effectively on the EVM, allowing easier interoperability between Ethereum and Zcash or any other Equihash-based PoW coin. For more information, check out the EIP-152 standard. Since the Solidity compiler does not support this function, this function must be called by assembly as follows.