Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,15 @@ contract FHEVMExecutorTest is FHEEvents {
emit TrivialEncrypt(msg.sender, val, toType, result);
}

function verifyCiphertext(
function validateInput(
Comment thread
jatZama marked this conversation as resolved.
Outdated
bytes32 inputHandle,
address userAddress,
bytes memory inputProof,
FheType inputType
FheType inputType
) public {
bytes32 result = bytes32(keccak256(abi.encodePacked("verifyCiphertext", inputHandle, userAddress, inputProof, inputType)));
emit VerifyCiphertext(msg.sender, inputHandle, userAddress, inputProof, inputType, result);
bytes32 result = bytes32(
keccak256(abi.encodePacked("validateInput", inputHandle, userAddress, inputProof, inputType))
);
emit ValidateInput(msg.sender, inputHandle, userAddress, inputProof, inputType, result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ impl Database {
| E::OwnershipTransferStarted(_)
| E::OwnershipTransferred(_)
| E::Upgraded(_)
| E::VerifyCiphertext(_)
| E::ValidateInput(_)
=> Ok(()),
}
}
Expand Down Expand Up @@ -637,7 +637,7 @@ fn event_to_op_int(op: &TfheContractEvents) -> FheOperation {
| E::OwnershipTransferStarted(_)
| E::OwnershipTransferred(_)
| E::Upgraded(_)
| E::VerifyCiphertext(_) => -1,
| E::ValidateInput(_) => -1,
}
}

Expand Down Expand Up @@ -675,7 +675,7 @@ pub fn event_name(op: &TfheContractEvents) -> &'static str {
E::OwnershipTransferStarted(_) => "OwnershipTransferStarted",
E::OwnershipTransferred(_) => "OwnershipTransferred",
E::Upgraded(_) => "Upgraded",
E::VerifyCiphertext(_) => "VerifyCiphertext",
E::ValidateInput(_) => "ValidateInput",
}
}

Expand Down Expand Up @@ -715,7 +715,7 @@ pub fn tfhe_result_handle(op: &TfheContractEvents) -> Option<Handle> {
| E::OwnershipTransferStarted(_)
| E::OwnershipTransferred(_)
| E::Upgraded(_)
| E::VerifyCiphertext(_) => None,
| E::ValidateInput(_) => None,
}
}

Expand Down
20 changes: 6 additions & 14 deletions host-contracts/codegen/hcuLimitGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,8 @@ contract HCULimit is UUPSUpgradeableEmptyProxy, Ownable2StepUpgradeable, ACLChec
* @dev This function uses inline assembly to load the HCU from a specific storage location.
*/
function _getHCUForHandle(bytes32 handle) internal view virtual returns (uint256 handleHCU) {
bytes32 slot = keccak256(abi.encodePacked(HCULimitStorageLocation, handle));
assembly {
// Ensure the slot is properly aligned and validated before using tload.
// This assumes the slot is derived from a secure and deterministic process.
handleHCU := tload(slot)
handleHCU := tload(handle)
}
}

Expand All @@ -361,10 +358,8 @@ contract HCULimit is UUPSUpgradeableEmptyProxy, Ownable2StepUpgradeable, ACLChec
* @dev This function uses inline assembly to store the HCU in a specific storage location.
*/
function _getHCUForTransaction() internal view virtual returns (uint256 transactionHCU) {
/// @dev keccak256(abi.encodePacked(HCULimitStorageLocation, "HCU"))
bytes32 slot = 0x9fe02aa19e370f46d43dc2b6620733ba9c3b193659e9699f55eefe911af8a4b4;
assembly {
transactionHCU := tload(slot)
transactionHCU := tload(0)
}
}

Expand All @@ -373,12 +368,11 @@ contract HCULimit is UUPSUpgradeableEmptyProxy, Ownable2StepUpgradeable, ACLChec
* @notice Sets the HCU for a handle in the transient storage.
* @param handle The handle for which to set the HCU.
* @param handleHCU The HCU to set for the handle.
* @dev This function uses inline assembly to store the HCU in a specific storage location.
* @dev This function uses inline assembly to store the HCU in a specific transient storage slot.
*/
function _setHCUForHandle(bytes32 handle, uint256 handleHCU) internal virtual {
bytes32 slot = keccak256(abi.encodePacked(HCULimitStorageLocation, handle));
assembly {
tstore(slot, handleHCU)
tstore(handle, handleHCU)
}
}

