Skip to content

Commit

Permalink
feat: upgrade from snarkyjs to o1js
Browse files Browse the repository at this point in the history
  • Loading branch information
maht0rz committed Oct 19, 2023
1 parent 3b59814 commit a0a8eb8
Show file tree
Hide file tree
Showing 99 changed files with 375 additions and 206 deletions.
89 changes: 44 additions & 45 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"typescript-memoize": "^1.1.1"
},
"peerDependencies": {
"snarkyjs": "0.12.0",
"o1js": "0.13.1",
"tsyringe": "^4.7.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/log.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/unbound-method, putout/putout */
import loglevel, { LogLevelDesc } from "loglevel";
import { Provable } from "snarkyjs";
import { Provable } from "o1js";

function logProvable(
logFunction: (...args: unknown[]) => void,
Expand Down
7 changes: 5 additions & 2 deletions packages/common/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Field, FlexibleProvablePure } from "snarkyjs";
import { Field, FlexibleProvablePure } from "o1js";

export function requireTrue(
condition: boolean,
Expand All @@ -16,7 +16,10 @@ export function range(startOrEnd: number, end: number | undefined): number[] {
end = startOrEnd;
startOrEnd = 0;
}
return Array.from({ length: end - startOrEnd }, (ignored, index) => index + startOrEnd);
return Array.from(
{ length: end - startOrEnd },
(ignored, index) => index + startOrEnd
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { FlexibleProvable, Proof } from "snarkyjs";
import type { FlexibleProvable, Proof } from "o1js";
import { singleton } from "tsyringe";
import uniqueId from "lodash/uniqueId";

Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/zkProgrammable/ZkProgrammable.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Experimental, FlexibleProvablePure, Proof } from "snarkyjs";
import { Experimental, FlexibleProvablePure, Proof } from "o1js";
import { Memoize } from "typescript-memoize";

import { mockProof } from "./provableMethod";
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/zkProgrammable/provableMethod.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FlexibleProvable } from "snarkyjs";
import { FlexibleProvable } from "o1js";
import { container } from "tsyringe";

import { ProvableMethodExecutionContext } from "./ProvableMethodExecutionContext";
Expand Down
2 changes: 1 addition & 1 deletion packages/common/test/zkProgrammable/ZkProgrammable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import "reflect-metadata";
// eslint-disable-next-line @typescript-eslint/no-shadow
import { jest } from "@jest/globals";
import { container } from "tsyringe";
import { Experimental, Field, Struct, Proof } from "snarkyjs";
import { Experimental, Field, Struct, Proof } from "o1js";

import {
mockProof,
Expand Down
2 changes: 1 addition & 1 deletion packages/module/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"peerDependencies": {
"@proto-kit/common": "*",
"@proto-kit/protocol": "*",
"snarkyjs": "0.12.0",
"o1js": "0.13.1",
"tsyringe": "^4.7.0"
},
"gitHead": "b2528538c73747d000cc3ea99ee26ee415d8248d"
Expand Down
2 changes: 1 addition & 1 deletion packages/module/src/method/MethodParameterDecoder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-underscore-dangle */
import { Field } from "snarkyjs";
import { Field } from "o1js";

import { RuntimeModule } from "../runtime/RuntimeModule";

Expand Down
2 changes: 1 addition & 1 deletion packages/module/src/method/decorator.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import "reflect-metadata";

import { Bool, Field } from "snarkyjs";
import { Bool, Field } from "o1js";
import { Option, StateTransition } from "@proto-kit/protocol";

import { toStateTransitionsHash } from "./runtimeMethod.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/module/src/method/runtimeMethod.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Field, FlexibleProvable, Poseidon } from "snarkyjs";
import { Field, FlexibleProvable, Poseidon } from "o1js";
import { container } from "tsyringe";
import {
StateTransition,
Expand Down
2 changes: 1 addition & 1 deletion packages/module/src/runtime/MethodIdResolver.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { stringToField } from "@proto-kit/protocol";
import { Poseidon } from "snarkyjs";
import { Poseidon } from "o1js";

import type { Runtime, RuntimeModulesRecord } from "./Runtime";

Expand Down
2 changes: 1 addition & 1 deletion packages/module/src/runtime/Runtime.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// eslint-disable-next-line max-len
/* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-assignment,max-lines */
import { Experimental } from "snarkyjs";
import { Experimental } from "o1js";
import { DependencyContainer, injectable } from "tsyringe";
import {
StringKeyOf,
Expand Down
2 changes: 1 addition & 1 deletion packages/module/src/state/InMemoryStateService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Field } from "snarkyjs";
import { Field } from "o1js";
import { StateService } from "@proto-kit/protocol";

/**
Expand Down
9 changes: 4 additions & 5 deletions packages/module/test/Runtime.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Bool } from "snarkyjs";
import { Bool } from "o1js";

import { InMemoryStateService, MethodIdResolver, Runtime } from "../src";

Expand Down Expand Up @@ -32,10 +32,9 @@ describe("runtime", () => {
const moduleName = "Balances";
const methodName = "getTotalSupply";

const methodId = runtime.dependencyContainer.resolve<MethodIdResolver>("MethodIdResolver").getMethodId(
moduleName,
methodName
);
const methodId = runtime.dependencyContainer
.resolve<MethodIdResolver>("MethodIdResolver")
.getMethodId(moduleName, methodName);
const method = runtime.getMethodById(methodId);

// eslint-disable-next-line jest/no-restricted-matchers
Expand Down
2 changes: 1 addition & 1 deletion packages/module/test/modules/Admin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PublicKey } from "snarkyjs";
import { PublicKey } from "o1js";

import { runtimeModule } from "../../src/module/decorator.js";
import { RuntimeModule } from "../../src/runtime/RuntimeModule.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/module/test/modules/Balances.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
Proof,
PublicKey,
UInt64,
} from "snarkyjs";
} from "o1js";
import { container } from "tsyringe";
import {
type ProvableStateTransition,
Expand Down
2 changes: 1 addition & 1 deletion packages/module/test/modules/Balances.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Bool, PublicKey, UInt64 } from "snarkyjs";
import { Bool, PublicKey, UInt64 } from "o1js";
import { Option, State, StateMap } from "@proto-kit/protocol";
import { Presets } from "@proto-kit/common";

Expand Down
9 changes: 3 additions & 6 deletions packages/module/test/modules/State.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import "reflect-metadata";
import { Bool, PublicKey, UInt64 } from "snarkyjs";
import { Bool, PublicKey, UInt64 } from "o1js";
import { container } from "tsyringe";
import {
NetworkState,
Option,
RuntimeMethodExecutionContext,
RuntimeTransaction,
StateService
StateService,
} from "@proto-kit/protocol";

import {
InMemoryStateService,
Runtime
} from "../../src";
import { InMemoryStateService, Runtime } from "../../src";

import { Admin } from "./Admin";
import { Balances } from "./Balances";
Expand Down
24 changes: 11 additions & 13 deletions packages/module/test/modules/methodId.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import "reflect-metadata";
import { Bool, Field } from "snarkyjs";
import { Bool, Field } from "o1js";
import { beforeAll, beforeEach } from "@jest/globals";

import { Runtime } from "../../src/runtime/Runtime";
Expand Down Expand Up @@ -56,21 +56,19 @@ describe("methodId", () => {
["Admin", "isAdminWithAVeryVeryVeryVeryLongName"],
["Balance", "getTotalSupply"],
["Balance", "getBalance"],
])(
"should pass and encode correctly",
(givenModuleName, givenMethodName) => {
expect.assertions(2);
])("should pass and encode correctly", (givenModuleName, givenMethodName) => {
expect.assertions(2);

const methodId = resolver.getMethodId(givenModuleName, givenMethodName);
const methodId = resolver.getMethodId(givenModuleName, givenMethodName);

const [moduleName, methodName] = resolver.getMethodNameFromId(
methodId
) ?? [undefined, undefined];
const [moduleName, methodName] = resolver.getMethodNameFromId(methodId) ?? [
undefined,
undefined,
];

expect(moduleName).toBe(givenModuleName);
expect(methodName).toBe(givenMethodName);
}
);
expect(moduleName).toBe(givenModuleName);
expect(methodName).toBe(givenMethodName);
});

it("should fail for invalid module name", () => {
expect.assertions(1);
Expand Down
Loading

0 comments on commit a0a8eb8

Please sign in to comment.