@@ -17,7 +17,7 @@ import { EventsLib } from "../libraries/EventsLib.sol";
17
17
import { UtilitiesLib } from "../libraries/UtilitiesLib.sol " ;
18
18
import { FHE, euint128 } from "@fhevm/solidity/lib/FHE.sol " ;
19
19
import { SepoliaConfig } from "@fhevm/solidity/config/ZamaConfig.sol " ;
20
-
20
+ import " hardhat/console.sol " ;
21
21
/**
22
22
* @title Internal States Orchestrator
23
23
* @notice Contract that orchestrates internal state management
@@ -458,7 +458,7 @@ contract InternalStatesOrchestrator is SepoliaConfig, Ownable, ReentrancyGuard,
458
458
(address [] memory portfolioTokens , euint128[] memory sharesPerAsset ) = vault.getPortfolio ();
459
459
460
460
// STEP 1: LIVE PORTFOLIO
461
- euint128 totalAssets = _ezero;
461
+ euint128 totalAssets = _ezero; // TODO: ensure no accidental _ezero modification.
462
462
for (uint16 j = 0 ; j < portfolioTokens.length ; ++ j) {
463
463
address token = portfolioTokens[j];
464
464
euint128 shares = sharesPerAsset[j];
@@ -492,7 +492,10 @@ contract InternalStatesOrchestrator is SepoliaConfig, Ownable, ReentrancyGuard,
492
492
totalAssets = FHE.add (totalAssets, value);
493
493
_addTokenIfNotExists (token);
494
494
}
495
- _currentEpoch.encryptedVaultsTotalAssets[address (vault)] = totalAssets;
495
+ uint128 tmp = uint128 (696969 ) + i;
496
+ console.log ("tmp in the main function " , tmp);
497
+ _currentEpoch.encryptedVaultsTotalAssets[address (vault)] = FHE.asEuint128 (tmp); // TODO: fix this.
498
+ FHE.allowThis (_currentEpoch.encryptedVaultsTotalAssets[address (vault)]);
496
499
}
497
500
498
501
if (i1 == nVaults) {
@@ -502,6 +505,7 @@ contract InternalStatesOrchestrator is SepoliaConfig, Ownable, ReentrancyGuard,
502
505
currentMinibatchIndex = 0 ;
503
506
} else {
504
507
uint16 mTokens = uint16 (_currentEpoch.tokens.length );
508
+ encryptedValuesLength = nVaults + mTokens;
505
509
bytes32 [] memory cypherTexts = new bytes32 [](nVaults + mTokens);
506
510
for (uint16 i = 0 ; i < nVaults; ++ i) {
507
511
address vault = encryptedVaultsEpoch[i];
@@ -518,24 +522,34 @@ contract InternalStatesOrchestrator is SepoliaConfig, Ownable, ReentrancyGuard,
518
522
cypherTexts[nVaults + i] = FHE.toBytes32 (position);
519
523
}
520
524
521
- // slither-disable-next-line unused-return
522
- FHE.requestDecryption (cypherTexts, this .callbackPreProcessDecrypt.selector );
525
+ requestId = FHE.requestDecryption (cypherTexts, this .callbackPreProcessDecrypt.selector );
523
526
}
524
527
}
525
528
}
526
529
// slither-disable-end reentrancy-no-eth
527
530
531
+ uint256 requestId;
532
+ uint16 encryptedValuesLength;
533
+
528
534
/// @inheritdoc IInternalStateOrchestrator
529
- function callbackPreProcessDecrypt (
530
- uint256 requestID ,
531
- uint256 [] calldata decryptedValues ,
532
- bytes [] calldata signatures
533
- ) external {
534
- FHE.checkSignatures (requestID, signatures);
535
+ function callbackPreProcessDecrypt (uint256 requestID ) external {
536
+ if (requestID != requestId) revert ErrorsLib.InvalidArguments ();
537
+
538
+ // Read multiple uint128 values and signatures from msg.data
539
+ // Skip function selector (4 bytes) + requestID (32 bytes) = 36 bytes
540
+ uint256 offset = 36 ;
541
+
542
+ // Read multiple uint128 values using encryptedValuesLength
543
+ uint128 [] memory values = new uint128 [](encryptedValuesLength);
544
+ for (uint16 i = 0 ; i < encryptedValuesLength; i++ ) {
545
+ values[i] = uint128 (uint256 (bytes32 (msg .data [offset:offset + 32 ])));
546
+ console.log ("value in the callback " , values[i]);
547
+ offset += 32 ;
548
+ }
535
549
536
550
// Store decrypted values for processing in the next phase.
537
551
// TODO: avoid breaking down this into two phases, consider letting Zama callback do all the work.
538
- _decryptedValues = decryptedValues;
552
+ // _decryptedValues = decryptedValues;
539
553
540
554
currentPhase = InternalUpkeepPhase.ProcessingDecryptedValues;
541
555
currentMinibatchIndex = 0 ;
0 commit comments