Expand All @@ -387,13 +381,11 @@ contract HCULimit is UUPSUpgradeableEmptyProxy, Ownable2StepUpgradeable, ACLChec
/**
* @notice Updates the current HCU consumption for the transaction and stores it in the transient storage.
* @param transactionHCU The total HCU for the transaction.
* @dev This function uses inline assembly to store the HCU in a specific storage location.
* @dev This function uses inline assembly to store the HCU in a specific transient storage slot.
*/
function _setHCUForTransaction(uint256 transactionHCU) internal virtual {
/// @dev keccak256(abi.encodePacked(HCULimitStorageLocation, "HCU"))
bytes32 slot = 0x9fe02aa19e370f46d43dc2b6620733ba9c3b193659e9699f55eefe911af8a4b4;
assembly {
tstore(slot, transactionHCU)
tstore(0, transactionHCU) // to avoid collisions with handles (see _setHCUForHandle)
}
}

Expand Down
25 changes: 9 additions & 16 deletions host-contracts/codegen/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ function coprocessorInterfaceCustomFunctions(): string {
* @param inputType Input type.
* @return result Result.
*/
function verifyCiphertext(bytes32 inputHandle, address callerAddress, bytes memory inputProof, FheType inputType) external returns (bytes32 result);
function validateInput(bytes32 inputHandle, address callerAddress, bytes memory inputProof, FheType inputType) external returns (bytes32 result);

/**
* @notice Performs the casting to a target type.
Expand Down Expand Up @@ -1138,20 +1138,13 @@ function generateSolidityDecryptionOracleMethods(fheTypes: AdjustedFheType[]): s
* @notice Warning: MUST be called directly in the callback function called by the relayer.
* @notice Warning: this function never reverts, its boolean return value must be checked.
* @dev The callback function has the following signature:
* - requestID (static uint256)
* - cleartexts (dynamic bytes)
* - decryptionProof (dynamic bytes)
*
* This means that the calldata is encoded in the following way:
* - 4 bytes: selector
* - 32 bytes: requestID
* - 32 bytes: offset of the cleartexts
* - 32 bytes: offset of the decryptionProof
* - 32 bytes: length of the cleartexts (total number of bytes)
* - n*32 bytes: the "n" cleartext values, with "n" the number of handles
* - 32 bytes: length of the decryptionProof (total number of bytes)
* - ... the data of the decryptionProof (signatures, extra data)
*/
* @dev - requestID (static uint256)
* @dev - cleartexts (dynamic bytes)
* @dev - decryptionProof (dynamic bytes)
* @dev clearTexts is the abi-encoding of the list of all decrypted values assiociated to handlesList, in same order.
* @dev Only static native solidity types for clear values are supported, so clearTexts is the concatenation of all clear values appended to 32 bytes.
* @dev decryptionProof contains KMS signatures corresponding to clearTexts and associated handlesList, and needed metadata for KMS context.
**/
function verifySignatures(
bytes32[] memory handlesList,
bytes memory cleartexts,
Expand Down Expand Up @@ -1206,7 +1199,7 @@ function generateCustomMethodsForImpl(): string {
FheType toType
) internal returns (bytes32 result) {
CoprocessorConfig storage $ = getCoprocessorConfig();
result = IFHEVMExecutor($.CoprocessorAddress).verifyCiphertext(inputHandle, msg.sender, inputProof, toType);
result = IFHEVMExecutor($.CoprocessorAddress).validateInput(inputHandle, msg.sender, inputProof, toType);
IACL($.ACLAddress).allowTransient(result, msg.sender);
}

Expand Down
2 changes: 1 addition & 1 deletion host-contracts/contracts/FHEEvents.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ contract FHEEvents {
event FheMax(address indexed caller, bytes32 lhs, bytes32 rhs, bytes1 scalarByte, bytes32 result);
event FheNeg(address indexed caller, bytes32 ct, bytes32 result);
event FheNot(address indexed caller, bytes32 ct, bytes32 result);
event VerifyCiphertext(
event ValidateInput(
address indexed caller,
bytes32 inputHandle,
address userAddress,
Expand Down
Loading
Loading