goas/ledger: move prove_input to ProvedInput::prove

This commit is contained in:
David Rusu 2024-07-19 01:29:26 +04:00
parent d424a95786
commit 5208164204
1 changed files with 49 additions and 52 deletions

View File

@ -10,35 +10,7 @@ pub struct ProvedInput {
}
impl ProvedInput {
pub fn verify(&self) -> bool {
self.proof.verify(&self.input)
}
}
#[derive(Debug, Clone)]
pub struct InputProof {
receipt: risc0_zkvm::Receipt,
}
impl InputProof {
pub fn public(&self) -> Result<InputPublic> {
Ok(self.receipt.journal.decode()?)
}
pub fn verify(&self, expected_public_inputs: &InputPublic) -> bool {
let Ok(public_inputs) = self.public() else {
return false;
};
&public_inputs == expected_public_inputs
&& self.receipt.verify(nomos_cl_risc0_proofs::INPUT_ID).is_ok()
}
}
pub fn prove_input(
input: cl::InputWitness,
note_commitments: &[cl::NoteCommitment],
) -> ProvedInput {
pub fn prove(input: cl::InputWitness, note_commitments: &[cl::NoteCommitment]) -> Self {
let output_cm = input.to_output().commit_note();
let cm_leaves = note_commitment_leaves(note_commitments);
@ -77,13 +49,38 @@ pub fn prove_input(
// extract the receipt.
let receipt = prove_info.receipt;
ProvedInput {
Self {
input: InputPublic {
cm_root: cl::merkle::root(cm_leaves),
input: input.commit(),
},
proof: InputProof { receipt },
}
}
pub fn verify(&self) -> bool {
self.proof.verify(&self.input)
}
}
#[derive(Debug, Clone)]
pub struct InputProof {
receipt: risc0_zkvm::Receipt,
}
impl InputProof {
pub fn public(&self) -> Result<InputPublic> {
Ok(self.receipt.journal.decode()?)
}
pub fn verify(&self, expected_public_inputs: &InputPublic) -> bool {
let Ok(public_inputs) = self.public() else {
return false;
};
&public_inputs == expected_public_inputs
&& self.receipt.verify(nomos_cl_risc0_proofs::INPUT_ID).is_ok()
}
}
fn note_commitment_leaves(note_commitments: &[cl::NoteCommitment]) -> [[u8; 32]; MAX_NOTE_COMMS] {
@ -112,7 +109,7 @@ mod test {
let notes = vec![input.to_output().commit_note()];
let proved_input = prove_input(input, &notes);
let proved_input = ProvedInput::prove(input, &notes);
let expected_public_inputs = InputPublic {
cm_root: cl::merkle::root(note_commitment_leaves(&notes)),