goas/ledger: move prove_input to ProvedInput::prove
This commit is contained in:
parent
d424a95786
commit
5208164204
|
@ -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,7 +49,7 @@ 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(),
|
||||
|
@ -86,6 +58,31 @@ pub fn prove_input(
|
|||
}
|
||||
}
|
||||
|
||||
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] {
|
||||
let note_comm_bytes = Vec::from_iter(note_commitments.iter().map(|c| c.as_bytes().to_vec()));
|
||||
let cm_leaves = cl::merkle::padded_leaves::<MAX_NOTE_COMMS>(¬e_comm_bytes);
|
||||
|
@ -112,7 +109,7 @@ mod test {
|
|||
|
||||
let notes = vec![input.to_output().commit_note()];
|
||||
|
||||
let proved_input = prove_input(input, ¬es);
|
||||
let proved_input = ProvedInput::prove(input, ¬es);
|
||||
|
||||
let expected_public_inputs = InputPublic {
|
||||
cm_root: cl::merkle::root(note_commitment_leaves(¬es)),
|
||||
|
|
Loading…
Reference in New Issue