diff --git a/mina/examples/Airdrop.test.ts b/mina/examples/Airdrop.test.ts index 8379d9a..253df8a 100644 --- a/mina/examples/Airdrop.test.ts +++ b/mina/examples/Airdrop.test.ts @@ -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"); @@ -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()) @@ -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))) @@ -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))) @@ -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)); diff --git a/mina/examples/Airdrop.ts b/mina/examples/Airdrop.ts index b6eceac..465e353 100644 --- a/mina/examples/Airdrop.ts +++ b/mina/examples/Airdrop.ts @@ -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(); @@ -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 }); } } diff --git a/mina/humanIDv1.ts b/mina/humanIDv1.ts index 58d038b..24e20f1 100644 --- a/mina/humanIDv1.ts +++ b/mina/humanIDv1.ts @@ -6,7 +6,7 @@ class Signatures extends Struct({ sig3: Signature }) { } -class HumanIDWitness extends MerkleWitness(17) { } +class HumanIDWitness extends MerkleWitness(33) { } const addToMerkleTree = (treeRoot: State, witness: HumanIDWitness) => { const currentTreeRoot = treeRoot.getAndRequireEquals(); @@ -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" ); }