Skip to content

Commit 6c33e07

Browse files
committed
complete pdp prepare for verification
1 parent 5ae8c84 commit 6c33e07

15 files changed

+273
-117
lines changed

README.md

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,29 @@ npx hardhat coverage
3232
Report:
3333

3434
```
35-
171 passing (13s)
35+
173 passing (14s)
3636
3737
-----------------|----------|----------|----------|----------|----------------|
3838
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
3939
-----------------|----------|----------|----------|----------|----------------|
40-
contracts/ | 58.39 | 38.32 | 67.27 | 57.77 | |
40+
contracts/ | 57 | 37.58 | 68.09 | 56.27 | |
4141
Config.sol | 95.83 | 83.33 | 100 | 95.83 | 47 |
4242
Dns.sol | 29.76 | 12.5 | 17.31 | 28.76 |... 731,739,740 |
4343
File.sol | 67.27 | 42.31 | 86.21 | 64 |... 448,497,498 |
4444
FileExtra.sol | 69.08 | 43.75 | 83.78 | 67.48 |... 466,477,500 |
4545
List.sol | 100 | 81.25 | 66.67 | 100 | |
4646
Node.sol | 81.11 | 67.65 | 100 | 81.32 |... 188,193,194 |
47-
PDP.sol | 78.3 | 53.85 | 63.04 | 75.77 |... 708,717,718 |
47+
PDP.sol | 78.63 | 53.57 | 69.57 | 76.31 |... 687,694,717 |
48+
PDPExtra.sol | 10.91 | 20 | 40 | 9.68 |... 137,139,141 |
4849
Prove.sol | 43.1 | 25 | 75 | 42.02 |... 517,519,526 |
49-
ProveExtra.sol | 60.47 | 23.53 | 61.9 | 60.74 |... 335,343,370 |
50+
ProveExtra.sol | 55.97 | 18.75 | 65.22 | 56.43 |... 346,354,381 |
5051
Sector.sol | 87.41 | 65.22 | 95.45 | 87.84 |... 392,393,420 |
5152
Space.sol | 50.25 | 38.27 | 84.38 | 50.12 |... 1,1052,1053 |
5253
Test.sol | 0 | 100 | 0 | 0 | 6 |
5354
interface.sol | 100 | 100 | 100 | 100 | |
5455
type.sol | 100 | 100 | 100 | 100 | |
5556
-----------------|----------|----------|----------|----------|----------------|
56-
All files | 58.39 | 38.32 | 67.27 | 57.77 | |
57+
All files | 57 | 37.58 | 68.09 | 56.27 | |
5758
-----------------|----------|----------|----------|----------|----------------|
5859
```
5960

@@ -66,24 +67,24 @@ npx hardhat size-contracts
6667
Report:
6768

6869
```
69-
·----------------------|--------------|----------------·
70+
·----------------------|--------------|----------------·
7071
| Contract Name · Size (KiB) · Change (KiB) │
7172
·······················|··············|·················
7273
| DNSNodeMapping · 0.084 · │
7374
·······················|··············|·················
74-
| PeerPoolMapping · 0.084 · │
75-
·······················|··············|·················
7675
| NameInfoMapping · 0.084 · │
7776
·······················|··············|·················
77+
| PeerPoolMapping · 0.084 · │
78+
·······················|··············|·················
7879
| ChallengeMapping · 0.084 · │
7980
·······················|··············|·················
8081
| MerklePathMapping · 0.084 · │
8182
·······················|··············|·················
82-
| ProofsMapping · 0.084 · │
83+
| MerkleNodeMapping · 0.084 · │
8384
·······················|··············|·················
8485
| IterableMapping · 0.084 · │
8586
·······················|··············|·················
86-
| MerkleNodeMapping · 0.084 · │
87+
| ProofsMapping · 0.084 · │
8788
·······················|··············|·················
8889
| console · 0.084 · │
8990
·······················|··············|·················
@@ -95,22 +96,24 @@ Report:
9596
·······················|··············|·················
9697
| List · 3.339 · │
9798
·······················|··············|·················
99+
| PDPExtra · 11.012 · │
100+
·······················|··············|·················
98101
| Node · 11.247 · │
99102
·······················|··············|·················
100-
| Sector · 15.663 · │
103+
| Sector · 15.762 · │
101104
·······················|··············|·················
102-
| PDP · 17.856 · │
105+
| ProveExtra · 19.202 · │
103106
·······················|··············|·················
104-
| ProveExtra · 18.175 · +5.175
107+
| FileExtra · 19.921 ·
105108
·······················|··············|·················
106-
| FileExtra · 19.390 · │
109+
| Space · 20.462 · │
107110
·······················|··············|·················
108-
| Space · 20.306 · │
111+
| Dns · 20.786 · │
109112
·······················|··············|·················
110-
| Prove · 20.645 · -3.465
113+
| Prove · 21.163 ·
111114
·······················|··············|·················
112-
| Dns · 20.786 · │
115+
| File · 22.896 · │
113116
·······················|··············|·················
114-
| File · 22.626 · │
117+
| PDP · 23.272 · │
115118
·----------------------|--------------|----------------·
116119
```

