Skip to content

Commit

Permalink
feat: fail verification of empty proof bytes (#1498)
Browse files Browse the repository at this point in the history
* feat: fail verification of empty proof bytes

* feat: update xcode version to a CI supported version
  • Loading branch information
cryptonemo authored Aug 26, 2021
1 parent 13967bf commit 9cc6444
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ jobs:
command: cargo +$(cat rust-toolchain) clippy --all-targets --workspace -- -D warnings
test_darwin:
macos:
xcode: "10.0.0"
xcode: "12.5.0"
working_directory: ~/crate
resource_class: large
environment: *setup-env
Expand Down
5 changes: 5 additions & 0 deletions filecoin-proofs/src/api/seal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -925,8 +925,10 @@ pub fn verify_seal<Tree: 'static + MerkleTreeTrait>(
proof_vec: &[u8],
) -> Result<bool> {
info!("verify_seal:start: {:?}", sector_id);

ensure!(comm_d_in != [0; 32], "Invalid all zero commitment (comm_d)");
ensure!(comm_r_in != [0; 32], "Invalid all zero commitment (comm_r)");
ensure!(!proof_vec.is_empty(), "Invalid proof bytes (empty vector)");

let comm_r: <Tree::Hasher as Hasher>::Domain = as_safe_commitment(&comm_r_in, "comm_r")?;
let comm_d: DefaultPieceDomain = as_safe_commitment(&comm_d_in, "comm_d")?;
Expand Down Expand Up @@ -1042,6 +1044,9 @@ pub fn verify_batch_seal<Tree: 'static + MerkleTreeTrait>(
"Invalid all zero commitment (comm_r)"
);
}
for proofs in proof_vecs {
ensure!(!proofs.is_empty(), "Invalid proof (empty bytes) found");
}

let sector_bytes = PaddedBytesAmount::from(porep_config);

Expand Down
46 changes: 46 additions & 0 deletions filecoin-proofs/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ fn test_verify_seal_fr32_validation() {
assert!(out.is_err(), "tripwire");

let arbitrary_porep_id = [87; 32];

// Test failure for invalid comm_r conversion.
{
let result = verify_seal::<DefaultOctLCTree>(
PoRepConfig {
Expand Down Expand Up @@ -60,6 +62,7 @@ fn test_verify_seal_fr32_validation() {
}
}

// Test failure for invalid comm_d conversion.
{
let result = verify_seal::<DefaultOctLCTree>(
PoRepConfig {
Expand Down Expand Up @@ -97,6 +100,49 @@ fn test_verify_seal_fr32_validation() {
panic_any("should have failed comm_d to Fr32 conversion");
}
}

// Test failure for verifying an empty proof.
{
let non_zero_commitment_fr_bytes = [1; 32];
let out = bytes_into_fr(&non_zero_commitment_fr_bytes);
assert!(out.is_ok(), "tripwire");

let result = verify_seal::<DefaultOctLCTree>(
PoRepConfig {
sector_size: SectorSize(SECTOR_SIZE_2_KIB),
partitions: PoRepProofPartitions(
*POREP_PARTITIONS
.read()
.expect("POREP_PARTITIONS poisoned")
.get(&SECTOR_SIZE_2_KIB)
.expect("unknown sector size"),
),
porep_id: arbitrary_porep_id,
api_version: ApiVersion::V1_1_0,
},
non_zero_commitment_fr_bytes,
non_zero_commitment_fr_bytes,
[0; 32],
SectorId::from(0),
[0; 32],
[0; 32],
&[],
);

if let Err(err) = result {
let needle = "Invalid proof bytes (empty vector)";
let haystack = format!("{}", err);

assert!(
haystack.contains(needle),
"\"{}\" did not contain \"{}\"",
haystack,
needle,
);
} else {
panic_any("should have failed due to empty proof bytes");
}
}
}

#[test]
Expand Down

0 comments on commit 9cc6444

Please sign in to comment.