Skip to content

Commit

Permalink
🌳 Increase MerkleTree depth to 32
Browse files Browse the repository at this point in the history
  • Loading branch information
KimlikDAO-bot committed May 13, 2024
1 parent 7d99bf4 commit 298c5b4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
17 changes: 8 additions & 9 deletions mina/examples/Airdrop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('Example Airdrop zkApp', () => {

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


const deploy = () => Mina.transaction(deployer, async () => {
const deploy = () => Mina.transaction(deployer, () => {
AccountUpdate.fundNewAccount(deployer);
return app.deploy()
}).then((txn) => txn.prove())
Expand All @@ -70,8 +69,8 @@ describe('Example Airdrop zkApp', () => {
await deploy();
await fundZkApp();

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

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

const id2 = 123123123123124n;
const truncatedId2 = id2 % 65536n;
const id2 = 123123123123123123123123123124n;
const truncatedId2 = id2 % (1n << 32n);
await Mina.transaction(
sender,
() => app.claimReward(Field(id2), sigs, new HumanIDWitness(tree.getWitness(truncatedId2)))
Expand Down Expand Up @@ -136,7 +135,7 @@ describe('Example Airdrop zkApp', () => {
)
.then((txn) => txn.prove())
.then((txn) => txn.sign([senderKey]).send());

let secondBalance = Mina.getBalance(sender);

expect(secondBalance.sub(firstBalance)).toEqual(UInt64.from(10 * 1e9));
Expand Down
6 changes: 3 additions & 3 deletions mina/examples/Airdrop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import {
acceptHumanIDv1,
} from "../humanIDv1";

const MINA = 1e9;

/**
* Example airdrop zkApp, which gives 10 MINA rewards to the first 1000
* unique humans.
*/

const MINA = 1e9;
class Airdrop extends SmartContract {
@state(Field) treeRoot = State<Field>();

Expand All @@ -32,7 +32,7 @@ class Airdrop extends SmartContract {
witness: HumanIDWitness,
) {
acceptHumanIDv1(humanIDv1, sigs, this.treeRoot, witness);
this.send({ to: this.sender.getAndRequireSignature(), amount: 10 * MINA });
this.send({ to: this.sender.getUnconstrained(), amount: 10 * MINA });
}
}

Expand Down
8 changes: 4 additions & 4 deletions mina/humanIDv1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Signatures extends Struct({
sig3: Signature
}) { }

class HumanIDWitness extends MerkleWitness(17) { }
class HumanIDWitness extends MerkleWitness(33) { }

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

const EmptyRoot = Field(0x24807cf0bfd8d61f0f431456489ca762fb4f967c7c58665e80eadd9878b3af19n);
const EmptyRoot = Field(0x21afce36daa1a2d67391072035f4555a85aea7197e5830b128f121aa382770cdn);

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

0 comments on commit 298c5b4

Please sign in to comment.