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
Show file tree
Hide file tree
Changes from all 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
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 => {
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;
};
}
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';
Loading