Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fail verification of empty proof bytes #1498

Merged
merged 2 commits into from
Aug 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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