Skip to content
This repository has been archived by the owner on Oct 16, 2024. It is now read-only.

Commit

Permalink
not working wip stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
gubsheep committed Oct 2, 2024
1 parent 0255179 commit 385dac9
Showing 1 changed file with 57 additions and 1 deletion.
58 changes: 57 additions & 1 deletion src/pod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,62 @@ impl<V: EntryValue> HashablePayload for Vec<Entry<V>> {
}
}

impl HashablePayload for Vec<Statement> {
fn to_field_vec(&self) -> Vec<GoldilocksField> {
// TODO WIP - incorrect AI generated code

// sort statements deterministically
// then turn each statement into a list of 8 field elements
// then concatenate all of this together
let mut sorted_statements = self.clone();

sorted_statements.sort_by(|a, b| {
let a_key = a.left_key_name.clone();
let b_key = b.left_key_name.clone();
a_key.cmp(&b_key)
});

let mut ins = Vec::new();
sorted_statements.iter().for_each(|statement| {
ins.push(statement.predicate as u64);
ins.push(statement.left_origin.origin_id);
ins.push(statement.left_origin.gadget_id.unwrap_or(GadgetID::NONE) as u64);
ins.push(
statement
.right_origin
.unwrap_or(Origin {
origin_id: GoldilocksField::ZERO,
gadget_id: None,
})
.origin_id,
);
ins.push(
statement
.right_origin
.unwrap_or(Origin {
origin_id: GoldilocksField::ZERO,
gadget_id: None,
})
.gadget_id
.unwrap_or(GadgetID::NONE) as u64,
);
ins.push(hash_string_to_field(&statement.left_key_name));
ins.push(
statement
.right_key_name
.clone()
.map_or(GoldilocksField::ZERO, |s| hash_string_to_field(&s)),
);
ins.push(statement.optional_value.unwrap_or(GoldilocksField::ZERO));
});
}

fn hash_payload(&self) -> GoldilocksField {
let ins = self.to_field_vec();
PoseidonHash::hash_no_pad(&ins).to_vec()[0]
}
}

pub trait ProofOf<Payload>: Clone {
fn verify(&self, payload: &Payload) -> Result<bool, Error>;
}
Expand Down Expand Up @@ -156,7 +212,7 @@ pub struct POD<Payload: HashablePayload, Proof: ProofOf<Payload>, const FromGadg

type SchnorrPOD = POD<Vec<Entry<ScalarOrVec>>, SchnorrSignature, { GadgetID::SCHNORR16 as usize }>;

type GODPOD = POD<Vec<Entry<ScalarOrVec>>, SchnorrSignature, { GadgetID::GOD as usize }>;
type GODPOD = POD<Vec<Statement>, SchnorrSignature, { GadgetID::GOD as usize }>;

#[derive(Clone, Debug, PartialEq)]
pub enum SchnorrOrGODPOD {
Expand Down

0 comments on commit 385dac9

Please sign in to comment.