Skip to content

Commit 019ed55

Browse files
committed
🙃 Replace Field.div() with Field.mul() (faster)
1 parent 298c5b4 commit 019ed55

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

‎mina/examples/Airdrop.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ describe('Example Airdrop zkApp', () => {
7070
await fundZkApp();
7171

7272
const id1 = 123123123123123123123123123123n;
73-
const truncatedId1 = id1 % (1n << 32n);
73+
const truncatedId1 = id1 & 0xFFFFFFFFn;
7474
await Mina.transaction(
7575
sender,
7676
() => app.claimReward(Field(id1), sigs, new HumanIDWitness(tree.getWitness(truncatedId1)))
@@ -81,7 +81,7 @@ describe('Example Airdrop zkApp', () => {
8181
tree.setLeaf(truncatedId1, Field(1));
8282

8383
const id2 = 123123123123123123123123123124n;
84-
const truncatedId2 = id2 % (1n << 32n);
84+
const truncatedId2 = id2 & 0xFFFFFFFFn;
8585
await Mina.transaction(
8686
sender,
8787
() => app.claimReward(Field(id2), sigs, new HumanIDWitness(tree.getWitness(truncatedId2)))

‎mina/humanIDv1.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ const authenticate = (humanIDv1: Field, sigs: Signatures) => {
2424

2525
const EmptyRoot = Field(0x21afce36daa1a2d67391072035f4555a85aea7197e5830b128f121aa382770cdn);
2626

27+
const Inverse2Exp32 = Field(0x3fffffffc00000000000000000000000224698fbe706601f8fe037d166d2cf14n);
28+
2729
const requireConsistent = (humanIDv1: Field, truncatedHumanIDv1: Field) => {
28-
humanIDv1.sub(truncatedHumanIDv1).div(1n << 32n).assertLessThan(
30+
humanIDv1.sub(truncatedHumanIDv1).mul(Inverse2Exp32).assertLessThan(
2931
(1n << 222n) + 0x224698fc094cf91b992d30edn,
3032
"HumanID does not match the witness"
3133
);

0 commit comments

Comments
 (0)