feat(compiler): support crt encoding in scalars during simulation

This commit is contained in:
youben11
2023-07-18 10:56:03 +01:00
committed by Ayoub Benaissa
parent 4f2b44c9d8
commit cd0f02d99c
2 changed files with 28 additions and 7 deletions

View File

@@ -54,10 +54,22 @@ public:
return value.getScalar().getValue<T>();
if (isSimulated()) {
// value is a scalar in simulation
auto ciphertext = value.getScalar().getValue<uint64_t>();
OUTCOME_TRY(auto decrypted, decryptValue(pos, &ciphertext));
return (T)decrypted;
OUTCOME_TRY(auto gate, outputGate(pos));
auto crtVec = gate.encryption->encoding.crt;
if (crtVec.empty()) {
// value is a scalar
auto ciphertext = value.getScalar().getValue<uint64_t>();
OUTCOME_TRY(auto decrypted, decryptValue(pos, &ciphertext));
return (T)decrypted;
} else {
// value is a tensor (crt)
auto &buffer = value.getTensor();
auto ciphertext = buffer.getOpaqueElementPointer(0);
OUTCOME_TRY(
auto decrypted,
decryptValue(pos, reinterpret_cast<uint64_t *>(ciphertext)));
return (T)decrypted;
}
}
auto &buffer = value.getTensor();

View File

@@ -238,9 +238,18 @@ protected:
/// Simulate encrypt and export a 64bits integer to a serializale value
outcome::checked<ScalarOrTensorData, StringError>
exportEncryptValue(uint64_t arg, CircuitGate &gate, size_t argPos) override {
uint64_t encValue = 0;
OUTCOME_TRYV(encryptValue(gate, argPos, &encValue, arg));
return ScalarData(encValue);
auto crtVec = gate.encryption->encoding.crt;
if (crtVec.empty()) {
uint64_t encValue = 0;
OUTCOME_TRYV(encryptValue(gate, argPos, &encValue, arg));
return ScalarData(encValue);
} else {
TensorData td(bufferShape(gate), clientlib::EncryptedScalarElementType,
clientlib::EncryptedScalarElementWidth);
OUTCOME_TRYV(
encryptValue(gate, argPos, td.getElementPointer<uint64_t>(0), arg));
return std::move(td);
}
}
outcome::checked<CircuitGate, StringError> inputGate(size_t argPos) override {