MPC Core

The MPC Core is a library that simplifies interactions with the precompiled contracts which provide core functionalities for secure multi-party computation (MPC) using the COTI protocol.

Usage

// SPDX-License-Identifier: MIT

pragma solidity 0.8.19;

import "@coti-io/coti-contracts/contracts/utils/mpc/MpcCore.sol";

contract MyContract { ... }

Types

Inputtext

struct itBool
struct itUint8
struct itUint16
struct itUint32
struct itUint64
struct itString

Garbledtext

type gtBool
type gtUint8
type gtUint16
type gtUint32
type gtUint64
struct gtString

Ciphertext

type ctBool
type ctUint8
type ctUint16
type ctUint32
type ctUint64
struct ctString

Usertext

struct utBool
struct utUint8
struct utUint16
struct utUint32
struct utUint64
struct utString

Functions

Since private data types mostly support the same functions, we have chosen to list only the functions pertaining to the itUint64, gtUint64 and ctUint64 types. See MpcCore.sol for the full list of supported functions.

Special Functions

function getUserKey(bytes calldata signedEK, bytes calldata signature) returns (bytes memory keyShare0, bytes memory keyShare1)
  • Retrieves the user's AES encryption key in encrypted format, by using the provided RSA public key to encrypt it.

  • A valid signature using the EOA private key is used to validate the account ownership.

function deleteUserKey(bytes calldata signature)
  • Removes the user's AES encryption key from the system.

function validateCiphertext(itUint64 memory input) returns (gtUint64)
  • Verifies that a given inputtext has a valid signature and onboards it into the gcEVM, returning a Garbledtext™ value.

  • If the input is not valid, the call will revert with no return data and no additional gas will be consumed.

function onBoard(ctUint64 ct) returns (gtUint64)
  • The function onboards a given Ciphertext to the gcEVM, resulting in a Garbledtext™ value.

  • Must be invoked with ciphertext encrypted by the system AES key, such as ciphertexts that are generated by calling offboard.

function offBoard(gtUint64 pt) returns (ctUint64)
  • The function offboards the given Garbledtext™ from the gcEVM, resulting in a Ciphertext.

  • The offboarding process uses the network AES key to encrypt the value inside the Garbledtext™.

function offBoardToUser(gtUint64 pt, address addr) returns (ctUint64)
  • The function offboards the given Garbledtext™ from the gcEVM, resulting in a Ciphertext.

  • The offboarding process uses the user AES key associated with the given address to encrypt the value inside the Garbledtext™.

function offBoardCombined(gtUint64 pt, address addr) returns (utUint64 memory ut)
  • The function offboards the given Garbledtext™ from the gcEVM, resulting in a struct containing two Ciphertexts.

  • The offboarding process uses both the network AES key and the user AES key associated with the given address to encrypt the value inside the Garbledtext™.

function decrypt(gtUint64 ct) returns (uint64)
  • Returns the clear value of the given Ciphertext.

function setPublic64(uint64 pt) returns (gtUint64)
  • Onboards the given clear input to the gcEVM, resulting in a Garbledtext™.

function rand64() returns (gtUint64)
  • Generates an encrypted random value in Garbledtext™ form.

function randBoundedBits64(uint8 numBits) returns (gtUint64)
  • Generates an encrypted random value that falls within the range of [0, 2^numBits] in Garbledtext™ form.

function transfer(gtUint64 a, gtUint64 b, gtUint64 amount) returns (gtUint64, gtUint64, gtBool)
  • Returns the encrypted balances of two accounts (one starting with balance a, the other starting with balance b) as a result of transferring amount from the account with balance a to the account with balance b, along with an encrypted boolean value indicating whether the transfer would succeed.

  • If a is less than amount, then the resulting values of a and b will remain unchanged.

function transferWithAllowance(gtUint64 a, gtUint64 b, gtUint64 amount, gtUint64 allowance) returns (gtUint64, gtUint64, gtBool, gtUint64)
  • Returns the encrypted balances of two accounts (one starting with balance a, the other starting with balance b) as a result of transferring amount with allowance allowance from the account with balance a to the account with balance b, along with an encrypted boolean value indicating whether the transfer would succeed.

  • If a is less than amount or if amount is greater than allowance, then the resulting values of a and b will remain unchanged.

Arithmetic Functions

function add(gtUint64 a, gtUint64 b) returns (gtUint64)
function checkedAdd(gtUint64 a, gtUint64 b) returns (gtUint64)
function sub(gtUint64 a, gtUint64 b) returns (gtUint64)
function checkedSub(gtUint64 a, gtUint64 b) returns (gtUint64)
function mul(gtUint64 a, gtUint64 b) returns (gtUint64)
function checkedMul(gtUint64 a, gtUint64 b) returns (gtUint64)
function div(gtUint64 a, gtUint64 b) returns (gtUint64)
function rem(gtUint64 a, gtUint64 b) returns (gtUint64)
function and(gtUint64 a, gtUint64 b) returns (gtUint64)
function or(gtUint64 a, gtUint64 b) returns (gtUint64)
function xor(gtUint64 a, gtUint64 b) returns (gtUint64)
function eq(gtUint64 a, gtUint64 b) returns (gtBool)
function ne(gtUint64 a, gtUint64 b) returns (gtBool)
function ge(gtUint64 a, gtUint64 b) returns (gtBool)
function gt(gtUint64 a, gtUint64 b) returns (gtBool)
function le(gtUint64 a, gtUint64 b) returns (gtBool)
function lt(gtUint64 a, gtUint64 b) returns (gtBool)
function min(gtUint64 a, gtUint64 b) returns (gtUint64)
function max(gtUint64 a, gtUint64 b) returns (gtUint64)
function mux(gtBool bit, gtUint64 a, gtUint64 b) returns (gtUint64)
  • Returns an encrypted value (either a or b) based on the encrypted boolean input

  • If bit is false, then the returned value is equal to a

  • If bit is true, then the returned value is equal to b

Enums

enum MPC_TYPE { SBOOL_T, SUINT8_T, SUINT16_T, SUINT32_T, SUINT64_T }
  • Represent different MPC data types

enum ARGS { BOTH_SECRET, LHS_PUBLIC, RHS_PUBLIC }
  • Represent different argument types

Encoding Functions

function combineEnumsToBytes2(MPC_TYPE mpcType, ARGS argsType) returns (bytes2)
  • Combines an MPC_TYPE and ARGS into a bytes2 value.

function combineEnumsToBytes3(MPC_TYPE mpcType1, MPC_TYPE mpcType2, ARGS argsType) returns (bytes3)
  • Combines two MPC_TYPE values and an ARGS value into a bytes3 value.

function combineEnumsToBytes4(MPC_TYPE mpcType1, MPC_TYPE mpcType2, MPC_TYPE mpcType3, ARGS argsType) returns (bytes4)
  • Combines three MPC_TYPE values and an ARGS value into a bytes4 value.

function combineEnumsToBytes5(MPC_TYPE mpcType1, MPC_TYPE mpcType2, MPC_TYPE mpcType3, MPC_TYPE mpcType4, ARGS argsType) returns (bytes5)
  • Combines four MPC_TYPE values and an ARGS value into a bytes4 value.

Last updated