Precompiled Contracts

The Metadium blockchain provides pre-compiled contracts. There are pre-compiled contracts in the Metadium blockchain. The compiled contracts include contracts deployed on Ethereum and newly supported by Metadium.

Public key recovery function for ECDSA signatures

At address 0x01, a function is provided to recover the public key of the elliptic curve digital signature algorithm. It receives the hash value of the transaction and the v, r, and s signature values ​​and returns the address. The contract’s address deployed on the Metadium testnet is 0x9AC3d2729e7e38949a5b7E9896C4b05B13765eaC and can be checked through Testnet Explorer.

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.10;

contract Ecrecover {
    function test() public pure returns(bool) {
        address addressTest = 0x12Cb274aAD8251C875c0bf6872b67d9983E53fDd;
        bytes32 msgHash = 0xc51dac836bc7841a01c4b631fa620904fc8724d7f9f1d3c420f0e02adf229d50;
        uint8 v = 0x1b;
        bytes32 r = 0x44287513919034a471a7dc2b2ed121f95984ae23b20f9637ba8dff471b6719ef;
        bytes32 s = 0x7d7dc30309a3baffbfd9342b97d0e804092c0aeb5821319aa732bc09146eafb4;

        return (recoverSignature(msgHash, v, r, s) == (addressTest));
    }

    function recoverSignature(bytes32 hash, uint8 v, bytes32 r, bytes32 s) public pure returns(address) {
        // Use ECRECOVER to verify address
        address addr = ecrecover(hash, v, r, s);
        require(addr != address(0), "signature is invalid");
        return addr;
    }
}

SHA256 hash function

Address 0x02 is given a SHA-256 hash function. When you enter data, the corresponding SHA-256 hash value is returned. The contract address deployed on the Metadium testnet is 0x1eFd33eaB481C903CB3e0766D71DAF4391B26043 and can be checked through Testnet Explorer.

RIPEMD160 hash function

Address 0x03 is given the RIPEMD-160 hash function. When you enter data, the corresponding RIPEMD-160 hash value is returned. The contract address deployed on the Metadium testnet is 0xf8C8cB0941b9A2fD511c87a73f9707D3c7Eb695c and can be checked through Testnet Explorer.

Data Copy function

A data copy function is provided at address 0x04. This function is intended as a cheaper way to copy data into memory. Currently, Solidity does not have dataCopy function support, so you must call it inline assembly. The contract address deployed on the Metadium testnet is 0xF1935F6236b6558d44aD2275B9d453082EBD9d68 and can be checked through Testnet Explorer.

Modular Exponentiation function

Address 0x05 provides a function to calculate the remainder when an integer b(base) is raised to the e-square(exponent) and divided by a positive integer m(modulus). The Solidity compiler does not support this, so you must call it inline assembly. The contract address deployed on the Metadium testnet is 0xA41b9c323527b1214cE7276364465183385a67fF and can be checked through Testnet Explorer.

Addition function for points on an elliptic curve

At address 0x06, a function is provided that implements the addition operation for points on an elliptic curve. This operation takes two valid points (ax,ay) and (bx,by) on the elliptic curve bn256 as input and returns the point (ax,ay)+(bx,by) on the elliptic curve as a result. The Solidity compiler does not support this function, so you must call it inline assembly. The contract address deployed on the Metadium testnet is 0xa6a7c21EbB8af0e7514daB6de8E8143E5E780e83 and can be checked through Testnet Explorer.

Multiplication function for points on an elliptic curve

At address 0x07, a function is provided that implements the multiplication operation for points on an elliptic curve expressed as scalar values. This operation takes as input a valid point (x,y) on the elliptic curve bn256. It returns the point scalar * (x,y) on the elliptic curve. The Solidity compiler does not support this function, so you must call it inline assembly. The contract address deployed on the Metadium testnet is 0xa424E85E2930375626612EaC99D6574eF59F090b and can be checked through Testnet Explorer.

Elliptic curve pairing function for zkSNARK verification

Address 0x08 provides a function for the elliptic curve pairing operation to verify zkSNARK as proposed in EIP-197. The Solidity compiler does not support this function, so you must call it inline assembly. The contract address deployed on the Metadium testnet is 0x405b7c971c2Ae9F1f79BD43ef59C680811B1612A and can be checked through Testnet Explorer.

Last updated