Skip to content

Commit

Permalink
some changes
Browse files Browse the repository at this point in the history
  • Loading branch information
cernicc committed Nov 28, 2024
1 parent d3891c1 commit 6986601
Show file tree
Hide file tree
Showing 16 changed files with 99 additions and 161 deletions.
6 changes: 3 additions & 3 deletions pallets/market/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ pub mod pallet {
piece::{PaddedPieceSize, PieceInfo},
CommP, Commitment, CommitmentError,
},
pallets::{Market, SectorDeal, StorageProviderValidation},
proofs::{ActiveDeal, ActiveSector, DealId, RegisteredSealProof},
pallets::{ActiveDeal, ActiveSector, Market, SectorDeal, StorageProviderValidation},
proofs::RegisteredSealProof,
sector::{SectorNumber, SectorSize},
MAX_DEALS_PER_SECTOR, MAX_SECTORS_PER_CALL,
DealId, MAX_DEALS_PER_SECTOR, MAX_SECTORS_PER_CALL,
};
use scale_info::TypeInfo;
use sp_arithmetic::traits::BaseArithmetic;
Expand Down
8 changes: 3 additions & 5 deletions pallets/proofs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@ pub mod pallet {
use frame_system::pallet_prelude::*;
use primitives::{
commitment::RawCommitment,
proofs::{
ProofVerification, ProverId, PublicReplicaInfo, RegisteredPoStProof,
RegisteredSealProof, Ticket, MAX_POST_PROOF_BYTES, MAX_SEAL_PROOF_BYTES,
MAX_SECTORS_PER_PROOF,
},
pallets::ProofVerification,
proofs::{ProverId, PublicReplicaInfo, RegisteredPoStProof, RegisteredSealProof, Ticket},
sector::SectorNumber,
MAX_POST_PROOF_BYTES, MAX_SEAL_PROOF_BYTES, MAX_SECTORS_PER_PROOF,
};

use crate::{
Expand Down
4 changes: 2 additions & 2 deletions pallets/proofs/src/post/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use frame_support::{pallet_prelude::*, sp_runtime::BoundedBTreeMap};
use polka_storage_proofs::get_partitions_for_window_post;
use primitives::{
commitment::RawCommitment,
proofs::{PublicReplicaInfo, RegisteredPoStProof, Ticket, MAX_SECTORS_PER_PROOF},
proofs::{PublicReplicaInfo, RegisteredPoStProof, Ticket},
sector::SectorNumber,
NODE_SIZE,
MAX_SECTORS_PER_PROOF, NODE_SIZE,
};
use sha2::{Digest, Sha256};

Expand Down
9 changes: 5 additions & 4 deletions pallets/storage-provider/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ pub mod pallet {
};
use primitives::{
commitment::{CommD, CommR, Commitment},
pallets::{CurrentDeadline, Market, Randomness, StorageProviderValidation},
proofs::{derive_prover_id, ProofVerification, PublicReplicaInfo, RegisteredPoStProof},
pallets::{
CurrentDeadline, Market, ProofVerification, Randomness, StorageProviderValidation,
},
proofs::{derive_prover_id, PublicReplicaInfo, RegisteredPoStProof},
randomness::{draw_randomness, DomainSeparationTag},
sector::SectorNumber,
MAX_SEAL_PROOF_BYTES, MAX_SECTORS_PER_CALL,
Expand Down Expand Up @@ -691,8 +693,7 @@ pub mod pallet {
);

ensure!(
windowed_post.proof.proof_bytes.len()
<= primitives::proofs::MAX_POST_PROOF_BYTES as usize,
windowed_post.proof.proof_bytes.len() <= primitives::MAX_POST_PROOF_BYTES as usize,
{
log::error!("submit_window_post: invalid proof size");
Error::<T>::PoStProofInvalid
Expand Down
2 changes: 1 addition & 1 deletion pallets/storage-provider/src/proofs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use frame_support::{
pallet_prelude::{ConstU32, RuntimeDebug},
sp_runtime::BoundedVec,
};
use primitives::proofs::{RegisteredPoStProof, MAX_POST_PROOF_BYTES};
use primitives::{proofs::RegisteredPoStProof, MAX_POST_PROOF_BYTES};
use scale_info::TypeInfo;
use sp_core::blake2_64;

Expand Down
4 changes: 1 addition & 3 deletions pallets/storage-provider/src/sector.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use codec::{Decode, Encode};
use frame_support::{pallet_prelude::*, BoundedVec};
use primitives::{
pallets::SectorDeal,
proofs::{DealId, RegisteredSealProof},
sector::SectorNumber,
pallets::SectorDeal, proofs::RegisteredSealProof, sector::SectorNumber, DealId,
CID_SIZE_IN_BYTES, MAX_DEALS_PER_SECTOR, MAX_SEAL_PROOF_BYTES, MAX_TERMINATIONS_PER_CALL,
};
use scale_info::TypeInfo;
Expand Down
2 changes: 1 addition & 1 deletion primitives/src/commitment/commd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ mod tests {
use cid::Cid;

use super::*;
use crate::proofs::SectorSize;
use crate::sector::SectorSize;

#[test]
fn test_compute_comm_d_empty() {
Expand Down
2 changes: 2 additions & 0 deletions primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ pub mod proofs;
pub mod randomness;
pub mod sector;

pub type DealId = u64;

/// Merkle tree node size in bytes.
pub const NODE_SIZE: usize = 32;

Expand Down
50 changes: 47 additions & 3 deletions primitives/src/pallets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ use cid::Cid;
use codec::{Codec, Decode, Encode};
use scale_info::TypeInfo;
use sp_core::{ConstU32, RuntimeDebug};
use sp_runtime::{BoundedVec, DispatchError, DispatchResult};
use sp_runtime::{BoundedBTreeMap, BoundedVec, DispatchError, DispatchResult};

use crate::{
proofs::{ActiveSector, DealId, RegisteredSealProof},
commitment::RawCommitment,
proofs::{ProverId, PublicReplicaInfo, RegisteredPoStProof, RegisteredSealProof, Ticket},
sector::SectorNumber,
MAX_DEALS_PER_SECTOR, MAX_SECTORS_PER_CALL,
DealId, MAX_DEALS_PER_SECTOR, MAX_POST_PROOF_BYTES, MAX_SEAL_PROOF_BYTES, MAX_SECTORS_PER_CALL,
MAX_SECTORS_PER_PROOF,
};

/// Represents functions that are provided by the Randomness Pallet
Expand All @@ -20,6 +22,27 @@ pub trait StorageProviderValidation<AccountId> {
fn is_registered_storage_provider(storage_provider: &AccountId) -> bool;
}

/// Entrypoint for proof verification implemented by Pallet Proofs.
pub trait ProofVerification {
fn verify_porep(
prover_id: ProverId,
seal_proof: RegisteredSealProof,
comm_r: RawCommitment,
comm_d: RawCommitment,
sector: SectorNumber,
ticket: Ticket,
seed: Ticket,
proof: BoundedVec<u8, ConstU32<MAX_SEAL_PROOF_BYTES>>,
) -> DispatchResult;

fn verify_post(
post_type: RegisteredPoStProof,
randomness: Ticket,
replicas: BoundedBTreeMap<SectorNumber, PublicReplicaInfo, ConstU32<MAX_SECTORS_PER_PROOF>>,
proof: BoundedVec<u8, ConstU32<MAX_POST_PROOF_BYTES>>,
) -> DispatchResult;
}

/// Represents functions that are provided by the Market Provider Pallet
pub trait Market<AccountId, BlockNumber> {
/// Verifies a given set of storage deals is valid for sectors being PreCommitted.
Expand Down Expand Up @@ -75,6 +98,27 @@ pub struct SectorDeal<BlockNumber> {
pub deal_ids: BoundedVec<DealId, ConstU32<MAX_DEALS_PER_SECTOR>>,
}

/// A sector with all of its active deals.
#[derive(RuntimeDebug, Eq, PartialEq)]
pub struct ActiveSector<AccountId> {
/// Information about each deal activated.
pub active_deals: BoundedVec<ActiveDeal<AccountId>, ConstU32<MAX_DEALS_PER_SECTOR>>,
/// Unsealed CID computed from the deals specified for the sector.
/// A None indicates no deals were specified, or the computation was not requested.
pub unsealed_cid: Option<Cid>,
}

/// An active deal with references to data that it stores
#[derive(RuntimeDebug, Eq, PartialEq)]
pub struct ActiveDeal<AccountId> {
/// Client's account
pub client: AccountId,
/// Data that was stored
pub piece_cid: Cid,
/// Real size of the data
pub piece_size: u64,
}

/// Current deadline in a proving period of a Storage Provider.
#[derive(Encode, Decode, TypeInfo)]
pub struct CurrentDeadline<BlockNumber> {
Expand Down
40 changes: 29 additions & 11 deletions primitives/src/proofs/types.rs → primitives/src/proofs.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
use core::{fmt::Display, marker::PhantomData};

use codec::{Decode, Encode, MaxEncodedLen};
use scale_decode::{
visitor::{self},
DecodeAsType, ToString, TypeResolver, Visitor,
};
use codec::{Decode, Encode};
use scale_decode::DecodeAsType;
use scale_encode::EncodeAsType;
use scale_info::TypeInfo;
use sp_runtime::RuntimeDebug;

use crate::sector::SectorSize;
use sp_core::blake2_256;

pub type DealId = u64;
use crate::{commitment::RawCommitment, sector::SectorSize};

/// Byte representation of the entity that was signing the proof.
/// It must match the ProverId used for Proving.
Expand All @@ -20,6 +13,31 @@ pub type ProverId = [u8; 32];
/// Byte representation of randomness seed, it's used for challenge generation.
pub type Ticket = [u8; 32];

/// Derives a unique prover ID for a given account.
///
/// The function takes an `AccountId` and generates a 32-byte array that serves
/// as a unique identifier for the prover associated with that account. The
/// prover ID is derived using the Blake2 hash of the encoded account ID.
pub fn derive_prover_id<AccountId>(account_id: AccountId) -> [u8; 32]
where
AccountId: Encode,
{
let encoded = account_id.encode();
let mut encoded = blake2_256(&encoded);

// Necessary to be a valid bls12 381 element.
encoded[31] &= 0x3f;
encoded
}

/// The minimal information required about a replica, in order to be able to verify
/// a PoSt over it.
#[derive(Clone, core::fmt::Debug, PartialEq, Eq)]
pub struct PublicReplicaInfo {
/// The replica commitment.
pub comm_r: RawCommitment,
}

#[allow(non_camel_case_types)]
#[derive(
Debug, Decode, Encode, DecodeAsType, EncodeAsType, TypeInfo, Eq, PartialEq, Clone, Copy,
Expand Down
24 changes: 0 additions & 24 deletions primitives/src/proofs/mod.rs

This file was deleted.

100 changes: 0 additions & 100 deletions primitives/src/proofs/traits.rs

This file was deleted.

2 changes: 1 addition & 1 deletion storage-provider/server/src/pipeline/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::path::PathBuf;

use primitives::{
commitment::{piece::PieceInfo, CommD, CommP, CommR, Commitment},
proofs::DealId,
sector::SectorNumber,
DealId,
};
use serde::{Deserialize, Serialize};
use storagext::types::market::DealProposal;
Expand Down
2 changes: 1 addition & 1 deletion storagext/cli/src/cmd/market.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::time::Duration;

use anyhow::bail;
use clap::{ArgGroup, Subcommand};
use primitives::proofs::DealId;
use primitives::DealId;
use storagext::{
deser::DeserializablePath,
multipair::{DebugPair, MultiPairSigner},
Expand Down
2 changes: 1 addition & 1 deletion storagext/lib/src/clients/market.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::future::Future;

use primitives::proofs::DealId;
use primitives::DealId;
use subxt::{ext::sp_core::crypto::Ss58Codec, utils::Static};

use crate::{
Expand Down
3 changes: 2 additions & 1 deletion storagext/lib/src/types/storage_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ use std::collections::BTreeSet;

use cid::Cid;
use primitives::{
proofs::{DealId, RegisteredPoStProof, RegisteredSealProof},
proofs::{RegisteredPoStProof, RegisteredSealProof},
sector::SectorNumber,
DealId,
};

use crate::{
Expand Down

0 comments on commit 6986601

Please sign in to comment.