Skip to content

Commit

Permalink
feat: verify multiple partitions in pallets (#658)
Browse files Browse the repository at this point in the history
  • Loading branch information
th7nder authored Jan 3, 2025
1 parent 09e27f6 commit 1f404ac
Show file tree
Hide file tree
Showing 25 changed files with 243 additions and 301 deletions.
14 changes: 0 additions & 14 deletions examples/deals.json

This file was deleted.

42 changes: 0 additions & 42 deletions examples/declare-fault.sh

This file was deleted.

9 changes: 0 additions & 9 deletions examples/fault-declaration.json

This file was deleted.

10 changes: 0 additions & 10 deletions examples/pre-commit-sector.json

This file was deleted.

6 changes: 0 additions & 6 deletions examples/prove-commit-sector.json

This file was deleted.

9 changes: 0 additions & 9 deletions examples/publish.sh

This file was deleted.

117 changes: 0 additions & 117 deletions examples/real-world-use-case-demo.sh

This file was deleted.

11 changes: 8 additions & 3 deletions examples/rpc_publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,14 @@ target/release/storagext-cli --sr25519-key "$PROVIDER" market add-balance 250000
# register one of them as the storage provider
wait

target/release/storagext-cli --sr25519-key "//Charlie" storage-provider register "peer_id"
target/release/storagext-cli --sr25519-key "//Charlie" proofs set-porep-verifying-key @2KiB.porep.vk.scale
target/release/storagext-cli --sr25519-key "//Charlie" proofs set-post-verifying-key @2KiB.post.vk.scale
# It's a test setup based on the local verifying keys, everyone can run those extrinsics currently.
# Each of the keys is different, because the processes are running in parallel.
# If they were running in parallel on the same account, they'd conflict with each other on the transaction nonce.
target/release/storagext-cli --sr25519-key "//Charlie" storage-provider register "peer_id" &
target/release/storagext-cli --sr25519-key "//Alice" proofs set-porep-verifying-key @2KiB.porep.vk.scale &
target/release/storagext-cli --sr25519-key "//Bob" proofs set-post-verifying-key @2KiB.post.vk.scale &

wait

DEAL_JSON=$(
jq -n \
Expand Down
70 changes: 70 additions & 0 deletions examples/rpc_publish_multiple_sectors.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env bash
set -e

if [ "$#" -ne 1 ]; then
echo "$0: input file required"
exit 1
fi

if [ -z "$1" ]; then
echo "$0: input file cannot be empty"
exit 1
fi

trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT

# requires the testnet to be running!
export DISABLE_XT_WAIT_WARNING=1

CLIENT="//Alice"
PROVIDER="//Charlie"

INPUT_FILE="$1"
INPUT_FILE_NAME="$(basename "$INPUT_FILE")"
INPUT_TMP_FILE="/tmp/$INPUT_FILE_NAME.car"

target/release/mater-cli convert -q --overwrite "$INPUT_FILE" "$INPUT_TMP_FILE" &&
INPUT_COMMP="$(target/release/polka-storage-provider-client proofs commp "$INPUT_TMP_FILE")"
PIECE_CID="$(echo "$INPUT_COMMP" | jq -r ".cid")"
PIECE_SIZE="$(echo "$INPUT_COMMP" | jq ".size")"


for i in $(seq 194 200);
do
DEAL_JSON=$(
jq -n \
--arg piece_cid "$PIECE_CID" \
--argjson start_block "$i" \
--argjson piece_size "$PIECE_SIZE" \
'{
"piece_cid": $piece_cid,
"piece_size": $piece_size,
"client": "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
"provider": "5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y",
"label": "",
"start_block": $start_block,
"end_block": 250,
"storage_price_per_block": 500,
"provider_collateral": 1250,
"state": "Published"
}'
)
SIGNED_DEAL_JSON="$(RUST_LOG=error target/release/polka-storage-provider-client sign-deal --sr25519-key "$CLIENT" "$DEAL_JSON")"

DEAL_CID="$(RUST_LOG=error target/release/polka-storage-provider-client propose-deal "$DEAL_JSON")"
echo "-------------------------- Uploading deal $i..."
echo
curl -X PUT -F "upload=@$INPUT_FILE" "http://localhost:8001/upload/$DEAL_CID"

echo
echo "-------------------------- Publishing deal $i..."
target/release/polka-storage-provider-client publish-deal "$SIGNED_DEAL_JSON" &
# If we try to prove commit 6 in a single row then we're done.
# we need to throttle prove commits.
# Sleeping until polka-storage#655 is done.
sleep 6

done

# wait until user Ctrl+Cs so that the commitment can actually be calculated
wait
27 changes: 27 additions & 0 deletions examples/start_sp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash
set -e

trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT

# requires the testnet to be running!
export DISABLE_XT_WAIT_WARNING=1

CLIENT="//Alice"
PROVIDER="//Charlie"

# Setup balances
RUST_LOG=debug target/release/storagext-cli --sr25519-key "$CLIENT" market add-balance 250000000000 &
RUST_LOG=debug target/release/storagext-cli --sr25519-key "$PROVIDER" market add-balance 250000000000 &
# We can process a transaction by charlie and alice, but we can't in the same transaction
# register one of them as the storage provider
wait

# It's a test setup based on the local verifying keys, everyone can run those extrinsics currently.
# Each of the keys is different, because the processes are running in parallel.
# If they were running in parallel on the same account, they'd conflict with each other on the transaction nonce.
RUST_LOG=debug target/release/storagext-cli --sr25519-key "//Charlie" storage-provider register "peer_id" &
RUST_LOG=debug target/release/storagext-cli --sr25519-key "//Alice" proofs set-porep-verifying-key @2KiB.porep.vk.scale &
RUST_LOG=debug target/release/storagext-cli --sr25519-key "//Bob" proofs set-post-verifying-key @2KiB.post.vk.scale &
wait

RUST_LOG=debug target/release/polka-storage-provider-server --sr25519-key "$PROVIDER" --seal-proof "2KiB" --post-proof "2KiB" --porep-parameters 2KiB.porep.params --post-parameters 2KiB.post.params
9 changes: 0 additions & 9 deletions examples/windowed-proof.json

This file was deleted.

12 changes: 6 additions & 6 deletions pallets/proofs/src/crypto/groth16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::Vec;
/// - <https://github.com/zkcrypto/bellman/blob/3a1c43b01a89d426842df39b432de979917951e6/groth16/src/lib.rs#L400>
/// - <https://github.com/filecoin-project/bellperson/blob/a594f329b05b6224047903fb51658e8a35a12fbd/src/groth16/verifying_key.rs#L200>
#[derive(Clone, Decode, Default, Encode)]
struct PreparedVerifyingKey<E: MultiMillerLoop> {
pub(crate) struct PreparedVerifyingKey<E: MultiMillerLoop> {
pub alpha_g1_beta_g2: E::Gt,
pub neg_gamma_g2: E::G2Prepared,
pub neg_delta_g2: E::G2Prepared,
Expand All @@ -36,11 +36,13 @@ impl<E: MultiMillerLoop> From<VerifyingKey<E>> for PreparedVerifyingKey<E> {
}
}

/// Method generates the `PreparedVerifyingKey` from the `VerifyingKey`.
/// Generates the `PreparedVerifyingKey` from the `VerifyingKey`.
///
/// References:
/// - <https://github.com/zkcrypto/bellman/blob/3a1c43b01a89d426842df39b432de979917951e6/groth16/src/verifier.rs#L11>
fn prepare_verifying_key<E: MultiMillerLoop>(vkey: VerifyingKey<E>) -> PreparedVerifyingKey<E> {
pub(crate) fn prepare_verifying_key<E: MultiMillerLoop>(
vkey: VerifyingKey<E>,
) -> PreparedVerifyingKey<E> {
PreparedVerifyingKey::<E>::from(vkey)
}

Expand All @@ -52,12 +54,10 @@ fn prepare_verifying_key<E: MultiMillerLoop>(vkey: VerifyingKey<E>) -> PreparedV
/// - <https://github.com/zkcrypto/bellman/blob/3a1c43b01a89d426842df39b432de979917951e6/groth16/src/verifier.rs#L23>
/// - <https://github.com/filecoin-project/bellperson/blob/a594f329b05b6224047903fb51658e8a35a12fbd/src/groth16/verifier.rs#L38>
pub fn verify_proof<E: MultiMillerLoop>(
vk: VerifyingKey<E>,
pvk: &PreparedVerifyingKey<E>,
proof: &Proof<E>,
public_inputs: &[E::Fr],
) -> Result<(), VerificationError> {
let pvk = prepare_verifying_key(vk);

if (public_inputs.len() + 1) != pvk.ic.len() {
return Err(VerificationError::InvalidVerifyingKey);
}
Expand Down
Loading

0 comments on commit 1f404ac

Please sign in to comment.