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

Incompatibility with mock SP1 verifier contract #1294

Closed
srdtrk opened this issue Aug 9, 2024 · 0 comments · Fixed by #1297
Closed

Incompatibility with mock SP1 verifier contract #1294

srdtrk opened this issue Aug 9, 2024 · 0 comments · Fixed by #1297

Comments

@srdtrk
Copy link
Contributor

srdtrk commented Aug 9, 2024

Description

Currently, the mock prover correctly generates an empty SP1ProofWithPublicValues, as intended (reference here). In typical usage, the .bytes() method (see reference) is used to convert the proof into a byte format that the on-chain verifier can accept. This method works seamlessly with the network prover.

However, when using the mock prover, the mock verification fails if the output of the .bytes() method is directly fed into the mock SP1 verifier. This is because:

  1. The MockSP1Verifier.sol expects proof bytes of length 0 (see here).
  2. The .bytes() method appends the plonk_vkey_hash to the proof (see here). The mock value of plonk_vkey_hash is defined here.

This discrepancy requires users to handle mock proofs and standard SP1 proofs differently before submitting them to their respective verifiers. To improve the user experience, it would be beneficial if the proof generated by the .bytes() method could be accepted directly by the mock verifier.

Proposal:

I propose modifying the .bytes() method instead of altering MockSP1Verifier.sol. Below is the proposed modification:

    /// For Plonk proofs, returns the proof in a byte encoding the onchain verifier accepts.
    /// The bytes consist of the first four bytes of Plonk vkey hash followed by the encoded proof.
    pub fn bytes(&self) -> Vec<u8> {
        match &self.proof {
            SP1Proof::Plonk(plonk_proof) => {
+               if plonk_proof.encoded_proof.is_empty() {
+                   return Vec::new();
+               }
+
                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"),
                );
                bytes
            }
            _ => unimplemented!("only Plonk proofs are verifiable onchain"),
        }
    }
}

If there is agreement on this solution, I would be happy to open a pull request to implement this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant