@@ -44,7 +44,6 @@ contract Paillier {
44
44
Ciphertext calldata b ,
45
45
PublicKey calldata publicKey
46
46
) public view returns (BigNumber memory ) {
47
- // Create BigNumber representations for the encrypted values and the public key
48
47
BigNumber memory enc_a = BigNumber (a.value, false , BigNum.bitLength (a.value));
49
48
BigNumber memory enc_b = BigNumber (b.value, false , BigNum.bitLength (b.value));
50
49
BigNumber memory pub_n = BigNumber (publicKey.n, false , BigNum.bitLength (publicKey.n));
@@ -69,7 +68,6 @@ contract Paillier {
69
68
BigNumber memory pub_n = BigNumber (publicKey.n, false , BigNum.bitLength (publicKey.n));
70
69
BigNumber memory g = BigNumber (publicKey.g, false , BigNum.bitLength (publicKey.g));
71
70
BigNumber memory enc_result = BigNum.mod (BigNum.mul (enc_a, BigNum.pow (g, b)), BigNum.pow (pub_n, 2 ));
72
-
73
71
return enc_result;
74
72
}
75
73
@@ -87,10 +85,8 @@ contract Paillier {
87
85
BigNumber memory enc_a = BigNumber (a.value, false , BigNum.bitLength (a.value));
88
86
BigNumber memory enc_b = BigNumber (b.value, false , BigNum.bitLength (b.value));
89
87
BigNumber memory pub_n = BigNumber (publicKey.n, false , BigNum.bitLength (publicKey.n));
90
-
91
88
BigNumber memory modulus = BigNum.pow (pub_n, 2 );
92
89
BigNumber memory neg_enc_b = BigNum.modexp (enc_b, BigNum.sub (pub_n, BigNum.one ()), modulus);
93
-
94
90
BigNumber memory enc_result = BigNum.mod (enc_a.mul (neg_enc_b), modulus);
95
91
return enc_result;
96
92
}
@@ -109,12 +105,10 @@ contract Paillier {
109
105
BigNumber memory enc_a = BigNumber (a.value, false , BigNum.bitLength (a.value));
110
106
BigNumber memory pub_n = BigNumber (publicKey.n, false , BigNum.bitLength (publicKey.n));
111
107
BigNumber memory g = BigNumber (publicKey.g, false , BigNum.bitLength (publicKey.g));
112
-
113
108
BigNumber memory bb = BigNumber (abi.encodePacked (b), true , 256 );
114
109
BigNumber memory inverse = BigNum.mod (bb, pub_n);
115
110
BigNumber memory modulus = BigNum.pow (pub_n, 2 );
116
111
BigNumber memory enc_result = enc_a.mul (BigNum.modexp (g, inverse, modulus)).mod (modulus);
117
-
118
112
return enc_result;
119
113
}
120
114
@@ -131,13 +125,16 @@ contract Paillier {
131
125
) public view returns (BigNumber memory ) {
132
126
BigNumber memory enc_value = BigNumber (a.value, false , BigNum.bitLength (a.value));
133
127
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
136
128
BigNumber memory enc_result = BigNum.mod (BigNum.pow (enc_value, b), BigNum.pow (pub_n, 2 ));
137
-
138
129
return enc_result;
139
130
}
140
131
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
141
138
function div_const (
142
139
Ciphertext calldata a ,
143
140
uint256 b ,
0 commit comments