Skip to content

Commit b817c01

Browse files
committed
feat(library-solidity): add feature to request decryption without saving handles
1 parent 9f69c4a commit b817c01

4 files changed

Lines changed: 117 additions & 23 deletions

File tree

host-contracts/codegen/templates.ts

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export function generateSolidityImplLib(operators: Operator[]): string {
121121
// SPDX-License-Identifier: BSD-3-Clause-Clear
122122
pragma solidity ^0.8.24;
123123
124-
import {FheType} from "../contracts/shared/FheType.sol";
124+
import {FheType} from "./FheType.sol";
125125
126126
${generateImplCoprocessorInterface(operators)}
127127
@@ -426,7 +426,7 @@ export function generateSolidityFHELib(operators: Operator[], fheTypes: FheType[
426426
pragma solidity ^0.8.24;
427427
428428
import "./Impl.sol";
429-
import {FheType} from "../contracts/shared/FheType.sol";
429+
import {FheType} from "./FheType.sol";
430430
431431
import "encrypted-types/EncryptedTypes.sol";
432432
@@ -1054,22 +1054,23 @@ function generateSolidityDecryptionOracleMethods(fheTypes: AdjustedFheType[]): s
10541054
return $.requestedHandles[requestID];
10551055
}
10561056
1057+
10571058
/**
10581059
* @dev Calls the DecryptionOracle contract to request the decryption of a list of handles.
10591060
* @notice Also does the needed call to ACL::allowForDecryption with requested handles.
10601061
*/
1061-
function requestDecryption(
1062+
function requestDecryptionWithoutSavingHandles(
10621063
bytes32[] memory ctsHandles,
10631064
bytes4 callbackSelector
10641065
) internal returns (uint256 requestID) {
1065-
requestID = requestDecryption(ctsHandles, callbackSelector, 0);
1066+
requestID = requestDecryptionWithoutSavingHandles(ctsHandles, callbackSelector, 0);
10661067
}
10671068
10681069
/**
10691070
* @dev Calls the DecryptionOracle contract to request the decryption of a list of handles, with a custom msgValue.
10701071
* @notice Also does the needed call to ACL::allowForDecryption with requested handles.
10711072
*/
1072-
function requestDecryption(
1073+
function requestDecryptionWithoutSavingHandles(
10731074
bytes32[] memory ctsHandles,
10741075
bytes4 callbackSelector,
10751076
uint256 msgValue
@@ -1079,10 +1080,33 @@ function generateSolidityDecryptionOracleMethods(fheTypes: AdjustedFheType[]): s
10791080
CoprocessorConfig storage $$ = Impl.getCoprocessorConfig();
10801081
IACL($$.ACLAddress).allowForDecryption(ctsHandles);
10811082
IDecryptionOracle($$.DecryptionOracleAddress).requestDecryption{value: msgValue}(requestID, ctsHandles, callbackSelector);
1082-
saveRequestedHandles(requestID, ctsHandles);
10831083
$.counterRequest++;
10841084
}
10851085
1086+
/**
1087+
* @dev Calls the DecryptionOracle contract to request the decryption of a list of handles.
1088+
* @notice Also does the needed call to ACL::allowForDecryption with requested handles.
1089+
*/
1090+
function requestDecryption(
1091+
bytes32[] memory ctsHandles,
1092+
bytes4 callbackSelector
1093+
) internal returns (uint256 requestID) {
1094+
requestID = requestDecryption(ctsHandles, callbackSelector, 0);
1095+
}
1096+
1097+
/**
1098+
* @dev Calls the DecryptionOracle contract to request the decryption of a list of handles, with a custom msgValue.
1099+
* @notice Also does the needed call to ACL::allowForDecryption with requested handles.
1100+
*/
1101+
function requestDecryption(
1102+
bytes32[] memory ctsHandles,
1103+
bytes4 callbackSelector,
1104+
uint256 msgValue
1105+
) internal returns (uint256 requestID) {
1106+
requestID = requestDecryptionWithoutSavingHandles(ctsHandles, callbackSelector, 0);
1107+
saveRequestedHandles(requestID, ctsHandles);
1108+
}
1109+
10861110
/**
10871111
* @dev MUST be called inside the callback function the dApp contract to verify the signatures,
10881112
* @dev otherwise fake decryption results could be submitted.
@@ -1130,7 +1154,7 @@ function generateSolidityDecryptionOracleMethods(fheTypes: AdjustedFheType[]): s
11301154
bytes32[] memory handlesList,
11311155
bytes memory cleartexts,
11321156
bytes memory decryptionProof
1133-
) private returns (bool) {
1157+
) internal returns (bool) {
11341158
// Compute the signature offset
11351159
// This offset is computed by considering the format encoded by the KMS when creating the
11361160
// "decryptedResult" bytes array (see comment below), which is the following:

host-contracts/lib/FHE.sol

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
pragma solidity ^0.8.24;
33

44
import "./Impl.sol";
5-
import {FheType} from "../contracts/shared/FheType.sol";
5+
import {FheType} from "./FheType.sol";
66

77
import "encrypted-types/EncryptedTypes.sol";
88

@@ -8871,18 +8871,18 @@ library FHE {
88718871
* @dev Calls the DecryptionOracle contract to request the decryption of a list of handles.
88728872
* @notice Also does the needed call to ACL::allowForDecryption with requested handles.
88738873
*/
8874-
function requestDecryption(
8874+
function requestDecryptionWithoutSavingHandles(
88758875
bytes32[] memory ctsHandles,
88768876
bytes4 callbackSelector
88778877
) internal returns (uint256 requestID) {
8878-
requestID = requestDecryption(ctsHandles, callbackSelector, 0);
8878+
requestID = requestDecryptionWithoutSavingHandles(ctsHandles, callbackSelector, 0);
88798879
}
88808880

88818881
/**
88828882
* @dev Calls the DecryptionOracle contract to request the decryption of a list of handles, with a custom msgValue.
88838883
* @notice Also does the needed call to ACL::allowForDecryption with requested handles.
88848884
*/
8885-
function requestDecryption(
8885+
function requestDecryptionWithoutSavingHandles(
88868886
bytes32[] memory ctsHandles,
88878887
bytes4 callbackSelector,
88888888
uint256 msgValue
@@ -8896,10 +8896,33 @@ library FHE {
88968896
ctsHandles,
88978897
callbackSelector
88988898
);
8899-
saveRequestedHandles(requestID, ctsHandles);
89008899
$.counterRequest++;
89018900
}
89028901

8902+
/**
8903+
* @dev Calls the DecryptionOracle contract to request the decryption of a list of handles.
8904+
* @notice Also does the needed call to ACL::allowForDecryption with requested handles.
8905+
*/
8906+
function requestDecryption(
8907+
bytes32[] memory ctsHandles,
8908+
bytes4 callbackSelector
8909+
) internal returns (uint256 requestID) {
8910+
requestID = requestDecryption(ctsHandles, callbackSelector, 0);
8911+
}
8912+
8913+
/**
8914+
* @dev Calls the DecryptionOracle contract to request the decryption of a list of handles, with a custom msgValue.
8915+
* @notice Also does the needed call to ACL::allowForDecryption with requested handles.
8916+
*/
8917+
function requestDecryption(
8918+
bytes32[] memory ctsHandles,
8919+
bytes4 callbackSelector,
8920+
uint256 msgValue
8921+
) internal returns (uint256 requestID) {
8922+
requestID = requestDecryptionWithoutSavingHandles(ctsHandles, callbackSelector, 0);
8923+
saveRequestedHandles(requestID, ctsHandles);
8924+
}
8925+
89038926
/**
89048927
* @dev MUST be called inside the callback function the dApp contract to verify the signatures,
89058928
* @dev otherwise fake decryption results could be submitted.
@@ -8947,7 +8970,7 @@ library FHE {
89478970
bytes32[] memory handlesList,
89488971
bytes memory cleartexts,
89498972
bytes memory decryptionProof
8950-
) private returns (bool) {
8973+
) internal returns (bool) {
89518974
// Compute the signature offset
89528975
// This offset is computed by considering the format encoded by the KMS when creating the
89538976
// "decryptedResult" bytes array (see comment below), which is the following:

library-solidity/codegen/templates.ts

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,22 +1054,23 @@ function generateSolidityDecryptionOracleMethods(fheTypes: AdjustedFheType[]): s
10541054
return $.requestedHandles[requestID];
10551055
}
10561056
1057+
10571058
/**
10581059
* @dev Calls the DecryptionOracle contract to request the decryption of a list of handles.
10591060
* @notice Also does the needed call to ACL::allowForDecryption with requested handles.
10601061
*/
1061-
function requestDecryption(
1062+
function requestDecryptionWithoutSavingHandles(
10621063
bytes32[] memory ctsHandles,
10631064
bytes4 callbackSelector
10641065
) internal returns (uint256 requestID) {
1065-
requestID = requestDecryption(ctsHandles, callbackSelector, 0);
1066+
requestID = requestDecryptionWithoutSavingHandles(ctsHandles, callbackSelector, 0);
10661067
}
10671068
10681069
/**
10691070
* @dev Calls the DecryptionOracle contract to request the decryption of a list of handles, with a custom msgValue.
10701071
* @notice Also does the needed call to ACL::allowForDecryption with requested handles.
10711072
*/
1072-
function requestDecryption(
1073+
function requestDecryptionWithoutSavingHandles(
10731074
bytes32[] memory ctsHandles,
10741075
bytes4 callbackSelector,
10751076
uint256 msgValue
@@ -1079,10 +1080,33 @@ function generateSolidityDecryptionOracleMethods(fheTypes: AdjustedFheType[]): s
10791080
CoprocessorConfig storage $$ = Impl.getCoprocessorConfig();
10801081
IACL($$.ACLAddress).allowForDecryption(ctsHandles);
10811082
IDecryptionOracle($$.DecryptionOracleAddress).requestDecryption{value: msgValue}(requestID, ctsHandles, callbackSelector);
1082-
saveRequestedHandles(requestID, ctsHandles);
10831083
$.counterRequest++;
10841084
}
10851085
1086+
/**
1087+
* @dev Calls the DecryptionOracle contract to request the decryption of a list of handles.
1088+
* @notice Also does the needed call to ACL::allowForDecryption with requested handles.
1089+
*/
1090+
function requestDecryption(
1091+
bytes32[] memory ctsHandles,
1092+
bytes4 callbackSelector
1093+
) internal returns (uint256 requestID) {
1094+
requestID = requestDecryption(ctsHandles, callbackSelector, 0);
1095+
}
1096+
1097+
/**
1098+
* @dev Calls the DecryptionOracle contract to request the decryption of a list of handles, with a custom msgValue.
1099+
* @notice Also does the needed call to ACL::allowForDecryption with requested handles.
1100+
*/
1101+
function requestDecryption(
1102+
bytes32[] memory ctsHandles,
1103+
bytes4 callbackSelector,
1104+
uint256 msgValue
1105+
) internal returns (uint256 requestID) {
1106+
requestID = requestDecryptionWithoutSavingHandles(ctsHandles, callbackSelector, 0);
1107+
saveRequestedHandles(requestID, ctsHandles);
1108+
}
1109+
10861110
/**
10871111
* @dev MUST be called inside the callback function the dApp contract to verify the signatures,
10881112
* @dev otherwise fake decryption results could be submitted.
@@ -1130,7 +1154,7 @@ function generateSolidityDecryptionOracleMethods(fheTypes: AdjustedFheType[]): s
11301154
bytes32[] memory handlesList,
11311155
bytes memory cleartexts,
11321156
bytes memory decryptionProof
1133-
) private returns (bool) {
1157+
) internal returns (bool) {
11341158
// Compute the signature offset
11351159
// This offset is computed by considering the format encoded by the KMS when creating the
11361160
// "decryptedResult" bytes array (see comment below), which is the following:

library-solidity/lib/FHE.sol

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8871,18 +8871,18 @@ library FHE {
88718871
* @dev Calls the DecryptionOracle contract to request the decryption of a list of handles.
88728872
* @notice Also does the needed call to ACL::allowForDecryption with requested handles.
88738873
*/
8874-
function requestDecryption(
8874+
function requestDecryptionWithoutSavingHandles(
88758875
bytes32[] memory ctsHandles,
88768876
bytes4 callbackSelector
88778877
) internal returns (uint256 requestID) {
8878-
requestID = requestDecryption(ctsHandles, callbackSelector, 0);
8878+
requestID = requestDecryptionWithoutSavingHandles(ctsHandles, callbackSelector, 0);
88798879
}
88808880

88818881
/**
88828882
* @dev Calls the DecryptionOracle contract to request the decryption of a list of handles, with a custom msgValue.
88838883
* @notice Also does the needed call to ACL::allowForDecryption with requested handles.
88848884
*/
8885-
function requestDecryption(
8885+
function requestDecryptionWithoutSavingHandles(
88868886
bytes32[] memory ctsHandles,
88878887
bytes4 callbackSelector,
88888888
uint256 msgValue
@@ -8896,10 +8896,33 @@ library FHE {
88968896
ctsHandles,
88978897
callbackSelector
88988898
);
8899-
saveRequestedHandles(requestID, ctsHandles);
89008899
$.counterRequest++;
89018900
}
89028901

8902+
/**
8903+
* @dev Calls the DecryptionOracle contract to request the decryption of a list of handles.
8904+
* @notice Also does the needed call to ACL::allowForDecryption with requested handles.
8905+
*/
8906+
function requestDecryption(
8907+
bytes32[] memory ctsHandles,
8908+
bytes4 callbackSelector
8909+
) internal returns (uint256 requestID) {
8910+
requestID = requestDecryption(ctsHandles, callbackSelector, 0);
8911+
}
8912+
8913+
/**
8914+
* @dev Calls the DecryptionOracle contract to request the decryption of a list of handles, with a custom msgValue.
8915+
* @notice Also does the needed call to ACL::allowForDecryption with requested handles.
8916+
*/
8917+
function requestDecryption(
8918+
bytes32[] memory ctsHandles,
8919+
bytes4 callbackSelector,
8920+
uint256 msgValue
8921+
) internal returns (uint256 requestID) {
8922+
requestID = requestDecryptionWithoutSavingHandles(ctsHandles, callbackSelector, 0);
8923+
saveRequestedHandles(requestID, ctsHandles);
8924+
}
8925+
89038926
/**
89048927
* @dev MUST be called inside the callback function the dApp contract to verify the signatures,
89058928
* @dev otherwise fake decryption results could be submitted.
@@ -8947,7 +8970,7 @@ library FHE {
89478970
bytes32[] memory handlesList,
89488971
bytes memory cleartexts,
89498972
bytes memory decryptionProof
8950-
) private returns (bool) {
8973+
) internal returns (bool) {
89518974
// Compute the signature offset
89528975
// This offset is computed by considering the format encoded by the KMS when creating the
89538976
// "decryptedResult" bytes array (see comment below), which is the following:

0 commit comments

Comments
 (0)