Skip to content

Commit 88ee659

Browse files
committed
Refactor solidity Data Processor module
1 parent 19346ec commit 88ee659

File tree

2 files changed

+26
-35
lines changed

2 files changed

+26
-35
lines changed

solidity/src/interfaces/modules/IDataProcessorModule.sol

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,19 @@ interface IDataProcessorModule is IFactsRegistryCommon {
7474
/// @notice Emitted when some program hashes are disabled
7575
event ProgramHashesDisabled(bytes32[] disabledProgramHashes);
7676

77+
// ========================= Setup Functions ========================= //
78+
7779
/// @notice Set the program hash for the HDP program
7880
function setDataProcessorProgramHash(bytes32 programHash) external;
7981

8082
/// @notice Disable some program hashes
8183
function disableProgramHashes(bytes32[] calldata programHashes) external;
8284

85+
/// @notice Checks if a program hash is currently authorized
86+
function isProgramHashAuthorized(bytes32 programHash) external view returns (bool);
87+
88+
// ========================= Core Functions ========================= //
89+
8390
/// @notice Requests the execution of a task with a module
8491
/// @param moduleTask module task
8592
function requestDataProcessorExecutionOfTask(ModuleTask calldata moduleTask) external;
@@ -89,12 +96,9 @@ interface IDataProcessorModule is IFactsRegistryCommon {
8996
/// @param taskData The task data
9097
function authenticateDataProcessorTaskExecution(TaskData calldata taskData) external;
9198

92-
/// @notice Returns the result of a finalized task
93-
function getDataProcessorFinalizedTaskResult(bytes32 taskCommitment) external view returns (bytes32);
94-
9599
/// @notice Returns the status of a task
96100
function getDataProcessorTaskStatus(bytes32 taskCommitment) external view returns (TaskStatus);
97101

98-
/// @notice Checks if a program hash is currently authorized
99-
function isProgramHashAuthorized(bytes32 programHash) external view returns (bool);
102+
/// @notice Returns the result of a finalized task
103+
function getDataProcessorFinalizedTaskResult(bytes32 taskCommitment) external view returns (bytes32);
100104
}

solidity/src/modules/DataProcessorModule.sol

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ contract DataProcessorModule is IDataProcessorModule, AccessController {
3333
}
3434
}
3535

36-
// ========================= Owner-only Functions ========================= //
36+
// ========================= Setup Functions ========================= //
3737

3838
/// @inheritdoc IDataProcessorModule
3939
function setDataProcessorProgramHash(bytes32 programHash) external onlyOwner {
@@ -52,6 +52,12 @@ contract DataProcessorModule is IDataProcessorModule, AccessController {
5252
emit ProgramHashesDisabled(programHashes);
5353
}
5454

55+
/// @inheritdoc IDataProcessorModule
56+
function isProgramHashAuthorized(bytes32 programHash) public view returns (bool) {
57+
DataProcessorModuleStorage storage ms = moduleStorage();
58+
return ms.authorizedProgramHashes[programHash];
59+
}
60+
5561
// ========================= Core Functions ========================= //
5662

5763
/// @inheritdoc IDataProcessorModule
@@ -78,6 +84,8 @@ contract DataProcessorModule is IDataProcessorModule, AccessController {
7884
function authenticateDataProcessorTaskExecution(TaskData calldata taskData) external {
7985
DataProcessorModuleStorage storage ms = moduleStorage();
8086

87+
require(taskData.taskHashLow >> 128 == 0, "INVALID taskHashLow");
88+
require(taskData.taskHashHigh >> 128 == 0, "INVALID taskHashHigh");
8189
bytes32 taskHash = bytes32((taskData.taskHashHigh << 128) | taskData.taskHashLow);
8290

8391
if (ms.cachedTasksResult[taskHash].status == TaskStatus.FINALIZED) {
@@ -101,7 +109,7 @@ contract DataProcessorModule is IDataProcessorModule, AccessController {
101109

102110
for (uint8 i = 0; i < taskData.mmrData.length; i++) {
103111
MmrData memory mmr = taskData.mmrData[i];
104-
bytes32 usedMmrRoot = loadMmrRoot(mmr.mmrId, mmr.mmrSize, mmr.chainId);
112+
bytes32 usedMmrRoot = LibSatellite.satelliteStorage().mmrs[mmr.chainId][mmr.mmrId][POSEIDON_HASHING_FUNCTION].mmrSizeToRoot[mmr.mmrSize];
105113
if (usedMmrRoot == bytes32(0)) {
106114
revert InvalidMmrRoot();
107115
}
@@ -122,14 +130,20 @@ contract DataProcessorModule is IDataProcessorModule, AccessController {
122130
revert InvalidFact();
123131
}
124132

133+
require(taskData.taskResultHigh >> 128 == 0, "INVALID taskResultHigh");
134+
require(taskData.taskResultLow >> 128 == 0, "INVALID taskResultLow");
125135
bytes32 taskResult = bytes32((taskData.taskResultHigh << 128) | taskData.taskResultLow);
126136

127137
// Store the task result
128138
ms.cachedTasksResult[taskHash] = TaskResult({status: TaskStatus.FINALIZED, result: taskResult});
129139
emit TaskFinalized(taskHash, taskResult);
130140
}
131141

132-
// ========================= View Functions ========================= //
142+
/// @inheritdoc IDataProcessorModule
143+
function getDataProcessorTaskStatus(bytes32 taskCommitment) external view returns (TaskStatus) {
144+
DataProcessorModuleStorage storage ms = moduleStorage();
145+
return ms.cachedTasksResult[taskCommitment].status;
146+
}
133147

134148
/// @inheritdoc IDataProcessorModule
135149
function getDataProcessorFinalizedTaskResult(bytes32 taskCommitment) external view returns (bytes32) {
@@ -140,31 +154,4 @@ contract DataProcessorModule is IDataProcessorModule, AccessController {
140154
}
141155
return ms.cachedTasksResult[taskCommitment].result;
142156
}
143-
144-
/// @inheritdoc IDataProcessorModule
145-
function getDataProcessorTaskStatus(bytes32 taskCommitment) external view returns (TaskStatus) {
146-
DataProcessorModuleStorage storage ms = moduleStorage();
147-
return ms.cachedTasksResult[taskCommitment].status;
148-
}
149-
150-
/// @inheritdoc IDataProcessorModule
151-
function isProgramHashAuthorized(bytes32 programHash) public view returns (bool) {
152-
DataProcessorModuleStorage storage ms = moduleStorage();
153-
return ms.authorizedProgramHashes[programHash];
154-
}
155-
156-
// ========================= Internal Functions ========================= //
157-
158-
/// @notice Load MMR root from cache with given mmrId and mmrSize
159-
function loadMmrRoot(uint256 mmrId, uint256 mmrSize, uint256 chainId) internal view returns (bytes32) {
160-
ISatellite.SatelliteStorage storage s = LibSatellite.satelliteStorage();
161-
return s.mmrs[chainId][mmrId][POSEIDON_HASHING_FUNCTION].mmrSizeToRoot[mmrSize];
162-
}
163-
164-
/// @notice Returns the leaf of standard merkle tree
165-
function standardEvmHDPLeafHash(bytes32 value) internal pure returns (bytes32) {
166-
bytes32 firstHash = keccak256(abi.encode(value));
167-
bytes32 leaf = keccak256(abi.encode(firstHash));
168-
return leaf;
169-
}
170157
}

0 commit comments

Comments
 (0)