Skip to content

Commit 132956a

Browse files
committed
feat: msg.data payload management
1 parent 409efeb commit 132956a

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

contracts/interfaces/IInternalStateOrchestrator.sol

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,7 @@ interface IInternalStateOrchestrator is AutomationCompatibleInterface {
6060

6161
/// @notice Callback function to decrypt the encrypted values
6262
/// @param requestID The request ID
63-
/// @param decryptedValues The decrypted values
64-
/// @param signatures The signatures
65-
function callbackPreProcessDecrypt(
66-
uint256 requestID,
67-
uint256[] memory decryptedValues,
68-
bytes[] memory signatures
69-
) external;
63+
function callbackPreProcessDecrypt(uint256 requestID) external;
7064

7165
/// @notice Get the selling orders
7266
/// @return tokens The tokens to sell

contracts/orchestrators/InternalStatesOrchestrator.sol

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { EventsLib } from "../libraries/EventsLib.sol";
1717
import { UtilitiesLib } from "../libraries/UtilitiesLib.sol";
1818
import { FHE, euint128 } from "@fhevm/solidity/lib/FHE.sol";
1919
import { SepoliaConfig } from "@fhevm/solidity/config/ZamaConfig.sol";
20-
20+
import "hardhat/console.sol";
2121
/**
2222
* @title Internal States Orchestrator
2323
* @notice Contract that orchestrates internal state management
@@ -458,7 +458,7 @@ contract InternalStatesOrchestrator is SepoliaConfig, Ownable, ReentrancyGuard,
458458
(address[] memory portfolioTokens, euint128[] memory sharesPerAsset) = vault.getPortfolio();
459459

460460
// STEP 1: LIVE PORTFOLIO
461-
euint128 totalAssets = _ezero;
461+
euint128 totalAssets = _ezero; // TODO: ensure no accidental _ezero modification.
462462
for (uint16 j = 0; j < portfolioTokens.length; ++j) {
463463
address token = portfolioTokens[j];
464464
euint128 shares = sharesPerAsset[j];
@@ -492,7 +492,10 @@ contract InternalStatesOrchestrator is SepoliaConfig, Ownable, ReentrancyGuard,
492492
totalAssets = FHE.add(totalAssets, value);
493493
_addTokenIfNotExists(token);
494494
}
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)]);
496499
}
497500

498501
if (i1 == nVaults) {
@@ -502,6 +505,7 @@ contract InternalStatesOrchestrator is SepoliaConfig, Ownable, ReentrancyGuard,
502505
currentMinibatchIndex = 0;
503506
} else {
504507
uint16 mTokens = uint16(_currentEpoch.tokens.length);
508+
encryptedValuesLength = nVaults + mTokens;
505509
bytes32[] memory cypherTexts = new bytes32[](nVaults + mTokens);
506510
for (uint16 i = 0; i < nVaults; ++i) {
507511
address vault = encryptedVaultsEpoch[i];
@@ -518,24 +522,34 @@ contract InternalStatesOrchestrator is SepoliaConfig, Ownable, ReentrancyGuard,
518522
cypherTexts[nVaults + i] = FHE.toBytes32(position);
519523
}
520524

521-
// slither-disable-next-line unused-return
522-
FHE.requestDecryption(cypherTexts, this.callbackPreProcessDecrypt.selector);
525+
requestId = FHE.requestDecryption(cypherTexts, this.callbackPreProcessDecrypt.selector);
523526
}
524527
}
525528
}
526529
// slither-disable-end reentrancy-no-eth
527530

531+
uint256 requestId;
532+
uint16 encryptedValuesLength;
533+
528534
/// @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+
}
535549

536550
// Store decrypted values for processing in the next phase.
537551
// TODO: avoid breaking down this into two phases, consider letting Zama callback do all the work.
538-
_decryptedValues = decryptedValues;
552+
// _decryptedValues = decryptedValues;
539553

540554
currentPhase = InternalUpkeepPhase.ProcessingDecryptedValues;
541555
currentMinibatchIndex = 0;

0 commit comments

Comments
 (0)