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

Explicit handling of public inputs #2

Merged
merged 5 commits into from
Jun 10, 2024
Merged

Explicit handling of public inputs #2

merged 5 commits into from
Jun 10, 2024

Conversation

JackPiri
Copy link
Contributor

@JackPiri JackPiri commented Jun 5, 2024

No description provided.

@JackPiri JackPiri requested review from la10736 and drgora June 5, 2024 12:04
/// - the proof or the pubs are not serializable respectively as a `risc0_zkvm::InnerReceipt` and a `risc0_zkvm::Journal`
/// - the proof is not valid
pub fn verify(vk: Vk, proof: Proof, pubs: PublicInputs) -> Result<(), VerifyError> {
let receipt = deserialize_full_proof(proof, pubs)?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've prefered that you inlined deserialized_full_proof() code here because a deserialize function that take teo buffer is a strange and un expected interface.

Anyway I's just a mater of taste... it's not madatory

receipt.verify(image_id.0).map_err(Into::into)
/// - the proof or the pubs are not serializable respectively as a `risc0_zkvm::InnerReceipt` and a `risc0_zkvm::Journal`
/// - the proof is not valid
pub fn verify(vk: Vk, proof: Proof, pubs: PublicInputs) -> Result<(), VerifyError> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think is better to take pubs as slice of bytes instead of use the serialized data.

Comment on lines 60 to 71
fn should_not_verify_invalid_pubs() {
let (vk, proof, mut pubs) = load_data(Path::new("./resources/valid_proof_1.json"));

pubs[0] = pubs.first().unwrap().wrapping_add(1);

assert!(matches!(
verify(vk.into(), &proof, &pubs),
Err(VerifyError::InvalidData {
cause: DeserializeError::InvalidPublicInputs
})
));
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're testing that your code is able to catch an inssu in the serialized inputs and not that the verification fails if your are using invalid pubs.

If you would to leave that your verify() method take serialized public input here you should deserialize them change the values and serialize them again... But (as you know) I prefer to change the interface.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I wrote a wrong comment... Iwas bysed by the the test name: maybe a should_not_deserialize_invelid_pubs() is better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok renamed accordingly.


assert!(verify(&proof_raw_data, image_id_data.into()).is_ok());
assert!(verify(vk.into(), &proof, &pubs).is_ok());
}

#[test]
fn should_not_verify_invalid_proof() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also here: should_not_deserialize_invalid_proof() is a better name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok renamed accordingly.

src/proof.rs Outdated
Comment on lines 16 to 18
/// The full proof (a serialized `risc0_zkvm::Receipt`) containing both proof and public inputs
pub type _FullProof<'a> = &'a [u8];

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you use it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually no, I'm removing it.

Copy link
Collaborator

@la10736 la10736 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove unsued _FullProof type definition and consider the other notes (they aren't mandatory).

Now there is a neat separation: proof (inner receipt) and pubs (journal)
@JackPiri JackPiri force-pushed the gp/public_inputs branch from cb33bd6 to 19ee2d0 Compare June 6, 2024 09:18
@JackPiri JackPiri force-pushed the gp/public_inputs branch from 986af1b to a07ead2 Compare June 7, 2024 08:31
Added unit test
@JackPiri JackPiri force-pushed the gp/public_inputs branch from a07910a to bbac31b Compare June 7, 2024 12:50
@JackPiri JackPiri merged commit 4b814a3 into master Jun 10, 2024
2 checks passed
@JackPiri JackPiri deleted the gp/public_inputs branch July 23, 2024 09:07
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 this pull request may close these issues.

2 participants