Skip to content

Example circuits

Warning

Some of these example circuits are untested and may be incorrect.

circuits

This package contains example circuits and tools for generating them.

aes

This module implements a high-level AES encryption circuit for a constant key.

gf = GF(2 ** 8) module-attribute
circuit = Circuit(encrypt([Input(f'{i}', gf) for i in range(16)], b'abcdabcdabcdabcd')).arithmetize() module-attribute
encrypt(plaintext, key)

Returns an AES encryption circuit for a constant key.

test_aes_128()

cardio

This module implements the cardio circuit that is often used in benchmarking compilers, see: https://arxiv.org/abs/2101.07078.

construct_cardio_risk_circuit(gf)

Returns the cardio circuit from https://arxiv.org/abs/2101.07078.

construct_cardio_elevated_risk_circuit(gf)

Returns a variant of the cardio circuit that returns a Boolean indicating whether any risk factor returned true.

test_cardio_p101()

median

This module implements circuits for computing the median.

gf = GF(1037347783) module-attribute
circuit = gen_median_circuit(range(10), gf) module-attribute
gen_median_circuit(inputs, gf)

Returns a naive circuit for finding the median value of inputs.

mimc

MIMC is an MPC-friendly cipher: https://eprint.iacr.org/2016/492.

gf = GF(680564733841876926926749214863536422929) module-attribute
node = encrypt(Input('m', gf), 12345) module-attribute
circuit = Circuit([node]).arithmetize() module-attribute
encrypt(plaintext, key, power_n=129)

Returns an MIMC encryption circuit using a constant key.

test_mimc_129()

sorting

This module contains sorting circuits and comparators.

gf = GF(13) module-attribute
circuit = gen_naive_sort_circuit(range(2), gf) module-attribute
cswp(lhs, rhs)

Conditionally swap inputs lhs and rhs such that lhs <= rhs.

Returns:

  • Tuple[Node, Node]

    A tuple representing (lower, higher)

gen_naive_sort_circuit(inputs, gf)

Returns a naive sorting circuit for the given sequence of inputs.

veto_voting

The veto voting circuit is the inverse of a consensus vote between a number of participants.

The circuit is essentially a large OR operation, returning 1 if any participant vetoes (by submitting a 1). This represents a vote that anyone can veto.

gf = GF(103) module-attribute
circuit = gen_veto_voting_circuit(10, gf).arithmetize() module-attribute
gen_veto_voting_circuit(participants, gf)

Returns a veto voting circuit between the number of participants.