@@ -84,6 +84,8 @@ export function generateSolidityImplLib(operators: Operator[]): string {
84
84
// SPDX-License-Identifier: BSD-3-Clause-Clear
85
85
pragma solidity ^0.8.24;
86
86
87
+ import {FheType} from "./TFHE.sol";
88
+
87
89
${ generateImplCoprocessorInterface ( operators ) }
88
90
89
91
${ generateACLInterface ( ) }
@@ -206,31 +208,31 @@ function coprocessorInterfaceCustomFunctions(): string {
206
208
* @param inputType Input type.
207
209
* @return result Result.
208
210
*/
209
- function verifyCiphertext(bytes32 inputHandle, address callerAddress, bytes memory inputProof, bytes1 inputType) external returns (bytes32 result);
211
+ function verifyCiphertext(bytes32 inputHandle, address callerAddress, bytes memory inputProof, FheType inputType) external returns (bytes32 result);
210
212
211
213
/**
212
214
* @notice Performs the casting to a target type.
213
215
* @param ct Value to cast.
214
216
* @param toType Target type.
215
217
* @return result Result value of the target type.
216
218
*/
217
- function cast(bytes32 ct, bytes1 toType) external returns (bytes32 result);
219
+ function cast(bytes32 ct, FheType toType) external returns (bytes32 result);
218
220
219
221
/**
220
222
* @notice Does trivial encryption.
221
223
* @param ct Value to encrypt.
222
224
* @param toType Target type.
223
225
* @return result Result value of the target type.
224
226
*/
225
- function trivialEncrypt(uint256 ct, bytes1 toType) external returns (bytes32 result);
227
+ function trivialEncrypt(uint256 ct, FheType toType) external returns (bytes32 result);
226
228
227
229
/**
228
230
* @notice Does trivial encryption.
229
231
* @param ct Value to encrypt.
230
232
* @param toType Target type.
231
233
* @return result Result value of the target type.
232
234
*/
233
- function trivialEncrypt(bytes memory ct, bytes1 toType) external returns (bytes32 result);
235
+ function trivialEncrypt(bytes memory ct, FheType toType) external returns (bytes32 result);
234
236
235
237
/**
236
238
* @notice Computes FHEEq operation.
@@ -264,15 +266,15 @@ function coprocessorInterfaceCustomFunctions(): string {
264
266
* @param randType Type for the random result.
265
267
* @return result Result.
266
268
*/
267
- function fheRand(bytes1 randType) external returns (bytes32 result);
269
+ function fheRand(FheType randType) external returns (bytes32 result);
268
270
269
271
/**
270
272
* @notice Computes FHERandBounded operation.
271
273
* @param upperBound Upper bound value.
272
274
* @param randType Type for the random result.
273
275
* @return result Result.
274
276
*/
275
- function fheRandBounded(uint256 upperBound, bytes1 randType) external returns (bytes32 result);
277
+ function fheRandBounded(uint256 upperBound, FheType randType) external returns (bytes32 result);
276
278
` ;
277
279
}
278
280
@@ -767,7 +769,7 @@ function handleSolidityTFHECustomCastBetweenTwoEuint(inputFheType: FheType, outp
767
769
* @dev Casts an encrypted integer from '${ inputFheType . type . toLowerCase ( ) } ' to '${ outputFheType . type . toLowerCase ( ) } '.
768
770
*/
769
771
function as${ outputFheType . type } (${ inputFheType . type . toLowerCase ( ) } value) internal returns (${ outputFheType . type . toLowerCase ( ) } ) {
770
- return ${ outputFheType . type . toLowerCase ( ) } .wrap(Impl.cast(${ inputFheType . type . toLowerCase ( ) } .unwrap(value), uint8( FheType.${ outputFheType . type } ) ));
772
+ return ${ outputFheType . type . toLowerCase ( ) } .wrap(Impl.cast(${ inputFheType . type . toLowerCase ( ) } .unwrap(value), FheType.${ outputFheType . type } ));
771
773
}
772
774
` ;
773
775
}
@@ -782,7 +784,7 @@ function handleSolidityTFHECustomCastBetweenEboolAndEuint(fheType: FheType): str
782
784
* @dev Converts an 'ebool' to an '${ fheType . type . toLowerCase ( ) } '.
783
785
*/
784
786
function as${ fheType . type } (ebool b) internal returns (${ fheType . type . toLowerCase ( ) } ) {
785
- return ${ fheType . type . toLowerCase ( ) } .wrap(Impl.cast(ebool.unwrap(b), uint8( FheType.${ fheType . type } ) ));
787
+ return ${ fheType . type . toLowerCase ( ) } .wrap(Impl.cast(ebool.unwrap(b), FheType.${ fheType . type } ));
786
788
}
787
789
` ) ;
788
790
@@ -838,7 +840,7 @@ function handleSolidityTFHEConvertPlaintextAndEinputToRespectiveType(fheType: Fh
838
840
* @dev Convert an inputHandle with corresponding inputProof to an encrypted ${ fheType . type . toLowerCase ( ) } integer.
839
841
*/
840
842
function as${ fheType . type } (einput inputHandle, bytes memory inputProof) internal returns (${ fheType . type . toLowerCase ( ) } ) {
841
- return ${ fheType . type . toLowerCase ( ) } .wrap(Impl.verify(einput.unwrap(inputHandle), inputProof, uint8( FheType.${ fheType . isAlias ? fheType . aliasType : fheType . type } ) ));
843
+ return ${ fheType . type . toLowerCase ( ) } .wrap(Impl.verify(einput.unwrap(inputHandle), inputProof, FheType.${ fheType . isAlias ? fheType . aliasType : fheType . type } ));
842
844
}
843
845
844
846
` ;
@@ -850,7 +852,7 @@ function handleSolidityTFHEConvertPlaintextAndEinputToRespectiveType(fheType: Fh
850
852
* @dev Converts a plaintext boolean to an encrypted boolean.
851
853
*/
852
854
function asEbool(bool value) internal returns (ebool) {
853
- return ebool.wrap(Impl.trivialEncrypt(value? 1 : 0, uint8( FheType.Ebool) ));
855
+ return ebool.wrap(Impl.trivialEncrypt(value? 1 : 0, FheType.Ebool));
854
856
}
855
857
856
858
` ;
@@ -860,7 +862,7 @@ function handleSolidityTFHEConvertPlaintextAndEinputToRespectiveType(fheType: Fh
860
862
* @dev Convert the plaintext bytes to a ${ fheType . type . toLowerCase ( ) } value.
861
863
*/
862
864
function as${ fheType . type } (${ fheType . clearMatchingType } value) internal returns (${ fheType . type . toLowerCase ( ) } ) {
863
- return ${ fheType . type . toLowerCase ( ) } .wrap(Impl.trivialEncrypt(value, uint8( FheType.${ fheType . isAlias ? fheType . aliasType : fheType . type } ) ));
865
+ return ${ fheType . type . toLowerCase ( ) } .wrap(Impl.trivialEncrypt(value, FheType.${ fheType . isAlias ? fheType . aliasType : fheType . type } ));
864
866
}
865
867
` ;
866
868
} else {
@@ -874,7 +876,7 @@ function handleSolidityTFHEConvertPlaintextAndEinputToRespectiveType(fheType: Fh
874
876
* @dev Convert a plaintext value to an encrypted ${ fheType . type . toLowerCase ( ) } integer.
875
877
*/
876
878
function as${ fheType . type } (${ fheType . clearMatchingType } value) internal returns (${ fheType . type . toLowerCase ( ) } ) {
877
- return ${ fheType . type . toLowerCase ( ) } .wrap(Impl.trivialEncrypt(uint256(${ value } ), uint8( FheType.${ fheType . isAlias ? fheType . aliasType : fheType . type } ) ));
879
+ return ${ fheType . type . toLowerCase ( ) } .wrap(Impl.trivialEncrypt(uint256(${ value } ), FheType.${ fheType . isAlias ? fheType . aliasType : fheType . type } ));
878
880
}
879
881
880
882
` ;
@@ -1018,10 +1020,10 @@ function generateCustomMethodsForImpl(): string {
1018
1020
function verify(
1019
1021
bytes32 inputHandle,
1020
1022
bytes memory inputProof,
1021
- uint8 toType
1023
+ FheType toType
1022
1024
) internal returns (bytes32 result) {
1023
1025
FHEVMConfigStruct storage $ = getFHEVMConfig();
1024
- result = ITFHEExecutor($.TFHEExecutorAddress).verifyCiphertext(inputHandle, msg.sender, inputProof, bytes1( toType) );
1026
+ result = ITFHEExecutor($.TFHEExecutorAddress).verifyCiphertext(inputHandle, msg.sender, inputProof, toType);
1025
1027
IACL($.ACLAddress).allowTransient(result, msg.sender);
1026
1028
}
1027
1029
@@ -1033,10 +1035,10 @@ function generateCustomMethodsForImpl(): string {
1033
1035
*/
1034
1036
function cast(
1035
1037
bytes32 ciphertext,
1036
- uint8 toType
1038
+ FheType toType
1037
1039
) internal returns (bytes32 result) {
1038
1040
FHEVMConfigStruct storage $ = getFHEVMConfig();
1039
- result = ITFHEExecutor($.TFHEExecutorAddress).cast(ciphertext, bytes1( toType) );
1041
+ result = ITFHEExecutor($.TFHEExecutorAddress).cast(ciphertext, toType);
1040
1042
}
1041
1043
1042
1044
/**
@@ -1047,10 +1049,10 @@ function generateCustomMethodsForImpl(): string {
1047
1049
*/
1048
1050
function trivialEncrypt(
1049
1051
uint256 value,
1050
- uint8 toType
1052
+ FheType toType
1051
1053
) internal returns (bytes32 result) {
1052
1054
FHEVMConfigStruct storage $ = getFHEVMConfig();
1053
- result = ITFHEExecutor($.TFHEExecutorAddress).trivialEncrypt(value, bytes1( toType) );
1055
+ result = ITFHEExecutor($.TFHEExecutorAddress).trivialEncrypt(value, toType);
1054
1056
}
1055
1057
1056
1058
/**
@@ -1061,10 +1063,10 @@ function generateCustomMethodsForImpl(): string {
1061
1063
*/
1062
1064
function trivialEncrypt(
1063
1065
bytes memory value,
1064
- uint8 toType
1066
+ FheType toType
1065
1067
) internal returns (bytes32 result) {
1066
1068
FHEVMConfigStruct storage $ = getFHEVMConfig();
1067
- result = ITFHEExecutor($.TFHEExecutorAddress).trivialEncrypt(value, bytes1( toType) );
1069
+ result = ITFHEExecutor($.TFHEExecutorAddress).trivialEncrypt(value, toType);
1068
1070
}
1069
1071
1070
1072
/**
@@ -1103,14 +1105,14 @@ function generateCustomMethodsForImpl(): string {
1103
1105
result = ITFHEExecutor($.TFHEExecutorAddress).fheNe(lhs, rhs, scalarByte);
1104
1106
}
1105
1107
1106
- function rand(uint8 randType) internal returns(bytes32 result) {
1108
+ function rand(FheType randType) internal returns(bytes32 result) {
1107
1109
FHEVMConfigStruct storage $ = getFHEVMConfig();
1108
- result = ITFHEExecutor($.TFHEExecutorAddress).fheRand(bytes1( randType) );
1110
+ result = ITFHEExecutor($.TFHEExecutorAddress).fheRand(randType);
1109
1111
}
1110
1112
1111
- function randBounded(uint256 upperBound, uint8 randType) internal returns(bytes32 result) {
1113
+ function randBounded(uint256 upperBound, FheType randType) internal returns(bytes32 result) {
1112
1114
FHEVMConfigStruct storage $ = getFHEVMConfig();
1113
- result = ITFHEExecutor($.TFHEExecutorAddress).fheRandBounded(upperBound, bytes1( randType) );
1115
+ result = ITFHEExecutor($.TFHEExecutorAddress).fheRandBounded(upperBound, randType);
1114
1116
}
1115
1117
1116
1118
/**
@@ -1181,7 +1183,7 @@ function handleSolidityTFHERand(fheType: FheType): string {
1181
1183
* @dev Generates a random encrypted value.
1182
1184
*/
1183
1185
function rand${ fheType . type } () internal returns (${ fheType . type . toLowerCase ( ) } ) {
1184
- return ${ fheType . type . toLowerCase ( ) } .wrap(Impl.rand(uint8( FheType.${ fheType . isAlias ? fheType . aliasType : fheType . type } ) ));
1186
+ return ${ fheType . type . toLowerCase ( ) } .wrap(Impl.rand(FheType.${ fheType . isAlias ? fheType . aliasType : fheType . type } ));
1185
1187
}
1186
1188
1187
1189
` ;
@@ -1194,7 +1196,7 @@ function handleSolidityTFHERand(fheType: FheType): string {
1194
1196
* The upperBound must be a power of 2.
1195
1197
*/
1196
1198
function rand${ fheType . type } (uint${ fheType . bitLength } upperBound) internal returns (${ fheType . type . toLowerCase ( ) } ) {
1197
- return ${ fheType . type . toLowerCase ( ) } .wrap(Impl.randBounded(upperBound, uint8( FheType.${ fheType . isAlias ? fheType . aliasType : fheType . type } ) ));
1199
+ return ${ fheType . type . toLowerCase ( ) } .wrap(Impl.randBounded(upperBound, FheType.${ fheType . isAlias ? fheType . aliasType : fheType . type } ));
1198
1200
}
1199
1201
1200
1202
` ;
0 commit comments