Skip to content

Commit

Permalink
feat: implement Zero-Knowlde circuits and logic for attaching metadat…
Browse files Browse the repository at this point in the history
… to exact geopoint proof
  • Loading branch information
iluxonchik committed Dec 31, 2023
1 parent f20718e commit d6cb8c0
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 272 deletions.
18 changes: 16 additions & 2 deletions contracts/src/logic/public/ExactGeoPoint.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Field } from "o1js";
import { Field, Poseidon } from "o1js";
import { GeoPoint } from "../../model/Geography";
import { GeoPointCommitment } from "../../model/public/Commitment";
import { GeoPointCommitment, MetadataGeoPointCommitment } from "../../model/public/Commitment";
import { GeoPointProviderCircuitProof } from "../../zkprogram/private/Geography";
import { Bytes64, SHA3_512 } from "../../model/public/SHA3";


/*
Expand All @@ -21,3 +22,16 @@ export function proveExactGeoPointFromProvider(geoPointProviderProof: GeoPointPr
geoPointHash: geoPointHash
});
}


export function attachMetadataToGeoPoint(geoPointProviderProof: GeoPointProviderCircuitProof, sha3_512: Bytes64): MetadataGeoPointCommitment {
geoPointProviderProof.verify();
const geoPoint: GeoPoint = geoPointProviderProof.publicOutput;
const geoPointHash: Field = geoPoint.hash();
const sha3_512PoseidonHash: Field = Poseidon.hash(sha3_512.toFields());

return new MetadataGeoPointCommitment({
geoPointHash: geoPointHash,
metadataHash: sha3_512PoseidonHash
});
}
12 changes: 11 additions & 1 deletion contracts/src/model/public/Commitment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,14 @@ export class GeoPointCommitment extends Struct({
toString(): string {
return `GeoPoint: ${this.geoPointHash.toString()}`;
}
}
}

export class MetadataGeoPointCommitment extends Struct({
geoPointHash: Field,
metadataHash: Field,
}) {
toString(): string {
return `GeoPoint ${this.geoPointHash.toString()}. Metadata: ${this.metadataHash.toString()}`;
}
}

269 changes: 0 additions & 269 deletions contracts/src/tests/SHA3Slice.test.ts

This file was deleted.

31 changes: 31 additions & 0 deletions contracts/src/zkprogram/public/Metadata.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { ZkProgram } from "o1js";
import { MetadataGeoPointCommitment } from "../../model/public/Commitment";
import { GeoPointProviderCircuitProof } from "../private/Geography";
import { attachMetadataToGeoPoint} from "../../logic/public/ExactGeoPoint";
import { SHA3_512 } from "../../model/public/SHA3";

// TODO | IMPORTANT //
// Add a method to ExactGeolocationMetadataCircuit that takes two recursive proofs as inputs:
// 1. GeoPointProviderCircuitProof
// 2. A proof that returns SHA3_512.provable as its public output. This way, it's possible to attached authenticated metadata.
// This is much better than passing metadata as magic value, since the circuit that produces the metadata itself can
// perform verifiable association of the metadata to the GeoPoint in question. For example, the circuit that produced the proof, can
// commit the metadata to a particular GeoPoint, and verify that that metadata is indeed associated to that GeoPont.

/*
* Set of Zero-Knowledge Circuits for associating arbitrary metadata to an exact GeoPoint proof.
*
* Visibility: Public
*/
export const ExactGeolocationMetadataCircuit = ZkProgram({
name: "ExactGeoPointMetadataCircuit",
publicOutput: MetadataGeoPointCommitment,
methods: {
attachMetadataToGeoPoint: {
privateInputs: [GeoPointProviderCircuitProof, SHA3_512.provable],
method: attachMetadataToGeoPoint,
}
}
});

export class ExactGeolocationMetadataCircuitProof extends ZkProgram.Proof(ExactGeolocationMetadataCircuit) { }

0 comments on commit d6cb8c0

Please sign in to comment.