Skip to content

Commit

Permalink
Update proofs to v4 (#507)
Browse files Browse the repository at this point in the history
* Bump dep versions

* Refactor to new proofs types

* Switch to from trait and cleanup
  • Loading branch information
austinabell authored Jun 18, 2020
1 parent 0f1dba0 commit 1ff34db
Show file tree
Hide file tree
Showing 26 changed files with 313 additions and 324 deletions.
2 changes: 1 addition & 1 deletion blockchain/beacon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ tls-api-rustls = "0.4"
bls-signatures = "0.6.0"
serde = { version = "1.0", features = ["derive"] }
encoding = { path = "../../encoding", package = "forest_encoding" }
sha2 = { version = "0.8", default-features = false }
sha2 = { version = "0.9", default-features = false }
byteorder = "1.3.4"
async-trait = "0.1"
base64 = { version = "0.12.1", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion blockchain/blocks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ derive_builder = "0.9"
serde = { version = "1.0", features = ["derive"] }
encoding = { package = "forest_encoding", path = "../../encoding" }
num-bigint = { path = "../../utils/bigint", package = "forest_bigint" }
sha2 = { version = "0.8", default-features = false }
sha2 = { version = "0.9", default-features = false }
thiserror = "1.0"
vm = { package = "forest_vm", path = "../../vm" }
fil_types = { path = "../../types" }
Expand Down
4 changes: 2 additions & 2 deletions blockchain/chain_sync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ log = "0.4.8"
async-std = { version = "1.6.0", features = ["unstable"] }
forest_libp2p = { path = "../../node/forest_libp2p" }
futures = "0.3.5"
lru = "0.4.3"
lru = "0.5.1"
thiserror = "1.0"
num-traits = "0.2"
filecoin-proofs-api = { git = "https://github.com/filecoin-project/rust-filecoin-proofs-api", rev = "0e1c7cb464707c7a7ad82b0f8303f000f6f3fc8a" }
filecoin-proofs-api = { git = "https://github.com/filecoin-project/rust-filecoin-proofs-api", rev = "b863301780791cbf529dadf08c713e0a97408833" }
fil_types = { path = "../../types" }
commcid = { path = "../../utils/commcid" }

Expand Down
9 changes: 5 additions & 4 deletions blockchain/chain_sync/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use state_manager::{utils, StateManager};
use state_tree::StateTree;
use std::cmp::min;
use std::collections::{BTreeMap, HashMap};
use std::convert::TryFrom;
use std::convert::{TryFrom, TryInto};
use std::sync::Arc;
use vm::TokenAmount;

Expand Down Expand Up @@ -785,11 +785,12 @@ where
let replica = PublicReplicaInfo::new(
sector_info
.proof
.registered_window_post_proof()
.registered_winning_post_proof()
.map_err(|err| Error::Validation(format!("Invalid proof code: {:}", err)))?
.try_into()
.map_err(|err| {
Error::Validation(format!("failed to get registered proof: {:}", err))
})?
.into(),
})?,
commr,
);
Ok((SectorId::from(sector_info.sector_number), replica))
Expand Down
2 changes: 1 addition & 1 deletion blockchain/state_manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ chain = { path = "../chain" }
async-std = "1.5.0"
async-log = "2.0.0"
log = "0.4.8"
filecoin-proofs-api = { git = "https://github.com/filecoin-project/rust-filecoin-proofs-api", rev = "0e1c7cb464707c7a7ad82b0f8303f000f6f3fc8a" }
filecoin-proofs-api = { git = "https://github.com/filecoin-project/rust-filecoin-proofs-api", rev = "b863301780791cbf529dadf08c713e0a97408833" }
fil_types = { path = "../../types" }
17 changes: 9 additions & 8 deletions blockchain/state_manager/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ use actor::miner;
use address::{Address, Protocol};
use blockstore::BlockStore;
use cid::Cid;
use fil_types::{RegisteredProof, SectorInfo, SectorSize};
use fil_types::{RegisteredSealProof, SectorInfo, SectorSize};
use filecoin_proofs_api::{post::generate_winning_post_sector_challenge, ProverId};
use std::convert::TryInto;

pub fn get_sectors_for_winning_post<DB>(
state_manager: &StateManager<DB>,
Expand All @@ -33,11 +34,11 @@ where
return Ok(Vec::new());
}
let seal_proof_type = match miner_actor_state.info.sector_size {
SectorSize::_2KiB => RegisteredProof::StackedDRG2KiBSeal,
SectorSize::_8MiB => RegisteredProof::StackedDRG8MiBSeal,
SectorSize::_512MiB => RegisteredProof::StackedDRG512MiBSeal,
SectorSize::_32GiB => RegisteredProof::StackedDRG32GiBSeal,
SectorSize::_64GiB => RegisteredProof::StackedDRG64GiBSeal,
SectorSize::_2KiB => RegisteredSealProof::StackedDRG2KiBV1,
SectorSize::_8MiB => RegisteredSealProof::StackedDRG8MiBV1,
SectorSize::_512MiB => RegisteredSealProof::StackedDRG512MiBV1,
SectorSize::_32GiB => RegisteredSealProof::StackedDRG32GiBV1,
SectorSize::_64GiB => RegisteredSealProof::StackedDRG64GiBV1,
};
let wpt = seal_proof_type.registered_winning_post_proof()?;

