Skip to content

Commit 14542a9

Browse files
committed
chore: docs
1 parent 2545804 commit 14542a9

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

contracts/Paillier.sol

+3-3
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,11 @@ contract Paillier {
173173
}
174174

175175
/// @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
177177
/// @param encValue The encrypted value in bytes
178178
/// @param privateKey The private key in bytes
179179
/// @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
180181
/// @return decryptedValue The decrypted value as a BigNumber
181182
function decrypt(
182183
Ciphertext calldata encValue,
@@ -190,10 +191,9 @@ contract Paillier {
190191
BigNumber memory mu = BigNumber(privateKey.mu, false, BigNum.bitLength(privateKey.mu));
191192
BigNumber memory n = BigNumber(publicKey.n, false, BigNum.bitLength(publicKey.n));
192193
BigNumber memory sig = BigNumber(sigma, false, BigNum.bitLength(sigma));
193-
194194
BigNumber memory alpha = BigNum.modexp(enc_value, lambda, BigNum.pow(n, 2));
195195

196-
// precompute the div operation and verify the sigma
196+
// verify the precomputed sigma was correct - c^lambda % n^2 / n == sigma
197197
require(BigNum.divVerify(alpha, n, sig), "Invalid sigma");
198198
return BigNum.mod(BigNum.mul(sig, mu), n);
199199
}

0 commit comments

Comments
 (0)