Skip to content

Commit

Permalink
Add regression tests for public-private and private-public multiplica…
Browse files Browse the repository at this point in the history
…tion.
  • Loading branch information
tshead2 committed Aug 15, 2023
1 parent 0d507ac commit d471fbd
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 6 deletions.
4 changes: 2 additions & 2 deletions cicada/active.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ def field_multiply(self, lhs, rhs):
self.aprotocol.field_multiply(lhs.additive, rhs),
self.sprotocol.field_multiply(lhs.shamir, rhs)))

raise NotImplementedError(f"Privacy-preserving multiplication not implemented for the given types: {type(lhs)} and {type(rhs)}.")
raise NotImplementedError(f"Privacy-preserving multiplication not implemented for the given types: {type(lhs)} and {type(rhs)}.") # pragma: no cover


def field_power(self, lhs, rhs):
Expand Down Expand Up @@ -1027,7 +1027,7 @@ def multiply(self, lhs, rhs, *, encoding=None):
self.aprotocol.multiply(lhs, rhs.additive, encoding=encoding),
self.sprotocol.multiply(lhs, rhs.shamir, encoding=encoding)))

raise NotImplementedError(f"Privacy-preserving multiplication not implemented for the given types: {type(lhs)} and {type(rhs)}.")
raise NotImplementedError(f"Privacy-preserving multiplication not implemented for the given types: {type(lhs)} and {type(rhs)}.") # pragma: no cover


def negative(self, operand):
Expand Down
4 changes: 2 additions & 2 deletions cicada/additive.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ def field_multiply(self, lhs, rhs):
if isinstance(lhs, AdditiveArrayShare) and isinstance(rhs, numpy.ndarray):
return AdditiveArrayShare(self.field.multiply(lhs.storage, rhs))

raise NotImplementedError(f"Privacy-preserving multiplication not implemented for the given types: {type(lhs)} and {type(rhs)}.")
raise NotImplementedError(f"Privacy-preserving multiplication not implemented for the given types: {type(lhs)} and {type(rhs)}.") # pragma: no cover


def field_power(self, lhs, rhs):
Expand Down Expand Up @@ -1185,7 +1185,7 @@ def multiply(self, lhs, rhs, *, encoding=None):
result = self.right_shift(result, bits=encoding.precision)
return result

raise NotImplementedError(f"Privacy-preserving multiplication not implemented for the given types: {type(lhs)} and {type(rhs)}.")
raise NotImplementedError(f"Privacy-preserving multiplication not implemented for the given types: {type(lhs)} and {type(rhs)}.") # pragma: no cover


def negative(self, operand):
Expand Down
4 changes: 2 additions & 2 deletions cicada/shamir.py
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,7 @@ def field_multiply(self, lhs, rhs):
if isinstance(lhs, ShamirArrayShare) and isinstance(rhs, numpy.ndarray):
return ShamirArrayShare(self.field.multiply(lhs.storage, rhs))

raise NotImplementedError(f"Privacy-preserving multiplication not implemented for the given types: {type(lhs)} and {type(rhs)}.")
raise NotImplementedError(f"Privacy-preserving multiplication not implemented for the given types: {type(lhs)} and {type(rhs)}.") # pragma: no cover


def field_power(self, lhs, rhs):
Expand Down Expand Up @@ -1529,7 +1529,7 @@ def multiply(self, lhs, rhs, *, encoding=None):
result = self.right_shift(result, bits=encoding.precision)
return result

raise NotImplementedError(f"Privacy-preserving multiplication not implemented for the given types: {type(lhs)} and {type(rhs)}.")
raise NotImplementedError(f"Privacy-preserving multiplication not implemented for the given types: {type(lhs)} and {type(rhs)}.") # pragma: no cover


def power(self, lhs, rhs, *, encoding=None):
Expand Down
38 changes: 38 additions & 0 deletions features/active.feature
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,44 @@ Feature: Active Protocol
| 3 | [5, 3.5] | [2, 4] | [10, 14] |


