Skip to content

Commit e99a6c9

Browse files
committed
add storage proof implementation to main, add proof generation to e2e script
1 parent ea470fe commit e99a6c9

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

saffron/src/main.rs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
use anyhow::Result;
22
use ark_poly::{EvaluationDomain, Radix2EvaluationDomain};
33
use clap::Parser;
4-
use mina_curves::pasta::{Fp, Vesta};
5-
use poly_commitment::{ipa::SRS, SRS as _};
4+
use kimchi::groupmap::GroupMap;
5+
use mina_curves::pasta::{Fp, Vesta, VestaParameters};
6+
use mina_poseidon::{constants::PlonkSpongeConstantsKimchi, sponge::DefaultFqSponge};
7+
use poly_commitment::{commitment::CommitmentCurve, ipa::SRS, SRS as _};
8+
use rand::rngs::OsRng;
69
use saffron::{
710
blob::FieldBlob,
811
cli::{self, HexString},
9-
commitment, env, utils,
12+
commitment, env, proof, utils,
1013
};
1114
use sha3::{Digest, Sha3_256};
1215
use std::{
@@ -102,6 +105,24 @@ pub fn compute_commitment(args: cli::ComputeCommitmentArgs) -> Result<HexString>
102105
Ok(HexString(hash))
103106
}
104107

108+
pub fn storage_proof(args: cli::StorageProofArgs) -> Result<HexString> {
109+
let file = File::open(args.input)?;
110+
let blob: FieldBlob<Vesta> = rmp_serde::decode::from_read(file)?;
111+
let proof =
112+
{
113+
let (srs, _) = get_srs(args.srs_cache);
114+
let group_map = <Vesta as CommitmentCurve>::Map::setup();
115+
let mut rng = OsRng;
116+
let evaluation_point = utils::encode(&args.challenge.0);
117+
proof::storage_proof::<
118+
Vesta,
119+
DefaultFqSponge<VestaParameters, PlonkSpongeConstantsKimchi>,
120+
>(&srs, &group_map, blob, evaluation_point, &mut rng)
121+
};
122+
let bytes = rmp_serde::to_vec(&proof).unwrap();
123+
Ok(HexString(bytes))
124+
}
125+
105126
pub fn main() -> Result<()> {
106127
env::init_console_subscriber();
107128
let args = cli::Commands::parse();
@@ -113,5 +134,10 @@ pub fn main() -> Result<()> {
113134
println!("{}", commitment);
114135
Ok(())
115136
}
137+
cli::Commands::StorageProof(args) => {
138+
let proof = storage_proof(args)?;
139+
println!("{}", proof);
140+
Ok(())
141+
}
116142
}
117143
}

saffron/src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use ark_poly::EvaluationDomain;
33

44
// For injectivity, you can only use this on inputs of length at most
55
// 'F::MODULUS_BIT_SIZE / 8', e.g. for Vesta this is 31.
6-
fn encode<Fp: PrimeField>(bytes: &[u8]) -> Fp {
6+
pub fn encode<Fp: PrimeField>(bytes: &[u8]) -> Fp {
77
Fp::from_be_bytes_mod_order(bytes)
88
}
99

saffron/test-encoding.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@ if ! cargo run --release --bin saffron encode -i "$INPUT_FILE" -o "$ENCODED_FILE
3131
exit 1
3232
fi
3333

34+
# Generate 32-byte random challenge as hex string
35+
echo "Generating random challenge..."
36+
CHALLENGE=$(head -c 32 /dev/urandom | xxd -p -c 32)
37+
echo "Challenge: $CHALLENGE"
38+
39+
# Generate storage proof and capture proof output
40+
echo "Generating storage proof..."
41+
PROOF=$(cargo run --release --bin saffron storage-proof -i "$ENCODED_FILE" --challenge "$CHALLENGE" $SRS_ARG | tee /dev/stderr | tail -n 1)
42+
if [ $? -ne 0 ]; then
43+
echo "Storage proof generation failed"
44+
exit 1
45+
fi
46+
3447
# Run decode
3548
echo "Decoding $ENCODED_FILE to $DECODED_FILE"
3649
if ! cargo run --release --bin saffron decode -i "$ENCODED_FILE" -o "$DECODED_FILE" $SRS_ARG; then

0 commit comments

Comments
 (0)