Skip to content

Commit 95e8cde

Browse files
authored
Merge of #2004
2 parents 974fe41 + cbf0cd8 commit 95e8cde

File tree

17 files changed

+7948
-2464
lines changed

17 files changed

+7948
-2464
lines changed

host-contracts/contracts/FHEVMExecutor.sol

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ contract FHEVMExecutor is UUPSUpgradeableEmptyProxy, FHEEvents, ACLOwnable {
122122
uint256 private constant MAJOR_VERSION = 0;
123123

124124
/// @notice Minor version of the contract.
125-
uint256 private constant MINOR_VERSION = 1;
125+
uint256 private constant MINOR_VERSION = 2;
126126

127127
/// @notice Patch version of the contract.
128128
uint256 private constant PATCH_VERSION = 0;
@@ -138,7 +138,7 @@ contract FHEVMExecutor is UUPSUpgradeableEmptyProxy, FHEEvents, ACLOwnable {
138138

139139
/// Constant used for making sure the version number used in the `reinitializer` modifier is
140140
/// identical between `initializeFromEmptyProxy` and the `reinitializeVX` method
141-
uint64 private constant REINITIALIZER_VERSION = 2;
141+
uint64 private constant REINITIALIZER_VERSION = 3;
142142

143143
/// keccak256(abi.encode(uint256(keccak256("fhevm.storage.FHEVMExecutor")) - 1)) & ~bytes32(uint256(0xff))
144144
bytes32 private constant FHEVMExecutorStorageLocation =
@@ -161,7 +161,7 @@ contract FHEVMExecutor is UUPSUpgradeableEmptyProxy, FHEEvents, ACLOwnable {
161161
*/
162162
/// @custom:oz-upgrades-unsafe-allow missing-initializer-call
163163
/// @custom:oz-upgrades-validate-as-initializer
164-
// function reinitializeV2() public virtual reinitializer(REINITIALIZER_VERSION) {}
164+
function reinitializeV2() public virtual reinitializer(REINITIALIZER_VERSION) {}
165165

166166
/**
167167
* @notice Computes FHEAdd operation.
@@ -178,7 +178,7 @@ contract FHEVMExecutor is UUPSUpgradeableEmptyProxy, FHEEvents, ACLOwnable {
178178
(1 << uint8(FheType.Uint128));
179179
FheType lhsType = _verifyAndReturnType(lhs, supportedTypes);
180180
result = _binaryOp(Operators.fheAdd, lhs, rhs, scalarByte, lhsType);
181-
hcuLimit.checkHCUForFheAdd(lhsType, scalarByte, lhs, rhs, result);
181+
hcuLimit.checkHCUForFheAdd(lhsType, scalarByte, lhs, rhs, result, msg.sender);
182182
emit FheAdd(msg.sender, lhs, rhs, scalarByte, result);
183183
}
184184

@@ -197,7 +197,7 @@ contract FHEVMExecutor is UUPSUpgradeableEmptyProxy, FHEEvents, ACLOwnable {
197197
(1 << uint8(FheType.Uint128));
198198
FheType lhsType = _verifyAndReturnType(lhs, supportedTypes);
199199
result = _binaryOp(Operators.fheSub, lhs, rhs, scalarByte, lhsType);
200-
hcuLimit.checkHCUForFheSub(lhsType, scalarByte, lhs, rhs, result);
200+
hcuLimit.checkHCUForFheSub(lhsType, scalarByte, lhs, rhs, result, msg.sender);
201201
emit FheSub(msg.sender, lhs, rhs, scalarByte, result);
202202
}
203203

@@ -216,7 +216,7 @@ contract FHEVMExecutor is UUPSUpgradeableEmptyProxy, FHEEvents, ACLOwnable {
216216
(1 << uint8(FheType.Uint128));
217217
FheType lhsType = _verifyAndReturnType(lhs, supportedTypes);
218218
result = _binaryOp(Operators.fheMul, lhs, rhs, scalarByte, lhsType);
219-
hcuLimit.checkHCUForFheMul(lhsType, scalarByte, lhs, rhs, result);
219+
hcuLimit.checkHCUForFheMul(lhsType, scalarByte, lhs, rhs, result, msg.sender);
220220
emit FheMul(msg.sender, lhs, rhs, scalarByte, result);
221221
}
222222

@@ -237,7 +237,7 @@ contract FHEVMExecutor is UUPSUpgradeableEmptyProxy, FHEEvents, ACLOwnable {
237237
(1 << uint8(FheType.Uint128));
238238
FheType lhsType = _verifyAndReturnType(lhs, supportedTypes);
239239
result = _binaryOp(Operators.fheDiv, lhs, rhs, scalarByte, lhsType);
240-
hcuLimit.checkHCUForFheDiv(lhsType, scalarByte, lhs, rhs, result);
240+
hcuLimit.checkHCUForFheDiv(lhsType, scalarByte, lhs, rhs, result, msg.sender);
241241
emit FheDiv(msg.sender, lhs, rhs, scalarByte, result);
242242
}
243243

@@ -258,7 +258,7 @@ contract FHEVMExecutor is UUPSUpgradeableEmptyProxy, FHEEvents, ACLOwnable {
258258
(1 << uint8(FheType.Uint128));
259259
FheType lhsType = _verifyAndReturnType(lhs, supportedTypes);
260260
result = _binaryOp(Operators.fheRem, lhs, rhs, scalarByte, lhsType);
261-
hcuLimit.checkHCUForFheRem(lhsType, scalarByte, lhs, rhs, result);
261+
hcuLimit.checkHCUForFheRem(lhsType, scalarByte, lhs, rhs, result, msg.sender);
262262
emit FheRem(msg.sender, lhs, rhs, scalarByte, result);
263263
}
264264

@@ -279,7 +279,7 @@ contract FHEVMExecutor is UUPSUpgradeableEmptyProxy, FHEEvents, ACLOwnable {
279279
(1 << uint8(FheType.Uint256));
280280
FheType lhsType = _verifyAndReturnType(lhs, supportedTypes);
281281
result = _binaryOp(Operators.fheBitAnd, lhs, rhs, scalarByte, lhsType);
282-
hcuLimit.checkHCUForFheBitAnd(lhsType, scalarByte, lhs, rhs, result);
282+
hcuLimit.checkHCUForFheBitAnd(lhsType, scalarByte, lhs, rhs, result, msg.sender);
283283
emit FheBitAnd(msg.sender, lhs, rhs, scalarByte, result);
284284
}
285285

@@ -300,7 +300,7 @@ contract FHEVMExecutor is UUPSUpgradeableEmptyProxy, FHEEvents, ACLOwnable {
300300
(1 << uint8(FheType.Uint256));
301301
FheType lhsType = _verifyAndReturnType(lhs, supportedTypes);
302302
result = _binaryOp(Operators.fheBitOr, lhs, rhs, scalarByte, lhsType);
303-
hcuLimit.checkHCUForFheBitOr(lhsType, scalarByte, lhs, rhs, result);
303+
hcuLimit.checkHCUForFheBitOr(lhsType, scalarByte, lhs, rhs, result, msg.sender);
304304
emit FheBitOr(msg.sender, lhs, rhs, scalarByte, result);
305305
}
306306

@@ -321,7 +321,7 @@ contract FHEVMExecutor is UUPSUpgradeableEmptyProxy, FHEEvents, ACLOwnable {
321321
(1 << uint8(FheType.Uint256));
322322
FheType lhsType = _verifyAndReturnType(lhs, supportedTypes);
323323
result = _binaryOp(Operators.fheBitXor, lhs, rhs, scalarByte, lhsType);
324-
hcuLimit.checkHCUForFheBitXor(lhsType, scalarByte, lhs, rhs, result);
324+
hcuLimit.checkHCUForFheBitXor(lhsType, scalarByte, lhs, rhs, result, msg.sender);
325325
emit FheBitXor(msg.sender, lhs, rhs, scalarByte, result);
326326
}
327327

@@ -341,7 +341,7 @@ contract FHEVMExecutor is UUPSUpgradeableEmptyProxy, FHEEvents, ACLOwnable {
341341
(1 << uint8(FheType.Uint256));
342342
FheType lhsType = _verifyAndReturnType(lhs, supportedTypes);
343343
result = _binaryOp(Operators.fheShl, lhs, rhs, scalarByte, lhsType);
344-
hcuLimit.checkHCUForFheShl(lhsType, scalarByte, lhs, rhs, result);
344+
hcuLimit.checkHCUForFheShl(lhsType, scalarByte, lhs, rhs, result, msg.sender);
345345
emit FheShl(msg.sender, lhs, rhs, scalarByte, result);
346346
}
347347

@@ -361,7 +361,7 @@ contract FHEVMExecutor is UUPSUpgradeableEmptyProxy, FHEEvents, ACLOwnable {
361361
(1 << uint8(FheType.Uint256));
362362
FheType lhsType = _verifyAndReturnType(lhs, supportedTypes);
363363
result = _binaryOp(Operators.fheShr, lhs, rhs, scalarByte, lhsType);
364-
hcuLimit.checkHCUForFheShr(lhsType, scalarByte, lhs, rhs, result);
364+
hcuLimit.checkHCUForFheShr(lhsType, scalarByte, lhs, rhs, result, msg.sender);
365365
emit FheShr(msg.sender, lhs, rhs, scalarByte, result);
366366
}
367367

@@ -381,7 +381,7 @@ contract FHEVMExecutor is UUPSUpgradeableEmptyProxy, FHEEvents, ACLOwnable {
381381
(1 << uint8(FheType.Uint256));
382382
FheType lhsType = _verifyAndReturnType(lhs, supportedTypes);
383383
result = _binaryOp(Operators.fheRotl, lhs, rhs, scalarByte, lhsType);
384-
hcuLimit.checkHCUForFheRotl(lhsType, scalarByte, lhs, rhs, result);
384+
hcuLimit.checkHCUForFheRotl(lhsType, scalarByte, lhs, rhs, result, msg.sender);
385385
emit FheRotl(msg.sender, lhs, rhs, scalarByte, result);
386386
}
387387

@@ -401,7 +401,7 @@ contract FHEVMExecutor is UUPSUpgradeableEmptyProxy, FHEEvents, ACLOwnable {
401401
(1 << uint8(FheType.Uint256));
402402
FheType lhsType = _verifyAndReturnType(lhs, supportedTypes);
403403
result = _binaryOp(Operators.fheRotr, lhs, rhs, scalarByte, lhsType);
404-
hcuLimit.checkHCUForFheRotr(lhsType, scalarByte, lhs, rhs, result);
404+
hcuLimit.checkHCUForFheRotr(lhsType, scalarByte, lhs, rhs, result, msg.sender);
405405
emit FheRotr(msg.sender, lhs, rhs, scalarByte, result);
406406
}
407407

@@ -423,7 +423,7 @@ contract FHEVMExecutor is UUPSUpgradeableEmptyProxy, FHEEvents, ACLOwnable {
423423
(1 << uint8(FheType.Uint256));
424424
FheType lhsType = _verifyAndReturnType(lhs, supportedTypes);
425425
result = _binaryOp(Operators.fheEq, lhs, rhs, scalarByte, FheType.Bool);
426-
hcuLimit.checkHCUForFheEq(lhsType, scalarByte, lhs, rhs, result);
426+
hcuLimit.checkHCUForFheEq(lhsType, scalarByte, lhs, rhs, result, msg.sender);
427427
emit FheEq(msg.sender, lhs, rhs, scalarByte, result);
428428
}
429429

@@ -445,7 +445,7 @@ contract FHEVMExecutor is UUPSUpgradeableEmptyProxy, FHEEvents, ACLOwnable {
445445
(1 << uint8(FheType.Uint256));
446446
FheType lhsType = _verifyAndReturnType(lhs, supportedTypes);
447447
result = _binaryOp(Operators.fheNe, lhs, rhs, scalarByte, FheType.Bool);
448-
hcuLimit.checkHCUForFheNe(lhsType, scalarByte, lhs, rhs, result);
448+
hcuLimit.checkHCUForFheNe(lhsType, scalarByte, lhs, rhs, result, msg.sender);
449449
emit FheNe(msg.sender, lhs, rhs, scalarByte, result);
450450
}
451451

@@ -464,7 +464,7 @@ contract FHEVMExecutor is UUPSUpgradeableEmptyProxy, FHEEvents, ACLOwnable {
464464
(1 << uint8(FheType.Uint128));
465465
FheType lhsType = _verifyAndReturnType(lhs, supportedTypes);
466466
result = _binaryOp(Operators.fheGe, lhs, rhs, scalarByte, FheType.Bool);
467-
hcuLimit.checkHCUForFheGe(lhsType, scalarByte, lhs, rhs, result);
467+
hcuLimit.checkHCUForFheGe(lhsType, scalarByte, lhs, rhs, result, msg.sender);
468468
emit FheGe(msg.sender, lhs, rhs, scalarByte, result);
469469
}
470470

@@ -483,7 +483,7 @@ contract FHEVMExecutor is UUPSUpgradeableEmptyProxy, FHEEvents, ACLOwnable {
483483
(1 << uint8(FheType.Uint128));
484484
FheType lhsType = _verifyAndReturnType(lhs, supportedTypes);
485485
result = _binaryOp(Operators.fheGt, lhs, rhs, scalarByte, FheType.Bool);
486-
hcuLimit.checkHCUForFheGt(lhsType, scalarByte, lhs, rhs, result);
486+
hcuLimit.checkHCUForFheGt(lhsType, scalarByte, lhs, rhs, result, msg.sender);
487487
emit FheGt(msg.sender, lhs, rhs, scalarByte, result);
488488
}
489489

@@ -502,7 +502,7 @@ contract FHEVMExecutor is UUPSUpgradeableEmptyProxy, FHEEvents, ACLOwnable {
502502
(1 << uint8(FheType.Uint128));
503503
FheType lhsType = _verifyAndReturnType(lhs, supportedTypes);
504504
result = _binaryOp(Operators.fheLe, lhs, rhs, scalarByte, FheType.Bool);
505-
hcuLimit.checkHCUForFheLe(lhsType, scalarByte, lhs, rhs, result);
505+
hcuLimit.checkHCUForFheLe(lhsType, scalarByte, lhs, rhs, result, msg.sender);
506506
emit FheLe(msg.sender, lhs, rhs, scalarByte, result);
507507
}
508508

@@ -521,7 +521,7 @@ contract FHEVMExecutor is UUPSUpgradeableEmptyProxy, FHEEvents, ACLOwnable {
521521
(1 << uint8(FheType.Uint128));
522522
FheType lhsType = _verifyAndReturnType(lhs, supportedTypes);
523523
result = _binaryOp(Operators.fheLt, lhs, rhs, scalarByte, FheType.Bool);
524-
hcuLimit.checkHCUForFheLt(lhsType, scalarByte, lhs, rhs, result);
524+
hcuLimit.checkHCUForFheLt(lhsType, scalarByte, lhs, rhs, result, msg.sender);
525525
emit FheLt(msg.sender, lhs, rhs, scalarByte, result);
526526
}
527527

@@ -540,7 +540,7 @@ contract FHEVMExecutor is UUPSUpgradeableEmptyProxy, FHEEvents, ACLOwnable {
540540
(1 << uint8(FheType.Uint128));
541541
FheType lhsType = _verifyAndReturnType(lhs, supportedTypes);
542542
result = _binaryOp(Operators.fheMin, lhs, rhs, scalarByte, lhsType);
543-
hcuLimit.checkHCUForFheMin(lhsType, scalarByte, lhs, rhs, result);
543+
hcuLimit.checkHCUForFheMin(lhsType, scalarByte, lhs, rhs, result, msg.sender);
544544
emit FheMin(msg.sender, lhs, rhs, scalarByte, result);
545545
}
546546

@@ -559,7 +559,7 @@ contract FHEVMExecutor is UUPSUpgradeableEmptyProxy, FHEEvents, ACLOwnable {
559559
(1 << uint8(FheType.Uint128));
560560
FheType lhsType = _verifyAndReturnType(lhs, supportedTypes);
561561
result = _binaryOp(Operators.fheMax, lhs, rhs, scalarByte, lhsType);
562-
hcuLimit.checkHCUForFheMax(lhsType, scalarByte, lhs, rhs, result);
562+
hcuLimit.checkHCUForFheMax(lhsType, scalarByte, lhs, rhs, result, msg.sender);
563563
emit FheMax(msg.sender, lhs, rhs, scalarByte, result);
564564
}
565565

@@ -577,7 +577,7 @@ contract FHEVMExecutor is UUPSUpgradeableEmptyProxy, FHEEvents, ACLOwnable {
577577
(1 << uint8(FheType.Uint256));
578578
FheType typeCt = _verifyAndReturnType(ct, supportedTypes);
579579
result = _unaryOp(Operators.fheNeg, ct);
580-
hcuLimit.checkHCUForFheNeg(typeCt, ct, result);
580+
hcuLimit.checkHCUForFheNeg(typeCt, ct, result, msg.sender);
581581
emit FheNeg(msg.sender, ct, result);
582582
}
583583

@@ -596,7 +596,7 @@ contract FHEVMExecutor is UUPSUpgradeableEmptyProxy, FHEEvents, ACLOwnable {
596596
(1 << uint8(FheType.Uint256));
597597
FheType typeCt = _verifyAndReturnType(ct, supportedTypes);
598598
result = _unaryOp(Operators.fheNot, ct);
599-
hcuLimit.checkHCUForFheNot(typeCt, ct, result);
599+
hcuLimit.checkHCUForFheNot(typeCt, ct, result, msg.sender);
600600
emit FheNot(msg.sender, ct, result);
601601
}
602602

@@ -618,7 +618,7 @@ contract FHEVMExecutor is UUPSUpgradeableEmptyProxy, FHEEvents, ACLOwnable {
618618
(1 << uint8(FheType.Uint256));
619619
FheType typeCt = _verifyAndReturnType(ifTrue, supportedTypes);
620620
result = _ternaryOp(Operators.fheIfThenElse, control, ifTrue, ifFalse);
621-
hcuLimit.checkHCUForIfThenElse(typeCt, control, ifTrue, ifFalse, result);
621+
hcuLimit.checkHCUForIfThenElse(typeCt, control, ifTrue, ifFalse, result, msg.sender);
622622
emit FheIfThenElse(msg.sender, control, ifTrue, ifFalse, result);
623623
}
624624

@@ -673,7 +673,7 @@ contract FHEVMExecutor is UUPSUpgradeableEmptyProxy, FHEEvents, ACLOwnable {
673673
if (typeCt == toType) revert InvalidType();
674674
result = keccak256(abi.encodePacked(Operators.cast, ct, toType, acl, block.chainid));
675675
result = _appendMetadataToPrehandle(result, toType);
676-
hcuLimit.checkHCUForCast(toType, ct, result);
676+
hcuLimit.checkHCUForCast(toType, ct, result, msg.sender);
677677
acl.allowTransient(result, msg.sender);
678678
emit Cast(msg.sender, ct, toType, result);
679679
}
@@ -697,7 +697,7 @@ contract FHEVMExecutor is UUPSUpgradeableEmptyProxy, FHEEvents, ACLOwnable {
697697
if ((1 << uint8(toType)) & supportedTypes == 0) revert UnsupportedType();
698698
result = keccak256(abi.encodePacked(Operators.trivialEncrypt, pt, toType, acl, block.chainid));
699699
result = _appendMetadataToPrehandle(result, toType);
700-
hcuLimit.checkHCUForTrivialEncrypt(toType, result);
700+
hcuLimit.checkHCUForTrivialEncrypt(toType, result, msg.sender);
701701
acl.allowTransient(result, msg.sender);
702702
emit TrivialEncrypt(msg.sender, pt, toType, result);
703703
}
@@ -885,7 +885,7 @@ contract FHEVMExecutor is UUPSUpgradeableEmptyProxy, FHEEvents, ACLOwnable {
885885
if ((1 << uint8(randType)) & supportedTypes == 0) revert UnsupportedType();
886886
result = keccak256(abi.encodePacked(Operators.fheRand, randType, seed));
887887
result = _appendMetadataToPrehandle(result, randType);
888-
hcuLimit.checkHCUForFheRand(randType, result);
888+
hcuLimit.checkHCUForFheRand(randType, result, msg.sender);
889889
acl.allowTransient(result, msg.sender);
890890
}
891891

@@ -906,7 +906,7 @@ contract FHEVMExecutor is UUPSUpgradeableEmptyProxy, FHEEvents, ACLOwnable {
906906
_checkBelowMaxBound(upperBound, randType);
907907
result = keccak256(abi.encodePacked(Operators.fheRandBounded, upperBound, randType, seed));
908908
result = _appendMetadataToPrehandle(result, randType);
909-
hcuLimit.checkHCUForFheRandBounded(randType, result);
909+
hcuLimit.checkHCUForFheRandBounded(randType, result, msg.sender);
910910
acl.allowTransient(result, msg.sender);
911911
}
912912

0 commit comments

Comments
 (0)