Skip to content

Commit

Permalink
sort query hashes before compare (#81)
Browse files Browse the repository at this point in the history
* sort query hashes before compare
  • Loading branch information
volodymyr-basiuk authored Feb 5, 2024
1 parent f3cdf61 commit 8fbeb18
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/circuits/linkedMultiQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ export class LinkedMultiQueryVerifier implements PubSignalsVerifier {
]);
});

if (!queryHashes.every((queryHash, i) => queryHash === this.pubSignals.circuitQueryHash[i])) {
const circuitQueryHashes = this.pubSignals.circuitQueryHash
.filter((i) => i !== 0n)
.sort(this.bigIntCompare);
queryHashes.sort(this.bigIntCompare);
if (!queryHashes.every((queryHash, i) => queryHash === circuitQueryHashes[i])) {
throw new Error('query hashes do not match');
}

Expand All @@ -73,4 +77,10 @@ export class LinkedMultiQueryVerifier implements PubSignalsVerifier {
async verifyStates(): Promise<void> {
return Promise.resolve();
}

private bigIntCompare = (a: bigint, b: bigint): number => {
if (a < b) return -1;
if (a > b) return 1;
return 0;
};
}
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * as auth from '@lib/auth/auth';
export * as resolver from '@lib/state/resolver';
export * as protocol from '@lib/types-sdk';
export { core } from '@0xpolygonid/js-sdk';
export { core } from '@0xpolygonid/js-sdk';

0 comments on commit 8fbeb18

Please sign in to comment.