Skip to content

Commit

Permalink
fix: removed incorrect test
Browse files Browse the repository at this point in the history
  • Loading branch information
10d9e committed May 11, 2024
1 parent b0c47b0 commit 3d89d0a
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 47 deletions.
16 changes: 0 additions & 16 deletions contracts/Paillier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -133,22 +133,6 @@ contract Paillier {
return enc_result;
}

function mul(
Ciphertext calldata a,
Ciphertext calldata b,
PublicKey calldata publicKey
) public view returns (BigNumber memory) {
BigNumber memory enc_a = BigNumber(a.value, false, BigNum.bitLength(a.value));
BigNumber memory enc_b = BigNumber(b.value, false, BigNum.bitLength(b.value));
BigNumber memory pub_n = BigNumber(publicKey.n, false, BigNum.bitLength(publicKey.n));

// Calculate the encrypted result as enc_a^enc_b * enc_b^enc_a % pub_n^2
BigNumber memory alpha = BigNum.modexp(enc_a, enc_b, BigNum.pow(pub_n, 2));
BigNumber memory beta = BigNum.modexp(enc_b, enc_a, BigNum.pow(pub_n, 2));
BigNumber memory enc_result = BigNum.mod(BigNum.mul(alpha, beta), BigNum.pow(pub_n, 2));
return enc_result;
}

/// @notice Divides an encrypted value by a plaintext constant
/// @dev The function computes Enc(a)^(n-1) % n^2 to divide Enc(a) by b
/// @param a The encrypted value as a Ciphertext
Expand Down
31 changes: 0 additions & 31 deletions test/Paillier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,37 +65,6 @@ describe('Paillier', function () {
expect(dec_sum).to.equal(3);
});

it('should multiply 2 ciphertexts', async function () {

const { Paillier, publicKey, privateKey } = await loadFixture(fixture);
const a: bigint = BigInt(2);
const b: bigint = BigInt(5);
const enc_a: Ciphertext = {
value: ethers.toBeHex(publicKey.encrypt(a)),
};
const enc_b: Ciphertext = {
value: ethers.toBeHex(publicKey.encrypt(b)),
};

// Public key
const pubKey: PublicKey = {
n: ethers.toBeHex(publicKey.n),
g: ethers.toBeHex(publicKey.g),
};

// bit length will differ to what has been stated in this script.
// if using 256-bit key, bit_length will be 264 as "0x" prefix may have been factored in
// Now lets deploy the contract and test the addition
const enc_prod = await Paillier.mul(enc_a, enc_b, pubKey);
const enc_prod_int = bigIntConversion.hexToBigint(enc_prod[0]);

// Conversion to int for convenience
const dec_prod = Number(privateKey.decrypt(enc_prod_int));
console.log(dec_prod);
// We want dec_prod to equal 10
expect(dec_prod).to.equal(10);
});

it('should add a ciphertext and plaintext', async function () {
const { Paillier, publicKey, privateKey } = await loadFixture(fixture);
const a: bigint = BigInt(1);
Expand Down

0 comments on commit 3d89d0a

Please sign in to comment.