@@ -27,6 +27,9 @@ library FHE {
2727 /// @notice Returned if the returned KMS signatures are not valid.
2828 error InvalidKMSSignatures ();
2929
30+ /// @notice Returned if the sender is not allowed to use the handle.
31+ error SenderNotAllowedToUseHandle (bytes32 handle , address sender );
32+
3033 /// @notice This event is emitted when public decryption has been successfully verified.
3134 event PublicDecryptionVerified (bytes32 [] handlesList , bytes abiEncodedCleartexts );
3235
@@ -8441,9 +8444,18 @@ library FHE {
84418444
84428445 /**
84438446 * @dev Convert an inputHandle with corresponding inputProof to an encrypted ebool integer.
8447+ * @dev If inputProof is empty, the externalEbool inputHandle can be used as a regular ebool handle if it
8448+ * has already been verified and allowed to the sender.
8449+ * This could facilitate integrating smart contract accounts with fhevm.
84448450 */
84458451 function fromExternal (externalEbool inputHandle , bytes memory inputProof ) internal returns (ebool) {
8446- return ebool.wrap (Impl.verify (externalEbool.unwrap (inputHandle), inputProof, FheType.Bool));
8452+ if (inputProof.length != 0 ) {
8453+ return ebool.wrap (Impl.verify (externalEbool.unwrap (inputHandle), inputProof, FheType.Bool));
8454+ } else {
8455+ bytes32 inputBytes32 = externalEbool.unwrap (inputHandle);
8456+ if (! Impl.isAllowed (inputBytes32, msg .sender )) revert SenderNotAllowedToUseHandle (inputBytes32, msg .sender );
8457+ return ebool.wrap (inputBytes32);
8458+ }
84478459 }
84488460
84498461 /**
@@ -8455,9 +8467,18 @@ library FHE {
84558467
84568468 /**
84578469 * @dev Convert an inputHandle with corresponding inputProof to an encrypted euint8 integer.
8470+ * @dev If inputProof is empty, the externalEuint8 inputHandle can be used as a regular euint8 handle if it
8471+ * has already been verified and allowed to the sender.
8472+ * This could facilitate integrating smart contract accounts with fhevm.
84588473 */
84598474 function fromExternal (externalEuint8 inputHandle , bytes memory inputProof ) internal returns (euint8) {
8460- return euint8.wrap (Impl.verify (externalEuint8.unwrap (inputHandle), inputProof, FheType.Uint8));
8475+ if (inputProof.length != 0 ) {
8476+ return euint8.wrap (Impl.verify (externalEuint8.unwrap (inputHandle), inputProof, FheType.Uint8));
8477+ } else {
8478+ bytes32 inputBytes32 = externalEuint8.unwrap (inputHandle);
8479+ if (! Impl.isAllowed (inputBytes32, msg .sender )) revert SenderNotAllowedToUseHandle (inputBytes32, msg .sender );
8480+ return euint8.wrap (inputBytes32);
8481+ }
84618482 }
84628483
84638484 /**
@@ -8469,9 +8490,18 @@ library FHE {
84698490
84708491 /**
84718492 * @dev Convert an inputHandle with corresponding inputProof to an encrypted euint16 integer.
8493+ * @dev If inputProof is empty, the externalEuint16 inputHandle can be used as a regular euint16 handle if it
8494+ * has already been verified and allowed to the sender.
8495+ * This could facilitate integrating smart contract accounts with fhevm.
84728496 */
84738497 function fromExternal (externalEuint16 inputHandle , bytes memory inputProof ) internal returns (euint16) {
8474- return euint16.wrap (Impl.verify (externalEuint16.unwrap (inputHandle), inputProof, FheType.Uint16));
8498+ if (inputProof.length != 0 ) {
8499+ return euint16.wrap (Impl.verify (externalEuint16.unwrap (inputHandle), inputProof, FheType.Uint16));
8500+ } else {
8501+ bytes32 inputBytes32 = externalEuint16.unwrap (inputHandle);
8502+ if (! Impl.isAllowed (inputBytes32, msg .sender )) revert SenderNotAllowedToUseHandle (inputBytes32, msg .sender );
8503+ return euint16.wrap (inputBytes32);
8504+ }
84758505 }
84768506
84778507 /**
@@ -8483,9 +8513,18 @@ library FHE {
84838513
84848514 /**
84858515 * @dev Convert an inputHandle with corresponding inputProof to an encrypted euint32 integer.
8516+ * @dev If inputProof is empty, the externalEuint32 inputHandle can be used as a regular euint32 handle if it
8517+ * has already been verified and allowed to the sender.
8518+ * This could facilitate integrating smart contract accounts with fhevm.
84868519 */
84878520 function fromExternal (externalEuint32 inputHandle , bytes memory inputProof ) internal returns (euint32) {
8488- return euint32.wrap (Impl.verify (externalEuint32.unwrap (inputHandle), inputProof, FheType.Uint32));
8521+ if (inputProof.length != 0 ) {
8522+ return euint32.wrap (Impl.verify (externalEuint32.unwrap (inputHandle), inputProof, FheType.Uint32));
8523+ } else {
8524+ bytes32 inputBytes32 = externalEuint32.unwrap (inputHandle);
8525+ if (! Impl.isAllowed (inputBytes32, msg .sender )) revert SenderNotAllowedToUseHandle (inputBytes32, msg .sender );
8526+ return euint32.wrap (inputBytes32);
8527+ }
84898528 }
84908529
84918530 /**
@@ -8497,9 +8536,18 @@ library FHE {
84978536
84988537 /**
84998538 * @dev Convert an inputHandle with corresponding inputProof to an encrypted euint64 integer.
8539+ * @dev If inputProof is empty, the externalEuint64 inputHandle can be used as a regular euint64 handle if it
8540+ * has already been verified and allowed to the sender.
8541+ * This could facilitate integrating smart contract accounts with fhevm.
85008542 */
85018543 function fromExternal (externalEuint64 inputHandle , bytes memory inputProof ) internal returns (euint64) {
8502- return euint64.wrap (Impl.verify (externalEuint64.unwrap (inputHandle), inputProof, FheType.Uint64));
8544+ if (inputProof.length != 0 ) {
8545+ return euint64.wrap (Impl.verify (externalEuint64.unwrap (inputHandle), inputProof, FheType.Uint64));
8546+ } else {
8547+ bytes32 inputBytes32 = externalEuint64.unwrap (inputHandle);
8548+ if (! Impl.isAllowed (inputBytes32, msg .sender )) revert SenderNotAllowedToUseHandle (inputBytes32, msg .sender );
8549+ return euint64.wrap (inputBytes32);
8550+ }
85038551 }
85048552
85058553 /**
@@ -8511,9 +8559,18 @@ library FHE {
85118559
85128560 /**
85138561 * @dev Convert an inputHandle with corresponding inputProof to an encrypted euint128 integer.
8562+ * @dev If inputProof is empty, the externalEuint128 inputHandle can be used as a regular euint128 handle if it
8563+ * has already been verified and allowed to the sender.
8564+ * This could facilitate integrating smart contract accounts with fhevm.
85148565 */
85158566 function fromExternal (externalEuint128 inputHandle , bytes memory inputProof ) internal returns (euint128) {
8516- return euint128.wrap (Impl.verify (externalEuint128.unwrap (inputHandle), inputProof, FheType.Uint128));
8567+ if (inputProof.length != 0 ) {
8568+ return euint128.wrap (Impl.verify (externalEuint128.unwrap (inputHandle), inputProof, FheType.Uint128));
8569+ } else {
8570+ bytes32 inputBytes32 = externalEuint128.unwrap (inputHandle);
8571+ if (! Impl.isAllowed (inputBytes32, msg .sender )) revert SenderNotAllowedToUseHandle (inputBytes32, msg .sender );
8572+ return euint128.wrap (inputBytes32);
8573+ }
85178574 }
85188575
85198576 /**
@@ -8525,9 +8582,18 @@ library FHE {
85258582
85268583 /**
85278584 * @dev Convert an inputHandle with corresponding inputProof to an encrypted eaddress integer.
8585+ * @dev If inputProof is empty, the externalEaddress inputHandle can be used as a regular eaddress handle if it
8586+ * has already been verified and allowed to the sender.
8587+ * This could facilitate integrating smart contract accounts with fhevm.
85288588 */
85298589 function fromExternal (externalEaddress inputHandle , bytes memory inputProof ) internal returns (eaddress) {
8530- return eaddress.wrap (Impl.verify (externalEaddress.unwrap (inputHandle), inputProof, FheType.Uint160));
8590+ if (inputProof.length != 0 ) {
8591+ return eaddress.wrap (Impl.verify (externalEaddress.unwrap (inputHandle), inputProof, FheType.Uint160));
8592+ } else {
8593+ bytes32 inputBytes32 = externalEaddress.unwrap (inputHandle);
8594+ if (! Impl.isAllowed (inputBytes32, msg .sender )) revert SenderNotAllowedToUseHandle (inputBytes32, msg .sender );
8595+ return eaddress.wrap (inputBytes32);
8596+ }
85318597 }
85328598
85338599 /**
@@ -8539,9 +8605,18 @@ library FHE {
85398605
85408606 /**
85418607 * @dev Convert an inputHandle with corresponding inputProof to an encrypted euint256 integer.
8608+ * @dev If inputProof is empty, the externalEuint256 inputHandle can be used as a regular euint256 handle if it
8609+ * has already been verified and allowed to the sender.
8610+ * This could facilitate integrating smart contract accounts with fhevm.
85428611 */
85438612 function fromExternal (externalEuint256 inputHandle , bytes memory inputProof ) internal returns (euint256) {
8544- return euint256.wrap (Impl.verify (externalEuint256.unwrap (inputHandle), inputProof, FheType.Uint256));
8613+ if (inputProof.length != 0 ) {
8614+ return euint256.wrap (Impl.verify (externalEuint256.unwrap (inputHandle), inputProof, FheType.Uint256));
8615+ } else {
8616+ bytes32 inputBytes32 = externalEuint256.unwrap (inputHandle);
8617+ if (! Impl.isAllowed (inputBytes32, msg .sender )) revert SenderNotAllowedToUseHandle (inputBytes32, msg .sender );
8618+ return euint256.wrap (inputBytes32);
8619+ }
85458620 }
85468621
85478622 /**
0 commit comments