Skip to content

Commit

Permalink
Merge pull request #1350 from o1-labs/feat/rename-snarkyjs-o1js
Browse files Browse the repository at this point in the history
Rename all references of `snarkyjs` to `o1js` internally
  • Loading branch information
MartinMinkov authored Jan 22, 2024
2 parents 4b2f32a + 5a784fb commit aa7669d
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[submodule "src/snarkyjs-bindings"]
[submodule "src/o1js-bindings"]
path = src/bindings
url = https://github.com/o1-labs/snarkyjs-bindings.git
url = https://github.com/o1-labs/o1js-bindings.git
[submodule "src/mina"]
path = src/mina
url = https://github.com/MinaProtocol/mina.git
6 changes: 3 additions & 3 deletions README-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ This command builds the OCaml and Rust artifacts and copies them to the `src/bin

### Build Scripts

The root build script which kicks off the build process is under `src/bindings/scripts/update-snarkyjs-bindings.sh`. This script is responsible for building the Node.js and web artifacts for o1js and places them under `src/bindings/compiled` to be used by o1js.
The root build script which kicks off the build process is under `src/bindings/scripts/update-o1js-bindings.sh`. This script is responsible for building the Node.js and web artifacts for o1js, and places them under `src/bindings/compiled`, to be used by o1js.

### OCaml Bindings

o1js depends on Pickles, snarky, and parts of the Mina transaction logic, all of which are compiled to JavaScript and stored as artifacts to be used by o1js natively. The OCaml bindings are located under `src/bindings`. See the [OCaml Bindings README](https://github.com/o1-labs/o1js-bindings/blob/main/README.md) for more information.

To compile the OCaml code, a build tool called Dune is used. Dune is a build system for OCaml projects and is used with Js_of_ocaml to compile the OCaml code to JavaScript. The Dune file responsible for compiling the OCaml code is located under `src/bindings/ocaml/dune`. Two build targets, `snarky_js_node` and `snarky_js_web`, compile the Mina dependencies and link the Wasm artifacts to build the Node.js and web artifacts, respectively. The output file is `snark_js_node.bc.js`, which is used by o1js.
To compile the OCaml code, a build tool called Dune is used. Dune is a build system for OCaml projects, and is used in addition with Js_of_ocaml to compile the OCaml code to JavaScript. The dune file that is responsible for compiling the OCaml code is located under `src/bindings/ocaml/dune`. There are two build targets: `o1js_node` and `o1js_web`, which compile the Mina dependencies as well as link the wasm artifacts to build the Node.js and web artifacts, respectively. The output file is `o1js_node.bc.js`, which is used by o1js.

### WebAssembly Bindings

Expand All @@ -74,7 +74,7 @@ For the Wasm build, the output files are:

### Generated Constant Types

In addition to building the OCaml and Rust code, the build script also generates TypeScript types for constants used in the Mina protocol. These types are generated from the OCaml source files and are located under `src/bindings/crypto/constants.ts` and `src/bindings/mina-transaction/gen`. When building the bindings, these constants are auto-generated by Dune. If you want to add a new constant, edit the `src/bindings/ocaml/snarky_js_constants` file and then run `npm run build:bindings` to regenerate the TypeScript files.
In addition to building the OCaml and Rust code, the build script also generates TypeScript types for constants used in the Mina protocol. These types are generated from the OCaml source files, and are located under `src/bindings/crypto/constants.ts` and `src/bindings/mina-transaction/gen`. When building the bindings, these constants are auto-generated by Dune. If you wish to add a new constant, you can edit the `src/bindings/ocaml/o1js_constants` file, and then run `npm run build:bindings` to regenerate the TypeScript files.

o1js uses these types to ensure that the constants used in the protocol are consistent with the OCaml source files.

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
"scripts": {
"dev": "npx tsc -p tsconfig.test.json && node src/build/copy-to-dist.js",
"build": "node src/build/copy-artifacts.js && rimraf ./dist/node && npm run dev && node src/build/buildNode.js",
"build:bindings": "./src/bindings/scripts/build-snarkyjs-node.sh",
"build:update-bindings": "./src/bindings/scripts/update-snarkyjs-bindings.sh",
"build:bindings": "./src/bindings/scripts/build-o1js-node.sh",
"build:update-bindings": "./src/bindings/scripts/update-o1js-bindings.sh",
"build:wasm": "./src/bindings/scripts/update-wasm-and-types.sh",
"build:web": "rimraf ./dist/web && node src/build/buildWeb.js",
"build:examples": "npm run build && rimraf ./dist/examples && npx tsc -p tsconfig.examples.json",
Expand Down
2 changes: 1 addition & 1 deletion src/build/buildWeb.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ async function buildWeb({ production }) {
await Promise.all([tscPromise, copyPromise]);

if (minify) {
let o1jsWebPath = './dist/web/web_bindings/snarky_js_web.bc.js';
let o1jsWebPath = './dist/web/web_bindings/o1js_web.bc.js';
let o1jsWeb = await readFile(o1jsWebPath, 'utf8');
let { code } = await esbuild.transform(o1jsWeb, {
target,
Expand Down
4 changes: 2 additions & 2 deletions src/examples/plain-html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<html>
<head>
<meta charset="utf-8" />
<title>hello-snarkyjs</title>
<title>hello-o1js</title>
<script type="importmap">
{ "imports": { "snarkyjs": "./index.js" } }
{ "imports": { "o1js": "./index.js" } }
</script>
<script type="module" src="./simple_zkapp.js">
</script>
Expand Down
2 changes: 1 addition & 1 deletion src/lib/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function handleResult(result: any) {
* A list of keywords used to filter out unwanted lines from the error stack trace.
*/
const lineRemovalKeywords = [
'snarky_js_node.bc.cjs',
'o1js_node.bc.cjs',
'/builtin/',
'CatchAndPrettifyStacktrace', // Decorator name to remove from stacktrace (covers both class and method decorator)
] as const;
Expand Down

0 comments on commit aa7669d

Please sign in to comment.