Skip to content

Commit 0e71b16

Browse files
feat: update to v19 params and new porep
* feat: update to v18 params and new porep * refactor: update dependencies and remove once_cell * update cbindgen and switch fil_logger * update to v19 params
2 parents 021d3ba + ef762ad commit 0e71b16

File tree

10 files changed

+268
-313
lines changed

10 files changed

+268
-313
lines changed

.circleci/config.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ commands:
166166
steps:
167167
- run:
168168
name: Obtain filecoin groth parameters
169-
command: ./paramcache --params-for-sector-sizes=1024
169+
command: ./paramcache --params-for-sector-sizes='1024'
170170
no_output_timeout: 60m
171171
build_project:
172172
steps:
@@ -177,7 +177,7 @@ commands:
177177
name: Ensure paramcache is installed to project root
178178
command: |
179179
test -f ./paramcache \
180-
|| (rustup run --install nightly cargo install filecoin-proofs --force --git=https://github.com/filecoin-project/rust-fil-proofs.git --branch=bugs/v17-manifest --bin=paramcache --root=./ \
180+
|| (rustup run --install nightly cargo install filecoin-proofs --force --git=https://github.com/filecoin-project/rust-fil-proofs.git --branch=master --bin=paramcache --root=./ \
181181
&& mv ./bin/paramcache ./paramcache)
182182
no_output_timeout: 60m
183183
build_and_run_tests:
@@ -195,10 +195,10 @@ commands:
195195
steps:
196196
- restore_cache:
197197
keys:
198-
- v17b-proof-params-{{ arch }}
198+
- v19-proof-params-{{ arch }}
199199
save_parameter_cache:
200200
steps:
201201
- save_cache:
202-
key: v17b-proof-params-{{ arch }}
202+
key: v19-proof-params-{{ arch }}
203203
paths:
204204
- "~/filecoin-proof-parameters/"

rust/Cargo.lock

Lines changed: 212 additions & 266 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/Cargo.toml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,18 @@ storage-proofs = { git = "https://github.com/filecoin-project/rust-fil-proofs.gi
1818
bls-signatures = { git = "https://github.com/filecoin-project/bls-signatures.git", branch = "master" }
1919
byteorder = "1.2"
2020
drop_struct_macro_derive = "0.4.0"
21-
failure = "0.1.5"
22-
ff = "0.4"
21+
ff = "0.5"
2322
ffi-toolkit = "0.4.0"
2423
libc = "0.2.58"
2524
log = "0.4.7"
26-
once_cell = "0.2.4"
2725
paired = "0.16.0"
28-
pretty_env_logger = "0.3.0"
29-
rand = "0.4"
26+
fil_logger = "0.1.0"
27+
rand = "0.7"
3028
rayon = "1"
29+
anyhow = "1.0.23"
3130

3231
[build-dependencies]
33-
cbindgen = "0.9"
32+
cbindgen = "0.10"
3433

3534
[dev-dependencies]
3635
tempfile = "3.0.8"

rust/src/bls/api.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
use std::slice::from_raw_parts;
22

33
use bls_signatures::{
4-
aggregate as aggregate_sig, hash as hash_sig,
4+
aggregate as aggregate_sig,
5+
groupy::{CurveAffine, CurveProjective, EncodedPoint, GroupDecodingError},
6+
hash as hash_sig,
57
paired::bls12_381::{G2Affine, G2Compressed},
6-
paired::GroupDecodingError,
7-
paired::{CurveAffine, CurveProjective, EncodedPoint},
88
verify as verify_sig, PrivateKey, PublicKey, Serialize, Signature,
99
};
1010
use libc;
11-
use rand::OsRng;
11+
use rand::rngs::OsRng;
1212

1313
use rayon::prelude::*;
1414

@@ -161,10 +161,8 @@ pub unsafe extern "C" fn verify(
161161
/// * `raw_seed_ptr` - pointer to a seed byte array
162162
#[no_mangle]
163163
pub unsafe extern "C" fn private_key_generate() -> *mut types::PrivateKeyGenerateResponse {
164-
let rng = &mut OsRng::new().expect("not enough randomness");
165-
166164
let mut raw_private_key: [u8; PRIVATE_KEY_BYTES] = [0; PRIVATE_KEY_BYTES];
167-
PrivateKey::generate(rng)
165+
PrivateKey::generate(&mut OsRng)
168166
.write_bytes(&mut raw_private_key.as_mut())
169167
.expect("preallocated");
170168

rust/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#![allow(clippy::missing_safety_doc)]
33

44
#[macro_use]
5-
extern crate failure;
5+
extern crate anyhow;
66
#[macro_use]
77
extern crate log;
88

rust/src/proofs/api.rs

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::mem;
22
use std::slice::from_raw_parts;
3+
use std::sync::Once;
34

45
use ffi_toolkit::{
56
c_str_to_pbuf, catch_panic_response, raw_ptr, rust_str_to_c_str, FCPResponseStatus,
@@ -10,7 +11,6 @@ use filecoin_proofs::{
1011
PoStConfig, SectorClass, SectorSize, UnpaddedByteIndex, UnpaddedBytesAmount,
1112
};
1213
use libc;
13-
use once_cell::sync::OnceCell;
1414
use storage_proofs::hasher::pedersen::PedersenDomain;
1515
use storage_proofs::hasher::Domain;
1616
use storage_proofs::sector::SectorId;
@@ -320,8 +320,11 @@ pub unsafe extern "C" fn verify_seal(
320320
let porep_bytes = super::helpers::try_into_porep_proof_bytes(proof_ptr, proof_len);
321321

322322
let result = porep_bytes.and_then(|bs| {
323-
super::helpers::porep_proof_partitions_try_from_bytes(&bs).and_then(|ppp| {
324-
let cfg = api_types::PoRepConfig(api_types::SectorSize(sector_size), ppp);
323+
super::helpers::porep_proof_partitions_try_from_bytes(&bs).and_then(|partitions| {
324+
let cfg = api_types::PoRepConfig {
325+
sector_size: api_types::SectorSize(sector_size),
326+
partitions,
327+
};
325328

326329
api_fns::verify_seal(
327330
cfg,
@@ -419,9 +422,11 @@ pub unsafe extern "C" fn verify_post(
419422
let result = convert.and_then(|map| {
420423
let proofs = c_to_rust_proofs(flattened_proofs_ptr, flattened_proofs_len)?;
421424
let winners = c_to_rust_candidates(winners_ptr, winners_len)?;
422-
425+
let cfg = api_types::PoStConfig {
426+
sector_size: api_types::SectorSize(sector_size),
427+
};
423428
api_fns::verify_post(
424-
api_types::PoStConfig(api_types::SectorSize(sector_size)),
429+
cfg,
425430
randomness,
426431
challenge_count,
427432
&proofs,
@@ -504,7 +509,10 @@ pub unsafe extern "C" fn generate_data_commitment(
504509
.collect();
505510

506511
let result = api_fns::compute_comm_d(
507-
PoRepConfig(SectorSize(sector_size), PoRepProofPartitions(0)),
512+
PoRepConfig {
513+
sector_size: SectorSize(sector_size),
514+
partitions: PoRepProofPartitions(0),
515+
},
508516
&public_pieces,
509517
);
510518

@@ -545,7 +553,9 @@ pub unsafe extern "C" fn generate_candidates(
545553

546554
let result = to_private_replica_info_map(replicas_ptr, replicas_len).and_then(|rs| {
547555
api_fns::generate_candidates(
548-
PoStConfig(SectorSize(sector_size)),
556+
PoStConfig {
557+
sector_size: SectorSize(sector_size),
558+
},
549559
randomness,
550560
challenge_count,
551561
&rs,
@@ -603,7 +613,9 @@ pub unsafe extern "C" fn generate_post(
603613

604614
let result = to_private_replica_info_map(replicas_ptr, replicas_len).and_then(|rs| {
605615
api_fns::generate_post(
606-
PoStConfig(SectorSize(sector_size)),
616+
PoStConfig {
617+
sector_size: SectorSize(sector_size),
618+
},
607619
randomness,
608620
&rs,
609621
c_to_rust_candidates(winners_ptr, winners_len)?,
@@ -718,13 +730,12 @@ pub unsafe extern "C" fn destroy_generate_candidates_response(
718730
}
719731

720732
/// Protects the init off the logger.
721-
static LOG_INIT: OnceCell<bool> = OnceCell::new();
733+
static LOG_INIT: Once = Once::new();
722734

723735
/// Ensures the logger is initialized.
724736
fn init_log() {
725-
LOG_INIT.get_or_init(|| {
726-
let _ = pretty_env_logger::try_init_timed();
727-
true
737+
LOG_INIT.call_once(|| {
738+
fil_logger::init();
728739
});
729740
}
730741

@@ -733,13 +744,14 @@ pub mod tests {
733744
use std::io::{Read, Seek, SeekFrom, Write};
734745
use std::os::unix::io::IntoRawFd;
735746

747+
use anyhow::Result;
736748
use ffi_toolkit::{c_str_to_rust_str, FCPResponseStatus};
737749
use rand::{thread_rng, Rng};
738750

739751
use super::*;
740752

741753
#[test]
742-
fn test_write_with_and_without_alignment() -> Result<(), failure::Error> {
754+
fn test_write_with_and_without_alignment() -> Result<()> {
743755
// write some bytes to a temp file to be used as the byte source
744756
let mut rng = thread_rng();
745757
let buf: Vec<u8> = (0..508).map(|_| rng.gen()).collect();
@@ -802,7 +814,7 @@ pub mod tests {
802814
}
803815

804816
#[test]
805-
fn test_sealing() -> Result<(), failure::Error> {
817+
fn test_sealing() -> Result<()> {
806818
// miscellaneous setup and shared values
807819
let sector_class = FFISectorClass {
808820
sector_size: 1024,

rust/src/proofs/error.rs

Lines changed: 0 additions & 1 deletion
This file was deleted.

rust/src/proofs/helpers.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
use std::collections::btree_map::BTreeMap;
22
use std::slice::from_raw_parts;
33

4+
use anyhow::Result;
45
use ffi_toolkit::{c_str_to_pbuf, c_str_to_rust_str};
56
use filecoin_proofs::{constants as api_constants, Commitment, PublicReplicaInfo};
67
use filecoin_proofs::{types as api_types, PrivateReplicaInfo};
78
use libc;
89
use paired::bls12_381::{Bls12, Fr};
10+
use storage_proofs::election_post::Candidate;
911
use storage_proofs::fr32::fr_into_bytes;
1012
use storage_proofs::sector::SectorId;
1113

1214
use super::types::{FFICandidate, FFIPrivateReplicaInfo};
13-
use storage_proofs::election_post::Candidate;
1415

1516
/// Produce a map from sector id to replica info by pairing sector ids and
1617
/// replica commitments (by index in their respective arrays), setting the
@@ -23,7 +24,7 @@ pub unsafe fn to_public_replica_info_map(
2324
sector_ids_len: libc::size_t,
2425
flattened_comm_rs_ptr: *const u8,
2526
flattened_comm_rs_len: libc::size_t,
26-
) -> super::error::Result<BTreeMap<SectorId, PublicReplicaInfo>> {
27+
) -> Result<BTreeMap<SectorId, PublicReplicaInfo>> {
2728
ensure!(!sector_ids_ptr.is_null(), "sector_ids_ptr must not be null");
2829
ensure!(
2930
!flattened_comm_rs_ptr.is_null(),
@@ -58,7 +59,7 @@ pub unsafe fn to_public_replica_info_map(
5859
pub unsafe fn try_into_porep_proof_bytes(
5960
proof_ptr: *const u8,
6061
proof_len: libc::size_t,
61-
) -> super::error::Result<Vec<u8>> {
62+
) -> Result<Vec<u8>> {
6263
into_proof_vecs(proof_len, proof_ptr, proof_len)?
6364
.first()
6465
.map(Vec::clone)
@@ -89,7 +90,7 @@ pub unsafe fn into_commitments(
8990
///
9091
pub fn porep_proof_partitions_try_from_bytes(
9192
proof: &[u8],
92-
) -> super::error::Result<api_types::PoRepProofPartitions> {
93+
) -> Result<api_types::PoRepProofPartitions> {
9394
let n = proof.len();
9495

9596
ensure!(
@@ -107,7 +108,7 @@ unsafe fn into_proof_vecs(
107108
proof_chunk: usize,
108109
flattened_proofs_ptr: *const u8,
109110
flattened_proofs_len: libc::size_t,
110-
) -> super::error::Result<Vec<Vec<u8>>> {
111+
) -> Result<Vec<Vec<u8>>> {
111112
ensure!(
112113
!flattened_proofs_ptr.is_null(),
113114
"flattened_proofs_ptr must not be a null pointer"
@@ -137,7 +138,7 @@ pub fn bls_12_fr_into_bytes(fr: Fr) -> [u8; 32] {
137138
pub unsafe fn to_private_replica_info_map(
138139
replicas_ptr: *const FFIPrivateReplicaInfo,
139140
replicas_len: libc::size_t,
140-
) -> super::error::Result<BTreeMap<SectorId, PrivateReplicaInfo>> {
141+
) -> Result<BTreeMap<SectorId, PrivateReplicaInfo>> {
141142
ensure!(!replicas_ptr.is_null(), "replicas_ptr must not be null");
142143

143144
from_raw_parts(replicas_ptr, replicas_len)
@@ -168,7 +169,7 @@ pub unsafe fn to_private_replica_info_map(
168169
pub unsafe fn c_to_rust_candidates(
169170
winners_ptr: *const FFICandidate,
170171
winners_len: libc::size_t,
171-
) -> super::error::Result<Vec<Candidate>> {
172+
) -> Result<Vec<Candidate>> {
172173
ensure!(!winners_ptr.is_null(), "winners_ptr must not be null");
173174

174175
from_raw_parts(winners_ptr, winners_len)
@@ -181,7 +182,7 @@ pub unsafe fn c_to_rust_candidates(
181182
pub unsafe fn c_to_rust_proofs(
182183
flattened_proofs_ptr: *const u8,
183184
flattened_proofs_len: libc::size_t,
184-
) -> super::error::Result<Vec<Vec<u8>>> {
185+
) -> Result<Vec<Vec<u8>>> {
185186
ensure!(
186187
!flattened_proofs_ptr.is_null(),
187188
"flattened_proof_ptr must not be null"

rust/src/proofs/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
mod error;
21
mod helpers;
32

43
pub mod api;

rust/src/proofs/types.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::ptr;
44
use drop_struct_macro_derive::DropStructMacro;
55
use paired::bls12_381::Bls12;
66
// `CodeAndMessage` is the trait implemented by `code_and_message_impl`
7+
use anyhow::Result;
78
use ffi_toolkit::{code_and_message_impl, free_c_str, CodeAndMessage, FCPResponseStatus};
89
use filecoin_proofs::{Candidate, PieceInfo, SectorClass, UnpaddedBytesAmount};
910
use storage_proofs::fr32::bytes_into_fr;
@@ -65,10 +66,10 @@ impl From<FFISectorClass> for SectorClass {
6566
porep_proof_partitions,
6667
} = fsc;
6768

68-
SectorClass(
69-
filecoin_proofs::SectorSize(sector_size),
70-
filecoin_proofs::PoRepProofPartitions(porep_proof_partitions),
71-
)
69+
SectorClass {
70+
sector_size: filecoin_proofs::SectorSize(sector_size),
71+
partitions: filecoin_proofs::PoRepProofPartitions(porep_proof_partitions),
72+
}
7273
}
7374
}
7475

@@ -99,7 +100,7 @@ pub struct FFICandidate {
99100
}
100101

101102
impl FFICandidate {
102-
pub fn try_into_candidate(self) -> Result<Candidate, storage_proofs::error::Error> {
103+
pub fn try_into_candidate(self) -> Result<Candidate> {
103104
let FFICandidate {
104105
sector_id,
105106
partial_ticket,

0 commit comments

Comments
 (0)