Skip to content

Commit

Permalink
fix: apply some review feedback
Browse files Browse the repository at this point in the history
feat: re-factor some tests
  • Loading branch information
cryptonemo committed Oct 30, 2023
1 parent 0b8975f commit c207e75
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 104 deletions.
24 changes: 4 additions & 20 deletions filecoin-proofs/src/api/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,6 @@ pub struct SectorUpdateProofInputs {
pub comm_d_new: Commitment,
}

impl SectorUpdateProofInputs {
pub fn write_bytes(&self, dest: &mut [u8]) {
dest[0..32].copy_from_slice(&self.comm_r_old[..]);
dest[33..64].copy_from_slice(&self.comm_r_new[..]);
dest[65..96].copy_from_slice(&self.comm_d_new[..]);
}

pub fn update_commitment(&self, hasher: &mut Sha256) {
hasher.update(self.comm_r_old);
hasher.update(self.comm_r_new);
hasher.update(self.comm_d_new);
}
}

// Re-instantiate a t_aux with the new cache path, then use the tree_d
// and tree_r_last configs from it. This is done to preserve the
// original tree configuration info (in particular, the
Expand Down Expand Up @@ -763,7 +749,9 @@ fn get_hashed_commitments(sector_update_inputs: &[SectorUpdateProofInputs]) -> [
let hashed_commitments: [u8; 32] = {
let mut hasher = Sha256::new();
for input in sector_update_inputs.iter() {
input.update_commitment(&mut hasher);
hasher.update(input.comm_r_old);
hasher.update(input.comm_r_new);
hasher.update(input.comm_d_new);
}
hasher.finalize().into()
};
Expand Down Expand Up @@ -800,15 +788,11 @@ pub fn aggregate_empty_sector_update_proofs<

let config = SectorUpdateConfig::from_porep_config(porep_config);
let partitions = usize::from(config.update_partitions);
let verifying_key = get_empty_sector_update_verifying_key::<Tree>(porep_config)?;

let mut proofs: Vec<_> = proofs
.iter()
.try_fold(Vec::new(), |mut acc, proof| -> Result<_> {
acc.extend(
MultiProof::new_from_reader(Some(partitions), proof.0.as_slice(), &verifying_key)?
.circuit_proofs,
);
acc.extend(groth16::Proof::read_many(proof.0.as_slice(), partitions)?);

Ok(acc)
})?;
Expand Down
221 changes: 137 additions & 84 deletions filecoin-proofs/tests/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ use filecoin_proofs::constants::MAX_LEGACY_REGISTERED_SEAL_PROOF_ID;

#[cfg(feature = "big-tests")]
use filecoin_proofs::{
SectorShape32GiB, SectorShape512MiB, SectorShape64GiB, SECTOR_SIZE_32_GIB, SECTOR_SIZE_512_MIB,
SECTOR_SIZE_64_GIB,
SectorShape512MiB, SectorShape64GiB, SECTOR_SIZE_512_MIB, SECTOR_SIZE_64_GIB,
};

// Use a fixed PoRep ID, so that the parents cache can be re-used between some tests.
Expand Down Expand Up @@ -147,32 +146,35 @@ fn test_get_sector_update_inputs() -> Result<()> {
fn test_seal_lifecycle_2kib_base_8() -> Result<()> {
// The first value is RegisteredSealProof value
// The second value is the ApiVersion to use
// The third value is whether to use SyntheticPoRep
// The third value is enabled Api features
let test_inputs = vec![
(0u64, ApiVersion::V1_0_0, false),
(0u64, ApiVersion::V1_0_0, Vec::new()),
(
MAX_LEGACY_REGISTERED_SEAL_PROOF_ID + 1,
ApiVersion::V1_1_0,
false,
Vec::new(),
),
(
MAX_LEGACY_REGISTERED_SEAL_PROOF_ID + 1,
ApiVersion::V1_2_0,
false,
Vec::new(),
),
(
MAX_LEGACY_REGISTERED_SEAL_PROOF_ID + 1,
ApiVersion::V1_2_0,
true,
vec![ApiFeature::SyntheticPoRep],
),
];

for (porep_id_num, api_version, use_synthetic) in test_inputs {
for (porep_id_num, api_version, features) in test_inputs {
let porep_id = to_porep_id_verified(porep_id_num, api_version);
let mut porep_config = PoRepConfig::new_groth16(SECTOR_SIZE_2_KIB, porep_id, api_version);
if use_synthetic {
porep_config.enable_feature(ApiFeature::SyntheticPoRep);
}
let porep_config = PoRepConfig::new_groth16_with_features(
SECTOR_SIZE_2_KIB,
porep_id,
api_version,
features,
);

seal_lifecycle::<SectorShape2KiB>(&porep_config)?;
}

Expand All @@ -184,31 +186,34 @@ fn test_seal_lifecycle_2kib_base_8() -> Result<()> {
fn test_seal_lifecycle_upgrade_2kib_base_8() -> Result<()> {
// The first value is RegisteredSealProof value
// The second value is the ApiVersion to use
// The third value is whether to use SyntheticPoRep
// The third value is enabled Api features
let test_inputs = vec![
(
MAX_LEGACY_REGISTERED_SEAL_PROOF_ID + 1,
ApiVersion::V1_1_0,
false,
Vec::new(),
),
(
MAX_LEGACY_REGISTERED_SEAL_PROOF_ID + 1,
ApiVersion::V1_2_0,
false,
Vec::new(),
),
(
MAX_LEGACY_REGISTERED_SEAL_PROOF_ID + 1,
ApiVersion::V1_2_0,
true,
vec![ApiFeature::SyntheticPoRep],
),
];

for (porep_id_num, api_version, use_synthetic) in test_inputs {
for (porep_id_num, api_version, features) in test_inputs {
let porep_id = to_porep_id_verified(porep_id_num, api_version);
let mut porep_config = PoRepConfig::new_groth16(SECTOR_SIZE_2_KIB, porep_id, api_version);
if use_synthetic {
porep_config.enable_feature(ApiFeature::SyntheticPoRep);
}
let porep_config = PoRepConfig::new_groth16_with_features(
SECTOR_SIZE_2_KIB,
porep_id,
api_version,
features,
);

seal_lifecycle_upgrade::<SectorShape2KiB>(&porep_config)?;
}

Expand All @@ -219,17 +224,24 @@ fn test_seal_lifecycle_upgrade_2kib_base_8() -> Result<()> {
#[ignore]
fn test_seal_lifecycle_4kib_base_8() -> Result<()> {
let test_inputs = vec![
(ARBITRARY_POREP_ID_V1_0_0, ApiVersion::V1_0_0, false),
(ARBITRARY_POREP_ID_V1_1_0, ApiVersion::V1_1_0, false),
(ARBITRARY_POREP_ID_V1_2_0, ApiVersion::V1_2_0, false),
(ARBITRARY_POREP_ID_V1_2_0, ApiVersion::V1_2_0, true),
(ARBITRARY_POREP_ID_V1_0_0, ApiVersion::V1_0_0, Vec::new()),
(ARBITRARY_POREP_ID_V1_1_0, ApiVersion::V1_1_0, Vec::new()),
(ARBITRARY_POREP_ID_V1_2_0, ApiVersion::V1_2_0, Vec::new()),
(
ARBITRARY_POREP_ID_V1_2_0,
ApiVersion::V1_2_0,
vec![ApiFeature::SyntheticPoRep],
),
];

for (porep_id, api_version, use_synthetic) in test_inputs {
let mut porep_config = PoRepConfig::new_groth16(SECTOR_SIZE_4_KIB, porep_id, api_version);
if use_synthetic {
porep_config.enable_feature(ApiFeature::SyntheticPoRep);
}
for (porep_id, api_version, features) in test_inputs {
let porep_config = PoRepConfig::new_groth16_with_features(
SECTOR_SIZE_4_KIB,
porep_id,
api_version,
features,
);

seal_lifecycle::<SectorShape4KiB>(&porep_config)?;
}

Expand All @@ -240,17 +252,24 @@ fn test_seal_lifecycle_4kib_base_8() -> Result<()> {
#[ignore]
fn test_seal_lifecycle_upgrade_4kib_base_8() -> Result<()> {
let test_inputs = vec![
(ARBITRARY_POREP_ID_V1_0_0, ApiVersion::V1_0_0, false),
(ARBITRARY_POREP_ID_V1_1_0, ApiVersion::V1_1_0, false),
(ARBITRARY_POREP_ID_V1_2_0, ApiVersion::V1_2_0, false),
(ARBITRARY_POREP_ID_V1_2_0, ApiVersion::V1_2_0, true),
(ARBITRARY_POREP_ID_V1_0_0, ApiVersion::V1_0_0, Vec::new()),
(ARBITRARY_POREP_ID_V1_1_0, ApiVersion::V1_1_0, Vec::new()),
(ARBITRARY_POREP_ID_V1_2_0, ApiVersion::V1_2_0, Vec::new()),
(
ARBITRARY_POREP_ID_V1_2_0,
ApiVersion::V1_2_0,
vec![ApiFeature::SyntheticPoRep],
),
];

for (porep_id, api_version, use_synthetic) in test_inputs {
let mut porep_config = PoRepConfig::new_groth16(SECTOR_SIZE_4_KIB, porep_id, api_version);
if use_synthetic {
porep_config.enable_feature(ApiFeature::SyntheticPoRep);
}
for (porep_id, api_version, features) in test_inputs {
let porep_config = PoRepConfig::new_groth16_with_features(
SECTOR_SIZE_4_KIB,
porep_id,
api_version,
features,
);

seal_lifecycle_upgrade::<SectorShape4KiB>(&porep_config)?;
}

Expand All @@ -261,17 +280,24 @@ fn test_seal_lifecycle_upgrade_4kib_base_8() -> Result<()> {
#[ignore]
fn test_seal_lifecycle_16kib_base_8() -> Result<()> {
let test_inputs = vec![
(ARBITRARY_POREP_ID_V1_0_0, ApiVersion::V1_0_0, false),
(ARBITRARY_POREP_ID_V1_1_0, ApiVersion::V1_1_0, false),
(ARBITRARY_POREP_ID_V1_2_0, ApiVersion::V1_2_0, false),
(ARBITRARY_POREP_ID_V1_2_0, ApiVersion::V1_2_0, true),
(ARBITRARY_POREP_ID_V1_0_0, ApiVersion::V1_0_0, Vec::new()),
(ARBITRARY_POREP_ID_V1_1_0, ApiVersion::V1_1_0, Vec::new()),
(ARBITRARY_POREP_ID_V1_2_0, ApiVersion::V1_2_0, Vec::new()),
(
ARBITRARY_POREP_ID_V1_2_0,
ApiVersion::V1_2_0,
vec![ApiFeature::SyntheticPoRep],
),
];

for (porep_id, api_version, use_synthetic) in test_inputs {
let mut porep_config = PoRepConfig::new_groth16(SECTOR_SIZE_16_KIB, porep_id, api_version);
if use_synthetic {
porep_config.enable_feature(ApiFeature::SyntheticPoRep);
}
for (porep_id, api_version, features) in test_inputs {
let porep_config = PoRepConfig::new_groth16_with_features(
SECTOR_SIZE_16_KIB,
porep_id,
api_version,
features,
);

seal_lifecycle::<SectorShape16KiB>(&porep_config)?;
}

Expand All @@ -282,17 +308,24 @@ fn test_seal_lifecycle_16kib_base_8() -> Result<()> {
#[ignore]
fn test_seal_lifecycle_upgrade_16kib_base_8() -> Result<()> {
let test_inputs = vec![
(ARBITRARY_POREP_ID_V1_0_0, ApiVersion::V1_0_0, false),
(ARBITRARY_POREP_ID_V1_1_0, ApiVersion::V1_1_0, false),
(ARBITRARY_POREP_ID_V1_2_0, ApiVersion::V1_2_0, false),
(ARBITRARY_POREP_ID_V1_2_0, ApiVersion::V1_2_0, true),
(ARBITRARY_POREP_ID_V1_0_0, ApiVersion::V1_0_0, Vec::new()),
(ARBITRARY_POREP_ID_V1_1_0, ApiVersion::V1_1_0, Vec::new()),
(ARBITRARY_POREP_ID_V1_2_0, ApiVersion::V1_2_0, Vec::new()),
(
ARBITRARY_POREP_ID_V1_2_0,
ApiVersion::V1_2_0,
vec![ApiFeature::SyntheticPoRep],
),
];

for (porep_id, api_version, use_synthetic) in test_inputs {
let mut porep_config = PoRepConfig::new_groth16(SECTOR_SIZE_16_KIB, porep_id, api_version);
if use_synthetic {
porep_config.enable_feature(ApiFeature::SyntheticPoRep);
}
for (porep_id, api_version, features) in test_inputs {
let porep_config = PoRepConfig::new_groth16_with_features(
SECTOR_SIZE_16_KIB,
porep_id,
api_version,
features,
);

seal_lifecycle_upgrade::<SectorShape16KiB>(&porep_config)?;
}

Expand All @@ -303,17 +336,24 @@ fn test_seal_lifecycle_upgrade_16kib_base_8() -> Result<()> {
#[ignore]
fn test_seal_lifecycle_32kib_base_8() -> Result<()> {
let test_inputs = vec![
(ARBITRARY_POREP_ID_V1_0_0, ApiVersion::V1_0_0, false),
(ARBITRARY_POREP_ID_V1_1_0, ApiVersion::V1_1_0, false),
(ARBITRARY_POREP_ID_V1_2_0, ApiVersion::V1_2_0, false),
(ARBITRARY_POREP_ID_V1_2_0, ApiVersion::V1_2_0, true),
(ARBITRARY_POREP_ID_V1_0_0, ApiVersion::V1_0_0, Vec::new()),
(ARBITRARY_POREP_ID_V1_1_0, ApiVersion::V1_1_0, Vec::new()),
(ARBITRARY_POREP_ID_V1_2_0, ApiVersion::V1_2_0, Vec::new()),
(
ARBITRARY_POREP_ID_V1_2_0,
ApiVersion::V1_2_0,
vec![ApiFeature::SyntheticPoRep],
),
];

for (porep_id, api_version, use_synthetic) in test_inputs {
let mut porep_config = PoRepConfig::new_groth16(SECTOR_SIZE_32_KIB, porep_id, api_version);
if use_synthetic {
porep_config.enable_feature(ApiFeature::SyntheticPoRep);
}
for (porep_id, api_version, features) in test_inputs {
let porep_config = PoRepConfig::new_groth16_with_features(
SECTOR_SIZE_32_KIB,
porep_id,
api_version,
features,
);

seal_lifecycle::<SectorShape32KiB>(&porep_config)?;
}

Expand Down Expand Up @@ -353,11 +393,16 @@ fn test_seal_lifecycle_512mib_porep_id_v1_top_8_0_0_api_v1_1() -> Result<()> {
#[cfg(feature = "big-tests")]
#[test]
fn test_seal_lifecycle_upgrade_512mib_top_8_0_0_v1_1() -> Result<()> {
seal_lifecycle_upgrade::<SectorShape512MiB>(
SECTOR_SIZE_512_MIB,
&ARBITRARY_POREP_ID_V1_1_0,
ApiVersion::V1_1_0,
)
use filecoin_proofs::{SectorShape512MiB, SECTOR_SIZE_512_MIB};
let porep_id_v1_1: u64 = 7; // This is a RegisteredSealProof value

let mut porep_id = [0u8; 32];
porep_id[..8].copy_from_slice(&porep_id_v1_1.to_le_bytes());
assert!(!is_legacy_porep_id(porep_id));

let porep_config = PoRepConfig::new_groth16(SECTOR_SIZE_512_MIB, porep_id, ApiVersion::V1_1_0);

seal_lifecycle_upgrade::<SectorShape512MiB>(&porep_config)
}

#[cfg(feature = "big-tests")]
Expand Down Expand Up @@ -404,11 +449,14 @@ fn test_seal_lifecycle_32gib_porep_id_v1_2_top_8_8_0_api_v1_2() -> Result<()> {
#[cfg(feature = "big-tests")]
#[test]
fn test_seal_lifecycle_upgrade_32gib_top_8_8_0_v1_1() -> Result<()> {
seal_lifecycle_upgrade::<SectorShape32GiB>(
SECTOR_SIZE_32_GIB,
&ARBITRARY_POREP_ID_V1_1_0,
ApiVersion::V1_1_0,
)
let porep_id_v1_1: u64 = 8; // This is a RegisteredSealProof value

let porep_id = to_porep_id_verified(porep_id_v1_1, ApiVersion::V1_1_0);
assert!(!is_legacy_porep_id(porep_id));

let porep_config = PoRepConfig::new_groth16(SECTOR_SIZE_32_GIB, porep_id, ApiVersion::V1_1_0);

seal_lifecycle_upgrade::<SectorShape32GiB>(&porep_config)
}

#[cfg(feature = "big-tests")]
Expand Down Expand Up @@ -445,21 +493,26 @@ fn test_seal_lifecycle_64gib_porep_id_v1_2_top_8_8_2_api_v1_2() -> Result<()> {
let porep_id = to_porep_id_verified(porep_id_v1_2, ApiVersion::V1_2_0);
assert!(!is_legacy_porep_id(porep_id));

let mut porep_config =
PoRepConfig::new_groth16(SECTOR_SIZE_64_GIB, porep_id, ApiVersion::V1_2_0);
porep_config.enable_feature(ApiFeature::SyntheticPoRep);
let porep_config = PoRepConfig::new_groth16_with_features(
SECTOR_SIZE_64_GIB,
porep_id,
ApiVersion::V1_2_0,
vec![ApiFeature::SyntheticPoRep],
);

seal_lifecycle::<SectorShape64GiB>(&porep_config)
}

#[cfg(feature = "big-tests")]
#[test]
fn test_seal_lifecycle_upgrade_64gib_top_8_8_2_v1_1() -> Result<()> {
seal_lifecycle_upgrade::<SectorShape64GiB>(
SECTOR_SIZE_64_GIB,
&ARBITRARY_POREP_ID_V1_1_0,
ApiVersion::V1_1_0,
)
let porep_id_v1_1: u64 = 9; // This is a RegisteredSealProof value

let porep_id = to_porep_id_verified(porep_id_v1_1, ApiVersion::V1_1_0);
assert!(!is_legacy_porep_id(porep_id));
let porep_config = PoRepConfig::new_groth16(SECTOR_SIZE_64_GIB, porep_id, ApiVersion::V1_1_0);

seal_lifecycle_upgrade::<SectorShape64GiB>(&porep_config)
}

fn seal_lifecycle<Tree: 'static + MerkleTreeTrait>(porep_config: &PoRepConfig) -> Result<()> {
Expand Down

0 comments on commit c207e75

Please sign in to comment.