Skip to content

Commit 47cfeb0

Browse files
committed
chore: updated formatting
1 parent 545ca1e commit 47cfeb0

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

contracts/Paillier.sol

+6-9
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ contract Paillier {
4444
Ciphertext calldata b,
4545
PublicKey calldata publicKey
4646
) public view returns (BigNumber memory) {
47-
// Create BigNumber representations for the encrypted values and the public key
4847
BigNumber memory enc_a = BigNumber(a.value, false, BigNum.bitLength(a.value));
4948
BigNumber memory enc_b = BigNumber(b.value, false, BigNum.bitLength(b.value));
5049
BigNumber memory pub_n = BigNumber(publicKey.n, false, BigNum.bitLength(publicKey.n));
@@ -69,7 +68,6 @@ contract Paillier {
6968
BigNumber memory pub_n = BigNumber(publicKey.n, false, BigNum.bitLength(publicKey.n));
7069
BigNumber memory g = BigNumber(publicKey.g, false, BigNum.bitLength(publicKey.g));
7170
BigNumber memory enc_result = BigNum.mod(BigNum.mul(enc_a, BigNum.pow(g, b)), BigNum.pow(pub_n, 2));
72-
7371
return enc_result;
7472
}
7573

@@ -87,10 +85,8 @@ contract Paillier {
8785
BigNumber memory enc_a = BigNumber(a.value, false, BigNum.bitLength(a.value));
8886
BigNumber memory enc_b = BigNumber(b.value, false, BigNum.bitLength(b.value));
8987
BigNumber memory pub_n = BigNumber(publicKey.n, false, BigNum.bitLength(publicKey.n));
90-
9188
BigNumber memory modulus = BigNum.pow(pub_n, 2);
9289
BigNumber memory neg_enc_b = BigNum.modexp(enc_b, BigNum.sub(pub_n, BigNum.one()), modulus);
93-
9490
BigNumber memory enc_result = BigNum.mod(enc_a.mul(neg_enc_b), modulus);
9591
return enc_result;
9692
}
@@ -109,12 +105,10 @@ contract Paillier {
109105
BigNumber memory enc_a = BigNumber(a.value, false, BigNum.bitLength(a.value));
110106
BigNumber memory pub_n = BigNumber(publicKey.n, false, BigNum.bitLength(publicKey.n));
111107
BigNumber memory g = BigNumber(publicKey.g, false, BigNum.bitLength(publicKey.g));
112-
113108
BigNumber memory bb = BigNumber(abi.encodePacked(b), true, 256);
114109
BigNumber memory inverse = BigNum.mod(bb, pub_n);
115110
BigNumber memory modulus = BigNum.pow(pub_n, 2);
116111
BigNumber memory enc_result = enc_a.mul(BigNum.modexp(g, inverse, modulus)).mod(modulus);
117-
118112
return enc_result;
119113
}
120114

@@ -131,13 +125,16 @@ contract Paillier {
131125
) public view returns (BigNumber memory) {
132126
BigNumber memory enc_value = BigNumber(a.value, false, BigNum.bitLength(a.value));
133127
BigNumber memory pub_n = BigNumber(publicKey.n, false, BigNum.bitLength(publicKey.n));
134-
135-
// Calculate the encrypted result as enc_value^b % pub_n^2
136128
BigNumber memory enc_result = BigNum.mod(BigNum.pow(enc_value, b), BigNum.pow(pub_n, 2));
137-
138129
return enc_result;
139130
}
140131

132+
/// @notice Divides an encrypted value by a plaintext constant
133+
/// @dev The function computes Enc(a)^(n-1) % n^2 to divide Enc(a) by b
134+
/// @param a The encrypted value as a Ciphertext
135+
/// @param b The plaintext constant as a uint256
136+
/// @param publicKey The public key as a PublicKey
137+
/// @return enc_result The result of the division as a BigNumber
141138
function div_const(
142139
Ciphertext calldata a,
143140
uint256 b,

contracts/examples/DiscreteERC20.sol

+2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ pragma solidity ^0.8.24;
33

44
import "../Paillier.sol";
55

6+
// Secp256k1Ciphertext struct
67
struct Secp256k1Ciphertext {
78
bytes iv;
89
bytes ephemPublicKey;
910
bytes ciphertext;
1011
bytes mac;
1112
}
13+
1214
/// @title DiscreteERC20: An ERC20 token contract with encrypted balances using the Paillier cryptosystem
1315
/// @dev This contract demonstrates an example of an ERC20 token where balances are encrypted to preserve user privacy.
1416
contract DiscreteERC20 {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@
2727
"bigint-conversion": "^2.4.3",
2828
"paillier-bigint": "^3.4.3"
2929
}
30-
}
30+
}

0 commit comments

Comments
 (0)