Pond

Pond is an implementation of the SPDZ algorithm for MPC.

class tf_encrypted.protocol.pond.Pond(server_0, server_1, crypto_producer, tensor_factory, fixedpoint_config)[source]

Pond is similar to SPDZ except it has been vectorized plus a few more optimizations.

Pond works with 2 parties for computation and one crypto producer for triples.

Parameters:
  • server_0 (Player) – The “alice” of MPC.
  • server_1 (Player) – The “bob” of MPC.
  • crypto_producer (Player) – The host to act as the crypto producer. In Pond this party is responsible for producing triples to aid in computation.
  • tensor_factory (AbstractFactory) – Which backing type of tensor you would like to use, e.g. int100 or int64
add(x, y) → PondTensor[source]

Adds two tensors x and y.

Parameters:
define_constant(value, apply_scaling, name, factory) → PondConstant[source]

Define a constant to use in computation.

x = prot.define_constant(np.array([1,2,3,4]), apply_scaling=False)
See:

tf.constant

Parameters:
  • value (np.ndarray) – The value to define as a constant.
  • apply_scaling (bool) – Whether or not to scale the value.
  • name (str) – What name to give to this node in the graph.
  • factory (AbstractFactory) – Which tensor type to represent this value with.
define_output(player, xs, outputter_fn, name) → tensorflow.Operation[source]

Define an output for this graph.

Parameters:player (Union[str,Player]) – Which player/device this output will be sent to.
define_private_input(player, inputter_fn, apply_scaling, name, masked, factory) -> PondPrivateTensor(s)[source]

Define a private input.

This represents a private input owned by the specified player into the graph.

Parameters:
  • player (Union[str,Player]) – Which player owns this input.
  • apply_scaling (bool) – Whether or not to scale the value.
  • name (str) – What name to give to this node in the graph.
  • masked (bool) – Whether or not to mask the input.
  • factory (AbstractFactory) – Which backing type to use for this input (e.g. int100 or int64).
define_private_placeholder(shape, apply_scaling, name, factory) → PondPrivatePlaceholder[source]

Define a private placeholder to use in computation. This will only be known by the party that defines it.

x = prot.define_private_placeholder(shape=(1024, 1024))
See:

tf.placeholder

Parameters:
  • shape (List[int]) – The shape of the placeholder.
  • apply_scaling (bool) – Whether or not to scale the value.
  • name (str) – What name to give to this node in the graph.
  • factory (AbstractFactory) – Which tensor type to represent this value with.
define_private_variable(initial_value, apply_scaling, name, factory) → PondPrivateVariable[source]

Define a private variable.

This will take the passed value and construct shares that will be split up between those involved in the computationself.

For example, in a two party architecture, this will split the value into two sets of shares and transfer them between each party in a secure manner.

:see tf.Variable

Parameters:
  • initial_value (Union[np.ndarray,tf.Tensor,PondPublicTensor]) – The initial value.
  • apply_scaling (bool) – Whether or not to scale the value.
  • name (str) – What name to give to this node in the graph.
  • factory (AbstractFactory) – Which tensor type to represent this value with.
define_public_input(player, inputter_fn, apply_scaling, name) -> PondPublicTensor(s)[source]

Define a public input.

This represents a public input owned by the specified player into the graph.

Parameters:
  • player (Union[str,Player]) – Which player owns this input.
  • apply_scaling (bool) – Whether or not to scale the value.
  • name (str) – What name to give to this node in the graph.
define_public_placeholder(shape, apply_scaling, name, factory) → PondPublicPlaceholder[source]

Define a public placeholder to use in computation. This will be known to both parties.

x = prot.define_public_placeholder(shape=(1024, 1024))
See:

tf.placeholder

Parameters:
  • shape (List[int]) – The shape of the placeholder.
  • apply_scaling (bool) – Whether or not to scale the value.
  • name (str) – What name to give to this node in the graph.
  • factory (AbstractFactory) – Which tensor type to represent this value with.
define_public_variable(initial_value, apply_scaling, name, factory) → PondPublicVariable[source]

Define a public variable.

This is like defining a variable in tensorflow except it creates one that can be used by the protocol.

For most cases, you can think of this as the same as the one from tensorflow and you don’t generally need to consider the difference.

For those curious, under the hood, the major difference is that this function will pin your data to a specific device which will be used to optimize the graph later on.

See:

tf.Variable

Parameters:
  • initial_value (Union[np.ndarray,tf.Tensor,PondPublicTensor]) – The initial value.
  • apply_scaling (bool) – Whether or not to scale the value.
  • name (str) – What name to give to this node in the graph.
  • factory (AbstractFactory) – Which tensor type to represent this value with.
lift(x, y=None, apply_scaling=None) -> PondTensor(s)[source]

Convenience method for working with mixed typed tensors in programs: combining any of the Pond objects together with e.g. ints and floats will automatically lift the latter into Pond objects.

Parameters:
reshape(x, shape) → PondTensor[source]

Reshape x into a tensor with a new shape.

Parameters:
  • x (PondTensor) – Input tensor.
  • shape ((int,..)) – Shape of output tensor.
strided_slice(x, *args, **kwargs) → PondTensor[source]

See https://www.tensorflow.org/api_docs/python/tf/strided_slice for further documentation.

transpose(x, perm=None) → PondTensor[source]

Transposes the input x, or permutes the axes of x if perm is given.

Parameters:
  • x (PondTensor) – The tensor to transpose or permute.
  • perm (List) – A permutation of axis indices.