mirror of
https://github.com/zama-ai/concrete.git
synced 2026-02-09 03:55:04 -05:00
feat: make virtual compilation unsafe
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user