-
Notifications
You must be signed in to change notification settings - Fork 0
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
fix(maat): proofs #600
base: develop
Are you sure you want to change the base?
fix(maat): proofs #600
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ use std::{ | |
str::FromStr, | ||
}; | ||
|
||
use codec::Encode; | ||
use mater::CarV2Reader; | ||
use polka_storage_proofs::{ | ||
porep::{self, sealer::Sealer}, | ||
|
@@ -16,7 +17,11 @@ use primitives_commitment::{ | |
piece::{PaddedPieceSize, PieceInfo}, | ||
Commitment, | ||
}; | ||
use primitives_proofs::{derive_prover_id, RegisteredPoStProof, RegisteredSealProof}; | ||
use primitives_proofs::{ | ||
derive_prover_id, | ||
randomness::{draw_randomness, DomainSeparationTag}, | ||
RegisteredPoStProof, RegisteredSealProof, SectorNumber, | ||
}; | ||
use storagext::multipair::{MultiPairArgs, MultiPairSigner}; | ||
use subxt::tx::Signer; | ||
|
||
|
@@ -72,6 +77,15 @@ pub enum ProofsCommand { | |
/// Directory where the proof files and the sector will be put. Defaults to the current directory. | ||
#[arg(short, long)] | ||
output_path: Option<PathBuf>, | ||
/// Sector number | ||
#[arg(long)] | ||
sector_id: u32, | ||
/// The height at which we draw the randomness for deriving a sealed cid. | ||
#[arg(long)] | ||
seal_randomness_height: u64, | ||
/// Precommit block number | ||
#[arg(long)] | ||
pre_commit_block_number: u64, | ||
}, | ||
/// Generates PoSt verifying key and proving parameters for zk-SNARK workflows (submit windowed PoSt) | ||
#[clap(name = "post-params")] | ||
|
@@ -203,17 +217,42 @@ impl ProofsCommand { | |
commp, | ||
output_path, | ||
cache_directory, | ||
sector_id, | ||
seal_randomness_height, | ||
pre_commit_block_number, | ||
} => { | ||
let Some(signer) = Option::<MultiPairSigner>::from(signer_key) else { | ||
return Err(UtilsCommandError::NoSigner)?; | ||
}; | ||
let prover_id = derive_prover_id(signer.account_id()); | ||
|
||
// Those are hardcoded for the showcase only. | ||
// They should come from Storage Provider Node, precommits and other information. | ||
let sector_id = 77.into(); | ||
let ticket = [12u8; 32]; | ||
let seed = [13u8; 32]; | ||
let sector_number = SectorNumber::try_from(sector_id) | ||
.map_err(|_| UtilsCommandError::InvalidSectorId)?; | ||
|
||
let entropy = signer.account_id().encode(); | ||
println!("Entropy: {}", hex::encode(&entropy)); | ||
|
||
let ticket = get_randomness( | ||
DomainSeparationTag::SealRandomness, | ||
seal_randomness_height, | ||
&entropy, | ||
); | ||
println!( | ||
"[{seal_randomness_height}] Ticket randomness: {}", | ||
hex::encode(ticket) | ||
); | ||
|
||
// The number added is configured in runtime: | ||
// https://github.com/eigerco/polka-storage/blob/18207759d7c6c175916d5bed70246d94a8f028f4/runtime/src/configs/mod.rs#L360 | ||
let interactive_block_number = pre_commit_block_number + 10; | ||
cernicc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let seed = get_randomness( | ||
DomainSeparationTag::InteractiveSealChallengeSeed, | ||
interactive_block_number, | ||
&entropy, | ||
); | ||
println!( | ||
"[{interactive_block_number}] Seed randomness: {}", | ||
hex::encode(seed) | ||
); | ||
|
||
let output_path = if let Some(output_path) = output_path { | ||
output_path | ||
|
@@ -273,14 +312,17 @@ impl ProofsCommand { | |
.create_sector(vec![(piece_file, piece_info)], unsealed_sector) | ||
.map_err(|e| UtilsCommandError::GeneratePoRepError(e))?; | ||
|
||
let prover_id = derive_prover_id(signer.account_id()); | ||
println!("Prover ID: {}", hex::encode(prover_id)); | ||
|
||
println!("Precommitting..."); | ||
let precommit = sealer | ||
.precommit_sector( | ||
&cache_directory, | ||
unsealed_sector_path, | ||
&sealed_sector_path, | ||
prover_id, | ||
sector_id, | ||
sector_number, | ||
ticket, | ||
&piece_infos, | ||
) | ||
|
@@ -293,7 +335,7 @@ impl ProofsCommand { | |
&cache_directory, | ||
&sealed_sector_path, | ||
prover_id, | ||
sector_id, | ||
sector_number, | ||
ticket, | ||
Some(seed), | ||
precommit, | ||
|
@@ -310,8 +352,10 @@ impl ProofsCommand { | |
.clone() | ||
.try_into() | ||
.expect("converstion between rust-fil-proofs and polka-storage-proofs to work"); | ||
proof_scale_file.write_all(&codec::Encode::encode(&proof_scale))?; | ||
let scale_encoded_proof = codec::Encode::encode(&proof_scale); | ||
proof_scale_file.write_all(&scale_encoded_proof)?; | ||
|
||
println!("Proof as HEX: {}", hex::encode(scale_encoded_proof)); | ||
println!("Wrote proof to {}", proof_scale_filename.display()); | ||
} | ||
ProofsCommand::GeneratePoStParams { | ||
|
@@ -446,6 +490,8 @@ pub enum UtilsCommandError { | |
InvalidPieceCommP(String, cid::Error), | ||
#[error("invalid piece type")] | ||
InvalidPieceType(String, &'static str), | ||
#[error("invalid sector id")] | ||
InvalidSectorId, | ||
#[error("file {0} is invalid CARv2 file {1}")] | ||
InvalidCARv2(PathBuf, mater::Error), | ||
#[error("no signer key was provider")] | ||
|
@@ -465,3 +511,13 @@ fn file_with_extension( | |
.map_err(|e| UtilsCommandError::FileCreateError(new_path.clone(), e))?; | ||
Ok((new_path, file)) | ||
} | ||
|
||
fn get_randomness( | ||
personalization: DomainSeparationTag, | ||
block_number: u64, | ||
entropy: &[u8], | ||
) -> [u8; 32] { | ||
// This randomness digest is hardcoded because it's always same on testnet. | ||
let digest = [0u8; 32]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But it's not [0u8; 32] on the testnet, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Answered here. It is now :D |
||
draw_randomness(&digest, personalization, block_number, &entropy) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Clear cache before run | ||
CACHE_FOLDER="/tmp/psp-cache" | ||
rm -r "$CACHE_FOLDER" | ||
mkdir "$CACHE_FOLDER" | ||
|
||
PROVIDER="//Charlie" | ||
CAR_FILE="../examples/test-data-big.car" | ||
SECTOR_CID="baga6ea4seaqbfhdvmk5qygevit25ztjwl7voyikb5k2fqcl2lsuefhaqtukuiii" | ||
PARAMS_PATH="../2KiB.porep.params" | ||
SECTOR_ID=1 | ||
SEAL_RANDOMNESS_HEIGHT=20 | ||
PRE_COMMIT_BLOCK_NUMBER=30 | ||
|
||
polka-storage-provider-client proofs porep \ | ||
--sr25519-key "$PROVIDER" \ | ||
--proof-parameters-path "$PARAMS_PATH" \ | ||
--cache-directory "$CACHE_FOLDER" \ | ||
--sector-id "$SECTOR_ID" \ | ||
--seal-randomness-height "$SEAL_RANDOMNESS_HEIGHT" \ | ||
--pre-commit-block-number "$PRE_COMMIT_BLOCK_NUMBER" \ | ||
"$CAR_FILE" \ | ||
"$SECTOR_CID" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should propose the defaults that were hardcoded here, If I were a new user, I wouldn't know where to put it and which number needs to be after which one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought that we will eventually remove those commands? The defaults were also specific for a single use case