Skip to content

Commit 0681caa

Browse files
committed
Merge branch 'fix/update-network-id' of github.com:o1-labs/o1js into fix/update-network-id
2 parents 3fdc3f1 + b926974 commit 0681caa

File tree

12 files changed

+503
-108
lines changed

12 files changed

+503
-108
lines changed

.github/workflows/build-bindings.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,15 @@ jobs:
2727
run: |
2828
set -Eeu
2929
./pin.sh
30-
nix develop o1js --command bash -c "npm run build:update-bindings"
30+
nix run o1js#update-bindings --max-jobs 4
31+
#fail if this changes any files
32+
cd src/bindings
33+
git diff --exit-code
34+
- name: add build to gc-root if on main
35+
if: github.ref == 'refs/heads/main'
36+
run: |
37+
nix build o1js#o1js-bindings --out-link /home/app/actions-runner/nix-cache/main-bindings-gcroot
3138
- name: Cleanup the Nix store
3239
run: |
33-
nix-env --delete-generations old
34-
nix-collect-garbage -d --quiet
3540
nix-store --gc --print-dead
3641
nix-store --optimise

CHANGELOG.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
1515
_Security_ in case of vulnerabilities.
1616
-->
1717

18-
## [Unreleased](https://github.com/o1-labs/o1js/compare/e1bac02...HEAD)
18+
## [Unreleased](https://github.com/o1-labs/o1js/compare/b857516...HEAD)
1919

20-
### Added
20+
## [2.2.0](https://github.com/o1-labs/o1js/compare/e1bac02...b857516) - 2024-12-10
2121

22-
-`ZkProgram` to support non-pure provable types as inputs and outputs https://github.com/o1-labs/o1js/pull/1828
22+
### Added
2323

