@@ -5,6 +5,7 @@ import "hardhat/console.sol";
5
5
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol " ;
6
6
import "./type.sol " ;
7
7
import "./interface.sol " ;
8
+ import "./PDPExtra.sol " ;
8
9
9
10
contract PDP is Initializable , IPDP , IFsEvent {
10
11
using ProofsMapping for ProofsPool;
@@ -14,6 +15,7 @@ contract PDP is Initializable, IPDP, IFsEvent {
14
15
15
16
IFile file;
16
17
ISector sector;
18
+ PDPExtra pdpExtra;
17
19
18
20
ProofsPool proofsPool; // proofs record
19
21
mapping (bytes => ChallengePool) challengeMap; // key => map(chKey => Challenge)
@@ -22,9 +24,14 @@ contract PDP is Initializable, IPDP, IFsEvent {
22
24
23
25
event VerifyProofWithMerklePathForFileEvent ();
24
26
25
- function initialize (IFile _file , ISector _sector ) public initializer {
27
+ function initialize (
28
+ IFile _file ,
29
+ ISector _sector ,
30
+ PDPExtra _pdpExtra
31
+ ) public initializer {
26
32
file = _file;
27
33
sector = _sector;
34
+ pdpExtra = _pdpExtra;
28
35
}
29
36
30
37
function GenChallenge (
@@ -118,108 +125,57 @@ contract PDP is Initializable, IPDP, IFsEvent {
118
125
function PrepareForPdpVerification (
119
126
PrepareForPdpVerificationParams memory pParams
120
127
) public view virtual override returns (PdpVerificationReturns memory ) {
121
- SectorInfo memory sectorInfo = pParams.SectorInfo_;
122
128
PdpVerificationReturns memory pReturns;
123
- string memory err = checkSectorProveData (sectorInfo, pParams.ProveData);
129
+ string memory err = pdpExtra.checkSectorProveData (
130
+ pParams.SectorInfo_,
131
+ pParams.ProveData
132
+ );
124
133
if (bytes (err).length > 0 ) {
125
134
pReturns.Error = err;
126
135
return pReturns;
127
136
}
128
- uint64 fileNum = sectorInfo.FileNum;
129
- SectorFileInfo[] memory sectorFileInfos = GetSectorFileInfosForSector (
130
- sectorInfo.NodeAddr,
131
- sectorInfo.SectorID,
132
- fileNum
133
- );
137
+ uint64 fileNum = pParams.SectorInfo_.FileNum;
138
+ SectorFileInfo[] memory sectorFileInfos = pdpExtra
139
+ .GetSectorFileInfosForSector (
140
+ sector,
141
+ pParams.SectorInfo_.NodeAddr,
142
+ pParams.SectorInfo_.SectorID,
143
+ fileNum
144
+ );
134
145
for (uint64 i = 0 ; i < fileNum; i++ ) {
135
146
SectorFileInfo memory sectorFileInfo = sectorFileInfos[i];
136
147
FileInfo memory fileInfo = file.GetFileInfo (
137
148
sectorFileInfo.FileHash
138
149
);
139
150
sectorFileInfo.BlockCount = fileInfo.FileBlockNum;
140
151
}
141
- Challenge[] memory challenges = pParams.Challenges;
142
152
143
- // TODO
144
153
pReturns.FileIDs = new bytes [](fileNum);
145
154
pReturns.Tags = new bytes [](fileNum);
146
- pReturns.UpdatedChal = new Challenge [](fileNum);
147
155
pReturns.Path = new MerklePath [](fileNum);
148
156
pReturns.RootHashes = new bytes [](fileNum);
157
+ pReturns.UpdatedChal = new Challenge [](fileNum);
149
158
150
- uint64 offset = 0 ;
151
- uint64 curIndex = 0 ;
152
- FileInfo memory firstFileInfo;
153
-
154
- for (uint64 i = 0 ; i < fileNum; i++ ) {
155
- SectorFileInfo memory sectorFileInfo = sectorFileInfos[i];
156
- bytes memory fileHash = sectorFileInfo.FileHash;
157
- uint64 blockCount = sectorFileInfo.BlockCount;
158
-
159
- uint64 start = offset;
160
- uint64 end = offset + blockCount - 1 ;
161
-
162
- for (uint64 j = curIndex; j < challenges.length ; j++ ) {
163
- Challenge memory challenge = challenges[curIndex];
164
- if (challenge.Index >= start && challenge.Index <= end) {
165
- FileInfo memory fileInfo = file.GetFileInfo (fileHash);
166
- // TODO
167
- }
168
- }
169
- }
159
+ // FileIDs, RootHashes
160
+ pReturns = pdpExtra.PrepareForPdpVerification1 (
161
+ file,
162
+ fileNum,
163
+ sectorFileInfos,
164
+ pParams.Challenges,
165
+ pReturns
166
+ );
167
+ // Tags, Path, UpdatedChal
168
+ pReturns = pdpExtra.PrepareForPdpVerification2 (
169
+ fileNum,
170
+ sectorFileInfos,
171
+ pParams.Challenges,
172
+ pParams.ProveData,
173
+ pReturns
174
+ );
170
175
171
176
return pReturns;
172
177
}
173
178
174
- function checkSectorProveData (
175
- SectorInfo memory sectorInfo ,
176
- SectorProveData memory proveData
177
- ) public pure returns (string memory ) {
178
- if (proveData.ProveFileNum > getSectorFileNum (sectorInfo)) {
179
- return
180
- "[checkSectorProveData] proveFileNum larger than file num in sector " ;
181
- }
182
- if (proveData.ProveFileNum > proveData.BlockNum) {
183
- return
184
- "[checkSectorProveData] proveFileNum larger than challenged block num in sector " ;
185
- }
186
- if (proveData.BlockNum > sectorInfo.TotalBlockNum) {
187
- return
188
- "[checkSectorProveData] challenged block num larger than total block num in sector " ;
189
- }
190
- if (sectorInfo.IsPlots && proveData.PlotData.length == 0 ) {
191
- return "[checkSectorProveData] " ;
192
- }
193
- return "" ;
194
- }
195
-
196
- function getSectorFileNum (
197
- SectorInfo memory sectorInfo
198
- ) internal pure returns (uint256 ) {
199
- return sectorInfo.FileNum;
200
- }
201
-
202
- function GetSectorFileInfosForSector (
203
- address nodeAddr ,
204
- uint64 sectorId ,
205
- uint64 fileNum
206
- ) public view returns (SectorFileInfo[] memory ) {
207
- SectorFileInfo[] memory sectorFileInfos = new SectorFileInfo [](fileNum);
208
- // TODO
209
- SectorInfo[] memory sectorInfos = sector.GetSectorsForNode (nodeAddr);
210
- SectorInfo memory sectorInfo;
211
- for (uint64 i = 0 ; i < sectorInfos.length ; i++ ) {
212
- if (sectorInfos[i].SectorID == sectorId) {
213
- sectorInfo = sectorInfos[i];
214
- break ;
215
- }
216
- }
217
- for (uint64 i = 0 ; i < fileNum; i++ ) {
218
- sectorFileInfos[i].FileHash = sectorInfo.FileList[i];
219
- }
220
- return sectorFileInfos;
221
- }
222
-
223
179
function VerifyProof (
224
180
ProofRecord memory vParams ,
225
181
Challenge[] memory chgs ,
0 commit comments