Skip to content

Commit b129156

Browse files
authored
feat(host-contracts): add support for msgValue in FHE.requestDecryption (#164)
* feat(host-contracts): add support for msgValue in FHE.requestDecryption * feat(library-solidity): add support for msgValue in FHE.requestDecryption * refactor(library-solidity): reduce duplicate logic
1 parent f7cdccc commit b129156

File tree

5 files changed

+73
-9
lines changed

5 files changed

+73
-9
lines changed

host-contracts/codegen/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import path from 'path';
33

44
import { validateFHETypes, validateOperators } from './common';
55
import { generateOverloads } from './generateOverloads';
6+
import { generateSolidityHCULimit } from './hcuLimitGenerator';
67
import { ALL_OPERATORS } from './operators';
78
import operatorsPrices from './operatorsPrices.json';
8-
import { generateSolidityHCULimit } from './hcuLimitGenerator';
99
import { generateSolidityFHELib, generateSolidityFheType, generateSolidityImplLib } from './templates';
1010
import {
1111
generateSolidityOverloadTestFiles,

host-contracts/codegen/templates.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ function generateDecryptionOracleInterface(): string {
490490
* @notice This interface contains the only function required from DecryptionOracle.
491491
*/
492492
interface IDecryptionOracle {
493-
function requestDecryption(uint256 requestID, bytes32[] calldata ctsHandles, bytes4 callbackSelector) external;
493+
function requestDecryption(uint256 requestID, bytes32[] calldata ctsHandles, bytes4 callbackSelector) external payable;
494494
}
495495
`;
496496
}
@@ -1204,12 +1204,24 @@ function generateSolidityDecryptionOracleMethods(fheTypes: AdjustedFheType[]): s
12041204
function requestDecryption(
12051205
bytes32[] memory ctsHandles,
12061206
bytes4 callbackSelector
1207+
) internal returns (uint256 requestID) {
1208+
requestID = requestDecryption(ctsHandles, callbackSelector, 0);
1209+
}
1210+
1211+
/**
1212+
* @dev Calls the DecryptionOracle contract to request the decryption of a list of handles, with a custom msgValue.
1213+
* @notice Also does the needed call to ACL::allowForDecryption with requested handles.
1214+
*/
1215+
function requestDecryption(
1216+
bytes32[] memory ctsHandles,
1217+
bytes4 callbackSelector,
1218+
uint256 msgValue
12071219
) internal returns (uint256 requestID) {
12081220
DecryptionRequestsStruct storage $ = Impl.getDecryptionRequests();
12091221
requestID = $.counterRequest;
12101222
FHEVMConfigStruct storage $$ = Impl.getFHEVMConfig();
12111223
IACL($$.ACLAddress).allowForDecryption(ctsHandles);
1212-
IDecryptionOracle($.DecryptionOracleAddress).requestDecryption(requestID, ctsHandles, callbackSelector);
1224+
IDecryptionOracle($.DecryptionOracleAddress).requestDecryption{value: msgValue}(requestID, ctsHandles, callbackSelector);
12131225
saveRequestedHandles(requestID, ctsHandles);
12141226
$.counterRequest++;
12151227
}

host-contracts/lib/FHE.sol

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ interface IKMSVerifier {
4444
* @notice This interface contains the only function required from DecryptionOracle.
4545
*/
4646
interface IDecryptionOracle {
47-
function requestDecryption(uint256 requestID, bytes32[] calldata ctsHandles, bytes4 callbackSelector) external;
47+
function requestDecryption(
48+
uint256 requestID,
49+
bytes32[] calldata ctsHandles,
50+
bytes4 callbackSelector
51+
) external payable;
4852
}
4953

5054
/**
@@ -9442,12 +9446,28 @@ library FHE {
94429446
function requestDecryption(
94439447
bytes32[] memory ctsHandles,
94449448
bytes4 callbackSelector
9449+
) internal returns (uint256 requestID) {
9450+
requestID = requestDecryption(ctsHandles, callbackSelector, 0);
9451+
}
9452+
9453+
/**
9454+
* @dev Calls the DecryptionOracle contract to request the decryption of a list of handles, with a custom msgValue.
9455+
* @notice Also does the needed call to ACL::allowForDecryption with requested handles.
9456+
*/
9457+
function requestDecryption(
9458+
bytes32[] memory ctsHandles,
9459+
bytes4 callbackSelector,
9460+
uint256 msgValue
94459461
) internal returns (uint256 requestID) {
94469462
DecryptionRequestsStruct storage $ = Impl.getDecryptionRequests();
94479463
requestID = $.counterRequest;
94489464
FHEVMConfigStruct storage $$ = Impl.getFHEVMConfig();
94499465
IACL($$.ACLAddress).allowForDecryption(ctsHandles);
9450-
IDecryptionOracle($.DecryptionOracleAddress).requestDecryption(requestID, ctsHandles, callbackSelector);
9466+
IDecryptionOracle($.DecryptionOracleAddress).requestDecryption{value: msgValue}(
9467+
requestID,
9468+
ctsHandles,
9469+
callbackSelector
9470+
);
94519471
saveRequestedHandles(requestID, ctsHandles);
94529472
$.counterRequest++;
94539473
}

library-solidity/codegen/templates.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ function generateDecryptionOracleInterface(): string {
490490
* @notice This interface contains the only function required from DecryptionOracle.
491491
*/
492492
interface IDecryptionOracle {
493-
function requestDecryption(uint256 requestID, bytes32[] calldata ctsHandles, bytes4 callbackSelector) external;
493+
function requestDecryption(uint256 requestID, bytes32[] calldata ctsHandles, bytes4 callbackSelector) external payable;
494494
}
495495
`;
496496
}
@@ -1204,12 +1204,24 @@ function generateSolidityDecryptionOracleMethods(fheTypes: AdjustedFheType[]): s
12041204
function requestDecryption(
12051205
bytes32[] memory ctsHandles,
12061206
bytes4 callbackSelector
1207+
) internal returns (uint256 requestID) {
1208+
requestID = requestDecryption(ctsHandles, callbackSelector, 0);
1209+
}
1210+
1211+
/**
1212+
* @dev Calls the DecryptionOracle contract to request the decryption of a list of handles, with a custom msgValue.
1213+
* @notice Also does the needed call to ACL::allowForDecryption with requested handles.
1214+
*/
1215+
function requestDecryption(
1216+
bytes32[] memory ctsHandles,
1217+
bytes4 callbackSelector,
1218+
uint256 msgValue
12071219
) internal returns (uint256 requestID) {
12081220
DecryptionRequestsStruct storage $ = Impl.getDecryptionRequests();
12091221
requestID = $.counterRequest;
12101222
FHEVMConfigStruct storage $$ = Impl.getFHEVMConfig();
12111223
IACL($$.ACLAddress).allowForDecryption(ctsHandles);
1212-
IDecryptionOracle($.DecryptionOracleAddress).requestDecryption(requestID, ctsHandles, callbackSelector);
1224+
IDecryptionOracle($.DecryptionOracleAddress).requestDecryption{value: msgValue}(requestID, ctsHandles, callbackSelector);
12131225
saveRequestedHandles(requestID, ctsHandles);
12141226
$.counterRequest++;
12151227
}

library-solidity/lib/FHE.sol

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ interface IKMSVerifier {
4444
* @notice This interface contains the only function required from DecryptionOracle.
4545
*/
4646
interface IDecryptionOracle {
47-
function requestDecryption(uint256 requestID, bytes32[] calldata ctsHandles, bytes4 callbackSelector) external;
47+
function requestDecryption(
48+
uint256 requestID,
49+
bytes32[] calldata ctsHandles,
50+
bytes4 callbackSelector
51+
) external payable;
4852
}
4953

5054
/**
@@ -9442,12 +9446,28 @@ library FHE {
94429446
function requestDecryption(
94439447
bytes32[] memory ctsHandles,
94449448
bytes4 callbackSelector
9449+
) internal returns (uint256 requestID) {
9450+
requestID = requestDecryption(ctsHandles, callbackSelector, 0);
9451+
}
9452+
9453+
/**
9454+
* @dev Calls the DecryptionOracle contract to request the decryption of a list of handles, with a custom msgValue.
9455+
* @notice Also does the needed call to ACL::allowForDecryption with requested handles.
9456+
*/
9457+
function requestDecryption(
9458+
bytes32[] memory ctsHandles,
9459+
bytes4 callbackSelector,
9460+
uint256 msgValue
94459461
) internal returns (uint256 requestID) {
94469462
DecryptionRequestsStruct storage $ = Impl.getDecryptionRequests();
94479463
requestID = $.counterRequest;
94489464
FHEVMConfigStruct storage $$ = Impl.getFHEVMConfig();
94499465
IACL($$.ACLAddress).allowForDecryption(ctsHandles);
9450-
IDecryptionOracle($.DecryptionOracleAddress).requestDecryption(requestID, ctsHandles, callbackSelector);
9466+
IDecryptionOracle($.DecryptionOracleAddress).requestDecryption{value: msgValue}(
9467+
requestID,
9468+
ctsHandles,
9469+
callbackSelector
9470+
);
94519471
saveRequestedHandles(requestID, ctsHandles);
94529472
$.counterRequest++;
94539473
}

0 commit comments

Comments
 (0)