24+
- `ZkProgram` to support non-pure provable types as inputs and outputs https://github.com/o1-labs/o1js/pull/1828
2425
- Add `enforceTransactionLimits` parameter on Network https://github.com/o1-labs/o1js/issues/1910
2526
- Method for optional types to assert none https://github.com/o1-labs/o1js/pull/1922
2627
- Increased maximum supported amount of methods in a `SmartContract` or `ZkProgram` to 30. https://github.com/o1-labs/o1js/pull/1918
@@ -65,7 +66,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
6566
- `divMod64()` division modulo 2^64 that returns the remainder and quotient of the operation
6667
- `addMod64()` addition modulo 2^64
6768
- Bitwise OR via `{UInt32, UInt64}.or()`
68-
- **BLAKE2B hash function** gadget [#1285](https://github.com/o1-labs/o1js/pull/1285)
69+
- **BLAKE2B hash function** gadget. https://github.com/o1-labs/o1js/pull/1767
6970

7071
## [1.9.1](https://github.com/o1-labs/o1js/compare/f15293a69...7e9394) - 2024-10-15
7172

README-dev.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ Before starting, ensure you have the following tools installed:
1515

1616
- [Git](https://git-scm.com/)
1717
- [Node.js and npm](https://nodejs.org/)
18-
- [Dune](https://github.com/ocaml/dune) (only needed when compiling o1js from source)
19-
- [Cargo](https://www.rust-lang.org/learn/get-started) (only needed when compiling o1js from source)
18+
- [Dune, ocamlc, opam](https://github.com/ocaml/dune) (only needed when compiling o1js from source)
19+
- [Cargo, rustup](https://www.rust-lang.org/learn/get-started) (only needed when compiling o1js from source)
2020

2121
After cloning the repository, you need to fetch the submodules:
2222

README-nix.md

Lines changed: 308 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,308 @@
1+
# o1js README-nix
2+
3+
[Nix](https://nixos.org/) is a tool for package management and system
4+
configuration that can help developers build a project in a reproducible and
5+
reliable manner, without messing up versions during upgrades.
6+
7+
Much like the `mina` repository, you can use Nix to
8+
handle the dependencies required across the codebase, including npm scripts.
9+
10+
> **When should I use Nix?**
11+
> If you cannot build the codebase locally (due to untrusty package manager,
12+
> faulty versioning, or unavailable libraries), it is a good idea to try the Nix
13+
> build instead. This can happen especially if you're using a Mac–and even more
14+
> likely–with non-Intel chips.
15+
16+
## Installing Nix
17+
18+
The following command will install Nix on your machine.
19+
20+
```console
21+
sh <(curl -L https://nixos.org/nix/install) --daemon
22+
```
23+
24+
If you're unsure about your Nix setup, the assistant will guide you towards a
25+
clean installation. It will involve backing up your old `/etc/X` and `/etc/X.backup-before-nix` for `X = {bash.bashrc, bashrc, zshrc}`, and finally
26+
uninstalling and reinstalling Nix from scratch.
27+
28+
> **warning for macOS users**: macOS updates will often break your nix
29+
> installation. To prevent that, you can add the following to your `~/.bashrc`
30+
> or `~/.zshrc`:
31+
>
32+
> ```bash
33+
> # avoid macOS updates to destroy nix
34+
> if [ -e '/nix/var/nix/profiles/default/etc/profile.d/>nix-daemon.sh' ]; then
35+
> source '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh'
36+
> fi
37+
> ```
38+
39+
After installing, the current shell won't be a Nix shell. To create one, open a
40+
new shell and type
41+
42+
```console
43+
nix-shell -p nix-info --run "nix-info -m"
44+
```
45+
46+
That should output some basic information about the configuration parameters for Nix.
47+
48+
## Enabling Flakes (recommended)
49+
50+
Mina is packaged using [Nix Flakes](https://nixos.wiki/wiki/Flakes),
51+
which are an experimental feature of Nix. However, compatibility with
52+
pre-flake Nix is provided. If you wish to contribute the Nix
53+
expressions in this repository, or want to get some convenience
54+
features and speed improvements, **it is advisable to enable flakes**. For
55+
this, you'll want to make sure you're running recent Nix (⩾2.5) and
56+
have enabled the relevant experimental features, either in
57+
`/etc/nix/nix.conf` or (recommended) in `~/.config/nix/nix.conf` (meaning to add
58+
`experimental-features = nix-command flakes` in that file):
59+
60+
```console
61+
mkdir -p "${XDG_CONFIG_HOME-${HOME}/.config}/nix"
62+
echo 'experimental-features = nix-command flakes' > "${XDG_CONFIG_HOME-${HOME}/.config}/nix/nix.conf"
63+
```
64+
65+
Verify your flake support is working by running:
66+
67+
```console
68+
nix flake metadata github:nixos/nixpkgs
69+
```
70+
71+
## Building with Nix
72+
73+
Start by cloning the repository. Optionally, you can install dependencies with
74+
`npm i`, but Nix should take care of all the packages.
75+
76+
```bash
77+
git clone --recurse-submodules [email protected]:o1-labs/o1js.git
78+
cd o1js
79+
# npm install
80+
```
81+
82+
From a new shell, go to `{REPO_PATH}/o1js` and from there execute `./pin.sh` to
83+
update the submodules and add the flakes entries. Then, you can open a Nix shell
84+
with all the dependencies required executing `nix develop o1js#default`, or
85+
alternatively `nix develop o1js#mina-shell` (which works better from MacOS).
86+
87+
```console
88+
./pin.sh
89+
nix develop o1js#default
90+
```
91+
92+
The first time you run this command, you can expect it to take hours (or even a full day) to complete. Then, you will observe that the current devshell becomes a Nix shell with the right
93+
configuration for `o1js` and `mina`.
94+
95+
In order to make sure that the bindings will be regenerated in the case that you
96+
are modifying them, make sure to comment out the conditionals in
97+
`src/mina/src/lib/crypto/kimchi_bindings/js/node_js/build.sh` and `src/mina/src/lib/crypto/kimchi_bindings/js/web/build.sh` locally. That's because otherwise the
98+
PLONK_WASM_WEB check prevents `proof-systems` from compiling with each build.
99+
100+
```sh
101+
if true; then # [[ -z "${PLONK_WASM_WEB-}" ]]; then
102+
export RUSTFLAGS="-C target-feature=+atomics,+bulk-memory,+mutable-globals -C link-arg=--no-check-features -C link-arg=--max-memory=4294967296"
103+
rustup run nightly-2023-09-01 wasm-pack build --target web --out-dir ../js/web ../../wasm -- -Z build-std=panic_abort,std
104+
else
105+
cp "$PLONK_WASM_WEB"/* -R .
106+
fi
107+
```
108+
109+
Then, you can build o1js and update the bindings.
110+
111+
```console
112+
npm run build
113+
npm run build:update-bindings
114+
```
115+
116+
If you need to update the underlying `mina` code, you can also do so with Nix,
117+
but from the corresopnding subdirectory. In particular, you should build Mina
118+
from the o1js subdirectory from a Nix shell. That means,
119+
120+
```console
121+
cd ./src/mina
122+
./nix/pin.sh
123+
nix develop mina
124+
```
125+
126+
## Desirable configurations
127+
128+
### Storage handling
129+
130+
Using Nix can take up a lot of disk space if not optimized. Every time you run `nix develop {SOMETHING}`, Nix will create new generations taking gigabytes of data instead of replacing the old ones. This can soon become a problem in your hard disk if you don't handle it carefully. Here are a few indications that can help with this.
131+
132+
Nix has a garbage collector that **is not used by default** after every run. Instead, artifacts get accumulated in your disk unless configured otherwise. But if the full gargabe collector is executed (`nix-store --gc`), it will get the dependencies removed completely, and you can expect that the next time executing the Nix build will take hours to complete.
133+
134+
Instead, you can try to run `nix-env --delete-generations old` or any other time bound like `7d`. This will not have any effect on MacOS though. Alternatively, the [direnv](https://github.com/direnv/direnv) / [nix-direnv](https://github.com/nix-community/nix-direnv) tool can create garbage collector roots that won't be collected for removal. It just keeps one gc-root to the latest build of the dev shell so that `nix-store --gc` only removes older generations.
135+
136+
On top of that, adding `auto-optimise-store = true` to `/etc/nix/nix.conf` and running `nix-store --optimize` shoud help with disk usage, as it replaces duplicated files with symlinks.
137+
138+
### Runtime optimization
139+
140+
Other configurations are worth adding into your `/etc/nix/nix.conf`:
141+
142+
```bash
143+
keep-otuputs = true
144+
max-jobs = 20
145+
extra-substituters = https://storage.googleapis.com/mina-nix-cache
146+
extra-trusted-public-keys = nix-cache.minaprotocol.org:fdcuDzmnM0Kbf7yU4yywBuUEJWClySc1WIF6t6Mm8h4= nix-cache.minaprotocol.org:D3B1W+V7ND1Fmfii8EhbAbF1JXoe2Ct4N34OKChwk2c= mina-nix-cache-1:djtioLfv2oxuK2lqPUgmZbf8bY8sK/BnYZCU2iU5Q10=
147+
```
148+
149+
The first of those flags tells the garbage collector to keep build time dependencies of current gc-roots, which should help reduce the amount of data that gets removed and rebuilt.
150+
151+
The second flag increases the default number of jobs being 1, so that rebuilding from scratch will take shorter time.
152+
153+
The last two lines tell Nix to use the Mina Foundation's cache whenever possible, which should as well speed things up when building code that has been build in Mina's CI before.
154+
155+
## Common errors
156+
157+
Errors while using Nix have been reported. This section collects a set of common
158+
errors and proposes fixes for them.
159+
160+
```console
161+
DISCLAIMER!
162+
163+
The proposed solutions might not work universally, and could vary depending on your local environment.
164+
This section should be read as a starting roadmap, and engineers are highly encouraged to add any new error found
165+
and possible fixes to improve the helpfulness of this document.
166+
```
167+
168+
### Compiling _export_test_vectors_
169+
170+
When trying to update the bindings for o1js in MacOS, Nix might fail at
171+
compiling the `export_test_vectors` with the following error log:
172+
173+
```console
174+
error: linking with `cc` failed: exit status: 1
175+
= note: ld: library not found for -liconv
176+
collect2: error: ld returned 1 exit status
177+
178+
error: could not compile `export_test_vectors` (bin "export_test_vectors") due to previous error
179+
```
180+
181+
That is because this library is not symlinked into `/opt/homebrew` since macOS
182+
already provides this software and installing another version could cause
183+
problems.
184+
185+
#### Fix for MacOS
186+
187+
Install `libiconv` with
188+
189+
```console
190+
brew install libiconv
191+
```
192+
193+
and update your `~/.zshrc` with the following lines
194+
195+
```bash
196+
# libiconv config
197+
export PATH="/opt/homebrew/opt/libiconv/bin:$PATH"
198+
export LDFLAGS="-L/opt/homebrew/opt/libiconv/lib"
199+
export CPPFLAGS="-I/opt/homebrew/opt/libiconv/include"
200+
export LIBRARY_PATH="/opt/homebrew/opt/libiconv/lib:$LIBRARY_PATH"
201+
```
202+
203+
Alternatively, try this change in the `src/mina/flake.nix` file:
204+
205+
```
206+
- devShellPackages = with pkgs; [ rosetta-cli wasm-pack nodejs binaryen ];
207+
+ devShellPackages = with pkgs; [ rosetta-cli wasm-pack nodejs binaryen cargo libiconvI];
208+
```
209+
210+
### wasm32-unknown-unknown
211+
212+
The rust compiler and/or Wasm-pack might not be correctly setup in the Nix shell.
213+
214+
```console
215+
Error: wasm32-unknown-unknown target not found in sysroot: "/nix/store/w30zw23kmgks77d870i502a3185hjycv-rust"
216+
217+
Used rustc from the following path: "/nix/store/wcm8caqd6g7bcbddpyxan1jzj3apkmxy-rustup-1.26.0/bin/rustc"
218+
It looks like Rustup is not being used. For non-Rustup setups, the wasm32-unknown-unknown target needs to be installed manually. See https://rustwasm.github.io/wasm-pack/book/prerequisites/non-rustup-setups.html on how to do this.
219+
220+
Caused by: wasm32-unknown-unknown target not found in sysroot: "/nix/store/w30zw23kmgks77d870i502a3185hjycv-rust"
221+
```
222+
223+
#### Fix
224+
225+
This is caused because the Rust compiler in Nix does not have access to the
226+
corresponding `wasm32-unknown-unknown` target. Let `{RUSTDIR}` be the directory
227+
of the Rust location inside Nix, as shown in the error code; e.g.
228+
`/nix/store/wcm8caqd6g7bcbddpyxan1jzj3apkmxy-rustup-1.26.0/bin`, then you can
229+
check the version of the compiler used by typing:
230+
231+
```bash
232+
{RUSTDIR}/rustc --version
233+
```
234+
235+
Which will reply with something like
236+
237+
```bash
238+
rustc 1.82.0 (f6e511eec 2024-10-15)
239+
```
240+
241+
Then the Wasm target can be automatically installed using
242+
243+
```console
244+
{RUSTDIR}/rustup target add wasm32-unknown-unknown
245+
```
246+
247+
Alternatively, this can be done manually downloading the right version of the
248+
target with
249+
250+
```console
251+
wget https://static.rust-lang.org/dist/rust-std-x.xx.x-wasm32-unknown-unknown.tar.gz
252+
```
253+
254+
where _`x.xx.x`_ corresponds to the version of `rustc` (in the example, 1.82.0).
255+
Once unpacked, you should see a similar structure:
256+
257+
```console
258+
rust-std-1.82.0-wasm32-unknown-unknown
259+
├── components
260+
├── install.sh
261+
├── rust-installer-version
262+
└── rust-std-wasm32-unknown-unknown
263+
├── lib
264+
│   └── rustlib
265+
│   └── wasm32-unknown-unknown
266+
```
267+
268+
Finally, the `wasm32-unknown-unknown` folder must be moved into the
269+
`./lib/rustlib/` directory in the sysroot like so:
270+
271+
Let `{SYSROOT}` be the directory of the Rust in Nix shown in the error code;
272+
e.g. `/nix/store/w30zw23kmgks77d870i502a3185hjycv-rust`, then the Wasm target
273+
can be automatically installed downloading it from
274+
275+
```bash
276+
mv rust-std-1.82.0-wasm32-unknown-unknown/rust-std-wasm32-unknown-unknown/lib/rustlib/wasm32-unknown-unknown {SYSROOT}/lib/rustlib/wasm32-unknown-unknown/
277+
```
278+
279+
### Cargo not found
280+
281+
```console
282+
error: "/nix/store/w30zw23kmgks77d870i502a3185hjycv-rust/lib/rustlib/src/rust/Cargo.lock"
283+
does not exist, unable to build with the standard library, try:
284+
rustup component add rust-src --toolchain nix
285+
```
286+
287+
#### Fix
288+
289+
Install `cargo` on your host machine. If doing so does not solve the problem, it
290+
is very likely that the whole Nix setup has gone wrong and it is very advisable
291+
to install it from scratch.
292+
293+
### Old path
294+
295+
When several clones of the repository are present in the system and both have
296+
used Nix (or if it has been moved from one location to another), Nix might cache
297+
an old path, breaking builds. For example, typing `nix develop mina`
298+
would complain and produce the following error:
299+
300+
```console
301+
error: resolving Git reference 'master': revspec 'master' not found
302+
```
303+
304+
Then, the error message would still contain old directories.
305+
306+
#### Fix
307+
308+
Create a new environment for Nix and start from scratch. In particular, run the garbage collector which will remove old dependencies.

flake.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)