contracts/PDP.sol

Lines changed: 37 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import "hardhat/console.sol";
55
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
66
import "./type.sol";
77
import "./interface.sol";
8+
import "./PDPExtra.sol";
89

910
contract PDP is Initializable, IPDP, IFsEvent {
1011
using ProofsMapping for ProofsPool;
@@ -14,6 +15,7 @@ contract PDP is Initializable, IPDP, IFsEvent {
1415

1516
IFile file;
1617
ISector sector;
18+
PDPExtra pdpExtra;
1719

1820
ProofsPool proofsPool; // proofs record
1921
mapping(bytes => ChallengePool) challengeMap; // key => map(chKey => Challenge)
@@ -22,9 +24,14 @@ contract PDP is Initializable, IPDP, IFsEvent {
2224

2325
event VerifyProofWithMerklePathForFileEvent();
2426

25-
function initialize(IFile _file, ISector _sector) public initializer {
27+
function initialize(
28+
IFile _file,
29+
ISector _sector,
30+
PDPExtra _pdpExtra
31+
) public initializer {
2632
file = _file;
2733
sector = _sector;
34+
pdpExtra = _pdpExtra;
2835
}
2936

3037
function GenChallenge(
@@ -118,108 +125,57 @@ contract PDP is Initializable, IPDP, IFsEvent {
118125
function PrepareForPdpVerification(
119126
PrepareForPdpVerificationParams memory pParams
120127
) public view virtual override returns (PdpVerificationReturns memory) {
121-
SectorInfo memory sectorInfo = pParams.SectorInfo_;
122128
PdpVerificationReturns memory pReturns;
123-
string memory err = checkSectorProveData(sectorInfo, pParams.ProveData);
129+
string memory err = pdpExtra.checkSectorProveData(
130+
pParams.SectorInfo_,
131+
pParams.ProveData
132+
);
124133
if (bytes(err).length > 0) {
125134
pReturns.Error = err;
126135
return pReturns;
127136
}
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+
);
134145
for (uint64 i = 0; i < fileNum; i++) {
135146
SectorFileInfo memory sectorFileInfo = sectorFileInfos[i];
136147
FileInfo memory fileInfo = file.GetFileInfo(
137148
sectorFileInfo.FileHash
138149
);
139150
sectorFileInfo.BlockCount = fileInfo.FileBlockNum;
140151
}
141-
Challenge[] memory challenges = pParams.Challenges;
142152

143-
// TODO
144153
pReturns.FileIDs = new bytes[](fileNum);
145154
pReturns.Tags = new bytes[](fileNum);
146-
pReturns.UpdatedChal = new Challenge[](fileNum);
147155
pReturns.Path = new MerklePath[](fileNum);
148156
pReturns.RootHashes = new bytes[](fileNum);
157+
pReturns.UpdatedChal = new Challenge[](fileNum);
149158

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+
);
170175

171176
return pReturns;
172177
}
173178

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-
223179
function VerifyProof(
224180
ProofRecord memory vParams,
225181
Challenge[] memory chgs,

0 commit comments

Comments
 (0)