Skip to content

Commit

Permalink
sort query hashes before compare
Browse files Browse the repository at this point in the history
  • Loading branch information
volodymyr-basiuk committed Feb 1, 2024
1 parent f3cdf61 commit 449672a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/circuits/linkedMultiQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
const fullQueryHashes: Array<bigint> = queryHashes.concat(zeros);
fullQueryHashes.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();
}

bigIntCompare = (a: bigint, b: bigint): number => {
if (a < b) return -1;
if (a > b) return 1;
return 0;
};
}

0 comments on commit 449672a

Please sign in to comment.