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:
assign(variable: PondPrivateVariable, value) → tensorflow.python.framework.ops.Operation[source]

See tf.assign.

avgpool2d(x, pool_size, strides, padding)[source]

See tf.nn.avgpool2d.

cache(xs)[source]

Wraps all input tensors, including private and masked, in variables so that computation and masking of these can be reused between different runs.

For private predictions this may be used to avoid re-masking model weights between each run, thereby saving on communication. For private training this may be used to avoid re-masked the traning data between each iteration, again saving on communication.

concat(xs: List[PondTensor], axis)[source]

See tf.concat.

conv2d(x, w, strides, padding)[source]

See tf.nn.conv2d.

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_local_computation(player, computation_fn, arguments=None, apply_scaling=True, name=None, masked=False, factory=None)[source]

Define a local computation that happens on plaintext tensors.

Parameters:
  • player – Who performs the computation and gets to see the values in plaintext.
  • apply_scaling – Whether or not to scale the outputs.
  • name – Optional name to give to this node in the graph.
  • masked – Whether or not to produce masked outputs.
  • factory – Backing tensor type to use for outputs.
define_output(player, arguments, outputter_fn, name=None)[source]

Define an output for this graph.

Parameters:player – Which player this output will be sent to.
define_private_input(player, inputter_fn, apply_scaling: bool = True, name: Optional[str] = None, masked: bool = False, factory: Optional[tf_encrypted.tensor.factory.AbstractFactory] = None)[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 computation.

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.
dispatch(base_name, *args, container=None, **kwargs)[source]

Finds the correct protocol logicto perform based on the dispatch_id attribute of the input tensors in args.

div(x, y)[source]

Performs a true division of x by y where y is public.

No flooring is performing if y is an integer type as it is implicitly treated as a float.

expand_dims(x: PondTensor, axis=None)[source]

See tf.expand_dims.

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:
mask(x)[source]

Convert to a PondMaskedTensor.

negative(x) → PondTensor[source]

Computes numerical negative value element-wise.

Parameters:x (PondTensor) – Input tensor.
pad(x: tf_encrypted.protocol.pond.pond.PondTensor, paddings: list)[source]

See tf.pad.

relu(x: PondTensor)[source]

A Chebyshev polynomial approximation of the ReLU function.

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.
sigmoid(x: PondTensor)[source]

A Chebyshev polynomial approximation of the sigmoid function.

squeeze(x: PondTensor, axis: Optional[List[int]] = None)[source]

See tf.squeeze.

stack(xs: List[PondTensor], axis=0)[source]

See tf.stack.

strided_slice(x, *args, **kwargs) → PondTensor[source]

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

tanh(x: PondTensor)[source]

A Chebyshev polynomial approximation of the hyperbolic tangent function.

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.