feat: make virtual compilation unsafe

This commit is contained in:
Umut
2022-04-27 10:02:38 +02:00
parent add923b291
commit ffbcdabab0
3 changed files with 16 additions and 11 deletions

View File

@@ -59,10 +59,6 @@ class Circuit:
self.virtual = virtual
if self.virtual:
print(
"Warning: You are using virtual compilation, "
"which means the evaluation will not be homomorphic."
)
return
options = CompilationOptions.new("main")

View File

@@ -278,6 +278,11 @@ class Compiler:
"""
try:
if virtual and not self.configuration.enable_unsafe_features:
raise RuntimeError(
"Virtual compilation is not allowed without enabling unsafe features"
)
self._evaluate("Compiling", inputset)
assert self.graph is not None

View File

@@ -121,8 +121,18 @@ def test_compiler_bad_compile(helpers):
assert str(excinfo.value) == "Compiling function 'f' without an inputset is not supported"
configuration.enable_unsafe_features = False
def test_compiler_virtual_compile(helpers, capsys):
with pytest.raises(RuntimeError) as excinfo:
compiler = Compiler(lambda x: x, {"x": "encrypted"}, configuration=configuration)
compiler.compile(virtual=True)
assert str(excinfo.value) == (
"Virtual compilation is not allowed without enabling unsafe features"
)
def test_compiler_virtual_compile(helpers):
"""
Test `compile` method of `Compiler` class with virtual=True.
"""
@@ -135,10 +145,4 @@ def test_compiler_virtual_compile(helpers, capsys):
compiler = Compiler(f, {"x": "encrypted"}, configuration=configuration)
circuit = compiler.compile(inputset=range(400), virtual=True)
captured = capsys.readouterr()
assert captured.out.strip() == (
"Warning: You are using virtual compilation, "
"which means the evaluation will not be homomorphic."
)
assert circuit.encrypt_run_decrypt(200) == 600