@@ -173,10 +173,11 @@ contract Paillier {
173
173
}
174
174
175
175
/// @notice Decrypts an encrypted value using a private key and a public key
176
- /// @dev The decryption is performed as (c^lambda % n^2) % n, where lambda is the private key (c^ (lambda) % n^2) * mu) % n
176
+ /// @dev The decryption is performed as (c^(lambda) % n^2) * mu) % n
177
177
/// @param encValue The encrypted value in bytes
178
178
/// @param privateKey The private key in bytes
179
179
/// @param publicKey The public key in bytes
180
+ /// @param sigma The precalculated sigma value ((c^lamba % n^2) / n) in bytes, to prevent expensive bigint division on chain
180
181
/// @return decryptedValue The decrypted value as a BigNumber
181
182
function decrypt (
182
183
Ciphertext calldata encValue ,
@@ -190,10 +191,9 @@ contract Paillier {
190
191
BigNumber memory mu = BigNumber (privateKey.mu, false , BigNum.bitLength (privateKey.mu));
191
192
BigNumber memory n = BigNumber (publicKey.n, false , BigNum.bitLength (publicKey.n));
192
193
BigNumber memory sig = BigNumber (sigma, false , BigNum.bitLength (sigma));
193
-
194
194
BigNumber memory alpha = BigNum.modexp (enc_value, lambda, BigNum.pow (n, 2 ));
195
195
196
- // precompute the div operation and verify the sigma
196
+ // verify the precomputed sigma was correct - c^lambda % n^2 / n == sigma
197
197
require (BigNum.divVerify (alpha, n, sig), "Invalid sigma " );
198
198
return BigNum.mod (BigNum.mul (sig, mu), n);
199
199
}
0 commit comments