Expand All @@ -51,7 +52,7 @@ where
let prover_bytes = address.to_bytes();
prover_id[..prover_bytes.len()].copy_from_slice(&prover_bytes);
let ids = generate_winning_post_sector_challenge(
wpt.into(),
wpt.try_into()?,
&rand,
sector_set.len() as u64,
prover_id,
Expand All @@ -78,7 +79,7 @@ where
.sealed_cid
.clone();
Ok(SectorInfo {
proof: wpt,
proof: seal_proof_type,
sector_number,
sealed_cid,
})
Expand Down
2 changes: 1 addition & 1 deletion types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ features = ["json"]
[dependencies]
serde = { version = "1.0", features = ["derive"] }
commcid = { path = "../utils/commcid" }
filecoin-proofs-api = { git = "https://github.com/filecoin-project/rust-filecoin-proofs-api", rev = "0e1c7cb464707c7a7ad82b0f8303f000f6f3fc8a" }
filecoin-proofs-api = { git = "https://github.com/filecoin-project/rust-filecoin-proofs-api", rev = "b863301780791cbf529dadf08c713e0a97408833" }
vm = { package = "forest_vm", path = "../vm" }
cid = { package = "forest_cid", path = "../ipld/cid", features = ["cbor"] }
num-bigint = { path = "../utils/bigint", package = "forest_bigint" }
Expand Down
3 changes: 0 additions & 3 deletions types/src/sector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ pub mod post;
mod registered_proof;
mod seal;

#[cfg(test)]
mod serde_tests;

pub use self::post::*;
pub use self::registered_proof::*;
pub use self::seal::*;
Expand Down
16 changes: 8 additions & 8 deletions types/src/sector/post.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
// Copyright 2020 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT

use super::{RegisteredProof, SectorNumber};
use super::{RegisteredPoStProof, RegisteredSealProof, SectorNumber};
use cid::Cid;
use encoding::{serde_bytes, tuple::*};
use vm::{ActorID, Randomness};

pub type PoStRandomness = Randomness;

/// Information about a sector necessary for PoSt verification
#[derive(Debug, PartialEq, Default, Clone, Eq, Serialize_tuple, Deserialize_tuple)]
#[derive(Debug, PartialEq, Clone, Eq, Serialize_tuple, Deserialize_tuple)]
pub struct SectorInfo {
/// Used when sealing - needs to be mapped to PoSt registered proof when used to verify a PoSt
pub proof: RegisteredProof,
pub proof: RegisteredSealProof,
pub sector_number: SectorNumber,
pub sealed_cid: Cid,
}

// TODO docs
#[derive(Debug, PartialEq, Default, Clone, Eq, Serialize_tuple, Deserialize_tuple)]
#[derive(Debug, PartialEq, Clone, Eq, Serialize_tuple, Deserialize_tuple)]
pub struct PoStProof {
pub registered_proof: RegisteredProof,
pub registered_proof: RegisteredPoStProof,
// TODO revisit if can be array in future
#[serde(with = "serde_bytes")]
pub proof_bytes: Vec<u8>,
Expand Down Expand Up @@ -76,7 +76,7 @@ pub mod json {
#[derive(Serialize, Deserialize)]
#[serde(rename_all = "PascalCase")]
struct JsonHelper {
registered_proof: u8,
registered_proof: i64,
proof_bytes: String,
}

Expand All @@ -85,7 +85,7 @@ pub mod json {
S: Serializer,
{
JsonHelper {
registered_proof: m.registered_proof as u8,
registered_proof: i64::from(m.registered_proof),
proof_bytes: base64::encode(&m.proof_bytes),
}
.serialize(serializer)
Expand All @@ -97,7 +97,7 @@ pub mod json {
{
let m: JsonHelper = Deserialize::deserialize(deserializer)?;
Ok(PoStProof {
registered_proof: RegisteredProof::from_byte(m.registered_proof).unwrap(),
registered_proof: RegisteredPoStProof::from(m.registered_proof),
proof_bytes: base64::decode(m.proof_bytes).map_err(de::Error::custom)?,
})
}
Expand Down
Loading

0 comments on commit 1ff34db

Please sign in to comment.