Skip to content

Commit 3e51b22

Browse files
authored
update ffi (#569)
Signed-off-by: turuslan <[email protected]>
1 parent 4403ba0 commit 3e51b22

File tree

9 files changed

+393
-68
lines changed

9 files changed

+393
-68
lines changed

core/proofs/impl/proof_engine_impl.cpp

Lines changed: 113 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -958,36 +958,6 @@ namespace fc::proofs {
958958
return res_ptr->is_valid;
959959
}
960960

961-
outcome::result<Bytes> ProofEngineImpl::generateUpdateProof(
962-
RegisteredUpdateProof proof_type,
963-
const CID &old_sealed_cid,
964-
const CID &new_sealed_cid,
965-
const CID &unsealed_cid,
966-
const std::string &new_replica_path,
967-
const std::string &new_replica_cache_path,
968-
const std::string &sector_key_path,
969-
const std::string &sector_key_cache_path) {
970-
OUTCOME_TRY(ffi_update_proof_type, cRegisteredUpdateProof(proof_type));
971-
OUTCOME_TRY(comm_r_old, CIDToReplicaCommitmentV1(old_sealed_cid));
972-
OUTCOME_TRY(comm_r_new, CIDToReplicaCommitmentV1(new_sealed_cid));
973-
OUTCOME_TRY(comm_d, CIDToDataCommitmentV1(unsealed_cid));
974-
const auto res_ptr{ffi::wrap(
975-
fil_generate_empty_sector_update_proof(ffi_update_proof_type,
976-
c32ByteArray(comm_r_old),
977-
c32ByteArray(comm_r_new),
978-
c32ByteArray(comm_d),
979-
sector_key_path.c_str(),
980-
sector_key_cache_path.c_str(),
981-
new_replica_path.c_str(),
982-
new_replica_cache_path.c_str()),
983-
fil_destroy_empty_sector_update_generate_proof_response)};
984-
PROOFS_TRY("generateUpdateProof");
985-
986-
const auto proof =
987-
gsl::span(res_ptr->proof_ptr, gsl::narrow<int64_t>(res_ptr->proof_len));
988-
return Bytes(proof.begin(), proof.end());
989-
}
990-
991961
outcome::result<bool> ProofEngineImpl::verifyUpdateProof(
992962
const ReplicaUpdateInfo &info) {
993963
OUTCOME_TRY(ffi_update_proof_type,
@@ -1133,4 +1103,117 @@ namespace fc::proofs {
11331103

11341104
ProofEngineImpl::ProofEngineImpl()
11351105
: logger_{common::createLogger("proofs")} {}
1106+
1107+
outcome::result<SealedAndUnsealedCID> ProofEngineImpl::updateSeal(
1108+
RegisteredUpdateProof type,
1109+
const std::string &path_update,
1110+
const std::string &path_update_cache,
1111+
const std::string &path_sealed,
1112+
const std::string &path_cache,
1113+
const std::string &path_unsealed,
1114+
gsl::span<const PieceInfo> pieces) {
1115+
OUTCOME_TRY(c_type, cRegisteredUpdateProof(type));
1116+
OUTCOME_TRY(c_pieces, cPublicPieceInfos(pieces));
1117+
const auto res_ptr{
1118+
ffi::wrap(fil_empty_sector_update_encode_into(c_type,
1119+
path_update.c_str(),
1120+
path_update_cache.c_str(),
1121+
path_sealed.c_str(),
1122+
path_cache.c_str(),
1123+
path_unsealed.c_str(),
1124+
c_pieces.data(),
1125+
c_pieces.size()),
1126+
fil_destroy_empty_sector_update_encode_into_response)};
1127+
PROOFS_TRY("updateSeal");
1128+
SealedAndUnsealedCID result;
1129+
OUTCOME_TRYA(result.sealed_cid,
1130+
replicaCommitmentV1ToCID(res_ptr->comm_r_new));
1131+
OUTCOME_TRYA(result.unsealed_cid,
1132+
dataCommitmentV1ToCID(res_ptr->comm_d_new));
1133+
return result;
1134+
}
1135+
1136+
outcome::result<void> ProofEngineImpl::updateUnseal(
1137+
RegisteredUpdateProof type,
1138+
const std::string &path_unsealed,
1139+
const std::string &path_update,
1140+
const std::string &path_sealed,
1141+
const std::string &path_cache,
1142+
const CID &cid_unsealed) {
1143+
OUTCOME_TRY(c_type, cRegisteredUpdateProof(type));
1144+
OUTCOME_TRY(c_unsealed, CIDToDataCommitmentV1(cid_unsealed));
1145+
const auto res_ptr{
1146+
ffi::wrap(fil_empty_sector_update_decode_from(c_type,
1147+
path_unsealed.c_str(),
1148+
path_update.c_str(),
1149+
path_sealed.c_str(),
1150+
path_cache.c_str(),
1151+
c32ByteArray(c_unsealed)),
1152+
fil_destroy_empty_sector_update_decode_from_response)};
1153+
PROOFS_TRY("updateUnseal");
1154+
return outcome::success();
1155+
}
1156+
1157+
outcome::result<UpdateProofs1> ProofEngineImpl::updateProve1(
1158+
RegisteredUpdateProof type,
1159+
const CID &cid_sealed_old,
1160+
const CID &cid_sealed,
1161+
const CID &cid_unsealed,
1162+
const std::string &path_update,
1163+
const std::string &path_update_cache,
1164+
const std::string &path_sealed,
1165+
const std::string &path_cache) {
1166+
OUTCOME_TRY(c_type, cRegisteredUpdateProof(type));
1167+
OUTCOME_TRY(c_sealed_old, CIDToReplicaCommitmentV1(cid_sealed_old));
1168+
OUTCOME_TRY(c_sealed, CIDToReplicaCommitmentV1(cid_sealed));
1169+
OUTCOME_TRY(c_unsealed, CIDToDataCommitmentV1(cid_unsealed));
1170+
const auto res_ptr{ffi::wrap(
1171+
fil_generate_empty_sector_update_partition_proofs(
1172+
c_type,
1173+
c32ByteArray(c_sealed_old),
1174+
c32ByteArray(c_sealed),
1175+
c32ByteArray(c_unsealed),
1176+
path_sealed.c_str(),
1177+
path_cache.c_str(),
1178+
path_update.c_str(),
1179+
path_update_cache.c_str()),
1180+
fil_destroy_generate_empty_sector_update_partition_proof_response)};
1181+
PROOFS_TRY("updateProve1");
1182+
const auto c_proofs{
1183+
gsl::make_span(res_ptr->proofs_ptr, res_ptr->proofs_len)};
1184+
UpdateProofs1 result;
1185+
result.reserve(c_proofs.size());
1186+
for (const auto &c_proof : c_proofs) {
1187+
result.push_back(copy(BytesIn(c_proof.proof_ptr, c_proof.proof_len)));
1188+
}
1189+
return result;
1190+
}
1191+
1192+
outcome::result<Bytes> ProofEngineImpl::updateProve2(
1193+
RegisteredUpdateProof type,
1194+
const CID &cid_sealed_old,
1195+
const CID &cid_sealed,
1196+
const CID &cid_unsealed,
1197+
UpdateProofs1 proofs1) {
1198+
OUTCOME_TRY(c_type, cRegisteredUpdateProof(type));
1199+
OUTCOME_TRY(c_sealed_old, CIDToReplicaCommitmentV1(cid_sealed_old));
1200+
OUTCOME_TRY(c_sealed, CIDToReplicaCommitmentV1(cid_sealed));
1201+
OUTCOME_TRY(c_unsealed, CIDToDataCommitmentV1(cid_unsealed));
1202+
std::vector<fil_PartitionProof> c_proofs;
1203+
c_proofs.reserve(proofs1.size());
1204+
for (const auto &proof : proofs1) {
1205+
c_proofs.push_back({proof.size(), proof.data()});
1206+
}
1207+
const auto res_ptr{
1208+
ffi::wrap(fil_generate_empty_sector_update_proof_with_vanilla(
1209+
c_type,
1210+
c_proofs.data(),
1211+
c_proofs.size(),
1212+
c32ByteArray(c_sealed_old),
1213+
c32ByteArray(c_sealed),
1214+
c32ByteArray(c_unsealed)),
1215+
fil_destroy_empty_sector_update_generate_proof_response)};
1216+
PROOFS_TRY("updateProve2");
1217+
return copy(BytesIn(res_ptr->proof_ptr, res_ptr->proof_len));
1218+
}
11361219
} // namespace fc::proofs

core/proofs/impl/proof_engine_impl.hpp

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,6 @@ namespace fc::proofs {
113113
outcome::result<bool> verifyAggregateSeals(
114114
const AggregateSealVerifyProofAndInfos &aggregate) override;
115115

116-
outcome::result<Bytes> generateUpdateProof(
117-
RegisteredUpdateProof proof_type,
118-
const CID &old_sealed_cid,
119-
const CID &new_sealed_cid,
120-
const CID &unsealed_cid,
121-
const std::string &new_replica_path,
122-
const std::string &new_replica_cache_path,
123-
const std::string &sector_key_path,
124-
const std::string &sector_key_cache_path) override;
125-
126116
outcome::result<bool> verifyUpdateProof(
127117
const ReplicaUpdateInfo &info) override;
128118

@@ -168,6 +158,38 @@ namespace fc::proofs {
168158

169159
outcome::result<Devices> getGPUDevices() override;
170160

161+
outcome::result<SealedAndUnsealedCID> updateSeal(
162+
RegisteredUpdateProof type,
163+
const std::string &path_update,
164+
const std::string &path_update_cache,
165+
const std::string &path_sealed,
166+
const std::string &path_cache,
167+
const std::string &path_unsealed,
168+
gsl::span<const PieceInfo> pieces) override;
169+
170+
outcome::result<void> updateUnseal(RegisteredUpdateProof type,
171+
const std::string &path_unsealed,
172+
const std::string &path_update,
173+
const std::string &path_sealed,
174+
const std::string &path_cache,
175+
const CID &cid_unsealed) override;
176+
177+
outcome::result<UpdateProofs1> updateProve1(
178+
RegisteredUpdateProof type,
179+
const CID &cid_sealed_old,
180+
const CID &cid_sealed,
181+
const CID &cid_unsealed,
182+
const std::string &path_update,
183+
const std::string &path_update_cache,
184+
const std::string &path_sealed,
185+
const std::string &path_cache) override;
186+
187+
outcome::result<Bytes> updateProve2(RegisteredUpdateProof type,
188+
const CID &cid_sealed_old,
189+
const CID &cid_sealed,
190+
const CID &cid_unsealed,
191+
UpdateProofs1 proofs1) override;
192+
171193
private:
172194
common::Logger logger_;
173195
};

core/proofs/parameters.json

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,56 @@
44
"digest": "ae20310138f5ba81451d723f858e3797",
55
"sector_size": 0
66
},
7+
"v28-empty-sector-update-merkletree-poseidon_hasher-8-0-0-61fa69f38b9cc771ba27b670124714b4ea77fbeae05e377fb859c4a43b73a30c.params": {
8+
"cid": "Qma5WL6abSqYg9uUQAZ3EHS286bsNsha7oAGsJBD48Bq2q",
9+
"digest": "c3ad7bb549470b82ad52ed070aebb4f4",
10+
"sector_size": 536870912
11+
},
12+
"v28-empty-sector-update-merkletree-poseidon_hasher-8-0-0-61fa69f38b9cc771ba27b670124714b4ea77fbeae05e377fb859c4a43b73a30c.vk": {
13+
"cid": "QmUa7f9JtJMsqJJ3s3ZXk6WyF4xJLE8FiqYskZGgk8GCDv",
14+
"digest": "994c5b7d450ca9da348c910689f2dc7f",
15+
"sector_size": 536870912
16+
},
17+
"v28-empty-sector-update-merkletree-poseidon_hasher-8-0-0-92180959e1918d26350b8e6cfe217bbdd0a2d8de51ebec269078b364b715ad63.params": {
18+
"cid": "QmQiT4qBGodrVNEgVTDXxBNDdPbaD8Ag7Sx3ZTq1zHX79S",
19+
"digest": "5aedd2cf3e5c0a15623d56a1b43110ad",
20+
"sector_size": 8388608
21+
},
22+
"v28-empty-sector-update-merkletree-poseidon_hasher-8-0-0-92180959e1918d26350b8e6cfe217bbdd0a2d8de51ebec269078b364b715ad63.vk": {
23+
"cid": "QmdcpKUQvHM8RFRVKbk1yHfEqMcBzhtFWKRp9SNEmWq37i",
24+
"digest": "abd80269054d391a734febdac0d2e687",
25+
"sector_size": 8388608
26+
},
27+
"v28-empty-sector-update-merkletree-poseidon_hasher-8-0-0-fb9e095bebdd77511c0269b967b4d87ba8b8a525edaa0e165de23ba454510194.params": {
28+
"cid": "QmYM6Hg7mjmvA3ZHTsqkss1fkdyDju5dDmLiBZGJ5pz9y9",
29+
"digest": "311f92a3e75036ced01b1c0025f1fa0c",
30+
"sector_size": 2048
31+
},
32+
"v28-empty-sector-update-merkletree-poseidon_hasher-8-0-0-fb9e095bebdd77511c0269b967b4d87ba8b8a525edaa0e165de23ba454510194.vk": {
33+
"cid": "QmaQsTLL3nc5dw6wAvaioJSBfd1jhQrA2o6ucFf7XeV74P",
34+
"digest": "eadad9784969890d30f2749708c79771",
35+
"sector_size": 2048
36+
},
37+
"v28-empty-sector-update-merkletree-poseidon_hasher-8-8-0-3b7f44a9362e3985369454947bc94022e118211e49fd672d52bec1cbfd599d18.params": {
38+
"cid": "QmeNqDvsvyam4vqwCkstbxgb9S7RZEUeBDrJvBWKcpFKr6",
39+
"digest": "532b53883ed4f794cb9d0db583d0df59",
40+
"sector_size": 34359738368
41+
},
42+
"v28-empty-sector-update-merkletree-poseidon_hasher-8-8-0-3b7f44a9362e3985369454947bc94022e118211e49fd672d52bec1cbfd599d18.vk": {
43+
"cid": "QmdLWr6moLUPScJZwoBckWqAeJkrBPAJPNLz8mWAfTdmXH",
44+
"digest": "46990eb1bf5159c394a10309f269c1b6",
45+
"sector_size": 34359738368
46+
},
47+
"v28-empty-sector-update-merkletree-poseidon_hasher-8-8-2-102e1444a7e9a97ebf1e3d6855dcc77e66c011ea66f936d9b2c508f87f2f83a7.params": {
48+
"cid": "QmdQsi9uFhxK9cGwuK4rHuwKQoHkz6upYTCz4UdLiy1vA2",
49+
"digest": "4223c63dbd94de1538006a14f37179e3",
50+
"sector_size": 68719476736
51+
},
52+
"v28-empty-sector-update-merkletree-poseidon_hasher-8-8-2-102e1444a7e9a97ebf1e3d6855dcc77e66c011ea66f936d9b2c508f87f2f83a7.vk": {
53+
"cid": "QmPirFX9wX99iMGA6zFY2CvcrdcDkj73X4MP6DLduvpbk9",
54+
"digest": "ce39b614d788d3aef26bac1b28521d94",
55+
"sector_size": 68719476736
56+
},
757
"v28-proof-of-spacetime-fallback-merkletree-poseidon_hasher-8-0-0-0170db1f394b35d995252228ee359194b13199d259380541dc529fb0099096b0.params": {
858
"cid": "QmVxjFRyhmyQaZEtCh7nk2abc7LhFkzhnRX4rcHqCCpikR",
959
"digest": "7610b9f82bfc88405b7a832b651ce2f6",

core/proofs/proof_engine.hpp

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ namespace fc::proofs {
4343
using ChallengeIndexes = std::vector<uint64_t>;
4444
using UnsealedCID = CID;
4545
using Seed = primitives::sector::InteractiveRandomness;
46+
using UpdateProofs1 = std::vector<Bytes>;
4647

4748
struct PrivateSectorInfo {
4849
SectorInfo info;
@@ -268,19 +269,6 @@ namespace fc::proofs {
268269
virtual outcome::result<bool> verifyAggregateSeals(
269270
const AggregateSealVerifyProofAndInfos &aggregate) = 0;
270271

271-
/**
272-
* Generates update proof for empty sector
273-
*/
274-
virtual outcome::result<Bytes> generateUpdateProof(
275-
RegisteredUpdateProof proof_type,
276-
const CID &old_sealed_cid,
277-
const CID &new_sealed_cid,
278-
const CID &unsealed_cid,
279-
const std::string &new_replica_path,
280-
const std::string &new_replica_cache_path,
281-
const std::string &sector_key_path,
282-
const std::string &sector_key_cache_path) = 0;
283-
284272
/**
285273
* Verifies update proof for empty sector.
286274
*/
@@ -347,5 +335,37 @@ namespace fc::proofs {
347335
* be used
348336
*/
349337
virtual outcome::result<Devices> getGPUDevices() = 0;
338+
339+
virtual outcome::result<SealedAndUnsealedCID> updateSeal(
340+
RegisteredUpdateProof type,
341+
const std::string &path_update,
342+
const std::string &path_update_cache,
343+
const std::string &path_sealed,
344+
const std::string &path_cache,
345+
const std::string &path_unsealed,
346+
gsl::span<const PieceInfo> pieces) = 0;
347+
348+
virtual outcome::result<void> updateUnseal(RegisteredUpdateProof type,
349+
const std::string &path_unsealed,
350+
const std::string &path_update,
351+
const std::string &path_sealed,
352+
const std::string &path_cache,
353+
const CID &cid_unsealed) = 0;
354+
355+
virtual outcome::result<UpdateProofs1> updateProve1(
356+
RegisteredUpdateProof type,
357+
const CID &cid_sealed_old,
358+
const CID &cid_sealed,
359+
const CID &cid_unsealed,
360+
const std::string &path_update,
361+
const std::string &path_update_cache,
362+
const std::string &path_sealed,
363+
const std::string &path_cache) = 0;
364+
365+
virtual outcome::result<Bytes> updateProve2(RegisteredUpdateProof type,
366+
const CID &cid_sealed_old,
367+
const CID &cid_sealed,
368+
const CID &cid_unsealed,
369+
UpdateProofs1 proofs1) = 0;
350370
};
351371
} // namespace fc::proofs

core/vm/actor/cgo/go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ module _
33
go 1.14
44

55
require (
6-
github.com/filecoin-project/go-address v0.0.5
7-
github.com/filecoin-project/go-state-types v0.1.1-0.20210915140513-d354ccf10379
6+
github.com/filecoin-project/go-address v0.0.6
7+
github.com/filecoin-project/go-state-types v0.1.3
88
github.com/filecoin-project/specs-actors v0.9.14
9-
github.com/filecoin-project/specs-actors/v2 v2.3.5
9+
github.com/filecoin-project/specs-actors/v2 v2.3.6
1010
github.com/filecoin-project/specs-actors/v3 v3.1.1
1111
github.com/filecoin-project/specs-actors/v4 v4.0.1
1212
github.com/filecoin-project/specs-actors/v5 v5.0.4
13-
github.com/filecoin-project/specs-actors/v6 v6.0.0
13+
github.com/filecoin-project/specs-actors/v6 v6.0.1
1414
github.com/ipfs/go-cid v0.1.0
1515
github.com/whyrusleeping/cbor-gen v0.0.0-20210713220151-be142a5ae1a8
1616
)

0 commit comments

Comments
 (0)