Skip to content

Commit

Permalink
semantic variable changes for better lore and add zk docs
Browse files Browse the repository at this point in the history
  • Loading branch information
kibagateaux committed Jan 29, 2025
1 parent ee827c4 commit ba250ad
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 31 deletions.
28 changes: 27 additions & 1 deletion build.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,30 @@ override fun onCreate(savedInstanceState: Bundle?) {

# iOS
TODO


# ZK
### ZKey
Used for proving and verification. Only the proving key should be public, verification key should remain private (TODO investigate security of circuit with public verification key since we want every player to be able to verify)

How to generate:
```sh
# 0. Ensure packages are installed in the project locally
npm i
# 1. Start the Powers of Tau ceremony
npx snarkjs powersoftau new bn254 18 summoning_circle_18_0000.ptau -v

# 2. Contribute some randomness to the ceremony (can repeatbe repeated)
npx snarkjs powersoftau contribute summoning_circle_18_0000.ptau summoning_circle_18_0001.ptau --name="First contribution" -v

# 3. Prepare phase 2 of the ceremony
npx snarkjs powersoftau prepare phase2 summoning_circle_18_0001.ptau summoning_circle_18_final.ptau -v

# 4. Generate the zkey file
npx snarkjs groth16 setup my_circuit.r1cs summoning_circle_18_final.ptau summoning_circle_18_0001.zkey

# 5. (optional_ Contribute more randomness to the zkey file
# npx snarkjs zkey contribute summoning_circle_18_0.zkey summoning_circle_18_1.zkey --name="1st Contributor Name" -v

# 6. Export the final zkey with verification + proving keys
npx snarkjs zkey export verificationkey summoning_circle_18_0001.zkey summoning_circle_verification_key.json
```
2 changes: 1 addition & 1 deletion src/assets/game-content/inventory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export default {
Github: {
meta: {
description:
'Login to Github so your Jinni learn from your dev skills and automagically evolve',
'Login to Github so your Jinni learn from your dev skills and automajikally evolve',
perks: `1. Train your Jinni on how you think
2. Track your daily work routines
3. Expand your network effect with other devs
Expand Down
26 changes: 13 additions & 13 deletions src/circuits/circle.circom
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ template CircleCertV1b() {
// Public outputs for verifier
signal output sigNullifier;
// allow verifier to derive signers ETH address
signal output magiPubKeyX; // Output the signer's public key X
signal output magiPubKeyY; // Output the signer's public key Y
signal output majiPubKeyX; // Output the signer's public key X
signal output majiPubKeyY; // Output the signer's public key Y

// --- 1. Verify tap signature ---
(sigNullifier, magiPubKeyX, magiPubKeyY) = CircleCertV1()(
(sigNullifier, majiPubKeyX, majiPubKeyY) = CircleCertV1()(
teS,
teTx,
teTy,
Expand Down Expand Up @@ -142,11 +142,11 @@ template CircleCertV1() {
// Public outputs
signal output sigNullifier;
// allow verifier to derive signers ETH address
signal output magiPubKeyX; // Output the signer's public key X
signal output magiPubKeyY; // Output the signer's public key Y
signal output majiPubKeyX; // Output the signer's public key X
signal output majiPubKeyY; // Output the signer's public key Y

// --- 1. Verify tap signature ---
(magiPubKeyX, magiPubKeyY) <== BabyJubJubECDSA()(
(majiPubKeyX, majiPubKeyY) <== BabyJubJubECDSA()(
teS,
teTx,
teTy,
Expand Down Expand Up @@ -215,8 +215,8 @@ component main = CircleCertV1();
// signal output pubKeyNullifierRandomnessHash;

// // Verify tap signature. Get back public key of signer
// var magiPubKeyX, magiPubKeyY;
// (magiPubKeyX, magiPubKeyY) <== BabyJubJubECDSA()(
// var majiPubKeyX, majiPubKeyY;
// (majiPubKeyX, majiPubKeyY) <== BabyJubJubECDSA()(
// tapS,
// tapTx,
// tapTy,
Expand All @@ -226,9 +226,9 @@ component main = CircleCertV1();

// // Extract public key from tap signature
// // @TODO this is pubkey not address
// signal magiPubKeyHash;
// magiPubKeyHash <== Poseidon(2)(
// [magiPubKeyX, magiPubKeyY]
// signal majiPubKeyHash;
// majiPubKeyHash <== Poseidon(2)(
// [majiPubKeyX, majiPubKeyY]
// );

// // Verify EdDSA signature on tap public key
Expand All @@ -240,14 +240,14 @@ component main = CircleCertV1();
// // pubKeySignatureS,
// // pubKeySignatureR8x,
// // pubKeySignatureR8y,
// // magiPubKeyHash
// // majiPubKeyHash
// // );

// // sigNullifier = hash(s, sigNullifierRandomness)
// sigNullifier <== Poseidon(2)([tapS, sigNullifierRandomness]);

// // pubKeyNullifier = hash(s, pubKeyNullifierRandomness)
// pubKeyNullifier <== Poseidon(2)([magiPubKeyHash, pubKeyNullifierRandomness]);
// pubKeyNullifier <== Poseidon(2)([majiPubKeyHash, pubKeyNullifierRandomness]);

// // pubKeyNullifierRandomnessHash = hash(pubKeyNullifierRandomness)
// pubKeyNullifierRandomnessHash <== Poseidon(1)([pubKeyNullifierRandomness]);
Expand Down
2 changes: 1 addition & 1 deletion src/contexts/AuthContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const AuthProvider: React.FC<Props> = ({ children }) => {
getStorage(ID_PLAYER_SLOT).then((s) => console.log('AuthContext: fget player id', s));
if (!player?.id) {
getStorage<string>(ID_PLAYER_SLOT).then((id) => id && login(id));
// magicRug();
// majikRug();
} else {
// we hydrate spellbook manually once required to prevent slow app start
}
Expand Down
4 changes: 2 additions & 2 deletions src/inventory/__tests__/maliks-majik.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
MAJIK_CARDS,
} from 'utils/config';
import maliksMajik, { getMaster } from '../maliks-majik';
import { JubjubSignature } from 'types/GameMechanics';
import { MajikSpell } from 'types/GameMechanics';
import { includes } from 'lodash';

describe('item inventory', () => {
Expand Down Expand Up @@ -62,7 +62,7 @@ describe('item inventory', () => {
});

describe('getMaster', () => {
const fakeSig = (addy: string): JubjubSignature => ({
const fakeSig = (addy: string): MajikSpell => ({
ether: addy,
der: '',
raw: { r: '', s: '', v: 28 },
Expand Down
2 changes: 1 addition & 1 deletion src/inventory/maliks-majik.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ const item: InventoryItem = {
spell: ABILITY_ACTIVATE_JINNI,
activityType: 'unauthenticated',
});
return { error: 'You need to create an magic ID first' };
return { error: 'You need to create an majik ID first' };
}

if (!myProof) {
Expand Down
12 changes: 7 additions & 5 deletions src/types/GameMechanics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,25 @@ export interface Avatar {
}

// ex. {"0x46C79830a421038E75853eD0b476Ae17bFeC289A":{"raw":{"r":"5605a907f71ab6dbbc894c7a9d118b8629104b5b20070217a4cba7fb591c102b","s":"49dff57b6b7740896f77187361ca098a2059b8979e7412ad18023f8c85112d9c","v":27},"der":"304502205605a907f71ab6dbbc894c7a9d118b8629104b5b20070217a4cba7fb591c102b022100b6200a849488bf769088e78c9e35f6749a55244f10d48d8ea7d01f004b2513a5","ether":"0x5605a907f71ab6dbbc894c7a9d118b8629104b5b20070217a4cba7fb591c102b49dff57b6b7740896f77187361ca098a2059b8979e7412ad18023f8c85112d9c1b"}}
export interface JubjubSignature {
export interface MajikSpell {
ether: string; // 0x hex value of signed messaged
der: string; // idk
raw: {
// proof to derive signature and signer?
// raw signature values to derive signer
r: string;
s: string;
v: number;
};
}
export interface JubJubSigResponse {

export interface MajikSpellMeta {
// TODO add success, spellName, and other metadata
etherAddress: string;
signature: JubjubSignature;
signature: MajikSpell;
}

export interface SummoningProofs {
[jubmojiAddress: string]: JubjubSignature;
[jubmojiAddress: string]: MajikSpell;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/utils/__tests__/zkpid.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
saveId,
toObject,
_delete_id,
// magicRug,
// majikRug,
// deleteSpellbook,
} from 'utils/zkpid';
import { Wallet, providers } from 'ethers';
Expand Down Expand Up @@ -344,12 +344,12 @@ describe('zkpid, Anonymous Authentication and Zero-Knowledge Proofs', () => {
// });
// });

// describe('magicRug', () => {
// describe('majikRug', () => {
// test('deletes all user data in development', async () => {
// const mockSaveStorage = jest.fn();
// saveStorage = mockSaveStorage;

// magicRug();
// majikRug();

// expect(mockSaveStorage).toHaveBeenCalledTimes(6);
// expect(mockSaveStorage).toHaveBeenCalledWith(ID_PLAYER_SLOT, '', false);
Expand All @@ -363,7 +363,7 @@ describe('zkpid, Anonymous Authentication and Zero-Knowledge Proofs', () => {
// test('throws error when called in production', () => {
// const originalEnv = process.env.NODE_ENV;

// expect(() => magicRug()).toThrow('CANNOT DELETE ZK IDs');
// expect(() => majikRug()).toThrow('CANNOT DELETE ZK IDs');

// });
// });
Expand Down
4 changes: 2 additions & 2 deletions src/utils/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from 'utils/config';
import { getSpellBook } from 'utils/zkpid';
import { debug, track } from './logging';
import { JubJubSigResponse } from 'types/GameMechanics';
import { MajikSpellMeta } from 'types/GameMechanics';
import { signWithId } from './zkpid';

// TODO persist cache to local storage for better offline use once internet connection lost?
Expand Down Expand Up @@ -359,7 +359,7 @@ export const saveHomeConfig = async ({
};

export type SignatureValidityParams<T> = {
signature: JubJubSigResponse;
signature: MajikSpellMeta;
args: T;
};

Expand Down
2 changes: 1 addition & 1 deletion src/utils/mayanese.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const archetypes: MayanArchetype[] = [
id: 'Monkey',
number: 11,
energyType: 'Connecting',
activations: ['Play', 'Illusion', 'Magic'],
activations: ['Play', 'Illusion', 'Majik'],
},
{
id: 'Human',
Expand Down

0 comments on commit ba250ad

Please sign in to comment.