Skip to content

Commit 4084eed

Browse files
fix: unsealing restrictions and padding (#958)
fix: unsealing restrictions and padding
2 parents ed3d65d + 8e3061a commit 4084eed

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

filecoin-proofs/src/api/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,16 @@ pub fn get_unsealed_range<T: Into<PathBuf> + AsRef<Path>>(
7676
porep_config.window_size_nodes,
7777
);
7878

79+
let offset_padded: PaddedBytesAmount = UnpaddedBytesAmount::from(offset).into();
80+
let num_bytes_padded: PaddedBytesAmount = num_bytes.into();
81+
7982
let unsealed = StackedDrg::<DefaultTreeHasher, DefaultPieceHasher>::extract_range(
8083
&pp,
8184
&replica_id,
8285
&data,
8386
Some(config),
84-
offset.into(),
85-
num_bytes.into(),
87+
offset_padded.into(),
88+
num_bytes_padded.into(),
8689
)?;
8790

8891
let written = write_unpadded(&unsealed, &mut buf_writer, offset.into(), num_bytes.into())?;

filecoin-proofs/src/types/bytes_amount.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ impl From<UnpaddedBytesAmount> for UnpaddedByteIndex {
6060
}
6161
}
6262

63+
impl From<UnpaddedByteIndex> for UnpaddedBytesAmount {
64+
fn from(n: UnpaddedByteIndex) -> Self {
65+
UnpaddedBytesAmount(n.0)
66+
}
67+
}
68+
6369
impl From<UnpaddedByteIndex> for u64 {
6470
fn from(n: UnpaddedByteIndex) -> Self {
6571
n.0

storage-proofs/src/stacked/proof.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -472,16 +472,6 @@ impl<'a, H: 'static + Hasher, G: 'static + Hasher> StackedDrg<'a, H, G> {
472472
num_bytes: usize,
473473
) -> Result<Vec<u8>> {
474474
ensure!(offset + num_bytes <= data.len(), "Out of bounds");
475-
ensure!(
476-
offset % NODE_SIZE == 0,
477-
"Invalid offset, must be a multiple of {}",
478-
NODE_SIZE
479-
);
480-
ensure!(
481-
num_bytes % NODE_SIZE == 0,
482-
"Invalid num_bytes, must be a multiple of {}",
483-
NODE_SIZE
484-
);
485475

486476
// determine the first window needed to be decoded
487477
let first_window_index = offset / pp.window_size_bytes();

0 commit comments

Comments
 (0)