Skip to content
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

refactor: reduce visibility of encoded_proof #1289

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion prover/scripts/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,6 @@ pub fn main() {

println!(
"{:?}",
String::from_utf8(hex::encode(proof.encoded_proof)).unwrap()
String::from_utf8(hex::encode(proof.encoded_proof())).unwrap()
);
}
7 changes: 4 additions & 3 deletions prover/src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,13 +400,14 @@ impl<C: SP1ProverComponents> SP1Prover<C> {
) -> Result<()> {
let prover = PlonkBn254Prover::new();

let vkey_hash = BigUint::from_str(&proof.public_inputs[0])?;
let committed_values_digest = BigUint::from_str(&proof.public_inputs[1])?;
let public_inputs = proof.public_inputs();
let vkey_hash = BigUint::from_str(&public_inputs[0])?;
let committed_values_digest = BigUint::from_str(&public_inputs[1])?;

// Verify the proof with the corresponding public inputs.
prover.verify(proof, &vkey_hash, &committed_values_digest, build_dir);

verify_plonk_bn254_public_inputs(vk, public_values, &proof.public_inputs)?;
verify_plonk_bn254_public_inputs(vk, public_values, &public_inputs)?;

Ok(())
}
Expand Down
40 changes: 36 additions & 4 deletions recursion/gnark-ffi/src/plonk_bn254.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,42 @@ pub struct PlonkBn254Prover;
/// A zero-knowledge proof generated by the PLONK protocol with a Base64 encoded gnark PLONK proof.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct PlonkBn254Proof {
pub public_inputs: [String; 2],
pub encoded_proof: String,
pub raw_proof: String,
pub plonk_vkey_hash: [u8; 32],
pub(crate) public_inputs: [String; 2],
pub(crate) encoded_proof: String,
pub(crate) raw_proof: String,
pub(crate) plonk_vkey_hash: [u8; 32],
}

impl PlonkBn254Proof {
pub fn new(
public_inputs: [String; 2],
encoded_proof: String,
raw_proof: String,
plonk_vkey_hash: [u8; 32],
) -> Self {
Self {
public_inputs,
encoded_proof,
raw_proof,
plonk_vkey_hash,
}
}

pub fn public_inputs(&self) -> [String; 2] {
self.public_inputs.clone()
}

pub fn encoded_proof(&self) -> String {
self.encoded_proof.clone()
}

pub fn raw_proof(&self) -> String {
self.raw_proof.clone()
}

pub fn plonk_vkey_hash(&self) -> [u8; 32] {
self.plonk_vkey_hash
}
}

impl PlonkBn254Prover {
Expand Down
12 changes: 6 additions & 6 deletions sdk/src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl SP1ProofWithPublicValues {
/// Returns the raw proof as a string.
pub fn raw(&self) -> String {
match &self.proof {
SP1Proof::Plonk(plonk) => plonk.raw_proof.clone(),
SP1Proof::Plonk(plonk) => plonk.raw_proof().clone(),
_ => unimplemented!(),
}
}
Expand All @@ -53,11 +53,11 @@ impl SP1ProofWithPublicValues {
pub fn bytes(&self) -> Vec<u8> {
match &self.proof {
SP1Proof::Plonk(plonk_proof) => {
let mut bytes = Vec::with_capacity(4 + plonk_proof.encoded_proof.len());
bytes.extend_from_slice(&plonk_proof.plonk_vkey_hash[..4]);
bytes.extend_from_slice(
&hex::decode(&plonk_proof.encoded_proof).expect("Invalid Plonk proof"),
);
let encoded_proof = plonk_proof.encoded_proof();
let vkey_hash = plonk_proof.plonk_vkey_hash();
let mut bytes = Vec::with_capacity(4 + encoded_proof.len());
bytes.extend_from_slice(&vkey_hash[..4]);
bytes.extend_from_slice(encoded_proof.as_bytes());
bytes
}
_ => unimplemented!("only Plonk proofs are verifiable onchain"),
Expand Down
22 changes: 12 additions & 10 deletions sdk/src/provers/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ impl Prover<DefaultProverComponents> for MockProver {
SP1ProofKind::Plonk => {
let (public_values, _) = self.prover.execute(&pk.elf, &stdin, context)?;
Ok(SP1ProofWithPublicValues {
proof: SP1Proof::Plonk(PlonkBn254Proof {
public_inputs: [
proof: SP1Proof::Plonk(PlonkBn254Proof::new(
[
pk.vk.hash_bn254().as_canonical_biguint().to_string(),
public_values.hash().to_string(),
],
encoded_proof: "".to_string(),
raw_proof: "".to_string(),
plonk_vkey_hash: [0; 32],
}),
"".to_string(),
"".to_string(),
[0; 32],
)),
stdin,
public_values,
sp1_version: self.version().to_string(),
Expand All @@ -117,10 +117,12 @@ impl Prover<DefaultProverComponents> for MockProver {
vkey: &SP1VerifyingKey,
) -> Result<(), SP1VerificationError> {
match &bundle.proof {
SP1Proof::Plonk(PlonkBn254Proof { public_inputs, .. }) => {
verify_plonk_bn254_public_inputs(vkey, &bundle.public_values, public_inputs)
.map_err(SP1VerificationError::Plonk)
}
SP1Proof::Plonk(plonk) => verify_plonk_bn254_public_inputs(
vkey,
&bundle.public_values,
&plonk.public_inputs(),
)
.map_err(SP1VerificationError::Plonk),
_ => Ok(()),
}
}
Expand Down
Loading