@calculator
Scenario Outline: Multiply Public Private
Given a calculator service with <players> players
And a new Active protocol suite
And public value <a>
And player 1 secret shares <b>
When the players multiply the shares
And the players reveal the secret
Then the result should match <result>

Examples:
| players | a | b | result |
| 3 | 5 | 2 | 10 |
| 3 | 5 | 2.5 | 12.5 |
| 3 | 5 | -2.5 | -12.5 |
| 3 | -5 | -2.5 | 12.5 |
| 3 | [5, 3.5] | [2, 4] | [10, 14] |


@calculator
Scenario Outline: Multiply Private Public
Given a calculator service with <players> players
And a new Active protocol suite
And player 0 secret shares <a>
And public value <b>
When the players multiply the shares
And the players reveal the secret
Then the result should match <result>

Examples:
| players | a | b | result |
| 3 | 5 | 2 | 10 |
| 3 | 5 | 2.5 | 12.5 |
| 3 | 5 | -2.5 | -12.5 |
| 3 | -5 | -2.5 | 12.5 |
| 3 | [5, 3.5] | [2, 4] | [10, 14] |


@calculator
Scenario Outline: Negative
Given a calculator service with <players> players
Expand Down
38 changes: 38 additions & 0 deletions features/additive.feature
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,44 @@ Feature: Additive Protocol
| 3 | [5, 3.5] | [2, 4] | [10, 14] |


@calculator
Scenario Outline: Multiply Public Private
Given a calculator service with <players> players
And a new Additive protocol suite
And public value <a>
And player 1 secret shares <b>
When the players multiply the shares
And the players reveal the secret
Then the result should match <result>

Examples:
| players | a | b | result |
| 3 | 5 | 2 | 10 |
| 3 | 5 | 2.5 | 12.5 |
| 3 | 5 | -2.5 | -12.5 |
| 3 | -5 | -2.5 | 12.5 |
| 3 | [5, 3.5] | [2, 4] | [10, 14] |


@calculator
Scenario Outline: Multiply Private Public
Given a calculator service with <players> players
And a new Additive protocol suite
And player 0 secret shares <a>
And public value <b>
When the players multiply the shares
And the players reveal the secret
Then the result should match <result>

Examples:
| players | a | b | result |
| 3 | 5 | 2 | 10 |
| 3 | 5 | 2.5 | 12.5 |
| 3 | 5 | -2.5 | -12.5 |
| 3 | -5 | -2.5 | 12.5 |
| 3 | [5, 3.5] | [2, 4] | [10, 14] |


@calculator
Scenario Outline: Negative
Given a calculator service with <players> players
Expand Down
38 changes: 38 additions & 0 deletions features/shamir.feature
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,44 @@ Feature: Shamir Protocol
| 3 | [5, 3.5] | [2, 4] | [10, 14] |


@calculator
Scenario Outline: Multiply Public Private
Given a calculator service with <players> players
And a new Shamir protocol suite
And public value <a>
And player 1 secret shares <b>
When the players multiply the shares
And the players reveal the secret
Then the result should match <result>

Examples:
| players | a | b | result |
| 3 | 5 | 2 | 10 |
| 3 | 5 | 2.5 | 12.5 |
| 3 | 5 | -2.5 | -12.5 |
| 3 | -5 | -2.5 | 12.5 |
| 3 | [5, 3.5] | [2, 4] | [10, 14] |


@calculator
Scenario Outline: Multiply Private Public
Given a calculator service with <players> players
And a new Shamir protocol suite
And player 0 secret shares <a>
And public value <b>
When the players multiply the shares
And the players reveal the secret
Then the result should match <result>

Examples:
| players | a | b | result |
| 3 | 5 | 2 | 10 |
| 3 | 5 | 2.5 | 12.5 |
| 3 | 5 | -2.5 | -12.5 |
| 3 | -5 | -2.5 | 12.5 |
| 3 | [5, 3.5] | [2, 4] | [10, 14] |


@calculator
Scenario Outline: Negative
Given a calculator service with <players> players
Expand Down

0 comments on commit d471fbd

Please sign in to comment.