Skip to content

Commit

Permalink
chore: docs
Browse files Browse the repository at this point in the history
  • Loading branch information
10d9e committed May 9, 2024
1 parent 2545804 commit 14542a9
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions contracts/Paillier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,11 @@ contract Paillier {
}

/// @notice Decrypts an encrypted value using a private key and a public key
/// @dev The decryption is performed as (c^lambda % n^2) % n, where lambda is the private key (c^(lambda) % n^2) * mu) % n
/// @dev The decryption is performed as (c^(lambda) % n^2) * mu) % n
/// @param encValue The encrypted value in bytes
/// @param privateKey The private key in bytes
/// @param publicKey The public key in bytes
/// @param sigma The precalculated sigma value ((c^lamba % n^2) / n) in bytes, to prevent expensive bigint division on chain
/// @return decryptedValue The decrypted value as a BigNumber
function decrypt(
Ciphertext calldata encValue,
Expand All @@ -190,10 +191,9 @@ contract Paillier {
BigNumber memory mu = BigNumber(privateKey.mu, false, BigNum.bitLength(privateKey.mu));
BigNumber memory n = BigNumber(publicKey.n, false, BigNum.bitLength(publicKey.n));
BigNumber memory sig = BigNumber(sigma, false, BigNum.bitLength(sigma));

BigNumber memory alpha = BigNum.modexp(enc_value, lambda, BigNum.pow(n, 2));

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

0 comments on commit 14542a9

Please sign in to comment.