Skip to content

Commit 298c5b4

Browse files
committed
🌳 Increase MerkleTree depth to 32
1 parent 7d99bf4 commit 298c5b4

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

‎mina/examples/Airdrop.test.ts

+8-9
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('Example Airdrop zkApp', () => {
2929

3030
beforeEach(() => Mina.LocalBlockchain({ proofsEnabled: true })
3131
.then((local) => {
32-
tree = new MerkleTree(17);
32+
tree = new MerkleTree(33);
3333
Mina.setActiveInstance(local);
3434
app = new Airdrop(appAddr);
3535
local.addAccount(deployer, "100000000000");
@@ -39,12 +39,11 @@ describe('Example Airdrop zkApp', () => {
3939
const fundZkApp = () => Mina.transaction(sender, async () => {
4040
let senderUpdate = AccountUpdate.create(sender);
4141
senderUpdate.requireSignature();
42-
senderUpdate.send({ to: appAddr, amount: UInt64.from(100 * 1e9) });
42+
senderUpdate.send({ to: appAddr, amount: 100 * 1e9 });
4343
}).then((txn) => txn.prove())
4444
.then((txn) => txn.sign([senderKey]).send());
4545

46-
47-
const deploy = () => Mina.transaction(deployer, async () => {
46+
const deploy = () => Mina.transaction(deployer, () => {
4847
AccountUpdate.fundNewAccount(deployer);
4948
return app.deploy()
5049
}).then((txn) => txn.prove())
@@ -70,8 +69,8 @@ describe('Example Airdrop zkApp', () => {
7069
await deploy();
7170
await fundZkApp();
7271

73-
const id1 = 123123123123123n;
74-
const truncatedId1 = id1 % 65536n;
72+
const id1 = 123123123123123123123123123123n;
73+
const truncatedId1 = id1 % (1n << 32n);
7574
await Mina.transaction(
7675
sender,
7776
() => app.claimReward(Field(id1), sigs, new HumanIDWitness(tree.getWitness(truncatedId1)))
@@ -81,8 +80,8 @@ describe('Example Airdrop zkApp', () => {
8180

8281
tree.setLeaf(truncatedId1, Field(1));
8382

84-
const id2 = 123123123123124n;
85-
const truncatedId2 = id2 % 65536n;
83+
const id2 = 123123123123123123123123123124n;
84+
const truncatedId2 = id2 % (1n << 32n);
8685
await Mina.transaction(
8786
sender,
8887
() => app.claimReward(Field(id2), sigs, new HumanIDWitness(tree.getWitness(truncatedId2)))
@@ -136,7 +135,7 @@ describe('Example Airdrop zkApp', () => {
136135
)
137136
.then((txn) => txn.prove())
138137
.then((txn) => txn.sign([senderKey]).send());
139-
138+
140139
let secondBalance = Mina.getBalance(sender);
141140

142141
expect(secondBalance.sub(firstBalance)).toEqual(UInt64.from(10 * 1e9));

‎mina/examples/Airdrop.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ import {
1212
acceptHumanIDv1,
1313
} from "../humanIDv1";
1414

15+
const MINA = 1e9;
16+
1517
/**
1618
* Example airdrop zkApp, which gives 10 MINA rewards to the first 1000
1719
* unique humans.
1820
*/
19-
20-
const MINA = 1e9;
2121
class Airdrop extends SmartContract {
2222
@state(Field) treeRoot = State<Field>();
2323

@@ -32,7 +32,7 @@ class Airdrop extends SmartContract {
3232
witness: HumanIDWitness,
3333
) {
3434
acceptHumanIDv1(humanIDv1, sigs, this.treeRoot, witness);
35-
this.send({ to: this.sender.getAndRequireSignature(), amount: 10 * MINA });
35+
this.send({ to: this.sender.getUnconstrained(), amount: 10 * MINA });
3636
}
3737
}
3838

‎mina/humanIDv1.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Signatures extends Struct({
66
sig3: Signature
77
}) { }
88

9-
class HumanIDWitness extends MerkleWitness(17) { }
9+
class HumanIDWitness extends MerkleWitness(33) { }
1010

1111
const addToMerkleTree = (treeRoot: State<Field>, witness: HumanIDWitness) => {
1212
const currentTreeRoot = treeRoot.getAndRequireEquals();
@@ -22,11 +22,11 @@ const authenticate = (humanIDv1: Field, sigs: Signatures) => {
2222
return true;
2323
}
2424

25-
const EmptyRoot = Field(0x24807cf0bfd8d61f0f431456489ca762fb4f967c7c58665e80eadd9878b3af19n);
25+
const EmptyRoot = Field(0x21afce36daa1a2d67391072035f4555a85aea7197e5830b128f121aa382770cdn);
2626

2727
const requireConsistent = (humanIDv1: Field, truncatedHumanIDv1: Field) => {
28-
humanIDv1.sub(truncatedHumanIDv1).div(65536).assertLessThan(
29-
(1n << 238n) + 0x224698fc094cf91b992d30ed0000n,
28+
humanIDv1.sub(truncatedHumanIDv1).div(1n << 32n).assertLessThan(
29+
(1n << 222n) + 0x224698fc094cf91b992d30edn,
3030
"HumanID does not match the witness"
3131
);
3232
}

0 commit comments

Comments
 (0)