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

sort query hashes before compare #81

Merged
merged 3 commits into from
Feb 5, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/circuits/linkedMultiQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class LinkedMultiQueryVerifier implements PubSignalsVerifier {
ldOpts
);

const queryHashes = queriesMetadata.map((queryMeta) => {
let queryHashes = queriesMetadata.map((queryMeta) => {
const valueHash = poseidon.spongeHashX(queryMeta.values, 6);
return poseidon.hash([
schemaHash.bigInt(),
Expand All @@ -63,6 +63,14 @@ export class LinkedMultiQueryVerifier implements PubSignalsVerifier {
]);
});

this.pubSignals.circuitQueryHash.sort(this.bigIntCompare);

const zeros: Array<bigint> = Array.from({
length: this.pubSignals.circuitQueryHash.length - queryHashes.length
}).fill(BigInt(0)) as Array<bigint>;
queryHashes = queryHashes.concat(zeros);
queryHashes.sort(this.bigIntCompare);

if (!queryHashes.every((queryHash, i) => queryHash === this.pubSignals.circuitQueryHash[i])) {
throw new Error('query hashes do not match');
}
Expand All @@ -73,4 +81,10 @@ export class LinkedMultiQueryVerifier implements PubSignalsVerifier {
async verifyStates(): Promise<void> {
return Promise.resolve();
}

private bigIntCompare = (a: bigint, b: bigint): number => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

=> a-b

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sort expects number as return tupe (a-b will return BigInt), could be something like this a<b?-1:(a>b?1:0)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, no in that case it's fine

if (a < b) return -1;
if (a > b) return 1;
return 0;
};
}
Loading