diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000000..145e7b29cb --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,5 @@ +[build] +rustflags = [] + +[target.aarch64-apple-darwin] +rustflags = ["-C", "link-args=-Wl,-undefined,dynamic_lookup"] diff --git a/.github/actions/setup-build-deps/action.yml b/.github/actions/setup-build-deps/action.yml index 6e9b511557..8f5417d8c1 100644 --- a/.github/actions/setup-build-deps/action.yml +++ b/.github/actions/setup-build-deps/action.yml @@ -27,7 +27,7 @@ runs: if: runner.os == 'macOS' shell: bash run: | - brew install protobuf + brew install protobuf ocaml opam - name: Install cargo-nextest if: inputs.install-nextest == 'true' diff --git a/.github/actions/setup-ocaml/action.yml b/.github/actions/setup-ocaml/action.yml index 5d743fdb8c..e7c7eba5f5 100644 --- a/.github/actions/setup-ocaml/action.yml +++ b/.github/actions/setup-ocaml/action.yml @@ -11,3 +11,10 @@ runs: uses: ocaml/setup-ocaml@v3 with: ocaml-compiler: ${{ inputs.ocaml_version }} + + # - name: Setup OPAM environment + # shell: bash + # run: | + # # Export all OPAM environment variables to GITHUB_ENV + # # This avoids other steps to run `eval $(opam env)` + # opam env | sed -E 's/; export [A-Za-z_][A-Za-z0-9_]*;?//g' >> $GITHUB_ENV diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 493ab2a208..80abb4e25d 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,13 +1,13 @@ name: Mina CI on: push: - branches: [ main, develop ] + branches: [main, develop] pull_request: - paths-ignore: [ "frontend" ] + paths-ignore: ["frontend"] workflow_dispatch: inputs: refresh_cache: - description: 'Refresh cargo cache' + description: "Refresh cargo cache" required: false type: boolean default: false @@ -17,7 +17,7 @@ env: RUST_BACKTRACE: full MINA_PANIC_ON_BUG: true CARGO_INCREMENTAL: 1 - RUSTFLAGS: "-C overflow-checks=off -C debug-assertions=off" + RUSTFLAGS: "-C overflow-checks=off -C debug-assertions=off -C link-args=-Wl,-undefined,dynamic_lookup" concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} @@ -40,6 +40,9 @@ jobs: ledger-tests: timeout-minutes: 20 runs-on: ubuntu-24.04 + strategy: + matrix: + ocaml_version: [4.14.2] steps: - name: Git checkout uses: actions/checkout@v5 @@ -47,6 +50,11 @@ jobs: - name: Setup build dependencies uses: ./.github/actions/setup-build-deps + - name: Use shared OCaml setting up steps + uses: ./.github/actions/setup-ocaml + with: + ocaml_version: ${{ matrix.ocaml_version }} + - name: Setup Rust uses: ./.github/actions/setup-rust with: @@ -62,41 +70,45 @@ jobs: - name: Run ledger tests run: make test-ledger - ledger-32x9-tests: - runs-on: ubuntu-24.04 - steps: - - name: Git checkout - uses: actions/checkout@v5 + # TODO: add back when reimplemented + # ledger-32x9-tests: + # runs-on: ubuntu-24.04 + # steps: + # - name: Git checkout + # uses: actions/checkout@v5 - - name: Setup build dependencies - uses: ./.github/actions/setup-build-deps + # - name: Setup build dependencies + # uses: ./.github/actions/setup-build-deps - - name: Setup Rust - uses: ./.github/actions/setup-rust - with: - toolchain: nightly - cache-prefix: ledger-32x9-v0 + # - name: Setup Rust + # uses: ./.github/actions/setup-rust + # with: + # toolchain: nightly + # cache-prefix: ledger-32x9-v0 - - name: Download circuits files - uses: ./.github/actions/setup-circuits + # - name: Download circuits files + # uses: ./.github/actions/setup-circuits - - name: Enable 32x9 fields implementation - run: | - cargo install sd - sd '^mina-curves.*$' '' ./Cargo.toml - sd '^ark-ff = \{ version .*$' '' ./Cargo.toml - sd -F '# UNCOMMENTED_IN_CI ' '' ./Cargo.toml - cat ./Cargo.toml + # - name: Enable 32x9 fields implementation + # run: | + # cargo install sd + # sd '^mina-curves.*$' '' ./Cargo.toml + # sd '^ark-ff = \{ version .*$' '' ./Cargo.toml + # sd -F '# UNCOMMENTED_IN_CI ' '' ./Cargo.toml + # cat ./Cargo.toml - - name: Build ledger tests - run: make build-ledger + # - name: Build ledger tests + # run: make build-ledger - - name: Run ledger tests - run: make test-ledger + # - name: Run ledger tests + # run: make test-ledger vrf-tests: - timeout-minutes: 8 + timeout-minutes: 20 runs-on: ubuntu-24.04 + strategy: + matrix: + ocaml_version: [4.14.2] steps: - name: Git checkout uses: actions/checkout@v5 @@ -104,6 +116,11 @@ jobs: - name: Setup build dependencies uses: ./.github/actions/setup-build-deps + - name: Use shared OCaml setting up steps + uses: ./.github/actions/setup-ocaml + with: + ocaml_version: ${{ matrix.ocaml_version }} + - name: Setup Rust uses: ./.github/actions/setup-rust with: @@ -140,9 +157,10 @@ jobs: # NOTE: If you add or remove platforms from this matrix, make sure to update # the documentation at website/docs/developers/getting-started.mdx strategy: - fail-fast: false # Allow other platforms to continue if one fails + fail-fast: false # Allow other platforms to continue if one fails matrix: os: [ubuntu-22.04, ubuntu-24.04, ubuntu-24.04-arm, macos-latest] + ocaml_version: [4.14.2] runs-on: ${{ matrix.os }} steps: - name: Git checkout @@ -151,6 +169,11 @@ jobs: - name: Setup build dependencies uses: ./.github/actions/setup-build-deps + - name: Use shared OCaml setting up steps + uses: ./.github/actions/setup-ocaml + with: + ocaml_version: ${{ matrix.ocaml_version }} + - name: Setup Rust uses: ./.github/actions/setup-rust with: @@ -173,9 +196,10 @@ jobs: # NOTE: If you add or remove platforms from this matrix, make sure to update # the documentation at website/docs/developers/getting-started.mdx strategy: - fail-fast: false # Allow other platforms to continue if one fails + fail-fast: false # Allow other platforms to continue if one fails matrix: os: [ubuntu-22.04, ubuntu-24.04, ubuntu-24.04-arm, macos-latest] + ocaml_version: [4.14.2] runs-on: ${{ matrix.os }} steps: - name: Git checkout @@ -184,6 +208,11 @@ jobs: - name: Setup build dependencies uses: ./.github/actions/setup-build-deps + - name: Use shared OCaml setting up steps + uses: ./.github/actions/setup-ocaml + with: + ocaml_version: ${{ matrix.ocaml_version }} + - name: Setup WebAssembly environment uses: ./.github/actions/setup-wasm with: @@ -191,15 +220,18 @@ jobs: - name: Release build run: make build-wasm + env: + RUSTFLAGS: "" build-tests: timeout-minutes: 60 # NOTE: If you add or remove platforms from this matrix, make sure to update # the documentation at website/docs/developers/getting-started.mdx strategy: - fail-fast: false # Allow other platforms to continue if one fails + fail-fast: false # Allow other platforms to continue if one fails matrix: os: [ubuntu-22.04, ubuntu-24.04, ubuntu-24.04-arm, macos-latest] + ocaml_version: [4.14.2] runs-on: ${{ matrix.os }} steps: - name: Git checkout @@ -208,6 +240,11 @@ jobs: - name: Setup build dependencies uses: ./.github/actions/setup-build-deps + - name: Use shared OCaml setting up steps + uses: ./.github/actions/setup-ocaml + with: + ocaml_version: ${{ matrix.ocaml_version }} + - name: Setup Rust uses: ./.github/actions/setup-rust with: @@ -230,9 +267,10 @@ jobs: # NOTE: If you add or remove platforms from this matrix, make sure to update # the documentation at website/docs/developers/getting-started.mdx strategy: - fail-fast: false # Allow other platforms to continue if one fails + fail-fast: false # Allow other platforms to continue if one fails matrix: os: [ubuntu-22.04, ubuntu-24.04, ubuntu-24.04-arm, macos-latest] + ocaml_version: [4.14.2] runs-on: ${{ matrix.os }} steps: - name: Git checkout @@ -241,6 +279,11 @@ jobs: - name: Setup build dependencies uses: ./.github/actions/setup-build-deps + - name: Use shared OCaml setting up steps + uses: ./.github/actions/setup-ocaml + with: + ocaml_version: ${{ matrix.ocaml_version }} + - name: Setup Rust uses: ./.github/actions/setup-rust with: @@ -259,7 +302,7 @@ jobs: retention-days: 7 p2p-scenario-tests: - needs: [ build-tests, build-tests-webrtc ] + needs: [build-tests, build-tests-webrtc] runs-on: ubuntu-24.04 timeout-minutes: 20 container: @@ -269,8 +312,15 @@ jobs: BPF_ALIAS: /coda/0.0.1/29936104443aaf264a7f0192ac64b1c7173198c1ed404c1bcff5e562e05eb7f6-0.0.0.0 strategy: matrix: - test: [p2p_basic_connections, p2p_basic_incoming, p2p_basic_outgoing, p2p_pubsub, p2p_kad, - webrtc_p2p_basic_connections] + test: + [ + p2p_basic_connections, + p2p_basic_incoming, + p2p_basic_outgoing, + p2p_pubsub, + p2p_kad, + webrtc_p2p_basic_connections, + ] fail-fast: false services: @@ -288,10 +338,10 @@ jobs: steps: - name: Install libssl3t64 # Our binaries are built on a newer ubuntu and require libssl3t64 run: | - apt-get update && \ - apt-get install -y --no-install-recommends libssl3t64 && \ - apt-get clean && \ - rm -rf /var/lib/apt/lists/* + apt-get update && \ + apt-get install -y --no-install-recommends libssl3t64 && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* - name: Download tests uses: actions/download-artifact@v5 @@ -369,10 +419,10 @@ jobs: steps: - name: Install libssl3t64 # Our binaries are built on a newer ubuntu and require libssl3t64 run: | - apt-get update && \ - apt-get install -y --no-install-recommends libssl3t64 && \ - apt-get clean && \ - rm -rf /var/lib/apt/lists/* + apt-get update && \ + apt-get install -y --no-install-recommends libssl3t64 && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* - name: Download tests uses: actions/download-artifact@v5 @@ -426,10 +476,10 @@ jobs: steps: - name: Install libssl3t64 # Our binaries are built on a newer ubuntu and require libssl3t64 run: | - apt-get update && \ - apt-get install -y --no-install-recommends libssl3t64 && \ - apt-get clean && \ - rm -rf /var/lib/apt/lists/* + apt-get update && \ + apt-get install -y --no-install-recommends libssl3t64 && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* - name: Download tests uses: actions/download-artifact@v5 @@ -447,7 +497,7 @@ jobs: bootstrap-test: timeout-minutes: 4 - needs: [ build, build-tests ] + needs: [build, build-tests] runs-on: ubuntu-24.04 env: MINA_HOME: data diff --git a/.github/workflows/doc-commands.yaml b/.github/workflows/doc-commands.yaml index f6750b2ac0..d236de85cd 100644 --- a/.github/workflows/doc-commands.yaml +++ b/.github/workflows/doc-commands.yaml @@ -22,6 +22,9 @@ concurrency: jobs: test-doc-commands: runs-on: ubuntu-22.04 + strategy: + matrix: + ocaml_version: [4.14.2] steps: - name: Git checkout uses: actions/checkout@v5 @@ -36,6 +39,11 @@ jobs: toolchain: 1.84 cache-prefix: test-doc-commands-v0 + - name: Use shared OCaml setting up steps + uses: ./.github/actions/setup-ocaml + with: + ocaml_version: ${{ matrix.ocaml_version }} + - name: Download circuits files uses: ./.github/actions/setup-circuits diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml index f997f1b021..57374cac84 100644 --- a/.github/workflows/docs.yaml +++ b/.github/workflows/docs.yaml @@ -35,7 +35,7 @@ jobs: - name: Setup build dependencies run: | sudo apt update - sudo apt install -y protobuf-compiler + sudo apt install -y protobuf-compiler ocaml - name: Install documentation dependencies run: make docs-install diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index f52980d9e7..0776a7ac0b 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -12,6 +12,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: + ocaml_version: [4.14.2] os: [ubuntu-24.04] toolchain: [1.84] steps: @@ -20,6 +21,10 @@ jobs: uses: ./.github/actions/setup-build-deps with: include-sqlite: true + - name: Use shared OCaml setting up steps + uses: ./.github/actions/setup-ocaml + with: + ocaml_version: ${{ matrix.ocaml_version }} - name: Setup SQLite database for SQLx run: | sqlite3 /tmp/heartbeats.db < tools/heartbeats-processor/schema.sql @@ -51,10 +56,15 @@ jobs: # - ./github/workflows/fmt.yaml # - ./github/workflows/lint.yaml toolchain: [nightly-2025-08-18] + ocaml_version: [4.14.2] steps: - uses: actions/checkout@v5 - name: Setup build dependencies uses: ./.github/actions/setup-build-deps + - name: Use shared OCaml setting up steps + uses: ./.github/actions/setup-ocaml + with: + ocaml_version: ${{ matrix.ocaml_version }} - name: Setup Rust uses: ./.github/actions/setup-rust with: diff --git a/CHANGELOG.md b/CHANGELOG.md index fe98100897..b3f231f142 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -76,6 +76,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Use consistent `use` statements for fields. Replace `mina_hasher::Fp` with `mina_curves::pasta::Fp`. ([#1269](https://github.com/o1-labs/openmina/pull/1269/)). +- **Proof systems**: Updated proof systems to use same version as Ocaml node - **CI**: set fail-fast to false to prevent cancellation of other jobs ([#1305](https://github.com/o1-labs/openmina/pull/1305)) - **Website**: (temporary) new design, for a first release and rename OpenMina diff --git a/Cargo.lock b/Cargo.lock index 33709d663b..d2877a7920 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -238,15 +238,33 @@ dependencies = [ "password-hash", ] +[[package]] +name = "ark-bn254" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d69eab57e8d2663efa5c63135b2af4f396d66424f88954c21104125ab6b3e6bc" +dependencies = [ + "ark-ec", + "ark-ff", + "ark-std 0.5.0", +] + [[package]] name = "ark-ec" -version = "0.3.0" -source = "git+https://github.com/openmina/algebra?rev=150ab8d#150ab8d4cf4918f256580c0d17249ddf11e20aeb" +version = "0.5.0" +source = "git+https://github.com/openmina/algebra?branch=rebase-fix-openmina-webnode#0ee1798c746a0cf44b1336f943be138e491a7804" dependencies = [ + "ahash 0.8.8", "ark-ff", - "ark-serialize 0.3.0", - "ark-std 0.3.0", - "derivative", + "ark-poly", + "ark-serialize 0.5.0", + "ark-std 0.5.0", + "educe", + "fnv", + "hashbrown 0.15.2", + "itertools 0.13.0", + "num-bigint", + "num-integer", "num-traits", "rayon", "zeroize", @@ -254,105 +272,113 @@ dependencies = [ [[package]] name = "ark-ff" -version = "0.3.0" -source = "git+https://github.com/openmina/algebra?rev=150ab8d#150ab8d4cf4918f256580c0d17249ddf11e20aeb" +version = "0.5.0" +source = "git+https://github.com/openmina/algebra?branch=rebase-fix-openmina-webnode#0ee1798c746a0cf44b1336f943be138e491a7804" dependencies = [ "ark-ff-asm", "ark-ff-macros", - "ark-serialize 0.3.0", - "ark-std 0.3.0", - "derivative", + "ark-serialize 0.5.0", + "ark-std 0.5.0", + "arrayvec", + "digest 0.10.7", + "educe", + "itertools 0.13.0", "num-bigint", "num-traits", "paste", "rayon", - "rustc_version 0.3.3", "zeroize", ] [[package]] name = "ark-ff-asm" -version = "0.3.0" -source = "git+https://github.com/openmina/algebra?rev=150ab8d#150ab8d4cf4918f256580c0d17249ddf11e20aeb" +version = "0.5.0" +source = "git+https://github.com/openmina/algebra?branch=rebase-fix-openmina-webnode#0ee1798c746a0cf44b1336f943be138e491a7804" dependencies = [ "quote 1.0.35", - "syn 1.0.109", + "syn 2.0.96", ] [[package]] name = "ark-ff-macros" -version = "0.3.0" -source = "git+https://github.com/openmina/algebra?rev=150ab8d#150ab8d4cf4918f256580c0d17249ddf11e20aeb" +version = "0.5.0" +source = "git+https://github.com/openmina/algebra?branch=rebase-fix-openmina-webnode#0ee1798c746a0cf44b1336f943be138e491a7804" dependencies = [ "num-bigint", "num-traits", + "proc-macro2 1.0.95", "quote 1.0.35", - "syn 1.0.109", + "syn 2.0.96", ] [[package]] name = "ark-poly" -version = "0.3.0" -source = "git+https://github.com/openmina/algebra?rev=150ab8d#150ab8d4cf4918f256580c0d17249ddf11e20aeb" +version = "0.5.0" +source = "git+https://github.com/openmina/algebra?branch=rebase-fix-openmina-webnode#0ee1798c746a0cf44b1336f943be138e491a7804" dependencies = [ + "ahash 0.8.8", "ark-ff", - "ark-serialize 0.3.0", - "ark-std 0.3.0", - "derivative", - "hashbrown 0.11.2", + "ark-serialize 0.5.0", + "ark-std 0.5.0", + "educe", + "fnv", + "hashbrown 0.15.2", "rayon", ] [[package]] name = "ark-serialize" -version = "0.3.0" -source = "git+https://github.com/openmina/algebra?rev=150ab8d#150ab8d4cf4918f256580c0d17249ddf11e20aeb" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adb7b85a02b83d2f22f89bd5cac66c9c89474240cb6207cb1efc16d098e822a5" dependencies = [ - "ark-serialize-derive", - "ark-std 0.3.0", - "digest 0.9.0", + "ark-std 0.4.0", + "digest 0.10.7", + "num-bigint", ] [[package]] name = "ark-serialize" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adb7b85a02b83d2f22f89bd5cac66c9c89474240cb6207cb1efc16d098e822a5" +version = "0.5.0" +source = "git+https://github.com/openmina/algebra?branch=rebase-fix-openmina-webnode#0ee1798c746a0cf44b1336f943be138e491a7804" dependencies = [ - "ark-std 0.4.0", + "ark-serialize-derive", + "ark-std 0.5.0", + "arrayvec", "digest 0.10.7", "num-bigint", + "rayon", ] [[package]] name = "ark-serialize-derive" -version = "0.3.0" -source = "git+https://github.com/openmina/algebra?rev=150ab8d#150ab8d4cf4918f256580c0d17249ddf11e20aeb" +version = "0.5.0" +source = "git+https://github.com/openmina/algebra?branch=rebase-fix-openmina-webnode#0ee1798c746a0cf44b1336f943be138e491a7804" dependencies = [ "proc-macro2 1.0.95", "quote 1.0.35", - "syn 1.0.109", + "syn 2.0.96", ] [[package]] name = "ark-std" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1df2c09229cbc5a028b1d70e00fdb2acee28b1055dfb5ca73eea49c5a25c4e7c" +checksum = "94893f1e0c6eeab764ade8dc4c0db24caf4fe7cbbaafc0eba0a9030f447b5185" dependencies = [ "num-traits", "rand", - "rayon", ] [[package]] name = "ark-std" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94893f1e0c6eeab764ade8dc4c0db24caf4fe7cbbaafc0eba0a9030f447b5185" +checksum = "246a225cc6131e9ee4f24619af0f19d67761fff15d7ccc22e42b80846e69449a" dependencies = [ "num-traits", "rand", + "rayon", ] [[package]] @@ -1087,7 +1113,7 @@ dependencies = [ "aws-smithy-async", "aws-smithy-runtime-api", "aws-smithy-types", - "rustc_version 0.4.0", + "rustc_version", "tracing", ] @@ -1207,9 +1233,9 @@ checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" [[package]] name = "base64" -version = "0.22.0" +version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9475866fec1451be56a3c2400fd081ff546538961565ccb5b7142cbd22bc7a51" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" [[package]] name = "base64-simd" @@ -1255,7 +1281,7 @@ dependencies = [ "bitflags 2.8.0", "cexpr", "clang-sys", - "itertools 0.12.0", + "itertools 0.12.1", "lazy_static", "lazycell", "log", @@ -1906,7 +1932,7 @@ version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3a47af21622d091a8f0fb295b88bc886ac74efcc613efc19f5d0b21de5c89e47" dependencies = [ - "rustc_version 0.4.0", + "rustc_version", ] [[package]] @@ -2086,7 +2112,7 @@ dependencies = [ "digest 0.10.7", "fiat-crypto", "platforms", - "rustc_version 0.4.0", + "rustc_version", "subtle", "zeroize", ] @@ -2102,16 +2128,6 @@ dependencies = [ "syn 2.0.96", ] -[[package]] -name = "darling" -version = "0.13.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a01d95850c592940db9b8194bc39f4bc0e89dee5c4265e4b1807c34a9aba453c" -dependencies = [ - "darling_core 0.13.4", - "darling_macro 0.13.4", -] - [[package]] name = "darling" version = "0.14.4" @@ -2132,20 +2148,6 @@ dependencies = [ "darling_macro 0.20.6", ] -[[package]] -name = "darling_core" -version = "0.13.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "859d65a907b6852c9361e3185c862aae7fafd2887876799fa55f5f99dc40d610" -dependencies = [ - "fnv", - "ident_case", - "proc-macro2 1.0.95", - "quote 1.0.35", - "strsim 0.10.0", - "syn 1.0.109", -] - [[package]] name = "darling_core" version = "0.14.4" @@ -2174,17 +2176,6 @@ dependencies = [ "syn 2.0.96", ] -[[package]] -name = "darling_macro" -version = "0.13.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835" -dependencies = [ - "darling_core 0.13.4", - "quote 1.0.35", - "syn 1.0.109", -] - [[package]] name = "darling_macro" version = "0.14.4" @@ -2377,7 +2368,7 @@ dependencies = [ "convert_case 0.4.0", "proc-macro2 1.0.95", "quote 1.0.35", - "rustc_version 0.4.0", + "rustc_version", "syn 1.0.109", ] @@ -2446,12 +2437,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "disjoint-set" -version = "0.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d102f1a462fdcdddce88d6d46c06c074a2d2749b262230333726b06c52bb7585" - [[package]] name = "displaydoc" version = "0.2.4" @@ -2505,6 +2490,12 @@ version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" +[[package]] +name = "dyn-clone" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0881ea181b1df73ff77ffaaf9c7544ecc11e82fba9b5f27b262a3c73a332555" + [[package]] name = "ecdsa" version = "0.14.8" @@ -2557,6 +2548,18 @@ dependencies = [ "zeroize", ] +[[package]] +name = "educe" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d7bc049e1bd8cdeb31b68bbd586a9464ecf9f3944af3958a7a9d0f8b9799417" +dependencies = [ + "enum-ordinalize", + "proc-macro2 1.0.95", + "quote 1.0.35", + "syn 2.0.96", +] + [[package]] name = "either" version = "1.9.0" @@ -2646,6 +2649,26 @@ dependencies = [ "syn 2.0.96", ] +[[package]] +name = "enum-ordinalize" +version = "4.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea0dcfa4e54eeb516fe454635a95753ddd39acda650ce703031c6973e315dd5" +dependencies = [ + "enum-ordinalize-derive", +] + +[[package]] +name = "enum-ordinalize-derive" +version = "4.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d28318a75d4aead5c4db25382e8ef717932d0346600cacae6357eb5941bc5ff" +dependencies = [ + "proc-macro2 1.0.95", + "quote 1.0.35", + "syn 2.0.96", +] + [[package]] name = "enum_dispatch" version = "0.3.12" @@ -3453,7 +3476,7 @@ dependencies = [ [[package]] name = "groupmap" version = "0.1.0" -source = "git+https://github.com/openmina/proof-systems?rev=f461b4b#f461b4bf65fe9677f81033ed7c3c4f997caea3fe" +source = "git+https://github.com/openmina/proof-systems?rev=d1912bca54d2609296b9af9d09ad1ef78702e203#d1912bca54d2609296b9af9d09ad1ef78702e203" dependencies = [ "ark-ec", "ark-ff", @@ -3516,15 +3539,6 @@ dependencies = [ "byteorder", ] -[[package]] -name = "hashbrown" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" -dependencies = [ - "ahash 0.7.8", -] - [[package]] name = "hashbrown" version = "0.12.3" @@ -3593,7 +3607,7 @@ checksum = "cdc6457c0eb62c71aac4bc17216026d8410337c4126773b9c5daba343f17964f" dependencies = [ "atomic-polyfill", "hash32", - "rustc_version 0.4.0", + "rustc_version", "serde", "spin 0.9.8", "stable_deref_trait", @@ -3604,7 +3618,7 @@ name = "heartbeats-processor" version = "0.16.0" dependencies = [ "anyhow", - "base64 0.22.0", + "base64 0.22.1", "chrono", "clap 4.5.20", "dotenv", @@ -3835,7 +3849,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "smallvec 1.13.2", + "smallvec", "tokio", "want", ] @@ -4014,7 +4028,7 @@ dependencies = [ "icu_normalizer_data", "icu_properties", "icu_provider", - "smallvec 1.13.2", + "smallvec", "utf16_iter", "utf8_iter", "write16", @@ -4099,7 +4113,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "686f825264d630750a544639377bae737628043f20d38bbc029e8f29ea968a7e" dependencies = [ "idna_adapter", - "smallvec 1.13.2", + "smallvec", "utf8_iter", ] @@ -4224,7 +4238,7 @@ dependencies = [ [[package]] name = "internal-tracing" version = "0.1.0" -source = "git+https://github.com/openmina/proof-systems?rev=f461b4b#f461b4bf65fe9677f81033ed7c3c4f997caea3fe" +source = "git+https://github.com/openmina/proof-systems?rev=d1912bca54d2609296b9af9d09ad1ef78702e203#d1912bca54d2609296b9af9d09ad1ef78702e203" [[package]] name = "io-lifetimes" @@ -4257,18 +4271,18 @@ checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" [[package]] name = "itertools" -version = "0.10.5" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" dependencies = [ "either", ] [[package]] name = "itertools" -version = "0.12.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25db6b064527c5d482d0423354fcd07a89a2dfe07b67892e62411946db7f07b0" +checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" dependencies = [ "either", ] @@ -4394,24 +4408,22 @@ dependencies = [ [[package]] name = "kimchi" version = "0.1.0" -source = "git+https://github.com/openmina/proof-systems?rev=f461b4b#f461b4bf65fe9677f81033ed7c3c4f997caea3fe" +source = "git+https://github.com/openmina/proof-systems?rev=d1912bca54d2609296b9af9d09ad1ef78702e203#d1912bca54d2609296b9af9d09ad1ef78702e203" dependencies = [ "ark-ec", "ark-ff", "ark-poly", - "ark-serialize 0.3.0", + "ark-serialize 0.5.0", "blake2", - "disjoint-set", "groupmap", "hex", "internal-tracing", - "itertools 0.10.5", + "itertools 0.12.1", + "log", "mina-curves", "mina-poseidon", "num-bigint", - "num-derive", "num-integer", - "num-traits", "o1-utils", "once_cell", "poly-commitment", @@ -4420,10 +4432,10 @@ dependencies = [ "rayon", "rmp-serde", "serde", - "serde_with 1.14.0", - "strum 0.24.1", - "strum_macros 0.24.3", - "thiserror 1.0.60", + "serde_with", + "strum", + "strum_macros", + "thiserror 2.0.11", "turshi", ] @@ -4573,7 +4585,7 @@ dependencies = [ "rand", "rw-stream-sink", "serde", - "smallvec 1.13.2", + "smallvec", "thiserror 1.0.60", "unsigned-varint 0.7.2", "void", @@ -4590,7 +4602,7 @@ dependencies = [ "libp2p-identity", "log", "parking_lot 0.12.1", - "smallvec 1.13.2", + "smallvec", "trust-dns-resolver", ] @@ -4621,7 +4633,7 @@ dependencies = [ "regex", "serde", "sha2 0.10.8", - "smallvec 1.13.2", + "smallvec", "unsigned-varint 0.7.2", "void", ] @@ -4643,7 +4655,7 @@ dependencies = [ "lru", "quick-protobuf", "quick-protobuf-codec", - "smallvec 1.13.2", + "smallvec", "thiserror 1.0.60", "void", ] @@ -4689,7 +4701,7 @@ dependencies = [ "rand", "serde", "sha2 0.10.8", - "smallvec 1.13.2", + "smallvec", "thiserror 1.0.60", "uint", "unsigned-varint 0.7.2", @@ -4709,7 +4721,7 @@ dependencies = [ "libp2p-swarm", "log", "rand", - "smallvec 1.13.2", + "smallvec", "socket2 0.5.5", "tokio", "trust-dns-proto", @@ -4819,7 +4831,7 @@ dependencies = [ "multistream-select", "once_cell", "rand", - "smallvec 1.13.2", + "smallvec", "tokio", "void", ] @@ -5108,7 +5120,7 @@ dependencies = [ name = "mina-bootstrap-sandbox" version = "0.16.0" dependencies = [ - "base64 0.22.0", + "base64 0.22.1", "binprot", "bs58 0.5.0", "env_logger", @@ -5135,7 +5147,7 @@ version = "0.16.0" dependencies = [ "argon2", "ark-ff", - "base64 0.22.0", + "base64 0.22.1", "binprot", "binprot_derive", "bs58 0.4.0", @@ -5175,10 +5187,12 @@ dependencies = [ [[package]] name = "mina-curves" version = "0.1.0" -source = "git+https://github.com/openmina/proof-systems?rev=f461b4b#f461b4bf65fe9677f81033ed7c3c4f997caea3fe" +source = "git+https://github.com/openmina/proof-systems?rev=d1912bca54d2609296b9af9d09ad1ef78702e203#d1912bca54d2609296b9af9d09ad1ef78702e203" dependencies = [ + "ark-bn254", "ark-ec", "ark-ff", + "num-bigint", ] [[package]] @@ -5209,7 +5223,7 @@ dependencies = [ [[package]] name = "mina-hasher" version = "0.1.0" -source = "git+https://github.com/openmina/proof-systems?rev=f461b4b#f461b4bf65fe9677f81033ed7c3c4f997caea3fe" +source = "git+https://github.com/openmina/proof-systems?rev=d1912bca54d2609296b9af9d09ad1ef78702e203#d1912bca54d2609296b9af9d09ad1ef78702e203" dependencies = [ "ark-ff", "bitvec", @@ -5302,8 +5316,8 @@ dependencies = [ "redux", "serde", "serde_json", - "strum 0.26.2", - "strum_macros 0.26.4", + "strum", + "strum_macros", ] [[package]] @@ -5337,8 +5351,8 @@ dependencies = [ "serde", "serde_json", "sha3", - "strum 0.26.2", - "strum_macros 0.26.4", + "strum", + "strum_macros", "thiserror 1.0.60", "tokio", "tracing", @@ -5353,7 +5367,7 @@ version = "0.16.0" dependencies = [ "anyhow", "axum", - "base64 0.22.0", + "base64 0.22.1", "bs58 0.4.0", "clap 4.5.20", "console", @@ -5381,8 +5395,8 @@ dependencies = [ "reqwest 0.11.24", "serde", "serde_json", - "strum 0.26.2", - "strum_macros 0.26.4", + "strum", + "strum_macros", "temp-dir", "thiserror 1.0.60", "time", @@ -5428,7 +5442,7 @@ dependencies = [ "alloc-test", "anyhow", "ark-ff", - "base64 0.22.0", + "base64 0.22.1", "binprot", "binprot_derive", "blake2", @@ -5453,8 +5467,8 @@ dependencies = [ "serde_bytes", "serde_json", "sha2 0.10.8", - "strum 0.26.2", - "strum_macros 0.26.4", + "strum", + "strum_macros", "thiserror 1.0.60", "time", "toml 0.5.11", @@ -5466,18 +5480,19 @@ dependencies = [ [[package]] name = "mina-poseidon" version = "0.1.0" -source = "git+https://github.com/openmina/proof-systems?rev=f461b4b#f461b4bf65fe9677f81033ed7c3c4f997caea3fe" +source = "git+https://github.com/openmina/proof-systems?rev=d1912bca54d2609296b9af9d09ad1ef78702e203#d1912bca54d2609296b9af9d09ad1ef78702e203" dependencies = [ "ark-ec", "ark-ff", "ark-poly", + "ark-serialize 0.5.0", "mina-curves", "o1-utils", "once_cell", "rand", "rayon", "serde", - "serde_with 1.14.0", + "serde_with", ] [[package]] @@ -5507,20 +5522,20 @@ dependencies = [ [[package]] name = "mina-signer" version = "0.1.0" -source = "git+https://github.com/openmina/proof-systems?rev=f461b4b#f461b4bf65fe9677f81033ed7c3c4f997caea3fe" +source = "git+https://github.com/openmina/proof-systems?rev=d1912bca54d2609296b9af9d09ad1ef78702e203#d1912bca54d2609296b9af9d09ad1ef78702e203" dependencies = [ "ark-ec", "ark-ff", "bitvec", "blake2", - "bs58 0.4.0", + "bs58 0.5.0", "hex", "mina-curves", "mina-hasher", "o1-utils", "rand", "sha2 0.10.8", - "thiserror 1.0.60", + "thiserror 2.0.11", ] [[package]] @@ -5542,7 +5557,7 @@ dependencies = [ "ark-ec", "ark-ff", "ark-poly", - "ark-serialize 0.3.0", + "ark-serialize 0.5.0", "backtrace", "base64 0.13.1", "bitvec", @@ -5553,7 +5568,7 @@ dependencies = [ "fraction", "getrandom", "hex", - "itertools 0.12.0", + "itertools 0.12.1", "juniper", "kimchi", "lazy_static", @@ -5581,10 +5596,10 @@ dependencies = [ "rsa", "serde", "serde_json", - "serde_with 3.7.0", + "serde_with", "sha2 0.10.8", - "strum 0.26.2", - "strum_macros 0.26.4", + "strum", + "strum_macros", "thiserror 1.0.60", "tuple-map", "uuid", @@ -5738,7 +5753,7 @@ dependencies = [ "futures", "log", "pin-project 1.1.5", - "smallvec 1.13.2", + "smallvec", "unsigned-varint 0.7.2", ] @@ -5901,7 +5916,7 @@ version = "0.16.0" dependencies = [ "anyhow", "ark-ff", - "base64 0.22.0", + "base64 0.22.1", "blake2", "derive_more", "graphannis-malloc_size_of", @@ -5927,11 +5942,11 @@ dependencies = [ "rust-format", "serde", "serde_json", - "serde_with 3.7.0", + "serde_with", "snark", "static_assertions", - "strum 0.26.2", - "strum_macros 0.26.4", + "strum", + "strum_macros", "thiserror 1.0.60", "time", "tokio", @@ -6002,7 +6017,7 @@ dependencies = [ [[package]] name = "num-bigint" version = "0.4.6" -source = "git+https://github.com/openmina/num-bigint?rev=8bb5ee4#8bb5ee4de12587b52d11eac13057c5e8664249a2" +source = "git+https://github.com/openmina/num-bigint?branch=rebase-onstack#5b79c7beecd32fd91ae2332b77d079f748eeacf5" dependencies = [ "num-integer", "num-traits", @@ -6024,7 +6039,7 @@ dependencies = [ "num-iter", "num-traits", "rand", - "smallvec 1.13.2", + "smallvec", "zeroize", ] @@ -6044,17 +6059,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" -[[package]] -name = "num-derive" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d" -dependencies = [ - "proc-macro2 1.0.95", - "quote 1.0.35", - "syn 1.0.109", -] - [[package]] name = "num-integer" version = "0.1.46" @@ -6078,7 +6082,7 @@ dependencies = [ [[package]] name = "num-rational" version = "0.4.2" -source = "git+https://github.com/openmina/num-rational?rev=336f11d#336f11da2ba1b65fb9472bad29ff3f58b566266f" +source = "git+https://github.com/openmina/num-rational?branch=rebase-onstack#be8f2bfa63191b3819739cbe286507cda88ce607" dependencies = [ "num-bigint", "num-integer", @@ -6160,24 +6164,25 @@ dependencies = [ [[package]] name = "o1-utils" version = "0.1.0" -source = "git+https://github.com/openmina/proof-systems?rev=f461b4b#f461b4bf65fe9677f81033ed7c3c4f997caea3fe" +source = "git+https://github.com/openmina/proof-systems?rev=d1912bca54d2609296b9af9d09ad1ef78702e203#d1912bca54d2609296b9af9d09ad1ef78702e203" dependencies = [ "ark-ec", "ark-ff", "ark-poly", - "ark-serialize 0.3.0", + "ark-serialize 0.5.0", "bcs", "hex", "num-bigint", "num-integer", - "num-traits", "rand", "rand_core", "rayon", + "rmp-serde", "serde", - "serde_with 1.14.0", + "serde_json", + "serde_with", "sha2 0.10.8", - "thiserror 1.0.60", + "thiserror 2.0.11", ] [[package]] @@ -6257,9 +6262,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.19.0" +version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" [[package]] name = "opaque-debug" @@ -6378,7 +6383,7 @@ version = "0.16.0" dependencies = [ "aes-gcm 0.10.3", "anyhow", - "base64 0.22.0", + "base64 0.22.1", "binprot", "binprot_derive", "bitflags 2.8.0", @@ -6423,11 +6428,11 @@ dependencies = [ "salsa-simple", "serde", "serde_json", - "serde_with 3.7.0", + "serde_with", "sha2 0.10.8", - "smallvec 1.13.2", - "strum 0.26.2", - "strum_macros 0.26.4", + "smallvec", + "strum", + "strum_macros", "thiserror 1.0.60", "tokio", "unsigned-varint 0.8.0", @@ -6514,7 +6519,7 @@ dependencies = [ "instant", "libc", "redox_syscall 0.2.16", - "smallvec 1.13.2", + "smallvec", "winapi 0.3.9", ] @@ -6527,7 +6532,7 @@ dependencies = [ "cfg-if", "libc", "redox_syscall 0.4.1", - "smallvec 1.13.2", + "smallvec", "windows-targets 0.48.5", ] @@ -6544,9 +6549,9 @@ dependencies = [ [[package]] name = "paste" -version = "1.0.14" +version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" [[package]] name = "pcap" @@ -6578,7 +6583,7 @@ version = "3.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e459365e590736a54c3fa561947c84837534b8e9af6fc5bf781307e82658fae" dependencies = [ - "base64 0.22.0", + "base64 0.22.1", "serde", ] @@ -6834,17 +6839,19 @@ dependencies = [ [[package]] name = "poly-commitment" version = "0.1.0" -source = "git+https://github.com/openmina/proof-systems?rev=f461b4b#f461b4bf65fe9677f81033ed7c3c4f997caea3fe" +source = "git+https://github.com/openmina/proof-systems?rev=d1912bca54d2609296b9af9d09ad1ef78702e203#d1912bca54d2609296b9af9d09ad1ef78702e203" dependencies = [ "ark-ec", "ark-ff", "ark-poly", - "ark-serialize 0.3.0", + "ark-serialize 0.5.0", "blake2", "groupmap", - "itertools 0.10.5", + "hex", + "itertools 0.12.1", "mina-curves", "mina-poseidon", + "num-bigint", "o1-utils", "once_cell", "rand", @@ -6852,9 +6859,8 @@ dependencies = [ "rayon", "rmp-serde", "serde", - "serde_with 1.14.0", - "smallvec 2.0.0-alpha.9", - "thiserror 1.0.60", + "serde_with", + "thiserror 2.0.11", ] [[package]] @@ -6914,8 +6920,10 @@ name = "poseidon" version = "0.16.0" dependencies = [ "ark-ff", + "ark-serialize 0.5.0", "mina-curves", "once_cell", + "serde", ] [[package]] @@ -7085,7 +7093,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac6c3320f9abac597dcbc668774ef006702672474aad53c6d596b62e487b40b1" dependencies = [ "heck 0.5.0", - "itertools 0.12.0", + "itertools 0.13.0", "log", "multimap", "once_cell", @@ -7105,7 +7113,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9554e3ab233f0a932403704f1a1d08c30d5ccd931adfdfa1e8b5a19b52c1d55a" dependencies = [ "anyhow", - "itertools 0.12.0", + "itertools 0.12.1", "proc-macro2 1.0.95", "quote 1.0.35", "syn 2.0.96", @@ -7118,7 +7126,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "157c5a9d7ea5c2ed2d9fb8f495b64759f7816c7eaea54ba3978f0d63000162e3" dependencies = [ "anyhow", - "itertools 0.12.0", + "itertools 0.13.0", "proc-macro2 1.0.95", "quote 1.0.35", "syn 2.0.96", @@ -7131,7 +7139,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9120690fafc389a67ba3803df527d0ec9cbbc9cc45e4cc20b332996dfb672425" dependencies = [ "anyhow", - "itertools 0.12.0", + "itertools 0.13.0", "proc-macro2 1.0.95", "quote 1.0.35", "syn 2.0.96", @@ -7375,9 +7383,9 @@ dependencies = [ [[package]] name = "rayon" -version = "1.8.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c27db03db7734835b3f53954b534c91069375ce6ccaa2e065441e07d9b6cdb1" +checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" dependencies = [ "either", "rayon-core", @@ -7385,9 +7393,9 @@ dependencies = [ [[package]] name = "rayon-core" -version = "1.12.0" +version = "1.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ce3fb6ad83f861aac485e76e1985cd109d9a3713802152be56c3b1f0e0658ed" +checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" dependencies = [ "crossbeam-deque", "crossbeam-utils", @@ -7460,6 +7468,26 @@ dependencies = [ "wasm-timer", ] +[[package]] +name = "ref-cast" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a0ae411dbe946a674d89546582cea4ba2bb8defac896622d6496f14c23ba5cf" +dependencies = [ + "ref-cast-impl", +] + +[[package]] +name = "ref-cast-impl" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1165225c21bff1f3bbce98f5a1f889949bc902d3575308cc7b0de30b4f6d27c7" +dependencies = [ + "proc-macro2 1.0.95", + "quote 1.0.35", + "syn 2.0.96", +] + [[package]] name = "regex" version = "1.10.2" @@ -7566,7 +7594,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "43e734407157c3c2034e0258f5e4473ddb361b1e85f95a66690d67264d7cd1da" dependencies = [ "async-compression", - "base64 0.22.0", + "base64 0.22.1", "bytes", "encoding_rs", "futures-channel", @@ -7697,9 +7725,9 @@ checksum = "944cd13fb0222712688b9e6cf8002c31eca42e9eb963bd0a1e4d36da2a27bdbf" [[package]] name = "rmp" -version = "0.8.12" +version = "0.8.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9860a6cc38ed1da53456442089b4dfa35e7cedaa326df63017af88385e6b20" +checksum = "228ed7c16fa39782c3b3468e974aec2795e9089153cd08ee2e9aefb3613334c4" dependencies = [ "byteorder", "num-traits", @@ -7708,9 +7736,9 @@ dependencies = [ [[package]] name = "rmp-serde" -version = "1.1.2" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bffea85eea980d8a74453e5d02a8d93028f3c34725de143085a844ebe953258a" +checksum = "52e599a477cf9840e92f2cde9a7189e67b42c57532749bf90aea6ec10facd4db" dependencies = [ "byteorder", "rmp", @@ -7843,22 +7871,13 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c7fb8039b3032c191086b10f11f319a6e99e1e82889c5cc6046f515c9db1d497" -[[package]] -name = "rustc_version" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0dfe2087c51c460008730de8b57e6a320782fbfb312e1f4d520e6c6fae155ee" -dependencies = [ - "semver 0.11.0", -] - [[package]] name = "rustc_version" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" dependencies = [ - "semver 1.0.20", + "semver", ] [[package]] @@ -8079,6 +8098,30 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "schemars" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd191f9397d57d581cddd31014772520aa448f65ef991055d7f61582c65165f" +dependencies = [ + "dyn-clone", + "ref-cast", + "serde", + "serde_json", +] + +[[package]] +name = "schemars" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82d20c4491bc164fa2f6c5d44565947a52ad80b9505d8e36f8d54c27c739fcd0" +dependencies = [ + "dyn-clone", + "ref-cast", + "serde", + "serde_json", +] + [[package]] name = "scoped-tls" version = "1.0.1" @@ -8189,35 +8232,17 @@ dependencies = [ "libc", ] -[[package]] -name = "semver" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6" -dependencies = [ - "semver-parser", -] - [[package]] name = "semver" version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" -[[package]] -name = "semver-parser" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0bef5b7f9e0df16536d3961cfb6e84331c065b4066afb39768d0e319411f7" -dependencies = [ - "pest", -] - [[package]] name = "serde" -version = "1.0.190" +version = "1.0.219" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91d3c334ca1ee894a2c6f6ad698fe8c435b76d504b13d436f0685d648d6d96f7" +checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" dependencies = [ "serde_derive", ] @@ -8233,9 +8258,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.190" +version = "1.0.219" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67c5609f394e5c2bd7fc51efda478004ea80ef42fee983d5c67a65e34f32c0e3" +checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" dependencies = [ "proc-macro2 1.0.95", "quote 1.0.35", @@ -8244,12 +8269,13 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.107" +version = "1.0.141" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" +checksum = "30b9eff21ebe718216c6ec64e1d9ac57087aad11efc64e32002bce4a0d4c03d3" dependencies = [ "indexmap 2.7.1", "itoa", + "memchr", "ryu", "serde", ] @@ -8287,49 +8313,29 @@ dependencies = [ [[package]] name = "serde_with" -version = "1.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "678b5a069e50bf00ecd22d0cd8ddf7c236f68581b03db652061ed5eb13a312ff" -dependencies = [ - "serde", - "serde_with_macros 1.5.2", -] - -[[package]] -name = "serde_with" -version = "3.7.0" +version = "3.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee80b0e361bbf88fd2f6e242ccd19cfda072cb0faa6ae694ecee08199938569a" +checksum = "f2c45cd61fefa9db6f254525d46e392b852e0e61d9a1fd36e5bd183450a556d5" dependencies = [ - "base64 0.21.7", + "base64 0.22.1", "chrono", "hex", "indexmap 1.9.3", "indexmap 2.7.1", + "schemars 0.9.0", + "schemars 1.0.4", "serde", "serde_derive", "serde_json", - "serde_with_macros 3.7.0", + "serde_with_macros", "time", ] [[package]] name = "serde_with_macros" -version = "1.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e182d6ec6f05393cc0e5ed1bf81ad6db3a8feedf8ee515ecdd369809bcce8082" -dependencies = [ - "darling 0.13.4", - "proc-macro2 1.0.95", - "quote 1.0.35", - "syn 1.0.109", -] - -[[package]] -name = "serde_with_macros" -version = "3.7.0" +version = "3.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6561dc161a9224638a31d876ccdfefbc1df91d3f3a8342eddb35f055d48c7655" +checksum = "de90945e6565ce0d9a25098082ed4ee4002e047cb59892c318d66821e14bb30f" dependencies = [ "darling 0.20.6", "proc-macro2 1.0.95", @@ -8521,11 +8527,6 @@ dependencies = [ "serde", ] -[[package]] -name = "smallvec" -version = "2.0.0-alpha.9" -source = "git+https://github.com/servo/rust-smallvec.git#a176a870987f61b04e001a7c4d0863fdeb427083" - [[package]] name = "smartstring" version = "1.0.1" @@ -8575,7 +8576,7 @@ dependencies = [ "serde", "serde_json", "sha2 0.10.8", - "strum_macros 0.26.4", + "strum_macros", "thiserror 1.0.60", "wasm-bindgen-test", ] @@ -8591,7 +8592,7 @@ dependencies = [ "curve25519-dalek", "rand_core", "ring 0.16.20", - "rustc_version 0.4.0", + "rustc_version", "sha2 0.10.8", "subtle", ] @@ -8657,7 +8658,7 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce81b7bd7c4493975347ef60d8c7e8b742d4694f4c49f93e0a12ea263938176c" dependencies = [ - "itertools 0.12.0", + "itertools 0.12.1", "nom 7.1.3", "unicode_categories", ] @@ -8707,7 +8708,7 @@ dependencies = [ "serde", "serde_json", "sha2 0.10.8", - "smallvec 1.13.2", + "smallvec", "sqlformat", "thiserror 1.0.60", "tokio", @@ -8762,7 +8763,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "64bb4714269afa44aef2755150a0fc19d756fb580a67db8885608cf02f47d06a" dependencies = [ "atoi", - "base64 0.22.0", + "base64 0.22.1", "bitflags 2.8.0", "byteorder", "bytes", @@ -8790,7 +8791,7 @@ dependencies = [ "serde", "sha1", "sha2 0.10.8", - "smallvec 1.13.2", + "smallvec", "sqlx-core", "stringprep", "thiserror 1.0.60", @@ -8805,7 +8806,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fa91a732d854c5d7726349bb4bb879bb9478993ceb764247660aee25f67c2f8" dependencies = [ "atoi", - "base64 0.22.0", + "base64 0.22.1", "bitflags 2.8.0", "byteorder", "chrono", @@ -8829,7 +8830,7 @@ dependencies = [ "serde", "serde_json", "sha2 0.10.8", - "smallvec 1.13.2", + "smallvec", "sqlx-core", "stringprep", "thiserror 1.0.60", @@ -8935,31 +8936,12 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "strum" -version = "0.24.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f" - [[package]] name = "strum" version = "0.26.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5d8cec3501a5194c432b2b7976db6b7d10ec95c253208b45f83f7136aa985e29" -[[package]] -name = "strum_macros" -version = "0.24.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59" -dependencies = [ - "heck 0.4.1", - "proc-macro2 1.0.95", - "quote 1.0.35", - "rustversion", - "syn 1.0.109", -] - [[package]] name = "strum_macros" version = "0.26.4" @@ -9483,7 +9465,7 @@ dependencies = [ "async-stream", "async-trait", "axum", - "base64 0.22.0", + "base64 0.22.1", "bytes", "h2 0.4.7", "http 1.1.0", @@ -9670,7 +9652,7 @@ dependencies = [ "serde", "serde_json", "sharded-slab", - "smallvec 1.13.2", + "smallvec", "thread_local", "tracing", "tracing-core", @@ -9702,7 +9684,7 @@ dependencies = [ "btreemultimap", "clap 4.5.20", "flate2", - "itertools 0.12.0", + "itertools 0.12.1", "leb128", "md5", "mina-core", @@ -9742,7 +9724,7 @@ dependencies = [ "ipnet", "once_cell", "rand", - "smallvec 1.13.2", + "smallvec", "socket2 0.5.5", "thiserror 1.0.60", "tinyvec", @@ -9765,7 +9747,7 @@ dependencies = [ "parking_lot 0.12.1", "rand", "resolv-conf", - "smallvec 1.13.2", + "smallvec", "thiserror 1.0.60", "tokio", "tracing", @@ -9826,7 +9808,7 @@ dependencies = [ [[package]] name = "turshi" version = "0.1.0" -source = "git+https://github.com/openmina/proof-systems?rev=f461b4b#f461b4bf65fe9677f81033ed7c3c4f997caea3fe" +source = "git+https://github.com/openmina/proof-systems?rev=d1912bca54d2609296b9af9d09ad1ef78702e203#d1912bca54d2609296b9af9d09ad1ef78702e203" dependencies = [ "ark-ff", "hex", @@ -10061,7 +10043,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "85e7dc29b3c54a2ea67ef4f953d5ec0c4085035c0ae2d325be1c0d2144bd9f16" dependencies = [ "anyhow", - "rustc_version 0.4.0", + "rustc_version", "rustversion", "time", ] @@ -10085,10 +10067,10 @@ dependencies = [ "anyhow", "ark-ec", "ark-ff", - "ark-serialize 0.3.0", + "ark-serialize 0.5.0", "bs58 0.4.0", "hex", - "itertools 0.12.0", + "itertools 0.12.1", "mina-curves", "mina-hasher", "mina-node-account", diff --git a/Cargo.toml b/Cargo.toml index 8729dbe790..37d388318e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,14 +50,22 @@ ledger = { path = "ledger", package = "mina-tree" } mina-p2p-messages = { path = "mina-p2p-messages" } poseidon = { path = "poseidon" } -mina-curves = { git = "https://github.com/openmina/proof-systems", rev = "f461b4b" } -mina-hasher = { git = "https://github.com/openmina/proof-systems", rev = "f461b4b" } -mina-signer = { git = "https://github.com/openmina/proof-systems", rev = "f461b4b" } -# UNCOMMENTED_IN_CI mina-curves = { git = "https://github.com/openmina/proof-systems", rev = "f461b4b", features = [ "32x9" ] } -kimchi = { git = "https://github.com/openmina/proof-systems", rev = "f461b4b" } -mina-poseidon = { git = "https://github.com/openmina/proof-systems", rev = "f461b4b" } -o1-utils = { git = "https://github.com/openmina/proof-systems", rev = "f461b4b" } -poly-commitment = { git = "https://github.com/openmina/proof-systems", rev = "f461b4b" } +# UNCOMMENTED_IN_CI mina-curves = { git = "https://github.com/openmina/proof-systems", rev = "d1912bca54d2609296b9af9d09ad1ef78702e203", features = [ "32x9" ] } +kimchi = { git = "https://github.com/openmina/proof-systems", rev = "d1912bca54d2609296b9af9d09ad1ef78702e203" } +mina-curves = { git = "https://github.com/openmina/proof-systems", rev = "d1912bca54d2609296b9af9d09ad1ef78702e203" } +mina-hasher = { git = "https://github.com/openmina/proof-systems", rev = "d1912bca54d2609296b9af9d09ad1ef78702e203" } +mina-poseidon = { git = "https://github.com/openmina/proof-systems", rev = "d1912bca54d2609296b9af9d09ad1ef78702e203" } +mina-signer = { git = "https://github.com/openmina/proof-systems", rev = "d1912bca54d2609296b9af9d09ad1ef78702e203" } +o1-utils = { git = "https://github.com/openmina/proof-systems", rev = "d1912bca54d2609296b9af9d09ad1ef78702e203" } +poly-commitment = { git = "https://github.com/openmina/proof-systems", rev = "d1912bca54d2609296b9af9d09ad1ef78702e203" } + +# kimchi.path = "../deps/proof-systems/kimchi" +# mina-curves.path = "../deps/proof-systems/curves" +# mina-hasher.path = "../deps/proof-systems/hasher" +# mina-poseidon.path = "../deps/proof-systems/poseidon" +# mina-signer.path = "../deps/proof-systems/signer" +# o1-utils.path = "../deps/proof-systems/utils" +# poly-commitment.path = "../deps/proof-systems/poly-commitment" juniper = { version = "0.16" } libp2p = { git = "https://github.com/openmina/rust-libp2p", rev = "5c44c7d9", default-features = false } @@ -72,8 +80,29 @@ serde_with = { version = "3.7.0", features = ["hex"] } static_assertions = "1.1.0" vrf = { path = "vrf" } -ark-ff = { version = "0.3.0", features = ["parallel", "asm", "std"] } -# UNCOMMENTED_IN_CI ark-ff = { version = "0.3.0", features = [ "parallel", "asm", "std", "32x9" ] } + +ark-ec = { git = "https://github.com/openmina/algebra", branch = "rebase-fix-openmina-webnode", features = [ + "std", +] } # branch: fix-openmina-webnode +ark-ff = { git = "https://github.com/openmina/algebra", branch = "rebase-fix-openmina-webnode", features = [ + "parallel", + "asm", + "std", +] } # branch: fix-openmina-webnode +ark-poly = { git = "https://github.com/openmina/algebra", branch = "rebase-fix-openmina-webnode" } # branch: fix-openmina-webnode +ark-serialize = { git = "https://github.com/openmina/algebra", branch = "rebase-fix-openmina-webnode", features = [ + "std", +] } # branch: fix-openmina-webnode +# Local +# ark-ec = { path = "../deps/algebra/ec", features = ["std"] } +# ark-ff = { path = "../deps/algebra/ff", features = ["parallel", "asm", "std"] } +# ark-poly = { path = "../deps/algebra/poly", features = ["std"] } +# ark-serialize = { path = "../deps/algebra/serialize" } + +num-bigint = { git = "https://github.com/openmina/num-bigint", branch = "rebase-onstack" } # branch: rebase-onstack +# num-bigint.path = "../deps/num-bigint" + +# UNCOMMENTED_IN_CI ark-ff = { git = "https://github.com/openmina/algebra", branch = "rebase-fix-openmina-webnode", features = ["parallel", "asm", "std", "32x9" ] } graphannis-malloc_size_of = { git = "https://github.com/openmina/graphannis-malloc_size_of.git", rev = "f7da9f6" } graphannis-malloc_size_of_derive = { git = "https://github.com/openmina/graphannis-malloc_size_of_derive.git" } @@ -92,13 +121,19 @@ incremental = false codegen-units = 1 [patch.crates-io] -ark-ff = { git = "https://github.com/openmina/algebra", rev = "150ab8d" } # branch: fix-openmina-webnode -ark-ec = { git = "https://github.com/openmina/algebra", rev = "150ab8d" } # branch: fix-openmina-webnode -ark-poly = { git = "https://github.com/openmina/algebra", rev = "150ab8d" } # branch: fix-openmina-webnode -ark-serialize = { git = "https://github.com/openmina/algebra", rev = "150ab8d" } # branch: fix-openmina-webnode - -num-bigint = { git = "https://github.com/openmina/num-bigint", rev = "8bb5ee4" } # branch: on-stack -num-rational = { git = "https://github.com/openmina/num-rational", rev = "336f11d" } # branch: on-stack +ark-ff = { git = "https://github.com/openmina/algebra", branch = "rebase-fix-openmina-webnode" } # branch: fix-openmina-webnode +ark-ec = { git = "https://github.com/openmina/algebra", branch = "rebase-fix-openmina-webnode" } # branch: fix-openmina-webnode +ark-poly = { git = "https://github.com/openmina/algebra", branch = "rebase-fix-openmina-webnode" } # branch: fix-openmina-webnode +ark-serialize = { git = "https://github.com/openmina/algebra", branch = "rebase-fix-openmina-webnode" } # branch: fix-openmina-webnode +# ark-ff.path = "../deps/algebra/ff" # branch: fix-openmina-webnode +# ark-ec.path = "../deps/algebra/ec" # branch: fix-openmina-webnode +# ark-poly.path = "../deps/algebra/poly" # branch: fix-openmina-webnode +# ark-serialize.path = "../deps/algebra/serialize" # branch: fix-openmina-webnode + +num-bigint = { git = "https://github.com/openmina/num-bigint", branch = "rebase-onstack" } # branch: rebase-onstack +# num-bigint.path = "../deps/num-bigint" # branch: on-stack +num-rational = { git = "https://github.com/openmina/num-rational", branch = "rebase-onstack" } # branch: rebase-onstack +# num-rational.path = "../deps/num-rational" # branch: on-stack [profile.test.package."*"] opt-level = 3 diff --git a/Dockerfile b/Dockerfile index d2130eddd9..08802fc579 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM rust:bullseye AS build # hadolint ignore=DL3008 RUN apt-get update && \ - apt-get install -y --no-install-recommends protobuf-compiler && \ + apt-get install -y --no-install-recommends protobuf-compiler ocaml && \ apt-get clean WORKDIR /mina diff --git a/Makefile b/Makefile index 38a92cd562..8e512dadec 100644 --- a/Makefile +++ b/Makefile @@ -30,6 +30,15 @@ NETWORK ?= devnet VERBOSITY ?= info GIT_COMMIT := $(shell git rev-parse --short=8 HEAD) +OPAM_PATH := $(shell command -v opam 2>/dev/null) + +ifdef OPAM_PATH +# This captures what `eval $(opam env)` would set in your shell +OPAM_ENV := $(shell eval $$(opam env) && env | grep '^OPAM\|^PATH\|^CAML' | sed 's/^/export /') +export $(shell eval $$(opam env) && env | grep '^OPAM\|^PATH\|^CAML' | cut -d= -f1) +$(foreach v,$(shell eval $$(opam env) && env | grep '^OPAM\|^PATH\|^CAML'),$(eval export $(v))) +endif + .PHONY: help help: ## Ask for help! @grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' diff --git a/core/src/network.rs b/core/src/network.rs index 7757c2d51c..8fdc1b4666 100644 --- a/core/src/network.rs +++ b/core/src/network.rs @@ -111,7 +111,6 @@ impl NetworkConfig { pub mod devnet { use super::{CircuitsConfig, NetworkId}; use crate::constants::{ConstraintConstants, ForkConstants}; - use mina_curves::pasta::Fp; pub const NETWORK_ID: NetworkId = NetworkId::TESTNET; pub const NAME: &str = "devnet"; @@ -151,8 +150,7 @@ pub mod devnet { // ourselves right now, we cannot react to changes in this value, // so it will be hardcoded for now. fork: Some(ForkConstants { - state_hash: ark_ff::field_new!( - Fp, + state_hash: ark_ff::MontFp!( "7908066420535064797069631664846455037440232590837253108938061943122344055350" ), blockchain_length: 296371, @@ -191,7 +189,6 @@ pub mod devnet { pub mod mainnet { use super::{CircuitsConfig, NetworkId}; use crate::constants::{ConstraintConstants, ForkConstants}; - use mina_curves::pasta::Fp; pub const NETWORK_ID: NetworkId = NetworkId::MAINNET; pub const NAME: &str = "mainnet"; @@ -231,8 +228,7 @@ pub mod mainnet { // ourselves right now, we cannot react to changes in this value, // so it will be hardcoded for now. fork: Some(ForkConstants { - state_hash: ark_ff::field_new!( - Fp, + state_hash: ark_ff::MontFp!( "24465973112608446515163575794792913472627621028836869800891179577915755065526" ), blockchain_length: 359604, diff --git a/ledger/Cargo.toml b/ledger/Cargo.toml index e632287c2f..2bbc6f1fad 100644 --- a/ledger/Cargo.toml +++ b/ledger/Cargo.toml @@ -46,16 +46,16 @@ sha2 = "0.10" itertools = "0.12" -ark-ec = { version = "0.3.0", features = ["std"] } -ark-ff = { workspace = true } -ark-poly = { version = "0.3.0", features = ["std"] } -ark-serialize = { version = "0.3.0", features = ["std"] } +ark-ec.workspace = true +ark-ff.workspace = true +ark-poly.workspace = true +ark-serialize.workspace = true rayon = "1.5" bitvec = "1.0.0" hex = "0.4.3" -num-bigint = "0.4" +num-bigint.workspace = true once_cell = "1" rand = { version = "0.8", features = ["small_rng"] } diff --git a/ledger/src/account/account.rs b/ledger/src/account/account.rs index 9ff5996622..786c384a04 100644 --- a/ledger/src/account/account.rs +++ b/ledger/src/account/account.rs @@ -126,8 +126,9 @@ impl TokenSymbol { let mut s = <[u8; 32]>::default(); self.to_bytes(&mut s); - let bigint = BigInteger256::read(&s[..]).unwrap(); - F::try_from(bigint).unwrap() // Never fail, `self` contain 6 bytes at most + let value = FromBytes::read(&s[..]).expect("Shoudn't fail"); + let bigint = BigInteger256::new(value); + F::from(bigint) // Never fail, `self` contain 6 bytes at most } } diff --git a/ledger/src/account/conv.rs b/ledger/src/account/conv.rs index b4b08b8578..7a434d5e63 100644 --- a/ledger/src/account/conv.rs +++ b/ledger/src/account/conv.rs @@ -1,6 +1,6 @@ #![allow(clippy::type_complexity)] -use ark_ec::short_weierstrass_jacobian::GroupAffine; +use ark_ec::short_weierstrass::Affine; use ark_ff::{fields::arithmetic::InvalidBigInt, Field, PrimeField}; use mina_curves::pasta::Fp; use mina_p2p_messages::{ @@ -82,7 +82,7 @@ where F: Field + Into, { fn from(fps: InnerCurve) -> Self { - let GroupAffine { x, y, .. } = fps.to_affine(); + let Affine { x, y, .. } = fps.to_affine(); (x.into(), y.into()) } } @@ -106,7 +106,7 @@ where F: Field + Into, { fn from(fps: &InnerCurve) -> Self { - let GroupAffine { x, y, .. } = fps.to_affine(); + let Affine { x, y, .. } = fps.to_affine(); (x.into(), y.into()) } } @@ -667,7 +667,7 @@ impl From for MinaBaseAccountIndexStableV1 { impl From for mina_p2p_messages::v2::ReceiptChainHash { fn from(value: ReceiptChainHash) -> Self { - MinaBaseReceiptChainHashStableV1(value.0.into_repr().into()).into() + MinaBaseReceiptChainHashStableV1(value.0.into_bigint().into()).into() } } diff --git a/ledger/src/cache.rs b/ledger/src/cache.rs index 26b9bf12f2..92f809ee8a 100644 --- a/ledger/src/cache.rs +++ b/ledger/src/cache.rs @@ -68,9 +68,9 @@ macro_rules! cache_one { #[cfg(test)] mod tests { - use crate::proofs::field::FieldWitness; - use ark_ec::short_weierstrass_jacobian::GroupAffine; - use poly_commitment::srs::endos; + use crate::proofs::{self, field::FieldWitness}; + use ark_ec::short_weierstrass::Affine; + use poly_commitment::ipa::endos; use std::sync::atomic::{AtomicUsize, Ordering::Relaxed}; #[cfg(target_family = "wasm")] @@ -82,10 +82,10 @@ mod tests { static COUNTER: AtomicUsize = AtomicUsize::new(0); - fn my_test() -> (F, F::Scalar) { - cache!((F, F::Scalar), { + fn my_test() -> (F, ::Scalar) { + cache!((F, ::Scalar), { COUNTER.fetch_add(1, Relaxed); - endos::>() + endos::>() }) } diff --git a/ledger/src/port_ocaml/hash.rs b/ledger/src/port_ocaml/hash.rs index 42542aec7b..6b974fba88 100644 --- a/ledger/src/port_ocaml/hash.rs +++ b/ledger/src/port_ocaml/hash.rs @@ -91,7 +91,7 @@ fn hash_field(f: &Fp) -> u32 { let mut acc = 0; let bigint: BigInteger256 = (*f).into(); - let bigint = bigint.to_64x4(); + let bigint = bigint.0; let nignore: usize = bigint.iter().rev().take_while(|&b| *b == 0).count(); for bigint in bigint.iter().take(BigInteger256::NUM_LIMBS - nignore) { diff --git a/ledger/src/poseidon/fp.rs b/ledger/src/poseidon/fp.rs index 15b9aaa89b..7c2c977d96 100644 --- a/ledger/src/poseidon/fp.rs +++ b/ledger/src/poseidon/fp.rs @@ -562,7 +562,7 @@ mod tests { let mina_fp = mina_curves::pasta::Fp::from_str(s).unwrap(); assert_eq!(fp.0, mina_fp.0 .0); - assert_eq!(fp.into_repr(), mina_fp.into_repr().0) + assert_eq!(fp.into_bigint(), mina_fp.into_bigint().0) } for chunk in CONSTANTS.chunks(2) { diff --git a/ledger/src/proofs/accumulator_check.rs b/ledger/src/proofs/accumulator_check.rs index adab8b5374..a3a1e3e3dc 100644 --- a/ledger/src/proofs/accumulator_check.rs +++ b/ledger/src/proofs/accumulator_check.rs @@ -1,7 +1,7 @@ use ark_ff::fields::arithmetic::InvalidBigInt; use mina_curves::pasta::{Fp, Vesta}; use mina_p2p_messages::{bigint::BigInt, v2::PicklesProofProofsVerified2ReprStableV2}; -use poly_commitment::{commitment::CommitmentCurve, srs::SRS}; +use poly_commitment::{commitment::CommitmentCurve, ipa::SRS}; use super::{public_input::scalar_challenge::ScalarChallenge, urs_utils}; diff --git a/ledger/src/proofs/block.rs b/ledger/src/proofs/block.rs index e45d36fa58..a8d2e34078 100644 --- a/ledger/src/proofs/block.rs +++ b/ledger/src/proofs/block.rs @@ -316,17 +316,17 @@ mod floating_point { } const COEFFICIENTS: [(Sgn, BigInteger256); 11] = [ - (Sgn::Pos, BigInteger256::from_64x4([405058, 0, 0, 0])), - (Sgn::Neg, BigInteger256::from_64x4([1007582, 0, 0, 0])), - (Sgn::Pos, BigInteger256::from_64x4([465602, 0, 0, 0])), - (Sgn::Neg, BigInteger256::from_64x4([161365, 0, 0, 0])), - (Sgn::Pos, BigInteger256::from_64x4([44739, 0, 0, 0])), - (Sgn::Neg, BigInteger256::from_64x4([10337, 0, 0, 0])), - (Sgn::Pos, BigInteger256::from_64x4([2047, 0, 0, 0])), - (Sgn::Neg, BigInteger256::from_64x4([354, 0, 0, 0])), - (Sgn::Pos, BigInteger256::from_64x4([54, 0, 0, 0])), - (Sgn::Neg, BigInteger256::from_64x4([7, 0, 0, 0])), - (Sgn::Pos, BigInteger256::from_64x4([0, 0, 0, 0])), + (Sgn::Pos, BigInteger256::new([405058, 0, 0, 0])), + (Sgn::Neg, BigInteger256::new([1007582, 0, 0, 0])), + (Sgn::Pos, BigInteger256::new([465602, 0, 0, 0])), + (Sgn::Neg, BigInteger256::new([161365, 0, 0, 0])), + (Sgn::Pos, BigInteger256::new([44739, 0, 0, 0])), + (Sgn::Neg, BigInteger256::new([10337, 0, 0, 0])), + (Sgn::Pos, BigInteger256::new([2047, 0, 0, 0])), + (Sgn::Neg, BigInteger256::new([354, 0, 0, 0])), + (Sgn::Pos, BigInteger256::new([54, 0, 0, 0])), + (Sgn::Neg, BigInteger256::new([7, 0, 0, 0])), + (Sgn::Pos, BigInteger256::new([0, 0, 0, 0])), ]; pub struct Params { @@ -501,7 +501,7 @@ mod floating_point { pub fn constant(value: &BigInteger256, precision: usize) -> anyhow::Result { Ok(Self { - value: (*value).try_into()?, + value: (*value).into(), precision, }) } @@ -1881,10 +1881,10 @@ pub(super) fn generate_block_proof( }; let dlog_plonk_index = super::merge::dlog_plonk_index(block_wrap_prover); - let verifier_index = &**block_wrap_prover.index.verifier_index.as_ref().unwrap(); + let verifier_index = block_wrap_prover.index.verifier_index.as_ref().unwrap(); let tx_dlog_plonk_index = super::merge::dlog_plonk_index(tx_wrap_prover); - let tx_verifier_index = &**tx_wrap_prover.index.verifier_index.as_ref().unwrap(); + let tx_verifier_index = tx_wrap_prover.index.verifier_index.as_ref().unwrap(); let dlog_plonk_index_cvar = dlog_plonk_index.to_cvar(CircuitVar::Var); let tx_dlog_plonk_index_cvar = tx_dlog_plonk_index.to_cvar(CircuitVar::Constant); diff --git a/ledger/src/proofs/caching.rs b/ledger/src/proofs/caching.rs index 9bc699b282..c7a268f88e 100644 --- a/ledger/src/proofs/caching.rs +++ b/ledger/src/proofs/caching.rs @@ -4,14 +4,15 @@ use std::{ sync::Arc, }; -use ark_ec::{short_weierstrass_jacobian::GroupAffine, AffineCurve, ModelParameters}; +use ark_ec::{short_weierstrass::Affine, AffineRepr, CurveConfig}; use ark_ff::fields::arithmetic::InvalidBigInt; use ark_poly::{univariate::DensePolynomial, Radix2EvaluationDomain}; use kimchi::{ alphas::Alphas, circuits::{ argument::{Argument, ArgumentType}, - expr::{Linearization, PolishToken}, + berkeley_columns::{BerkeleyChallengeTerm, Column}, + expr::{ConstantTerm, Linearization, PolishToken}, gate::GateType, polynomials::{permutation, varbasemul::VarbaseMul}, wires::{COLUMNS, PERMUTS}, @@ -22,7 +23,9 @@ use kimchi::{ use mina_curves::pasta::Fq; use mina_p2p_messages::bigint::BigInt; use once_cell::sync::OnceCell; -use poly_commitment::{commitment::CommitmentCurve, srs::SRS, PolyComm}; +use poly_commitment::{ + commitment::CommitmentCurve, hash_map_cache::HashMapCache, ipa::SRS, PolyComm, +}; use serde::{Deserialize, Serialize}; use super::VerifierIndex; @@ -59,7 +62,9 @@ struct Radix2EvaluationDomainCached { size_inv: BigInt, group_gen: BigInt, group_gen_inv: BigInt, - generator_inv: BigInt, + offset: BigInt, + offset_inv: BigInt, + offset_pow_size: BigInt, } impl From<&Radix2EvaluationDomainCached> for Radix2EvaluationDomain { @@ -71,7 +76,9 @@ impl From<&Radix2EvaluationDomainCached> for Radix2EvaluationDomain { size_inv: domain.size_inv.to_field().unwrap(), // We trust cached data group_gen: domain.group_gen.to_field().unwrap(), // We trust cached data group_gen_inv: domain.group_gen_inv.to_field().unwrap(), // We trust cached data - generator_inv: domain.generator_inv.to_field().unwrap(), // We trust cached data + offset: domain.offset.to_field().unwrap(), + offset_inv: domain.offset_inv.to_field().unwrap(), + offset_pow_size: domain.offset_pow_size.to_field().unwrap(), } } } @@ -85,7 +92,9 @@ impl From<&Radix2EvaluationDomain> for Radix2EvaluationDomainCached { size_inv: domain.size_inv.into(), group_gen: domain.group_gen.into(), group_gen_inv: domain.group_gen_inv.into(), - generator_inv: domain.generator_inv.into(), + offset: domain.offset.into(), + offset_inv: domain.offset_inv.into(), + offset_pow_size: domain.offset_pow_size.into(), } } } @@ -98,12 +107,12 @@ pub struct GroupAffineCached { infinity: bool, } -impl<'a, T> From<&'a GroupAffine> for GroupAffineCached +impl<'a, T> From<&'a Affine> for GroupAffineCached where - T: ark_ec::SWModelParameters, - BigInt: From<&'a ::BaseField>, + T: ark_ec::short_weierstrass::SWCurveConfig, + BigInt: From<&'a ::BaseField>, { - fn from(pallas: &'a GroupAffine) -> Self { + fn from(pallas: &'a Affine) -> Self { Self { x: (&pallas.x).into(), y: (&pallas.y).into(), @@ -112,17 +121,21 @@ where } } -impl From<&GroupAffineCached> for GroupAffine +impl From<&GroupAffineCached> for ark_ec::models::short_weierstrass::Affine where - T: ark_ec::SWModelParameters, - ::BaseField: TryFrom, + T: ark_ec::short_weierstrass::SWCurveConfig, + ::BaseField: From, { + // This is copy of old `GroupAffine::new` function fn from(pallas: &GroupAffineCached) -> Self { - Self::new( - pallas.x.to_field().unwrap(), // We trust cached data - pallas.y.to_field().unwrap(), // We trust cached data - pallas.infinity, - ) + let point = Self { + x: pallas.x.to_field().unwrap(), // We trust cached data + y: pallas.y.to_field().unwrap(), // We trust cached data + infinity: pallas.infinity, + }; + assert!(point.is_on_curve()); + assert!(point.is_in_correct_subgroup_assuming_on_curve()); + point } } @@ -136,9 +149,11 @@ where GroupAffineCached: From<&'a A>, { fn from(value: &'a PolyComm) -> Self { - let PolyComm { elems } = value; + let PolyComm { chunks } = value; - Self { elems: into(elems) } + Self { + elems: into(chunks), + } } } @@ -149,7 +164,9 @@ where fn from(value: &'a PolyCommCached) -> Self { let PolyCommCached { elems } = value; - Self { elems: into(elems) } + Self { + chunks: into(elems), + } } } @@ -159,20 +176,33 @@ struct SRSCached { h: GroupAffineCached, lagrange_bases: HashMap>, } - impl<'a, G> From<&'a SRS> for SRSCached where G: CommitmentCurve, - GroupAffineCached: From<&'a G>, - PolyCommCached: From<&'a PolyComm>, - BigInt: From<&'a ::ScalarField>, - BigInt: From<&'a ::BaseField>, + GroupAffineCached: for<'b> From<&'b G>, + PolyCommCached: for<'x> From<&'x PolyComm>, + BigInt: From<&'a ::ScalarField>, + BigInt: From<&'a ::BaseField>, { fn from(srs: &'a SRS) -> Self { Self { g: into(&srs.g), h: (&srs.h).into(), - lagrange_bases: into_with(&srs.lagrange_bases, |(key, value)| (*key, into(value))), + lagrange_bases: { + let cloned = srs.lagrange_bases.clone(); + let map = HashMap::from(cloned); + map.into_iter() + .map(|(key, value)| { + ( + key, + value + .into_iter() + .map(|pc| PolyCommCached::from(&pc)) + .collect(), + ) + }) + .collect() + }, } } } @@ -185,7 +215,15 @@ where Self { g: into(&srs.g), h: (&srs.h).into(), - lagrange_bases: into_with(&srs.lagrange_bases, |(key, value)| (*key, into(value))), + lagrange_bases: { + let lagrange_bases = srs + .lagrange_bases + .iter() + .map(|(key, value)| (*key, value.iter().map(PolyComm::from).collect())) + .collect(); + + HashMapCache::new_from_hashmap(lagrange_bases) + }, } } } @@ -237,47 +275,54 @@ struct VerifierIndexCached { w: BigInt, // Fq endo: BigInt, // Fq lookup_index: Option>, - linearization: Linearization>>, // Fq + linearization: Linearization>, Column>, // Fq zk_rows: u64, } -fn conv_token<'a, T, U, F>(token: &'a PolishToken, fun: F) -> PolishToken +fn conv_token<'a, T, U, F>( + token: &'a PolishToken, + fun: F, +) -> PolishToken where T: 'a, F: Fn(&T) -> U, { match token { - PolishToken::Alpha => PolishToken::Alpha, - PolishToken::Beta => PolishToken::Beta, - PolishToken::Gamma => PolishToken::Gamma, - PolishToken::JointCombiner => PolishToken::JointCombiner, - PolishToken::EndoCoefficient => PolishToken::EndoCoefficient, - PolishToken::Mds { row, col } => PolishToken::Mds { - row: *row, - col: *col, + PolishToken::Constant(constant_term) => match constant_term { + ConstantTerm::EndoCoefficient => PolishToken::Constant(ConstantTerm::EndoCoefficient), + &ConstantTerm::Mds { row, col } => { + PolishToken::Constant(ConstantTerm::Mds { row, col }) + } + ConstantTerm::Literal(literal) => { + PolishToken::Constant(ConstantTerm::Literal(fun(literal))) + } }, - PolishToken::Literal(f) => PolishToken::Literal(fun(f)), - PolishToken::Cell(var) => PolishToken::Cell(*var), + PolishToken::Challenge(challenge) => PolishToken::Challenge(*challenge), + PolishToken::Cell(variable) => PolishToken::Cell(*variable), PolishToken::Dup => PolishToken::Dup, - PolishToken::Pow(int) => PolishToken::Pow(*int), + PolishToken::Pow(p) => PolishToken::Pow(*p), PolishToken::Add => PolishToken::Add, PolishToken::Mul => PolishToken::Mul, PolishToken::Sub => PolishToken::Sub, PolishToken::VanishesOnZeroKnowledgeAndPreviousRows => { PolishToken::VanishesOnZeroKnowledgeAndPreviousRows } - PolishToken::UnnormalizedLagrangeBasis(int) => PolishToken::UnnormalizedLagrangeBasis(*int), + PolishToken::UnnormalizedLagrangeBasis(row_offset) => { + PolishToken::UnnormalizedLagrangeBasis(*row_offset) + } PolishToken::Store => PolishToken::Store, - PolishToken::Load(int) => PolishToken::Load(*int), - PolishToken::SkipIf(flags, int) => PolishToken::SkipIf(*flags, *int), - PolishToken::SkipIfNot(flags, int) => PolishToken::SkipIfNot(*flags, *int), + PolishToken::Load(load) => PolishToken::Load(*load), + PolishToken::SkipIf(feature_flag, value) => PolishToken::SkipIf(*feature_flag, *value), + PolishToken::SkipIfNot(feature_flag, value) => { + PolishToken::SkipIfNot(*feature_flag, *value) + } } } fn conv_linearization<'a, T, U, F>( - linearization: &'a Linearization>>, + linearization: &'a Linearization>, Column>, fun: F, -) -> Linearization>> +) -> Linearization>, Column> where T: 'a, F: Fn(&T) -> U, @@ -285,7 +330,8 @@ where let constant_term = &linearization.constant_term; let index_terms = &linearization.index_terms; - let conv_token = |token: &PolishToken| conv_token(token, &fun); + let conv_token = + |token: &PolishToken| conv_token(token, &fun); Linearization { constant_term: into_with(constant_term, conv_token), @@ -330,7 +376,10 @@ impl From<&VerifierIndex> for VerifierIndexCached { Self { domain: domain.into(), max_poly_size: *max_poly_size, - srs: (&**srs).into(), + srs: { + let s = srs.as_ref(); + SRSCached::from(s) + }, public: *public, prev_challenges: *prev_challenges, sigma_comm: sigma_comm.clone(), @@ -395,7 +444,10 @@ impl From<&VerifierIndexCached> for VerifierIndex { Self { domain: domain.into(), max_poly_size: *max_poly_size, - srs: Arc::new(srs.into()), + srs: { + let s: SRS<_> = SRS::from(srs); + Arc::new(s) + }, public: *public, prev_challenges: *prev_challenges, sigma_comm: sigma_comm.clone(), @@ -464,9 +516,9 @@ pub fn verifier_index_from_bytes( pub fn srs_to_bytes<'a, G>(srs: &'a SRS) -> Vec where G: CommitmentCurve, - GroupAffineCached: From<&'a G>, - BigInt: From<&'a ::ScalarField>, - BigInt: From<&'a ::BaseField>, + GroupAffineCached: for<'y> From<&'y G>, + BigInt: From<&'a ::ScalarField>, + BigInt: From<&'a ::BaseField>, { let srs: SRSCached = srs.into(); diff --git a/ledger/src/proofs/data/devnet_blockchain_verifier_index.json b/ledger/src/proofs/data/devnet_blockchain_verifier_index.json index 4ce9df6cb1..d11239af2e 100644 --- a/ledger/src/proofs/data/devnet_blockchain_verifier_index.json +++ b/ledger/src/proofs/data/devnet_blockchain_verifier_index.json @@ -1,150 +1,150 @@ { - "domain": "00400000000000000e000000004000000000000000000000000000000000000000000000000000000000000001007c5305bad0e88a82a4a5e10f46220000000000000000000000000000ff3fe7beaf68d0348b89bdd305c696e458495971539c8db379b03b2524706887551e19429440c0d6dda9640e2856b0ed40f84fc0f5f9ed7dd028cf3d4d38cd355b2e6766666640914f6b25dda1d064704fa799999999999999999999999999999919", + "domain": "00400000000000000e000000004000000000000000000000000000000000000000000000000000000000000001007c5305bad0e88a82a4a5e10f46220000000000000000000000000000ff3fe7beaf68d0348b89bdd305c696e458495971539c8db379b03b2524706887551e19429440c0d6dda9640e2856b0ed40f84fc0f5f9ed7dd028cf3d4d38cd355b2e010000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000", "max_poly_size": 32768, "zk_rows": 3, "public": 40, "prev_challenges": 2, "sigma_comm": [ { - "elems": [ + "chunks": [ "ac8bd027a9304142af5875c8777ff30e682454af9eb1efaa27d6330fb0cba21600" ] }, { - "elems": [ + "chunks": [ "cc9b639929d7f0670d7007e01720285ae24759586436138ebe918f112eadcf2280" ] }, { - "elems": [ + "chunks": [ "ebc961cc7ea035f0aa68243f3c2618ede4b1a989038b7cfc2a2611ee6166fb0280" ] }, { - "elems": [ + "chunks": [ "055d143d1309e33249fc0052d6bc0a35874f0df68d848582be92f37ce715d60f80" ] }, { - "elems": [ + "chunks": [ "ab2db78a806736648a414ef6a0f97b9076a6b99aff7d071f83438ecf379fc82080" ] }, { - "elems": [ + "chunks": [ "d1bd9a7ab6f956c73362e41d806a159ea6790b402f511804b9b7674fee8a541380" ] }, { - "elems": [ + "chunks": [ "55e51fd3031e1ef98fba6ecc179df2e69719143f6ff62626c466744b066d212000" ] } ], "coefficients_comm": [ { - "elems": [ + "chunks": [ "b46c878c9534d6f5d2ff8974f353378611436dd2f7830ec1dee754231210ec2680" ] }, { - "elems": [ + "chunks": [ "2299130706c7d6a85573afc967d2a1d841aec1a54ea026e740ae3852d10f060800" ] }, { - "elems": [ + "chunks": [ "0fafec88aa611ed0eddfdb49bf3c399e351c80091f1af766602487557307e03a00" ] }, { - "elems": [ + "chunks": [ "36b208e72f08825cb3f3ef4f5320acb432e6bcb3a160b5ef8a598f257ffdcb3d80" ] }, { - "elems": [ + "chunks": [ "14d68d61f70190e00e6db4054868b7a45a1aae006496f5a6c02ca7c509164f3600" ] }, { - "elems": [ + "chunks": [ "e812c853609db257416d6a21c3fa40ece3cada381ece80160cc5041b21efa42e80" ] }, { - "elems": [ + "chunks": [ "2111541adb7611dd720dd94c761b357afe755ddce944360453e6612770e6323e00" ] }, { - "elems": [ + "chunks": [ "ca2f65be9c06ae3bd38e3c1a9855cf2b7a768158eb5f56412f74974a81cee21a00" ] }, { - "elems": [ + "chunks": [ "1f524503bbfaa37ffa3d597672ea191dc586ae2bee125418e8616cbb40fa100a80" ] }, { - "elems": [ + "chunks": [ "66a71a1a7776235a4a863b9651da7a3b71a88d299d6b05919a139128d6c2b22100" ] }, { - "elems": [ + "chunks": [ "36d0bbb91110354a2b4c47caf7b712504a505c0db581037a1487c3b2a5e7632700" ] }, { - "elems": [ + "chunks": [ "037163fe33de4d9b4078a9787f4329cb9efeab6c10a378e41e5753a0436e593280" ] }, { - "elems": [ + "chunks": [ "8ece63908d483eb3778899f9b017edbaba5067fa229ec6b2378af32472fe731d80" ] }, { - "elems": [ + "chunks": [ "af4cd42b539de9355d04ea33b9f05a2b733236a4b706acaf6504c77b885ddf2f80" ] }, { - "elems": [ + "chunks": [ "394d46b4e0c0ffd4d6ff518a8454c3f5caa363345721b3cf15d9547d88ba290d80" ] } ], "generic_comm": { - "elems": [ + "chunks": [ "1b921bb273d9ec54df3ad9bcfa27bb0512df51b65fcfc0183e694e3b7462363600" ] }, "psm_comm": { - "elems": [ + "chunks": [ "24433049d9d52411a0fe32472a60b1181c51af40aaed21c767630c67f53e8b0a00" ] }, "complete_add_comm": { - "elems": [ + "chunks": [ "4b4d315bb85c236ac63c69ebde7b30bd7c450353fd065ce77c781ff11892851e80" ] }, "mul_comm": { - "elems": [ + "chunks": [ "c5b9c77cc3aeea7a67285a0627159bb92579818471b6312ba905d48c3a7dc93e80" ] }, "emul_comm": { - "elems": [ + "chunks": [ "b90c824d829e89424b21a866a827908221716b665bd7d760665eaf0f0272471100" ] }, "endomul_scalar_comm": { - "elems": [ + "chunks": [ "dd6aa757b582dc4ff7018e86082bc5bb59b7d420caef5ecd4e5912649b0ac30400" ] }, diff --git a/ledger/src/proofs/data/devnet_transaction_verifier_index.json b/ledger/src/proofs/data/devnet_transaction_verifier_index.json index aa84c09365..91defda1d9 100644 --- a/ledger/src/proofs/data/devnet_transaction_verifier_index.json +++ b/ledger/src/proofs/data/devnet_transaction_verifier_index.json @@ -1,150 +1,150 @@ { - "domain": "00400000000000000e000000004000000000000000000000000000000000000000000000000000000000000001007c5305bad0e88a82a4a5e10f46220000000000000000000000000000ff3fe7beaf68d0348b89bdd305c696e458495971539c8db379b03b2524706887551e19429440c0d6dda9640e2856b0ed40f84fc0f5f9ed7dd028cf3d4d38cd355b2e6766666640914f6b25dda1d064704fa799999999999999999999999999999919", + "domain": "00400000000000000e000000004000000000000000000000000000000000000000000000000000000000000001007c5305bad0e88a82a4a5e10f46220000000000000000000000000000ff3fe7beaf68d0348b89bdd305c696e458495971539c8db379b03b2524706887551e19429440c0d6dda9640e2856b0ed40f84fc0f5f9ed7dd028cf3d4d38cd355b2e010000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000", "max_poly_size": 32768, "zk_rows": 3, "public": 40, "prev_challenges": 2, "sigma_comm": [ { - "elems": [ + "chunks": [ "90c73b1ec54c26bae22caca2ebfb7f428273d8bb4e707cb411e10da092a31b2e80" ] }, { - "elems": [ + "chunks": [ "bcb575448cecbf9c1395c1d68056f5ff42a46d286763e264bc75281e779b140d00" ] }, { - "elems": [ + "chunks": [ "eda3d8981033895b4212aef150ea7bd4183414e0292eae7c6968450f1dd4662800" ] }, { - "elems": [ + "chunks": [ "b20ca3c2e55ccc53430ec74e85afde8d52934609f88ba397bba0e137900f0a0c00" ] }, { - "elems": [ + "chunks": [ "eb98c43a4354ed8ce7e486fd09401423f72c06c674fe97312cf1b4a1f0fe2a3400" ] }, { - "elems": [ + "chunks": [ "99db19342a4e6101c2a0307d64a2233a636dcfb00a3757725a0f0499c5a3e91400" ] }, { - "elems": [ + "chunks": [ "9a0500bbe7e4ff39f236658f15ab3ab7a9492199f4f336601e60bb90b6073b1480" ] } ], "coefficients_comm": [ { - "elems": [ + "chunks": [ "299f4b3e51427c64b4681f8b3e315556076d3ccb76e2d2328d8a1ac753016c1a00" ] }, { - "elems": [ + "chunks": [ "965430e5c1615641e0cc8c5e371a3ce402d7adf50dfa109602ed7ee7eec1df0200" ] }, { - "elems": [ + "chunks": [ "27f6e5c0cb30793dd572d830db227b696211fd3b3f37f7096e80fce44a29713c80" ] }, { - "elems": [ + "chunks": [ "1770f3f6bc84d5287d550f8abcd9df38f25ef0f3dd1b161bd3cbcea66fec650380" ] }, { - "elems": [ + "chunks": [ "8d3394f89b8e5814754a99885c19856137a3de15ba8079ea586bc2e71d058c2c00" ] }, { - "elems": [ + "chunks": [ "e1043c2698170acf5ac6e0621db06689884ab62e953a8292e73143ae0354482280" ] }, { - "elems": [ + "chunks": [ "eb45515b4445bef8beea8f72c456b9d147ed28c0eeea8b21d7b7a4b58042bc1400" ] }, { - "elems": [ + "chunks": [ "03dd51e41b61d6e52d3e370fded80e6a25c1aa35715c1481dfd533e3ed81453180" ] }, { - "elems": [ + "chunks": [ "a3a26573549290670c346a03b3d2cbfb1ea834cbd748688ba10790efb02a893180" ] }, { - "elems": [ + "chunks": [ "21c87f7f2e6e6aa2ad762b01db220c90574f5e2fc1c572f469b9fa25d02fc81300" ] }, { - "elems": [ + "chunks": [ "5f3f0a0b06cb16ddf2ef13d54fbde08f3cfc5721126f8f1e8038de67921dd13780" ] }, { - "elems": [ + "chunks": [ "fb9a0d228e8cdc829c748c8b8d7751998b81805959d307dcbf2f3b601daa813300" ] }, { - "elems": [ + "chunks": [ "1019ec7567d56fc10eefa766c8b75033eab1dccea27b413d748549485213263300" ] }, { - "elems": [ + "chunks": [ "641190c8bb3021d87f0c0c20dcfee80c2287e986ba0c818077ff73a67e6d393f80" ] }, { - "elems": [ + "chunks": [ "6db248045f24c41a5557c5fac1c95f3500c97476746035a9c58a1a5e1a88d72c00" ] } ], "generic_comm": { - "elems": [ + "chunks": [ "a1c3dfaace548babe5bcee0b85cef11d19e5a4fa0b34174761a4780582a2b61100" ] }, "psm_comm": { - "elems": [ + "chunks": [ "e40983dc71ab596a8ada1c5b61f562a8aef8ffbc5f1b597f39da39bc6eb5233880" ] }, "complete_add_comm": { - "elems": [ + "chunks": [ "5eb9158f8e25ff0d9b11a16ccd67af47a189a0d30093c09026c2420742033d1a00" ] }, "mul_comm": { - "elems": [ + "chunks": [ "854aa61b80095185fa2a85001652da3cb73857aa72359ceb0241ca5928479e2f00" ] }, "emul_comm": { - "elems": [ + "chunks": [ "6c916fe9d7aea7194dac9509e8e424234761dbbe038ab48f73115cc4e3538b0180" ] }, "endomul_scalar_comm": { - "elems": [ + "chunks": [ "845f2d1bdbcc25c5ad005decc9bd3f0cdd928c157aadc55a88dd1cd74f8ee51b00" ] }, diff --git a/ledger/src/proofs/field.rs b/ledger/src/proofs/field.rs index 3facb1f124..14a14c8734 100644 --- a/ledger/src/proofs/field.rs +++ b/ledger/src/proofs/field.rs @@ -1,18 +1,16 @@ -use ark_ec::{ - short_weierstrass_jacobian::GroupProjective, AffineCurve, ProjectiveCurve, SWModelParameters, -}; -use ark_ff::{ - fields::arithmetic::InvalidBigInt, BigInteger256, FftField, Field, FpParameters, PrimeField, - SquareRootField, -}; +use ark_ec::{short_weierstrass::Projective, AffineRepr, CurveGroup}; +use ark_ff::{BigInteger256, FftField, Field, PrimeField}; use kimchi::curve::KimchiCurve; use mina_curves::pasta::{ - Fp, Fq, PallasParameters, ProjectivePallas, ProjectiveVesta, VestaParameters, + fields::fft::FpParameters as _, Fp, Fq, PallasParameters, ProjectivePallas, ProjectiveVesta, + VestaParameters, }; use mina_poseidon::{constants::PlonkSpongeConstantsKimchi, sponge::DefaultFqSponge}; use poseidon::SpongeParamsForField; +use crate::proofs; + use super::{ public_input::plonk_checks::{self, ShiftedValue}, to_field_elements::ToFieldElements, @@ -21,8 +19,7 @@ use super::{ BACKEND_TICK_ROUNDS_N, BACKEND_TOCK_ROUNDS_N, }; -pub type GroupAffine = - ark_ec::short_weierstrass_jacobian::GroupAffine<::Parameters>; +pub type GroupAffine = ark_ec::short_weierstrass::Affine<::Parameters>; /// All the generics we need during witness generation pub trait FieldWitness @@ -31,7 +28,7 @@ where + Send + Sync + Into - + TryFrom + + From + Into + From + From @@ -39,26 +36,41 @@ where + Check + FromFpFq + PrimeField - + SquareRootField + FftField + SpongeParamsForField + std::fmt::Debug + 'static, { type Scalar: FieldWitness; - type Affine: AffineCurve - + Into> + type Affine: AffineRepr< + Group = Self::Projective, + BaseField = Self, + ScalarField = ::Scalar, + > + Into> + KimchiCurve + std::fmt::Debug; - type Projective: ProjectiveCurve - + From> + type Projective: CurveGroup< + Affine = Self::Affine, + BaseField = Self, + ScalarField = ::Scalar, + > + From> + std::fmt::Debug; - type Parameters: SWModelParameters - + Clone + type Parameters: ark_ec::short_weierstrass::SWCurveConfig< + BaseField = Self, + ScalarField = ::Scalar, + > + Clone + std::fmt::Debug; type Shifting: plonk_checks::ShiftingValue + Clone + std::fmt::Debug; - type OtherCurve: KimchiCurve; - type FqSponge: Clone + mina_poseidon::FqSponge; + type OtherCurve: KimchiCurve< + ScalarField = Self, + BaseField = ::Scalar, + >; + type FqSponge: Clone + + mina_poseidon::FqSponge< + ::Scalar, + Self::OtherCurve, + Self, + >; const PARAMS: Params; const SIZE: BigInteger256; @@ -82,8 +94,8 @@ impl FieldWitness for Fp { /// const PARAMS: Params = Params:: { - a: ark_ff::field_new!(Fp, "0"), - b: ark_ff::field_new!(Fp, "5"), + a: ark_ff::MontFp!("0"), + b: ark_ff::MontFp!("5"), }; const SIZE: BigInteger256 = mina_curves::pasta::fields::FpParameters::MODULUS; const NROUNDS: usize = BACKEND_TICK_ROUNDS_N; @@ -101,8 +113,8 @@ impl FieldWitness for Fq { /// const PARAMS: Params = Params:: { - a: ark_ff::field_new!(Fq, "0"), - b: ark_ff::field_new!(Fq, "5"), + a: ark_ff::MontFp!("0"), + b: ark_ff::MontFp!("5"), }; const SIZE: BigInteger256 = mina_curves::pasta::fields::FqParameters::MODULUS; const NROUNDS: usize = BACKEND_TOCK_ROUNDS_N; @@ -131,7 +143,7 @@ impl FromFpFq for Fq { fn from_fp(fp: Fp) -> Self { // `Fp` is smaller than `Fq`, so the conversion is fine let bigint: BigInteger256 = fp.into(); - bigint.try_into().unwrap() + Self::from(bigint) } fn from_fq(fq: Fq) -> Self { fq diff --git a/ledger/src/proofs/group_map.rs b/ledger/src/proofs/group_map.rs index 5663a5d8db..d8d7d717e3 100644 --- a/ledger/src/proofs/group_map.rs +++ b/ledger/src/proofs/group_map.rs @@ -98,8 +98,8 @@ pub mod bw19 { } } -use ark_ff::{FpParameters, One}; -use mina_curves::pasta::Fp; +use ark_ff::One; +use mina_curves::pasta::{fields::fft::FpParameters as _, Fp}; use self::tock::Conic; @@ -113,9 +113,9 @@ fn sqrt_exn(x: F, w: &mut Witness) -> F { } fn is_square(x: F) -> bool { - use ark_ff::BigInteger; + let modulus_minus_one_div_two = + mina_curves::pasta::fields::FpParameters::MODULUS_MINUS_ONE_DIV_TWO.0; - let modulus_minus_one_div_two = F::Params::MODULUS_MINUS_ONE_DIV_TWO.to_64x4(); let s = x.pow(modulus_minus_one_div_two); s.is_zero() || s.is_one() } @@ -187,7 +187,7 @@ pub fn wrap(potential_xs: (F, F, F), w: &mut Witness) -> Gro mod tock { use super::*; - use ark_ff::{SquareRootField, Zero}; + use ark_ff::{Field, Zero}; /// A good name from OCaml #[derive(Clone, Debug)] diff --git a/ledger/src/proofs/merge.rs b/ledger/src/proofs/merge.rs index f15aa7123c..d8cc41521b 100644 --- a/ledger/src/proofs/merge.rs +++ b/ledger/src/proofs/merge.rs @@ -95,7 +95,7 @@ fn merge_main( } pub fn dlog_plonk_index(wrap_prover: &Prover) -> PlonkVerificationKeyEvals { - PlonkVerificationKeyEvals::from(&**wrap_prover.index.verifier_index.as_ref().unwrap()) + PlonkVerificationKeyEvals::from(wrap_prover.index.verifier_index.as_ref().unwrap()) } impl From<&v2::PicklesProofProofsVerified2ReprStableV2StatementProofStateDeferredValuesPlonkFeatureFlags> for crate::proofs::step::FeatureFlags:: { @@ -260,7 +260,7 @@ pub(super) fn generate_merge_proof( let dlog_plonk_index = dlog_plonk_index(wrap_prover); let dlog_plonk_index_cvar = dlog_plonk_index.to_cvar(CircuitVar::Var); - let verifier_index = &**wrap_prover.index.verifier_index.as_ref().unwrap(); + let verifier_index = wrap_prover.index.verifier_index.as_ref().unwrap(); let tx_data = make_step_transaction_data(&dlog_plonk_index_cvar); let for_step_datas = [&tx_data, &tx_data]; diff --git a/ledger/src/proofs/mod.rs b/ledger/src/proofs/mod.rs index cd2c76ac0f..a3349ac95c 100644 --- a/ledger/src/proofs/mod.rs +++ b/ledger/src/proofs/mod.rs @@ -1,5 +1,5 @@ use field::FieldWitness; -use poly_commitment::evaluation_proof::OpeningProof; +use poly_commitment::ipa::OpeningProof; pub mod accumulator_check; pub mod block; diff --git a/ledger/src/proofs/prover.rs b/ledger/src/proofs/prover.rs index d955c50549..c30314c546 100644 --- a/ledger/src/proofs/prover.rs +++ b/ledger/src/proofs/prover.rs @@ -6,7 +6,7 @@ use kimchi::{ }; use mina_curves::pasta::{Fp, Pallas}; use once_cell::sync::Lazy; -use poly_commitment::{commitment::CommitmentCurve, evaluation_proof::OpeningProof}; +use poly_commitment::{commitment::CommitmentCurve, ipa::OpeningProof}; use super::{util::extract_bulletproof, ProverProof}; use mina_curves::pasta::Fq; @@ -42,7 +42,7 @@ pub fn make_padded_proof_from_p2p( let make_poly = |poly: &(BigInt, BigInt)| -> anyhow::Result<_> { Ok(PolyComm { - elems: vec![of_coord(poly)?], + chunks: vec![of_coord(poly)?], }) }; @@ -50,13 +50,13 @@ pub fn make_padded_proof_from_p2p( crate::try_array_into_with(&proof.commitments.w_comm, make_poly)?; let z_comm: PolyComm = make_poly(&proof.commitments.z_comm)?; let t_comm: PolyComm = { - let elems = proof + let chunks = proof .commitments .t_comm .iter() .map(of_coord) .collect::>()?; - PolyComm { elems } + PolyComm { chunks } }; let bulletproof = &proof.bulletproof; @@ -131,7 +131,9 @@ pub fn make_padded_proof_from_p2p( let make_poly = |poly: &(BigInt, BigInt)| -> anyhow::Result<_> { let point = of_coord(poly)?; - Ok(PolyComm { elems: vec![point] }) + Ok(PolyComm { + chunks: vec![point], + }) }; let mut challenge_polynomial_commitments = Cow::Borrowed( diff --git a/ledger/src/proofs/public_input/messages.rs b/ledger/src/proofs/public_input/messages.rs index d52638e88b..f11058bd65 100644 --- a/ledger/src/proofs/public_input/messages.rs +++ b/ledger/src/proofs/public_input/messages.rs @@ -6,7 +6,7 @@ use crate::proofs::{ witness::Witness, VerifierIndex, }; -use ark_ec::short_weierstrass_jacobian::GroupAffine; +use ark_ec::short_weierstrass::Affine; use ark_ff::{BigInteger256, PrimeField}; use mina_curves::pasta::{Fp, Fq, Pallas}; use poly_commitment::PolyComm; @@ -15,7 +15,7 @@ use poseidon::hash::hash_fields; impl<'a> From<&'a VerifierIndex> for PlonkVerificationKeyEvals { fn from(verifier_index: &'a VerifierIndex) -> Self { - let to_curve = |v: &PolyComm| InnerCurve::of_affine(v.elems[0]); + let to_curve = |v: &PolyComm| InnerCurve::of_affine(v.chunks[0]); Self { sigma: verifier_index.sigma_comm.each_ref().map(to_curve), @@ -58,16 +58,16 @@ impl MessagesForNextWrapProof { let fields: Vec = self.to_fields(); let field: Fq = hash_fields(&fields); - let bigint: BigInteger256 = field.into_repr(); - bigint.to_64x4() + let bigint: BigInteger256 = field.into_bigint(); + bigint.0 } pub fn hash_checked(&self, w: &mut Witness) -> [u64; 4] { let fields: Vec = self.to_fields(); let field: Fq = checked_hash2(&fields, w); - let bigint: BigInteger256 = field.into_repr(); - bigint.to_64x4() + let bigint: BigInteger256 = field.into_bigint(); + bigint.0 } // TODO: De-duplicate with above @@ -75,8 +75,8 @@ impl MessagesForNextWrapProof { let fields: Vec = self.to_fields(); let field: Fq = crate::proofs::transaction::checked_hash3(&fields, w); - let bigint: BigInteger256 = field.into_repr(); - bigint.to_64x4() + let bigint: BigInteger256 = field.into_bigint(); + bigint.0 } /// Implementation of `to_field_elements` @@ -98,7 +98,7 @@ impl MessagesForNextWrapProof { fields.extend_from_slice(challenges); } - let GroupAffine { x, y, .. } = self.challenge_polynomial_commitment.to_affine(); + let Affine { x, y, .. } = self.challenge_polynomial_commitment.to_affine(); fields.extend([x, y]); assert_eq!(fields.len(), NFIELDS); @@ -152,8 +152,8 @@ where let fields: Vec = self.to_fields(); let field: Fp = hash_fields(&fields); - let bigint: BigInteger256 = field.into_repr(); - bigint.to_64x4() + let bigint: BigInteger256 = field.into_bigint(); + bigint.0 } /// Implementation of `to_field_elements` @@ -177,30 +177,30 @@ where endomul_scalar, } = &self.dlog_plonk_index; - for GroupAffine { x, y, .. } in sigma.iter().map(InnerCurve::to_affine) { + for Affine { x, y, .. } in sigma.iter().map(InnerCurve::to_affine) { fields.extend([x, y]); } - for GroupAffine { x, y, .. } in coefficients.iter().map(InnerCurve::to_affine) { + for Affine { x, y, .. } in coefficients.iter().map(InnerCurve::to_affine) { fields.extend([x, y]); } - let GroupAffine { x, y, .. } = generic.to_affine(); + let Affine { x, y, .. } = generic.to_affine(); fields.extend([x, y]); - let GroupAffine { x, y, .. } = psm.to_affine(); + let Affine { x, y, .. } = psm.to_affine(); fields.extend([x, y]); - let GroupAffine { x, y, .. } = complete_add.to_affine(); + let Affine { x, y, .. } = complete_add.to_affine(); fields.extend([x, y]); - let GroupAffine { x, y, .. } = mul.to_affine(); + let Affine { x, y, .. } = mul.to_affine(); fields.extend([x, y]); - let GroupAffine { x, y, .. } = emul.to_affine(); + let Affine { x, y, .. } = emul.to_affine(); fields.extend([x, y]); - let GroupAffine { x, y, .. } = endomul_scalar.to_affine(); + let Affine { x, y, .. } = endomul_scalar.to_affine(); fields.extend([x, y]); } @@ -210,7 +210,7 @@ where let commitments = &self.challenge_polynomial_commitments; let old_challenges = &self.old_bulletproof_challenges; for (commitments, old) in commitments.iter().zip(old_challenges) { - let GroupAffine { x, y, .. } = commitments.to_affine(); + let Affine { x, y, .. } = commitments.to_affine(); fields.extend([x, y]); fields.extend_from_slice(old); } diff --git a/ledger/src/proofs/public_input/plonk_checks.rs b/ledger/src/proofs/public_input/plonk_checks.rs index e7a961464a..36d57627b5 100644 --- a/ledger/src/proofs/public_input/plonk_checks.rs +++ b/ledger/src/proofs/public_input/plonk_checks.rs @@ -483,8 +483,12 @@ mod scalars { use kimchi::{ circuits::{ + berkeley_columns::{BerkeleyChallengeTerm, Column}, constraints::FeatureFlags, - expr::{CacheId, Column, ConstantExpr, Constants, Expr, ExprError, Op2, Variable}, + expr::{ + CacheId, ConstantExpr, ConstantExprInner, Constants, Expr, ExprError, ExprInner, + Operations, Variable, + }, gate::{CurrOrNext, GateType}, lookup::lookups::{LookupFeatures, LookupPatterns}, }, @@ -497,9 +501,9 @@ mod scalars { // This method `Variable::evaluate` is private in proof-systems :( fn var_evaluate( - v: &Variable, + v: &Variable, evals: &ProofEvaluations>, - ) -> Result { + ) -> Result> { let point_evaluations = { use kimchi::circuits::lookup::lookups::LookupPattern; use Column::*; @@ -600,34 +604,42 @@ mod scalars { pub cache: BTreeMap, pub env: &'a ScalarsEnv, pub w: &'a mut Witness, + pub alpha: F, + pub beta: F, + pub gamma: F, + pub joint_combiner: Option, } // TODO: Use cvar instead - fn is_const(e: &Expr>) -> bool { - use ConstantExpr::*; + fn is_const(e: &Expr, Column>) -> bool { match e { - Expr::Constant(c) => matches!(c, EndoCoefficient | Literal(_) | Mds { .. }), - Expr::BinOp(_, x, y) => is_const(x) && is_const(y), + Expr::Atom(ExprInner::Constant(Operations::Atom(ConstantExprInner::Constant(_)))) => { + true + } Expr::Pow(x, _) => is_const(x), _ => false, } } - pub fn eval(e: &Expr>, ctx: &mut EvalContext) -> F { - use Expr::*; + pub fn eval( + e: &Expr, Column>, + ctx: &mut EvalContext, + ) -> F { + use Operations; match e { - Double(x) => { - let v = eval(x, ctx); - v.double() + Operations::Atom(ExprInner::Cell(variable)) => { + var_evaluate(variable, ctx.evals).unwrap_or_else(|_| F::zero()) } - Constant(x) => { - let v = x.value(ctx.constants); - if let ConstantExpr::Mul(_, _) = x { - ctx.w.exists_no_check(v); - }; - v + Operations::Atom(ExprInner::VanishesOnZeroKnowledgeAndPreviousRows) => { + ctx.env.vanishes_on_zero_knowledge_and_previous_rows } - Pow(x, p) => { + Operations::Atom(ExprInner::UnnormalizedLagrangeBasis(row_offset)) => { + let unnormalized_lagrange_basis = + ctx.env.unnormalized_lagrange_basis.as_ref().unwrap(); + unnormalized_lagrange_basis(*row_offset, ctx.w) + } + Operations::Atom(ExprInner::Constant(c)) => sub_eval(c, ctx), + Operations::Pow(x, p) => { let p = *p; let v = eval(x, ctx); @@ -637,7 +649,12 @@ mod scalars { pow(v, p, ctx.w) } } - BinOp(Op2::Mul, x, y) => { + Operations::Add(x, y) => { + let y = eval(y, ctx); + let x = eval(x, ctx); + x + y + } + Operations::Mul(x, y) => { let is_x_const = is_const(x); let is_y_const = is_const(y); let y = eval(y, ctx); @@ -648,7 +665,16 @@ mod scalars { field::mul(x, y, ctx.w) } } - Square(x) => { + Operations::Sub(x, y) => { + let y = eval(y, ctx); + let x = eval(x, ctx); + x - y + } + Operations::Double(x) => { + let v = eval(x, ctx); + v.double() + } + Operations::Square(x) => { let is_x_const = is_const(x); let x = eval(x, ctx); if is_x_const { @@ -657,40 +683,98 @@ mod scalars { field::mul(x, x, ctx.w) } } - BinOp(Op2::Add, x, y) => { - let y = eval(y, ctx); - let x = eval(x, ctx); - x + y + Operations::Cache(id, _e) => ctx.cache.get(id).copied().unwrap(), + Operations::IfFeature(feature, e1, e2) => match ctx.env.feature_flags.as_ref() { + None => eval(e2, ctx), + Some(feature_flags) => { + let is_feature_enabled = match get_feature_flag(feature_flags, feature, ctx.w) { + None => return eval(e2, ctx), + Some(enabled) => enabled, + }; + + let on_false = eval(e2, ctx); + let on_true = eval(e1, ctx); + + ctx.w.exists_no_check(match is_feature_enabled { + Boolean::True => on_true, + Boolean::False => on_false, + }) + } + }, + } + } + + /// This function use to look like following + /// but `x.value` has changed to accept list of challenges + /// + /// let v = x.value(ctx.constants); + /// if let ConstantExpr::Mul(_, _) = x { + /// ctx.w.exists_no_check(v); + /// }; + /// v + pub fn sub_eval( + e: &Operations>, + ctx: &mut EvalContext, + ) -> F { + use Operations; + match e { + Operations::Atom(a) => match a { + ConstantExprInner::Challenge(term) => match term { + BerkeleyChallengeTerm::Alpha => ctx.alpha, + BerkeleyChallengeTerm::Beta => ctx.beta, + BerkeleyChallengeTerm::Gamma => ctx.gamma, + BerkeleyChallengeTerm::JointCombiner => ctx.joint_combiner.expect("Unexcepted"), + }, + ConstantExprInner::Constant(constant_term) => match constant_term { + kimchi::circuits::expr::ConstantTerm::EndoCoefficient => { + ctx.constants.endo_coefficient + } + kimchi::circuits::expr::ConstantTerm::Mds { row, col } => { + ctx.constants.mds[*row][*col] + } + kimchi::circuits::expr::ConstantTerm::Literal(literal) => *literal, + }, + }, + Operations::Pow(x, p) => { + let p = *p; + let v = sub_eval(x, ctx); + + pow(v, p, ctx.w) } - BinOp(Op2::Sub, x, y) => { - let y = eval(y, ctx); - let x = eval(x, ctx); - x - y + Operations::Add(x, y) => { + let y = sub_eval(y, ctx); + let x = sub_eval(x, ctx); + x + y } - VanishesOnZeroKnowledgeAndPreviousRows => { - ctx.env.vanishes_on_zero_knowledge_and_previous_rows + Operations::Mul(x, y) => { + let y = sub_eval(y, ctx); + let x = sub_eval(x, ctx); + field::mul(x, y, ctx.w) } - UnnormalizedLagrangeBasis(i) => { - let unnormalized_lagrange_basis = - ctx.env.unnormalized_lagrange_basis.as_ref().unwrap(); - unnormalized_lagrange_basis(*i, ctx.w) + Operations::Sub(x, y) => { + let x = sub_eval(x, ctx); + let y = sub_eval(y, ctx); + x - y } - Cell(v) => { - var_evaluate(v, ctx.evals).unwrap_or_else(|_| F::zero()) // TODO: Is that correct ? + Operations::Double(x) => { + let x = sub_eval(x, ctx); + x.double() } - Cache(id, _e) => { - ctx.cache.get(id).copied().unwrap() // Cached values were already computed + Operations::Square(x) => { + let x = sub_eval(x, ctx); + field::mul(x, x, ctx.w) } - IfFeature(feature, e1, e2) => match ctx.env.feature_flags.as_ref() { - None => eval(e2, ctx), + Operations::Cache(id, _e) => ctx.cache.get(id).copied().unwrap(), + Operations::IfFeature(feature, e1, e2) => match ctx.env.feature_flags.as_ref() { + None => sub_eval(e2, ctx), Some(feature_flags) => { let is_feature_enabled = match get_feature_flag(feature_flags, feature, ctx.w) { - None => return eval(e2, ctx), + None => return sub_eval(e2, ctx), Some(enabled) => enabled, }; - let on_false = eval(e2, ctx); - let on_true = eval(e1, ctx); + let on_false = sub_eval(e2, ctx); + let on_true = sub_eval(e1, ctx); ctx.w.exists_no_check(match is_feature_enabled { Boolean::True => on_true, @@ -704,44 +788,35 @@ mod scalars { #[derive(Default)] pub struct Cached { /// cache may contain their own caches - expr: BTreeMap>, Box>>)>, + expr: BTreeMap< + CacheId, + ( + Box>, + Box, Column>>, + ), + >, } #[inline(never)] - pub fn extract_caches(e: &Expr>, cache: &mut Cached) { - use Expr::*; + pub fn extract_caches( + e: &Expr, Column>, + cache: &mut Cached, + ) { match e { - Double(x) => { - extract_caches(x, cache); - } - Constant(_x) => (), - Pow(x, _p) => { - extract_caches(x, cache); - } - BinOp(Op2::Mul, x, y) => { - extract_caches(y, cache); - extract_caches(x, cache); - } - Square(x) => { - extract_caches(x, cache); - } - BinOp(Op2::Add, x, y) => { - extract_caches(y, cache); - extract_caches(x, cache); - } - BinOp(Op2::Sub, x, y) => { + Operations::Atom(_) => {} + Operations::Pow(x, _) => extract_caches(x, cache), + Operations::Add(x, y) | Operations::Mul(x, y) | Operations::Sub(x, y) => { extract_caches(y, cache); extract_caches(x, cache); } - VanishesOnZeroKnowledgeAndPreviousRows => todo!(), - UnnormalizedLagrangeBasis(_i) => todo!(), - Cell(_v) => (), - Cache(id, e) => { + Operations::Double(x) => extract_caches(x, cache), + Operations::Square(x) => extract_caches(x, cache), + Operations::Cache(id, e) => { let mut cached = Cached::default(); extract_caches(e, &mut cached); cache.expr.insert(*id, (Box::new(cached), e.clone())); } - IfFeature(_feature, e1, e2) => { + Operations::IfFeature(_, e1, e2) => { if false { extract_caches(e1, cache) } else { @@ -776,8 +851,9 @@ mod scalars { w: &mut Witness, ) -> F { let (constant_term, index_terms) = &*{ - type TermsMap = BTreeMap>>; - type Const = Expr>; + type TermsMap = + BTreeMap, Column>>; + type Const = Expr, Column>; type Terms = Rc<(Const, TermsMap)>; cache! { Terms::, { @@ -824,11 +900,8 @@ mod scalars { } }; + // Moved internally let constants = kimchi::circuits::expr::Constants:: { - alpha: minimal.alpha, - beta: minimal.beta, - gamma: minimal.gamma, - joint_combiner: minimal.lookup, endo_coefficient: { let (base, _) = endos::(); base @@ -843,6 +916,10 @@ mod scalars { cache: BTreeMap::new(), env, w, + alpha: minimal.alpha, + beta: minimal.beta, + gamma: minimal.gamma, + joint_combiner: minimal.lookup, }; let term = match gate { diff --git a/ledger/src/proofs/public_input/prepared_statement.rs b/ledger/src/proofs/public_input/prepared_statement.rs index 54e1b6ddda..d83143c254 100644 --- a/ledger/src/proofs/public_input/prepared_statement.rs +++ b/ledger/src/proofs/public_input/prepared_statement.rs @@ -91,7 +91,7 @@ impl PreparedStatement { let to_fq = |fp: Fp| -> Fq { let bigint: BigInteger256 = fp.into(); - bigint.try_into().unwrap() // Never fail, `Fq` is larger than `Fp` + Fq::from(bigint) // Never fail, `Fq` is larger than `Fp` }; // Fp @@ -226,7 +226,7 @@ impl PreparedStatement { let to_fq = |fp: Fp| -> Fq { let bigint: BigInteger256 = fp.into(); - bigint.try_into().unwrap() // Never fail, `Fq` is larger than `Fp` + Fq::from(bigint) // Never fail, `Fq` is larger than `Fp` }; let var = |x| Packed::Field(CircuitVar::Var(x)); diff --git a/ledger/src/proofs/public_input/scalar_challenge.rs b/ledger/src/proofs/public_input/scalar_challenge.rs index 580ef7c6d4..f72f16cc3e 100644 --- a/ledger/src/proofs/public_input/scalar_challenge.rs +++ b/ledger/src/proofs/public_input/scalar_challenge.rs @@ -2,7 +2,7 @@ use std::array::IntoIter; use ark_ff::{BigInteger256, Field}; -use crate::proofs::{field::FieldWitness, transaction::endos}; +use crate::proofs::{self, field::FieldWitness, transaction::endos}; #[derive(Clone, Debug)] pub struct ScalarChallenge { @@ -12,7 +12,7 @@ pub struct ScalarChallenge { impl From for ScalarChallenge { fn from(value: F) -> Self { let bigint: BigInteger256 = value.into(); - let bigint = bigint.to_64x4(); + let bigint = bigint.0; Self::new(bigint[0], bigint[1]) } } @@ -95,12 +95,12 @@ impl ScalarChallenge { } pub fn array_to_fields(array: &[F; N]) -> [F; N] { - let (_, endo) = endos::(); + let (_, endo) = endos::<::Scalar>(); array.each_ref().map(|v| Self::from(*v).to_field(&endo)) } pub fn limbs_to_field(limbs: &[u64; 2]) -> F { - let (_, endo) = endos::(); + let (_, endo) = endos::<::Scalar>(); Self::from(*limbs).to_field(&endo) } } diff --git a/ledger/src/proofs/public_input/scalars.rs b/ledger/src/proofs/public_input/scalars.rs index 471584c0bc..f310824b7e 100644 --- a/ledger/src/proofs/public_input/scalars.rs +++ b/ledger/src/proofs/public_input/scalars.rs @@ -1,4 +1,4 @@ -use ark_ff::{fields::arithmetic::InvalidBigInt, BigInteger256, Field, FromBytes}; +use ark_ff::{BigInteger256, Field, FromBytes}; use kimchi::proof::ProofEvaluations; use mina_curves::pasta::{Fp, Fq}; @@ -38,7 +38,7 @@ where pub fn field_from_hex(mut s: &str) -> F where - F: Field + TryFrom, + F: Field + From, { if s.starts_with("0x") { s = &s[2..]; @@ -48,8 +48,9 @@ where hex::decode_to_slice(s, &mut bytes).unwrap(); bytes.reverse(); - let bigint = BigInteger256::read(&bytes[..]).unwrap(); - bigint.try_into().unwrap() // Never fail, we hardcode them with string literals + let value = FromBytes::read(&bytes[..]).expect("Should not fail"); + let bigint = BigInteger256::new(value); + F::from(bigint) // Never fail, we hardcode them with string literals } fn field(s: &str) -> F { diff --git a/ledger/src/proofs/step.rs b/ledger/src/proofs/step.rs index 0190bd2cd1..adcb459fc8 100644 --- a/ledger/src/proofs/step.rs +++ b/ledger/src/proofs/step.rs @@ -20,12 +20,12 @@ use crate::{ use anyhow::Context; use ark_ff::{fields::arithmetic::InvalidBigInt, BigInteger256, One, Zero}; use ark_poly::{ - univariate::DensePolynomial, EvaluationDomain, Radix2EvaluationDomain, UVPolynomial, + univariate::DensePolynomial, DenseUVPolynomial, EvaluationDomain, Radix2EvaluationDomain, }; use kimchi::proof::{PointEvaluations, ProverCommitments, RecursionChallenge}; use mina_curves::pasta::{Fp, Fq, Pallas}; use mina_p2p_messages::v2; -use poly_commitment::{commitment::b_poly_coefficients, evaluation_proof::OpeningProof}; +use poly_commitment::{commitment::b_poly_coefficients, ipa::OpeningProof}; use crate::proofs::{ public_input::{ @@ -316,6 +316,7 @@ pub mod step_verifier { use super::*; use crate::proofs::{ + self, field::{field, ToBoolean}, opt_sponge::OptSponge, public_input::plonk_checks::{self, ft_eval0_checked}, @@ -337,7 +338,7 @@ pub mod step_verifier { }; use itertools::Itertools; use kimchi::circuits::wires::PERMUTS; - use poly_commitment::{srs::SRS, PolyComm}; + use poly_commitment::{ipa::SRS, PolyComm}; fn squeeze_challenge(s: &mut Sponge, w: &mut Witness) -> Fp { lowest_128_bits(s.squeeze(w), true, w) @@ -712,7 +713,7 @@ pub mod step_verifier { let to_bytes = |f: Fp| { let bigint: BigInteger256 = f.into(); - bigint.to_64x4() + bigint.0 }; let plonk_mininal = PlonkMinimal:: { @@ -1061,12 +1062,12 @@ pub mod step_verifier { let s_parts = w.exists({ // TODO: Here `s` is a `F` but needs to be read as a `F::Scalar` let bigint: BigInteger256 = s.into(); - let bigint = bigint.to_64x4(); + let bigint = bigint.0; let s_odd = bigint[0] & 1 != 0; let v = if s_odd { s - F2::one() } else { s }; // TODO: Remove this ugly hack let v: BigInteger256 = (v / F2::from(2u64)).into(); - (F::try_from(v).unwrap(), s_odd.to_boolean()) // `unwrap` never fail + (F::from(v), s_odd.to_boolean()) // `unwrap` never fail }); scale_fast2(g, s_parts, num_bits, w) @@ -1074,7 +1075,7 @@ pub mod step_verifier { // TODO: Dedup with the one in `wrap_verifier` pub(super) fn ft_comm( - plonk: &Plonk, + plonk: &Plonk<::Scalar>, t_comm: &PolyComm>, verification_key: &CircuitPlonkVerificationKeyEvals, scale: Scale, @@ -1083,7 +1084,7 @@ pub mod step_verifier { where Scale: Fn( CircuitVar>, - ::Shifting, + <::Scalar as FieldWitness>::Shifting, &mut Witness, ) -> GroupAffine, { @@ -1100,7 +1101,7 @@ pub mod step_verifier { .unwrap(); let chunked_t_comm = t_comm - .elems + .chunks .iter() .rev() .copied() @@ -1127,15 +1128,15 @@ pub mod step_verifier { fn public_input_commitment_dynamic( which: &[Boolean], - srs: &mut poly_commitment::srs::SRS, + srs: &mut poly_commitment::ipa::SRS, domains: Vec, public_input: Vec, w: &mut Witness, ) -> GroupAffine { let lagrange_commitment = - |d: &Domains, i: usize, srs: &mut poly_commitment::srs::SRS| { + |d: &Domains, i: usize, srs: &mut poly_commitment::ipa::SRS| { let d = 2u64.pow(d.h.log2_size() as u32); - let elems = wrap_verifier::lagrange_commitment::(srs, d, i).elems; + let elems = wrap_verifier::lagrange_commitment::(srs, d, i).chunks; assert_eq!(elems.len(), 1); InnerCurve::::of_affine(elems[0]) }; @@ -1143,11 +1144,11 @@ pub mod step_verifier { fn select_curve_points( domains: &[Domains], which: &[Boolean], - srs: &mut poly_commitment::srs::SRS, + srs: &mut poly_commitment::ipa::SRS, w: &mut Witness, points_for_domain: impl Fn( &Domains, - &mut poly_commitment::srs::SRS, + &mut poly_commitment::ipa::SRS, ) -> Vec>, ) -> Vec> { let (d, ds) = domains.split_first().unwrap(); @@ -1166,7 +1167,7 @@ pub mod step_verifier { } let lagrange = - |i: usize, srs: &mut poly_commitment::srs::SRS, w: &mut Witness| { + |i: usize, srs: &mut poly_commitment::ipa::SRS, w: &mut Witness| { let vec = select_curve_points(&domains, which, srs, w, |d, srs| { vec![lagrange_commitment(d, i, srs)] }); @@ -1177,7 +1178,7 @@ pub mod step_verifier { let lagrange_with_correction = |input_length: usize, i: usize, - srs: &mut poly_commitment::srs::SRS, + srs: &mut poly_commitment::ipa::SRS, w: &mut Witness| -> Vec> { let actual_shift = OPS_BITS_PER_CHUNK * chunks_needed(input_length); @@ -1339,7 +1340,7 @@ pub mod step_verifier { i: usize, ) -> InnerCurve { let d = domain.size(); - let elems = wrap_verifier::lagrange_commitment::(srs, d, i).elems; + let elems = wrap_verifier::lagrange_commitment::(srs, d, i).chunks; assert_eq!(elems.len(), 1); InnerCurve::of_affine(elems[0]) @@ -1532,7 +1533,7 @@ pub mod step_verifier { struct IncrementallyVerifyProofParams<'a> { pub proofs_verified: usize, - pub srs: &'a mut poly_commitment::srs::SRS, + pub srs: &'a mut poly_commitment::ipa::SRS, pub wrap_domain: &'a ForStepKind>, pub sponge: Sponge, pub sponge_after_index: Sponge, @@ -1612,7 +1613,7 @@ pub mod step_verifier { absorb_curve(&x_hat, &mut sponge, w); let w_comm = &messages.w_comm; - for g in w_comm.iter().flat_map(|w| &w.elems) { + for g in w_comm.iter().flat_map(|w| &w.chunks) { absorb_curve(g, &mut sponge, w); } @@ -1620,14 +1621,14 @@ pub mod step_verifier { let _gamma = sample(&mut sponge, w); let z_comm = &messages.z_comm; - for z in z_comm.elems.iter() { + for z in z_comm.chunks.iter() { absorb_curve(z, &mut sponge, w); } let _alpha = sample_scalar(&mut sponge, w); let t_comm = &messages.t_comm; - for t in t_comm.elems.iter() { + for t in t_comm.chunks.iter() { absorb_curve(t, &mut sponge, w); } @@ -1651,7 +1652,7 @@ pub mod step_verifier { let sg_old = sg_old.iter().copied().map(cvar); let rest = [cvar(x_hat), cvar(ft_comm)] .into_iter() - .chain(z_comm.elems.iter().cloned().map(cvar)) + .chain(z_comm.chunks.iter().cloned().map(cvar)) .chain([ wrap_verification_key.generic, wrap_verification_key.psm, @@ -1663,7 +1664,7 @@ pub mod step_verifier { .chain( w_comm .iter() - .flat_map(|w| w.elems.iter().cloned().map(cvar)), + .flat_map(|w| w.chunks.iter().cloned().map(cvar)), ) .chain(wrap_verification_key.coefficients) .chain(sigma_comm_init.iter().cloned()); @@ -1690,7 +1691,7 @@ pub mod step_verifier { } pub(super) struct VerifyParams<'a> { - pub(super) srs: &'a mut poly_commitment::srs::SRS, + pub(super) srs: &'a mut poly_commitment::ipa::SRS, pub(super) feature_flags: &'a FeatureFlags, pub(super) lookup_parameters: (), pub(super) proofs_verified: usize, @@ -1787,7 +1788,7 @@ pub mod step_verifier { } struct VerifyOneParams<'a> { - srs: &'a mut poly_commitment::srs::SRS, + srs: &'a mut poly_commitment::ipa::SRS, proof: &'a PerProofWitness, data: &'a ForStep, messages_for_next_wrap_proof: Fp, @@ -1909,7 +1910,7 @@ fn verify_one(params: VerifyOneParams, w: &mut Witness) -> anyhow::Result<(V fn to_bytes(f: Fp) -> [u64; 4] { let bigint: BigInteger256 = f.into(); - bigint.to_64x4() + bigint.0 } fn to_4limbs(v: [u64; 2]) -> [u64; 4] { @@ -2100,7 +2101,7 @@ fn wrap_compute_sg(challenges: &[[u64; 2]]) -> GroupAffine { let srs = get_srs::(); srs.commit_non_hiding(&p, 1) }; - comm.elems[0] + comm.chunks[0] } struct ExpandProofParams<'a> { @@ -2302,7 +2303,7 @@ fn expand_proof(params: ExpandProofParams) -> anyhow::Result { let to_bytes = |f: Fq| { let bigint: BigInteger256 = f.into(); - let [a, b, c, d] = bigint.to_64x4(); + let [a, b, c, d] = bigint.0; assert_eq!([c, d], [0, 0]); [a, b] }; @@ -2405,7 +2406,7 @@ fn expand_proof(params: ExpandProofParams) -> anyhow::Result { let to_bytes = |f: Fq| { let bigint: BigInteger256 = f.into(); - bigint.to_64x4() + bigint.0 }; PlonkMinimal { @@ -2478,7 +2479,7 @@ fn expand_proof(params: ExpandProofParams) -> anyhow::Result { should_finalize: must_verify.value().as_bool(), sponge_digest_before_evaluations: { let bigint: BigInteger256 = sponge_digest_before_evaluations.into(); - bigint.to_64x4() + bigint.0 }, }; @@ -2578,10 +2579,10 @@ impl Check for PerProofWitness { } = wrap_proof; for poly in w_comm { - poly.elems.check(w); + poly.chunks.check(w); } - z_comm.elems.check(w); - t_comm.elems.check(w); + z_comm.chunks.check(w); + t_comm.chunks.check(w); lr.check(w); let shift = |f: Fq| ::Shifting::of_field(f); @@ -2622,7 +2623,7 @@ impl Check for PerProofWitness { perm.check(w); combined_inner_product.check(w); b.check(w); - two_u64_to_field::(xi).check(w); + two_u64_to_field::(xi).check(w); bulletproof_challenges.check(w); { @@ -2674,7 +2675,7 @@ pub fn extract_recursion_challenges( .zip(comms) .map(|(chals, (x, y))| { let comm = PolyComm:: { - elems: vec![make_group(x, y)], + chunks: vec![make_group(x, y)], }; RecursionChallenge { chals: chals.to_vec(), @@ -2763,7 +2764,7 @@ pub fn step( w.exists(expanded_proofs.each_ref().map(|p| &p.unfinalized)); let messages_for_next_wrap_proof: [Fp; N_PREVIOUS] = { - let f = four_u64_to_field::; + let f = four_u64_to_field::; crate::try_array_into_with(&expanded_proofs, |p| { f(&p.prev_statement_with_hashes diff --git a/ledger/src/proofs/to_field_elements.rs b/ledger/src/proofs/to_field_elements.rs index 7741053975..51261e2689 100644 --- a/ledger/src/proofs/to_field_elements.rs +++ b/ledger/src/proofs/to_field_elements.rs @@ -9,7 +9,7 @@ use kimchi::proof::{PointEvaluations, ProofEvaluations, ProverCommitments, Prove use mina_curves::pasta::{Fp, Fq}; use mina_p2p_messages::{string::ByteString, v2}; use mina_signer::CompressedPubKey; -use poly_commitment::evaluation_proof::OpeningProof; +use poly_commitment::ipa::OpeningProof; use crate::{ proofs::{ @@ -894,11 +894,11 @@ impl ToFieldElements for PerProofWitness { } = wrap_proof; for w in w_comm { - push_affines(&w.elems, fields); + push_affines(&w.chunks, fields); } - push_affines(&z_comm.elems, fields); - push_affines(&t_comm.elems, fields); + push_affines(&z_comm.chunks, fields); + push_affines(&t_comm.chunks, fields); for (a, b) in lr { push_affine(*a, fields); @@ -937,10 +937,10 @@ impl ToFieldElements for PerProofWitness { messages_for_next_wrap_proof: _, } = proof_state; - two_u64_to_field::(alpha).to_field_elements(fields); - two_u64_to_field::(beta).to_field_elements(fields); - two_u64_to_field::(gamma).to_field_elements(fields); - two_u64_to_field::(zeta).to_field_elements(fields); + two_u64_to_field::(alpha).to_field_elements(fields); + two_u64_to_field::(beta).to_field_elements(fields); + two_u64_to_field::(gamma).to_field_elements(fields); + two_u64_to_field::(zeta).to_field_elements(fields); zeta_to_srs_length.to_field_elements(fields); zeta_to_domain_size.to_field_elements(fields); @@ -966,7 +966,7 @@ impl ToFieldElements for PerProofWitness { combined_inner_product.to_field_elements(fields); b.to_field_elements(fields); - two_u64_to_field::(xi).to_field_elements(fields); + two_u64_to_field::(xi).to_field_elements(fields); bulletproof_challenges.to_field_elements(fields); // Index @@ -987,7 +987,7 @@ impl ToFieldElements for PerProofWitness { Fp::from(domain_log2).to_field_elements(fields); } - four_u64_to_field::(sponge_digest_before_evaluations) + four_u64_to_field::(sponge_digest_before_evaluations) .unwrap() // Never fail, `sponge_digest_before_evaluations` was previously a `Fp` .to_field_elements(fields); diff --git a/ledger/src/proofs/transaction.rs b/ledger/src/proofs/transaction.rs index a3bb3912fa..24ad26cb50 100644 --- a/ledger/src/proofs/transaction.rs +++ b/ledger/src/proofs/transaction.rs @@ -1,10 +1,11 @@ use std::{collections::HashMap, rc::Rc, str::FromStr, sync::Arc}; use anyhow::Context; -use ark_ec::{short_weierstrass_jacobian::GroupProjective, AffineCurve, ProjectiveCurve}; -use ark_ff::{fields::arithmetic::InvalidBigInt, BigInteger256, Field, PrimeField}; +use ark_ec::{short_weierstrass::Projective, AffineRepr, CurveGroup, PrimeGroup}; +use ark_ff::{fields::arithmetic::InvalidBigInt, AdditiveGroup, BigInteger256, Field, PrimeField}; use kimchi::{ circuits::{gate::CircuitGate, wires::COLUMNS}, + groupmap::GroupMap, proof::RecursionChallenge, }; use mina_curves::pasta::{Fp, Fq}; @@ -27,6 +28,7 @@ use mina_signer::{CompressedPubKey, PubKey}; use crate::{ decompress_pk, gen_keypair, proofs::{ + self, constants::{StepTransactionProof, WrapTransactionProof}, unfinalized::AllEvals, util::sha256_sum, @@ -83,7 +85,7 @@ impl Iterator for FieldBitsIterator { pub fn bigint_to_bits(bigint: BigInteger256) -> [bool; NBITS] { let mut bits = FieldBitsIterator { index: 0, - bigint: bigint.to_64x4(), + bigint: bigint.0, } .take(NBITS); std::array::from_fn(|_| bits.next().unwrap()) @@ -101,7 +103,7 @@ where fn bigint_to_bits2(bigint: BigInteger256, nbits: usize) -> Box<[bool]> { FieldBitsIterator { index: 0, - bigint: bigint.to_64x4(), + bigint: bigint.0, } .take(nbits) .collect() @@ -125,24 +127,33 @@ where bits } -pub fn endos() -> (F, F::Scalar) +pub fn endos() -> (F, ::Scalar) where F: FieldWitness, { - use poly_commitment::srs::endos; + use poly_commitment::ipa::endos; // Let's keep them in cache since they're used everywhere - cache!((F, F::Scalar), endos::>()) + cache!( + (F, ::Scalar), + endos::>() + ) } pub fn make_group(x: F, y: F) -> GroupAffine where F: FieldWitness, { - GroupAffine::::new(x, y, false) + if x == F::ZERO && y == F::ZERO { + GroupAffine::::zero() + } else { + GroupAffine::::new(x, y) + } } pub mod scalar_challenge { + use crate::proofs; + use super::*; // TODO: `scalar` might be a `F::Scalar` here @@ -319,7 +330,8 @@ pub mod scalar_challenge { let res = w.exists({ let chal = ScalarChallenge::from(chal).to_field(&e); - InnerCurve::::of_affine(t).scale(::one() / chal) + InnerCurve::::of_affine(t) + .scale(<::Scalar>::one() / chal) }); let _ = endo::(res.to_affine(), chal, w); res.to_affine() @@ -1239,7 +1251,7 @@ impl From<(F, F)> for InnerCurve { impl InnerCurve { pub fn one() -> Self { - let inner = F::Projective::prime_subgroup_generator(); + let inner = F::Projective::generator(); Self { inner } } @@ -1254,10 +1266,8 @@ impl InnerCurve { S: Into, { let scale: BigInteger256 = scale.into(); - let scale = scale.to_64x4(); - Self { - inner: self.inner.mul(scale), - } + let inner = self.inner.mul_bigint(scale); + Self { inner } } fn add_fast(&self, other: Self, w: &mut Witness) -> Self { @@ -1277,7 +1287,7 @@ impl InnerCurve { pub fn of_affine(affine: GroupAffine) -> Self { // Both `inner` below are the same type, but we use `into()` to make it generic - let inner: GroupProjective = affine.into_projective(); + let inner: Projective = affine.into_group(); let inner: F::Projective = inner.into(); Self { inner } } @@ -1287,7 +1297,7 @@ impl InnerCurve { let mut rng = get_rng(); // Both `proj` below are the same type, but we use `into()` to make it generic - let proj: GroupProjective = ark_ff::UniformRand::rand(&mut rng); + let proj: Projective = ark_ff::UniformRand::rand(&mut rng); let proj: F::Projective = proj.into(); let proj2 = proj; @@ -1300,6 +1310,7 @@ impl InnerCurve { } } +use poly_commitment::SRS; use std::cell::RefCell; thread_local! { @@ -3680,7 +3691,7 @@ pub fn messages_for_next_wrap_proof_padding() -> Fp { old_bulletproof_challenges: vec![], // Filled with padding, in `hash()` below }; let hash: [u64; 4] = msg.hash(); - Fp::try_from(BigInteger256::from_64x4(hash)).unwrap() // Never fail + Fp::from(BigInteger256::new(hash)) // Never fail }) } @@ -3746,8 +3757,8 @@ impl MessagesForNextStepProof<'_> { let fields: Vec = self.to_fields(); let field: Fp = ::poseidon::hash::hash_fields(&fields); - let bigint: BigInteger256 = field.into_repr(); - bigint.to_64x4() + let bigint: BigInteger256 = field.into_bigint(); + bigint.0 } /// Implementation of `to_field_elements` @@ -3889,15 +3900,15 @@ pub fn make_prover_index( let (endo_q, _endo_r) = endos::(); // TODO: `proof-systems` needs to change how the SRS is used - let srs: poly_commitment::srs::SRS = { + let srs: poly_commitment::ipa::SRS = { let srs = get_srs_mut::(); - let mut srs = srs.lock().unwrap(); - srs.add_lagrange_basis(cs.domain.d1); - srs.clone() + let srs = srs.lock().unwrap().clone(); + srs.get_lagrange_basis(cs.domain.d1); + srs }; - let mut index = ProverIndex::::create(cs, endo_q, Arc::new(srs)); - index.verifier_index = verifier_index; + let mut index = ProverIndex::::create(cs, endo_q, Arc::new(srs), false); + index.verifier_index = verifier_index.map(|i| i.as_ref().clone()); // Compute and cache the verifier index digest index.compute_verifier_index_digest::(); @@ -3981,11 +3992,13 @@ pub(super) fn create_proof( } // NOTE: Not random in `cfg(test)` + // let mut rng = get_rng(); let mut rng = get_rng(); let now = redux::Instant::now(); - let group_map = kimchi::groupmap::GroupMap::::setup(); - let proof = kimchi::proof::ProverProof::create_recursive::>( + let group_map = + kimchi::groupmap::GroupMap::<::Scalar>::setup(); + let proof = kimchi::proof::ProverProof::create_recursive::, _>( &group_map, computed_witness, &[], @@ -3995,8 +4008,6 @@ pub(super) fn create_proof( &mut rng, ) .map_err(|e| { - use kimchi::groupmap::GroupMap; - let prev_challenges_hash = debug::hash_prev_challenge::(&prev_challenges); let witness_primary_hash = debug::hash_slice(&w.primary); let witness_aux_hash = debug::hash_slice(w.aux()); @@ -4040,14 +4051,18 @@ pub mod debug { use sha2::Digest; fn hash_field(state: &mut sha2::Sha256, f: &F) { - for limb in f.montgomery_form_ref() { + let ark_ff::BigInt(int): BigInteger256 = (*f).into(); + for limb in int { state.update(limb.to_le_bytes()); } } fn hash_field_slice(state: &mut sha2::Sha256, slice: &[F]) { state.update(slice.len().to_le_bytes()); - for f in slice.iter().flat_map(|f| f.montgomery_form_ref()) { + for f in slice.iter().flat_map(|f| { + let ark_ff::BigInt(int): BigInteger256 = (*f).into(); + int + }) { state.update(f.to_le_bytes()); } } @@ -4066,8 +4081,8 @@ pub mod debug { let mut hasher = sha2::Sha256::new(); for RecursionChallenge { chals, comm } in prevs { hash_field_slice(&mut hasher, chals); - let poly_commitment::PolyComm { elems } = comm; - for elem in elems { + let poly_commitment::PolyComm { chunks } = comm; + for elem in chunks { match elem.to_coordinates() { None => { hasher.update([0]); @@ -4235,7 +4250,7 @@ pub(super) fn generate_tx_proof( let statement_with_sok = statement.with_digest(sok_digest); let dlog_plonk_index = - PlonkVerificationKeyEvals::from(&**tx_wrap_prover.index.verifier_index.as_ref().unwrap()); + PlonkVerificationKeyEvals::from(tx_wrap_prover.index.verifier_index.as_ref().unwrap()); let statement_with_sok = Rc::new(w.exists(statement_with_sok)); transaction_snark::main(&statement_with_sok, tx_witness, w)?; diff --git a/ledger/src/proofs/unfinalized.rs b/ledger/src/proofs/unfinalized.rs index ae6a137770..9334bc7aff 100644 --- a/ledger/src/proofs/unfinalized.rs +++ b/ledger/src/proofs/unfinalized.rs @@ -426,7 +426,7 @@ impl ToFieldElements for Unfinalized { fields.extend( bulletproof_challenges .iter() - .map(|c| two_u64_to_field::(c)), + .map(|c| two_u64_to_field::(c)), ); // Bool diff --git a/ledger/src/proofs/urs_utils.rs b/ledger/src/proofs/urs_utils.rs index 69af137473..2967b2ebeb 100644 --- a/ledger/src/proofs/urs_utils.rs +++ b/ledger/src/proofs/urs_utils.rs @@ -1,18 +1,17 @@ /// Copy-pasted from https://github.com/MinaProtocol/mina/blob/cf2a732ae39f4e784707e1fc32832da805bb7d09/src/lib/crypto/kimchi_bindings/stubs/src/urs_utils.rs -use ark_ec::{msm::VariableBaseMSM, ProjectiveCurve}; -use ark_ff::{batch_inversion, One, PrimeField, UniformRand, Zero}; +use ark_ec::{AffineRepr, CurveGroup, VariableBaseMSM}; +use ark_ff::{batch_inversion, One, UniformRand, Zero}; use poly_commitment::{ commitment::{b_poly_coefficients, CommitmentCurve}, - srs::SRS, + ipa::SRS, }; use rayon::prelude::*; // TODO: Not compatible with variable rounds -pub fn batch_dlog_accumulator_check( - urs: &SRS, - comms: &[G], - chals: &[G::ScalarField], -) -> bool { +pub fn batch_dlog_accumulator_check(urs: &SRS, comms: &[G], chals: &[G::ScalarField]) -> bool +where + G: CommitmentCurve + AffineRepr, +{ let k = comms.len(); if k == 0 { @@ -65,8 +64,7 @@ pub fn batch_dlog_accumulator_check( } } - let scalars: Vec<_> = scalars.iter().map(|x| x.into_repr()).collect(); - VariableBaseMSM::multi_scalar_mul(&points, &scalars) == G::Projective::zero() + ::msm(&points, &scalars).unwrap() == G::Group::zero() } #[allow(unused)] @@ -90,12 +88,11 @@ pub fn batch_dlog_accumulator_generate( .chunks(rounds) .map(|chals| { let chals: Vec = chals.into_iter().copied().collect(); - let scalars: Vec<_> = b_poly_coefficients(&chals) - .into_iter() - .map(|x| x.into_repr()) - .collect(); + let scalars: Vec<_> = b_poly_coefficients(&chals); let points: Vec<_> = urs.g.clone(); - VariableBaseMSM::multi_scalar_mul(&points, &scalars).into_affine() + ::msm(&points, &scalars) + .unwrap() // Not sure have safe this unwrap is but function is unused + .into_affine() }) .collect(); diff --git a/ledger/src/proofs/util.rs b/ledger/src/proofs/util.rs index 83d096c475..060fe4fa24 100644 --- a/ledger/src/proofs/util.rs +++ b/ledger/src/proofs/util.rs @@ -1,3 +1,5 @@ +use std::fmt::Debug; + use ark_ff::{fields::arithmetic::InvalidBigInt, BigInteger256, Field}; use kimchi::proof::{PointEvaluations, ProofEvaluations}; use mina_p2p_messages::{ @@ -55,25 +57,26 @@ pub fn extract_bulletproof< .collect() } -pub fn four_u64_to_field(v: &[u64; 4]) -> Result +pub fn four_u64_to_field(v: &[u64; 4]) -> Result where - F: Field + TryFrom, + F: Field + TryFrom, { let mut bigint: [u64; 4] = [0; 4]; bigint[..4].copy_from_slice(v); - let bigint = BigInteger256::from_64x4(bigint); - F::try_from(bigint) + let bigint = BigInteger256::new(bigint); + F::try_from(bigint).map_err(|_| InvalidBigInt) } -pub fn two_u64_to_field(v: &[u64; 2]) -> F +pub fn two_u64_to_field(v: &[u64; 2]) -> F where - F: Field + TryFrom, + F: Field + TryFrom, + E: Debug, { let mut bigint: [u64; 4] = [0; 4]; bigint[..2].copy_from_slice(v); - let bigint = BigInteger256::from_64x4(bigint); + let bigint = BigInteger256::new(bigint); F::try_from(bigint).unwrap() // Never fail with 2 limbs } diff --git a/ledger/src/proofs/verification.rs b/ledger/src/proofs/verification.rs index 07a2a8897c..277cf0f8cf 100644 --- a/ledger/src/proofs/verification.rs +++ b/ledger/src/proofs/verification.rs @@ -4,7 +4,7 @@ use ark_ff::fields::arithmetic::InvalidBigInt; use ark_poly::{EvaluationDomain, Radix2EvaluationDomain}; use ark_serialize::Write; use itertools::Itertools; -use poly_commitment::srs::SRS; +use poly_commitment::ipa::SRS; use crate::{ proofs::{ @@ -502,7 +502,7 @@ fn verify_with( ) -> Result<(), VerifyError> { use kimchi::{groupmap::GroupMap, mina_curves::pasta::PallasParameters}; use mina_poseidon::sponge::{DefaultFqSponge, DefaultFrSponge}; - use poly_commitment::evaluation_proof::OpeningProof; + use poly_commitment::ipa::OpeningProof; type SpongeParams = mina_poseidon::constants::PlonkSpongeConstantsKimchi; type EFqSponge = DefaultFqSponge; @@ -527,7 +527,7 @@ pub struct VerificationContext<'a> { fn batch_verify(proofs: &[VerificationContext]) -> Result<(), VerifyError> { use kimchi::{groupmap::GroupMap, mina_curves::pasta::PallasParameters, verifier::Context}; use mina_poseidon::sponge::{DefaultFqSponge, DefaultFrSponge}; - use poly_commitment::evaluation_proof::OpeningProof; + use poly_commitment::ipa::OpeningProof; type SpongeParams = mina_poseidon::constants::PlonkSpongeConstantsKimchi; type EFqSponge = DefaultFqSponge; diff --git a/ledger/src/proofs/verifiers.rs b/ledger/src/proofs/verifiers.rs index c14098e18f..bdf2ef785c 100644 --- a/ledger/src/proofs/verifiers.rs +++ b/ledger/src/proofs/verifiers.rs @@ -22,7 +22,7 @@ use kimchi::{ mina_curves::pasta::Pallas, }; use mina_curves::pasta::{Fp, Fq}; -use poly_commitment::srs::SRS; +use poly_commitment::{ipa::SRS, SRS as _}; use crate::{proofs::BACKEND_TOCK_ROUNDS_N, VerificationKey}; @@ -337,8 +337,8 @@ fn make_verifier_index(index: VerifierIndex) -> VerifierIndex { // let srs = { - let mut srs = SRS::create(max_poly_size); - srs.add_lagrange_basis(domain); + let srs = SRS::create(max_poly_size); + srs.get_lagrange_basis(domain); Arc::new(srs) }; @@ -396,13 +396,13 @@ pub fn make_zkapp_verifier_index(vk: &VerificationKey) -> VerifierIndex { let srs = { let degree = 1 << BACKEND_TOCK_ROUNDS_N; - let mut srs = SRS::::create(degree); - srs.add_lagrange_basis(domain); + let srs = SRS::::create(degree); + srs.get_lagrange_basis(domain); srs }; let make_poly = |poly: &InnerCurve| poly_commitment::PolyComm { - elems: vec![poly.to_affine()], + chunks: vec![poly.to_affine()], }; let feature_flags = FeatureFlags { diff --git a/ledger/src/proofs/wrap.rs b/ledger/src/proofs/wrap.rs index 90e6a2eab3..6d4c04d00c 100644 --- a/ledger/src/proofs/wrap.rs +++ b/ledger/src/proofs/wrap.rs @@ -1,7 +1,7 @@ use std::{borrow::Cow, ops::Neg, rc::Rc}; use ark_ff::{fields::arithmetic::InvalidBigInt, BigInteger256, One, Zero}; -use ark_poly::{univariate::DensePolynomial, EvaluationDomain, UVPolynomial}; +use ark_poly::{univariate::DensePolynomial, DenseUVPolynomial, EvaluationDomain}; use kimchi::{ circuits::{expr::RowOffset, scalars::RandomOracles, wires::COLUMNS}, oracles::OraclesResult, @@ -13,10 +13,11 @@ use mina_p2p_messages::v2::{ PicklesBaseProofsVerifiedStableV1, }; use mina_poseidon::{sponge::ScalarChallenge, FqSponge}; -use poly_commitment::{commitment::b_poly_coefficients, PolyComm}; +use poly_commitment::{commitment::b_poly_coefficients, ipa::OpeningProof, PolyComm, SRS}; use crate::{ proofs::{ + self, field::{field, Boolean, CircuitVar, FieldWitness, ToBoolean}, opt_sponge::OptSponge, public_input::{ @@ -199,9 +200,9 @@ pub fn create_oracle_with_public_input( use poly_commitment::commitment::shift_scalar; // TODO: Don't clone the SRS here - let mut srs = (*verifier_index.srs).clone(); + let srs = (*verifier_index.srs).clone(); let log_size_of_group = verifier_index.domain.log_size_of_group; - let lgr_comm = make_lagrange::(&mut srs, log_size_of_group); + let lgr_comm = make_lagrange::(&srs, log_size_of_group); let lgr_comm: Vec> = lgr_comm.into_iter().take(public_input.len()).collect(); @@ -258,17 +259,16 @@ pub fn create_oracle_with_public_input( } fn make_lagrange( - srs: &mut poly_commitment::srs::SRS, + srs: &poly_commitment::ipa::SRS, domain_log2: u32, ) -> Vec> { let domain_size = 2u64.pow(domain_log2) as usize; let x_domain = EvaluationDomain::::new(domain_size).expect("invalid argument"); - srs.add_lagrange_basis(x_domain); - - let lagrange_bases = &srs.lagrange_bases[&x_domain.size()]; - lagrange_bases[..domain_size].to_vec() + let lagrange_bases = srs.get_lagrange_basis(x_domain)[..domain_size].to_vec(); + // lagrange_bases[..domain_size].to_vec() + lagrange_bases.clone() } /// Defined in `plonk_checks.ml` @@ -338,7 +338,7 @@ fn deferred_values(params: DeferredValuesParams) -> DeferredValuesAndHints { let to_bytes = |f: Fp| { let bigint: BigInteger256 = f.into(); - let [a, b, c, d] = bigint.to_64x4(); + let [a, b, c, d] = bigint.0; assert_eq!([c, d], [0, 0]); [a, b] }; @@ -498,21 +498,21 @@ fn make_public_input( unfinalized_proofs.to_field_elements(&mut fields); } - let to_fp = |v: [u64; 4]| Fp::try_from(BigInteger256::from_64x4(v)).unwrap(); // Never fail, `messages_for_next_step_proof_hash` was a `Fp` + let to_fp = |v: [u64; 4]| Fp::from(BigInteger256::new(v)); // Never fail, `messages_for_next_step_proof_hash` was a `Fp` to_fp(messages_for_next_step_proof_hash).to_field_elements(&mut fields); // `messages_for_next_wrap_proof_hash` were `Fq` previously, so we have to // build a `Fp` from them with care: they can overflow let to_fp = |v: [u64; 4]| { - match Fp::try_from(BigInteger256::from_64x4(v)) { - Ok(fp) => fp, // fast-path: we get the `Fp` without modulo/reducing - Err(_) => { - // slow path: we build the `Fp` bit by bit, so it will reduce it - let bits = - crate::proofs::transaction::bigint_to_bits::<255>(BigInteger256::from_64x4(v)); - super::util::field_of_bits(&bits) - } - } + // match Fp::try_from(BigInteger256::new(v)) { + // Ok(fp) => fp, // fast-path: we get the `Fp` without modulo/reducing + // Err(_) => { + // // slow path: we build the `Fp` bit by bit, so it will reduce it + // let bits = crate::proofs::transaction::bigint_to_bits::<255>(BigInteger256::new(v)); + // super::util::field_of_bits(&bits) + // } + // } + Fp::from(BigInteger256::new(v)) }; for msg in messages_for_next_wrap_proof_hash.iter().copied().map(to_fp) { msg.to_field_elements(&mut fields); @@ -542,7 +542,9 @@ fn exists_prev_statement( for unfinalized in &step_statement.proof_state.unfinalized_proofs { w.exists_no_check(unfinalized); } - w.exists(four_u64_to_field::(&messages_for_next_step_proof_hash)?); + w.exists(four_u64_to_field::( + &messages_for_next_step_proof_hash, + )?); Ok(()) } @@ -569,7 +571,7 @@ pub fn dummy_ipa_wrap_sg() -> GroupAffine { let srs = get_srs::(); srs.commit_non_hiding(&p, 1) }; - comm.elems[0] + comm.chunks[0] }) } @@ -683,7 +685,7 @@ pub fn wrap( prover_index: step_prover_index, }); - let to_fq = |[a, b]: [u64; 2]| Fq::try_from(BigInteger256::from_64x4([a, b, 0, 0])).unwrap(); // Never fail with 2 limbs + let to_fq = |[a, b]: [u64; 2]| Fq::from(BigInteger256::new([a, b, 0, 0])); // Never fail with 2 limbs let to_fqs = |v: &[[u64; 2]]| v.iter().copied().map(to_fq).collect::>(); let messages_for_next_wrap_proof = MessagesForNextWrapProof { @@ -761,7 +763,7 @@ pub fn wrap( .proof_state .sponge_digest_before_evaluations .into(); - bigint.to_64x4() + bigint.0 }, messages_for_next_wrap_proof: messages_for_next_wrap_proof_prepared.hash(), }, @@ -792,7 +794,7 @@ pub fn wrap( .iter() .map(|m| RecursionChallenge { comm: poly_commitment::PolyComm:: { - elems: vec![m.commitment.to_affine()], + chunks: vec![m.commitment.to_affine()], }, chals: m.challenges.to_vec(), }) @@ -833,15 +835,15 @@ impl Check for ShiftedValue { fn check(&self, w: &mut Witness) { // TODO: Compute those values instead of hardcoded const FORBIDDEN_SHIFTED_VALUES: &[Fq; 2] = &[ - ark_ff::field_new!(Fq, "91120631062839412180561524743370440705"), - ark_ff::field_new!(Fq, "91120631062839412180561524743370440706"), + ark_ff::MontFp!("91120631062839412180561524743370440705"), + ark_ff::MontFp!("91120631062839412180561524743370440706"), ]; let bools = FORBIDDEN_SHIFTED_VALUES.map(|forbidden| { let shifted: Fq = { let ShiftedValue { shifted } = self.clone(); let f: BigInteger256 = shifted.into(); - f.try_into().unwrap() // Never fail, `Fq` is larger than `Fp` + f.into() // Never fail, `Fq` is larger than `Fp` }; field::equal(shifted, forbidden, w) }); @@ -854,10 +856,10 @@ impl Check for ShiftedValue { // TODO: Compute those values instead of hardcoded #[rustfmt::skip] const FORBIDDEN_SHIFTED_VALUES: &[(Fp, Boolean); 4] = &[ - (ark_ff::field_new!(Fp, "45560315531506369815346746415080538112"), Boolean::False), - (ark_ff::field_new!(Fp, "45560315531506369815346746415080538113"), Boolean::False), - (ark_ff::field_new!(Fp, "14474011154664524427946373126085988481727088556502330059655218120611762012161"), Boolean::True), - (ark_ff::field_new!(Fp, "14474011154664524427946373126085988481727088556502330059655218120611762012161"), Boolean::True), + (ark_ff::MontFp!("45560315531506369815346746415080538112"), Boolean::False), + (ark_ff::MontFp!("45560315531506369815346746415080538113"), Boolean::False), + (ark_ff::MontFp!("14474011154664524427946373126085988481727088556502330059655218120611762012161"), Boolean::True), + (ark_ff::MontFp!("14474011154664524427946373126085988481727088556502330059655218120611762012161"), Boolean::True), ]; fn of_bits(bs: &[bool; 254]) -> F { @@ -1356,7 +1358,7 @@ pub const PERMUTS_MINUS_1_ADD_N1: usize = 6; const OTHER_FIELD_PACKED_CONSTANT_SIZE_IN_BITS: usize = 255; fn ft_comm( - plonk: &Plonk, + plonk: &Plonk<::Scalar>, t_comm: &PolyComm>, verification_key: &PlonkVerificationKeyEvals, scale: Scale, @@ -1365,7 +1367,7 @@ fn ft_comm( where Scale: Fn( GroupAffine, - ::Shifting, + <::Scalar as FieldWitness>::Shifting, &mut Witness, ) -> GroupAffine, { @@ -1382,7 +1384,7 @@ where .unwrap(); let chunked_t_comm = t_comm - .elems + .chunks .iter() .rev() .copied() @@ -1449,10 +1451,12 @@ pub mod pcs_batch { pub mod wrap_verifier { use std::sync::Arc; + use ark_ec::short_weierstrass::{Affine, Projective}; use itertools::Itertools; - use poly_commitment::{evaluation_proof::OpeningProof, srs::SRS}; + use poly_commitment::{ipa::SRS, SRS as _}; use crate::proofs::{ + self, public_input::plonk_checks::{self, ft_eval0_checked}, step::Opt, transaction::scalar_challenge::{self, to_field_checked}, @@ -1473,7 +1477,7 @@ pub mod wrap_verifier { let vk = prover_index.verifier_index.as_ref().unwrap(); let to_curve = |v: &PolyComm| { - let v = v.elems[0]; + let v = v.chunks[0]; InnerCurve::::of_affine(v) }; @@ -1560,11 +1564,11 @@ pub mod wrap_verifier { } pub fn lowest_128_bits(f: F, assert_low_bits: bool, w: &mut Witness) -> F { - let (_, endo) = endos::(); + let (_, endo) = endos::<::Scalar>(); let (lo, hi): (F, F) = w.exists({ let bigint: BigInteger256 = f.into(); - let [a, b, c, d] = bigint.to_64x4(); + let [a, b, c, d] = bigint.0; (two_u64_to_field(&[a, b]), two_u64_to_field(&[c, d])) }); @@ -1674,7 +1678,7 @@ pub mod wrap_verifier { let to_bytes = |f: Fq| { let bigint: BigInteger256 = f.into(); - let [a, b, c, d] = bigint.to_64x4(); + let [a, b, c, d] = bigint.0; [a, b, c, d] }; @@ -1811,16 +1815,16 @@ pub mod wrap_verifier { } pub fn lagrange_commitment( - srs: &mut SRS>, + srs: &SRS>, d: u64, i: usize, ) -> PolyComm> { let d = d as usize; - let x_domain = EvaluationDomain::::new(d).expect("invalid argument"); + let x_domain = + EvaluationDomain::<::Scalar>::new(d) + .expect("invalid argument"); - srs.add_lagrange_basis(x_domain); - - let lagrange_bases = &srs.lagrange_bases[&x_domain.size()]; + let lagrange_bases = &srs.get_lagrange_basis(x_domain); lagrange_bases[i].clone() } @@ -1834,7 +1838,7 @@ pub mod wrap_verifier { .filter(|(_, b)| b.as_bool()) .map(|(d, _)| { let d = 2u64.pow(d.h.log2_size() as u32); - match lagrange_commitment::(srs, d, i).elems.as_slice() { + match lagrange_commitment::(srs, d, i).chunks.as_slice() { &[GroupAffine:: { x, y, .. }] => (x, y), _ => unreachable!(), } @@ -1867,9 +1871,9 @@ pub mod wrap_verifier { let actual_shift = { OPS_BITS_PER_CHUNK * chunks_needed(input_length) }; let pow2pow = |x: InnerCurve, n: usize| (0..n).fold(x, |acc, _| acc.clone() + acc); - let mut base_and_correction = |h: Domain| { + let base_and_correction = |h: Domain| { let d = 2u64.pow(h.log2_size() as u32); - match lagrange_commitment::(srs, d, i).elems.as_slice() { + match lagrange_commitment::(srs, d, i).chunks.as_slice() { &[g] => { let g = InnerCurve::of_affine(g); let b = pow2pow(g.clone(), actual_shift).neg(); @@ -1902,17 +1906,22 @@ pub mod wrap_verifier { }; (x, y) }) - .reduce(|mut acc, v| { - acc.0 += &v.0; - acc.1 += &v.1; - acc - }) - .unwrap(); + .fold( + (Projective::default(), Projective::default()), + |mut acc, v| { + acc.0 += v.0; + acc.1 += v.1; + acc + }, + ); w.exists([y.y, y.x]); w.exists([x.y, x.x]); - (InnerCurve::of_affine(x), InnerCurve::of_affine(y)) + ( + InnerCurve::of_affine(Affine::from(x)), + InnerCurve::of_affine(Affine::from(y)), + ) }; // TODO: Hack until we have proper cvar :( @@ -1969,7 +1978,7 @@ pub mod wrap_verifier { let s_parts = w.exists({ // TODO: Here `s` is a `F` but needs to be read as a `F::Scalar` let bigint: BigInteger256 = s.into(); - let bigint: [u64; 4] = bigint.to_64x4(); + let bigint: [u64; 4] = bigint.0; let s_odd = bigint[0] & 1 != 0; let v = if s_odd { s - F::one() } else { s }; (v / F::from(2u64), s_odd.to_boolean()) @@ -2169,7 +2178,7 @@ pub mod wrap_verifier { let combined_inner_product: Fq = { let bigint: BigInteger256 = advice.combined_inner_product.shifted.into(); - bigint.try_into().unwrap() // Never fail, `Fq` is larger than `Fp` + bigint.into() // Never fail, `Fq` is larger than `Fp` }; sponge.absorb(&[combined_inner_product], w); @@ -2222,8 +2231,8 @@ pub mod wrap_verifier { #[derive(Debug)] pub struct Advice { - pub b: ShiftedValue, - pub combined_inner_product: ShiftedValue, + pub b: ShiftedValue<::Scalar>, + pub combined_inner_product: ShiftedValue<::Scalar>, } pub(super) struct IncrementallyVerifyProofParams<'a> { @@ -2398,7 +2407,7 @@ pub mod wrap_verifier { let w_comm = &messages.w_comm; - for w in w_comm.iter().flat_map(|w| &w.elems) { + for w in w_comm.iter().flat_map(|w| &w.chunks) { absorb_curve( &CircuitVar::Constant(Boolean::True), &InnerCurve::of_affine(*w), @@ -2410,7 +2419,7 @@ pub mod wrap_verifier { let _gamma = sample(&mut sponge, w); let z_comm = &messages.z_comm; - for z in z_comm.elems.iter() { + for z in z_comm.chunks.iter() { absorb_curve( &CircuitVar::Constant(Boolean::True), &InnerCurve::of_affine(*z), @@ -2421,7 +2430,7 @@ pub mod wrap_verifier { let _alpha = sample_scalar(&mut sponge, w); let t_comm = &messages.t_comm; - for t in t_comm.elems.iter() { + for t in t_comm.chunks.iter() { absorb_curve( &CircuitVar::Constant(Boolean::True), &InnerCurve::of_affine(*t), @@ -2458,7 +2467,7 @@ pub mod wrap_verifier { let sg_old = sg_old.iter().map(|(b, v)| (*b, v.to_affine())); let rest = [x_hat, ft_comm] .into_iter() - .chain(z_comm.elems.iter().cloned()) + .chain(z_comm.chunks.iter().cloned()) .chain([ verification_key.generic.to_affine(), verification_key.psm.to_affine(), @@ -2467,7 +2476,7 @@ pub mod wrap_verifier { verification_key.emul.to_affine(), verification_key.endomul_scalar.to_affine(), ]) - .chain(w_comm.iter().flat_map(|w| w.elems.iter().cloned())) + .chain(w_comm.iter().flat_map(|w| w.chunks.iter().cloned())) .chain(verification_key.coefficients.iter().map(|v| v.to_affine())) .chain(sigma_comm_init.iter().map(|v| v.to_affine())) .map(|v| (CircuitVar::Constant(Boolean::True), v)); @@ -2519,7 +2528,7 @@ pub mod one_hot_vector { } } -impl Check for poly_commitment::evaluation_proof::OpeningProof { +impl Check for OpeningProof { fn check(&self, w: &mut Witness) { let Self { lr, @@ -2543,7 +2552,7 @@ impl Check for poly_commitment::evaluation_proof::OpeningProof { } } -impl ToFieldElements for poly_commitment::evaluation_proof::OpeningProof { +impl ToFieldElements for OpeningProof { fn to_field_elements(&self, fields: &mut Vec) { let Self { lr, @@ -2597,8 +2606,8 @@ impl ToFieldElements for kimchi::proof::ProverCommitments { } = self; let mut push_poly = |poly: &PolyComm| { - let PolyComm { elems } = poly; - for GroupAffine:: { x, y, .. } in elems { + let PolyComm { chunks } = poly; + for GroupAffine:: { x, y, .. } in chunks { x.to_field_elements(fields); y.to_field_elements(fields); } @@ -2621,8 +2630,8 @@ impl Check for kimchi::proof::ProverCommitments { assert!(lookup.is_none()); let mut check_poly = |poly: &PolyComm| { - let PolyComm { elems } = poly; - for affine in elems { + let PolyComm { chunks } = poly; + for affine in chunks { InnerCurve::of_affine(*affine).check(w); } }; @@ -2728,7 +2737,7 @@ fn pack_statement( packed.extend( bulletproof_challenges .iter() - .map(|v| Packed::PackedBits(var(two_u64_to_field::(v)), 128)), // Never fail with 2 limbs + .map(|v| Packed::PackedBits(var(two_u64_to_field::(v)), 128)), // Never fail with 2 limbs ); // Bool @@ -2761,7 +2770,7 @@ fn pack_statement( fn split_field(x: Fq, w: &mut Witness) -> (Fq, Boolean) { let n: BigInteger256 = x.into(); - let n: [u64; 4] = n.to_64x4(); + let n: [u64; 4] = n.0; let is_odd = n[0] & 1 != 0; diff --git a/ledger/src/proofs/zkapp.rs b/ledger/src/proofs/zkapp.rs index ded2ab1763..cd46d48847 100644 --- a/ledger/src/proofs/zkapp.rs +++ b/ledger/src/proofs/zkapp.rs @@ -4,6 +4,7 @@ use ark_ff::{fields::arithmetic::InvalidBigInt, BigInteger256, Zero}; use kimchi::proof::PointEvaluations; use mina_curves::pasta::{Fp, Fq}; use mina_p2p_messages::v2; +use poly_commitment::ipa::OpeningProof; use poseidon::hash::{ hash_with_kimchi, params::{MINA_ACCOUNT_UPDATE_CONS, MINA_PROTO_STATE_BODY}, @@ -1421,7 +1422,7 @@ impl From<&WrapProof> for v2::PicklesProofProofsVerified2ReprStableV2 { lookup, }, proof: - poly_commitment::evaluation_proof::OpeningProof { + OpeningProof { lr, delta, z1, @@ -1503,7 +1504,7 @@ impl From<&WrapProof> for v2::PicklesProofProofsVerified2ReprStableV2 { prechallenge: v2::PicklesReducedMessagesForNextProofOverSameFieldWrapChallengesVectorStableV2AChallenge { inner: { let bigint: BigInteger256 = bulletproof_challenges[i].into(); - let bigint = bigint.to_64x4(); + let bigint = bigint.0; PaddedSeq([v2::LimbVectorConstantHex64StableV1(bigint[0].into()), v2::LimbVectorConstantHex64StableV1(bigint[1].into())]) }, }, @@ -1516,7 +1517,7 @@ impl From<&WrapProof> for v2::PicklesProofProofsVerified2ReprStableV2 { v2::CompositionTypesDigestConstantStableV1({ let bigint: BigInteger256 = (*sponge_digest_before_evaluations).into(); - let bigint = bigint.to_64x4(); + let bigint = bigint.0; PaddedSeq( bigint .each_ref() @@ -1536,7 +1537,7 @@ impl From<&WrapProof> for v2::PicklesProofProofsVerified2ReprStableV2 { prechallenge: v2::PicklesReducedMessagesForNextProofOverSameFieldWrapChallengesVectorStableV2AChallenge { inner: { let bigint: BigInteger256 = old_bulletproof_challenges[i][j].into(); - let bigint = bigint.to_64x4(); + let bigint = bigint.0; PaddedSeq([v2::LimbVectorConstantHex64StableV1(bigint[0].into()), v2::LimbVectorConstantHex64StableV1(bigint[1].into())]) }, }, @@ -1564,7 +1565,7 @@ impl From<&WrapProof> for v2::PicklesProofProofsVerified2ReprStableV2 { prechallenge: v2::PicklesReducedMessagesForNextProofOverSameFieldWrapChallengesVectorStableV2AChallenge { inner: { let bigint: BigInteger256 = v[i].into(); - let bigint = bigint.to_64x4(); + let bigint = bigint.0; PaddedSeq([v2::LimbVectorConstantHex64StableV1(bigint[0].into()), v2::LimbVectorConstantHex64StableV1(bigint[1].into())]) }, }, @@ -1598,9 +1599,9 @@ impl From<&WrapProof> for v2::PicklesProofProofsVerified2ReprStableV2 { }, proof: v2::PicklesWrapWireProofStableV1 { commitments: v2::PicklesWrapWireProofCommitmentsStableV1 { - w_comm: PaddedSeq(w_comm.each_ref().map(|w| to_tuple(&w.elems[0]))), - z_comm: to_tuple(&z_comm.elems[0]), - t_comm: PaddedSeq(array::from_fn(|i| to_tuple(&t_comm.elems[i]))), + w_comm: PaddedSeq(w_comm.each_ref().map(|w| to_tuple(&w.chunks[0]))), + z_comm: to_tuple(&z_comm.chunks[0]), + t_comm: PaddedSeq(array::from_fn(|i| to_tuple(&t_comm.chunks[i]))), }, evaluations: { let kimchi::proof::ProofEvaluations { diff --git a/ledger/src/scan_state/currency.rs b/ledger/src/scan_state/currency.rs index cf595fbb23..d7c4862e74 100644 --- a/ledger/src/scan_state/currency.rs +++ b/ledger/src/scan_state/currency.rs @@ -1,6 +1,6 @@ use std::cmp::Ordering::{Equal, Greater, Less}; -use ark_ff::{fields::arithmetic::InvalidBigInt, BigInteger256, Field}; +use ark_ff::{BigInteger256, Field}; use mina_p2p_messages::v2::BlockTimeTimeStableV1; use rand::Rng; @@ -447,7 +447,7 @@ macro_rules! impl_number { fn of_field(field: F) -> Self { let amount: BigInteger256 = field.into(); - let amount: $inner = amount.to_64x4()[0].try_into().unwrap(); + let amount: $inner = amount.0[0].try_into().unwrap(); Self::$from_name(amount) } @@ -531,7 +531,7 @@ macro_rules! impl_number { std::array::from_fn(|_| iter.next().unwrap()) } - pub fn to_field>(&self) -> F { + pub fn to_field>(&self) -> F { let int = self.0 as u64; F::from(int) } diff --git a/ledger/src/scan_state/fee_excess.rs b/ledger/src/scan_state/fee_excess.rs index 614e7a84b2..cb4756ccb5 100644 --- a/ledger/src/scan_state/fee_excess.rs +++ b/ledger/src/scan_state/fee_excess.rs @@ -319,7 +319,7 @@ impl FeeExcess { let bigint: BigInteger256 = excess.into(); let is_neg = bigint.get_bit(255 - 1); let sgn = if is_neg { Sgn::Neg } else { Sgn::Pos }; - let magnitude = Fee::from_u64(bigint.to_64x4()[0]); + let magnitude = Fee::from_u64(bigint.0[0]); Signed::create(magnitude, sgn) }; diff --git a/ledger/src/scan_state/transaction_logic.rs b/ledger/src/scan_state/transaction_logic.rs index 2a951a8d4d..63ddc4d2d1 100644 --- a/ledger/src/scan_state/transaction_logic.rs +++ b/ledger/src/scan_state/transaction_logic.rs @@ -4310,9 +4310,10 @@ pub mod verifiable { pub fn compressed_to_pubkey(pubkey: &CompressedPubKey) -> mina_signer::PubKey { // Taken from https://github.com/o1-labs/proof-systems/blob/e3fc04ce87f8695288de167115dea80050ab33f4/signer/src/pubkey.rs#L95-L106 - let mut pt = mina_signer::CurvePoint::get_point_from_x(pubkey.x, pubkey.is_odd).unwrap(); + let mut pt = + mina_signer::CurvePoint::get_point_from_x_unchecked(pubkey.x, pubkey.is_odd).unwrap(); - if pt.y.into_repr().is_even() == pubkey.is_odd { + if pt.y.into_bigint().is_even() == pubkey.is_odd { pt.y = pt.y.neg(); } @@ -7284,8 +7285,8 @@ pub mod transaction_union_payload { arbitrary values different from the default token-id, for this we will extract the LS u64 of the token-id. */ - let fee_token_id = self.common.fee_token.0.into_repr().to_64x4()[0]; - let token_id = self.body.token_id.0.into_repr().to_64x4()[0]; + let fee_token_id = self.common.fee_token.0.into_bigint().0[0]; + let token_id = self.body.token_id.0.into_bigint().0[0]; let mut roi = LegacyInput::new() .append_field(self.common.fee_payer_pk.x) diff --git a/ledger/src/staged_ledger/hash.rs b/ledger/src/staged_ledger/hash.rs index bd38a26a75..238110d37b 100644 --- a/ledger/src/staged_ledger/hash.rs +++ b/ledger/src/staged_ledger/hash.rs @@ -158,8 +158,11 @@ impl NonStark { let mut ledger_hash_bytes: [u8; 32] = <[u8; 32]>::default(); - let ledger_hash = ledger_hash.into_repr(); - ledger_hash.write(ledger_hash_bytes.as_mut_slice()).unwrap(); + let ledger_hash = ledger_hash.into_bigint(); + ledger_hash + .0 + .write(ledger_hash_bytes.as_mut_slice()) + .unwrap(); ledger_hash_bytes.reverse(); sha.update(ledger_hash_bytes.as_slice()); diff --git a/ledger/src/staged_ledger/staged_ledger.rs b/ledger/src/staged_ledger/staged_ledger.rs index ad3c397e4e..6c0000c9f1 100644 --- a/ledger/src/staged_ledger/staged_ledger.rs +++ b/ledger/src/staged_ledger/staged_ledger.rs @@ -2010,7 +2010,7 @@ mod tests_ocaml { sync::atomic::{AtomicUsize, Ordering::Relaxed}, }; - use ark_ec::{AffineCurve, ProjectiveCurve}; + use ark_ec::{AffineRepr, CurveGroup}; use ark_ff::Zero; use mina_curves::pasta::Fq; use mina_signer::{Keypair, Signature, Signer}; @@ -3772,14 +3772,15 @@ mod tests_ocaml { Vec>, ) { fn keypair_from_private(private: &str) -> Keypair { + use std::ops::Mul; + let bytes = bs58::decode(private).into_vec().unwrap(); let bytes = &bytes[1..]; // ignore base58 check byte let secret = mina_signer::ScalarField::from_bytes(&bytes[1..]).unwrap(); - let public: mina_signer::CurvePoint = - mina_signer::CurvePoint::prime_subgroup_generator() - .mul(secret) - .into_affine(); + let public: mina_signer::CurvePoint = mina_signer::CurvePoint::generator() + .mul(secret) + .into_affine(); if !public.is_on_curve() { panic!() diff --git a/ledger/src/util/mod.rs b/ledger/src/util/mod.rs index 67c07df279..91a21f4b96 100644 --- a/ledger/src/util/mod.rs +++ b/ledger/src/util/mod.rs @@ -28,7 +28,7 @@ pub trait FpExt { impl FpExt for Fp { fn to_decimal(&self) -> String { - let r = self.into_repr(); + let r = self.into_bigint(); let bigint: num_bigint::BigUint = r.into(); bigint.to_string() } @@ -36,7 +36,7 @@ impl FpExt for Fp { impl FpExt for Fq { fn to_decimal(&self) -> String { - let r = self.into_repr(); + let r = self.into_bigint(); let bigint: num_bigint::BigUint = r.into(); bigint.to_string() } @@ -58,9 +58,9 @@ pub fn decompress_pk(pk: &CompressedPubKey) -> Option { let y_parity = pk.is_odd; let x = pk.x; - let mut pt = CurvePoint::get_point_from_x(x, y_parity)?; + let mut pt = CurvePoint::get_point_from_x_unchecked(x, y_parity)?; - if pt.y.into_repr().is_even() == y_parity { + if pt.y.into_bigint().is_even() == y_parity { pt.y = pt.y.neg(); } diff --git a/ledger/src/verifier/mod.rs b/ledger/src/verifier/mod.rs index 3485bebebe..7f8a145b89 100644 --- a/ledger/src/verifier/mod.rs +++ b/ledger/src/verifier/mod.rs @@ -1,7 +1,9 @@ use std::sync::{Arc, Mutex}; use crate::{ - proofs::{field::FieldWitness, verification, verifiers::TransactionVerifier, VerifierIndex}, + proofs::{ + self, field::FieldWitness, verification, verifiers::TransactionVerifier, VerifierIndex, + }, scan_state::{ scan_state::transaction_snark::{ LedgerProof, LedgerProofWithSokMessage, SokMessage, TransactionSnark, @@ -23,7 +25,7 @@ use mina_p2p_messages::v2::{ }; use mina_signer::CompressedPubKey; use once_cell::sync::Lazy; -use poly_commitment::srs::SRS; +use poly_commitment::{ipa::SRS, SRS as _}; // TODO: Move this into `Verifier` struct above pub static VERIFIER_INDEX: Lazy>> = Lazy::new(|| { @@ -37,7 +39,7 @@ pub fn get_srs() -> Arc> { cache! { Arc>, { - let srs = SRS::::create(F::Scalar::SRS_DEPTH); + let srs = SRS::::create(::Scalar::SRS_DEPTH); Arc::new(srs) } } @@ -48,7 +50,7 @@ pub fn get_srs_mut() -> Arc>> { cache! { Arc>>, { - let srs = SRS::::create(F::Scalar::SRS_DEPTH); + let srs = SRS::::create(::Scalar::SRS_DEPTH); Arc::new(Mutex::new(srs)) } } @@ -229,6 +231,8 @@ impl Verifier { pub mod common { use std::sync::Arc; + use ark_ec::{AffineRepr, CurveGroup}; + use ark_ff::PrimeField; use mina_p2p_messages::v2::PicklesProofProofsVerifiedMaxStableV2; use mina_signer::{CompressedPubKey, PubKey, Signature}; use poseidon::hash::hash_with_kimchi; @@ -376,27 +380,26 @@ pub mod common { pubkey: &PubKey, msg: &TransactionCommitment, ) -> bool { - use ark_ec::{AffineCurve, ProjectiveCurve}; - use ark_ff::{BigInteger, PrimeField, Zero}; + use ark_ff::{BigInteger, Zero}; use mina_curves::pasta::{Fq, Pallas}; use mina_signer::CurvePoint; - use std::ops::Neg; + use std::ops::{Mul, Neg}; let Pallas { x, y, .. } = pubkey.point(); let Signature { rx, s } = signature; let signature_prefix = mina_core::NetworkConfig::global().signature_prefix; let hash = hash_with_kimchi(signature_prefix, &[**msg, *x, *y, *rx]); - let hash: Fq = Fq::try_from(hash.into_repr()).unwrap(); // Never fail, `Fq` is larger than `Fp` + let hash: Fq = Fq::from(hash.into_bigint()); // Never fail, `Fq` is larger than `Fp` - let sv: CurvePoint = CurvePoint::prime_subgroup_generator().mul(*s).into_affine(); + let sv: CurvePoint = CurvePoint::generator().mul(*s).into_affine(); // Perform addition and infinity check in projective coordinates for performance - let rv = pubkey.point().mul(hash).neg().add_mixed(&sv); + let rv = pubkey.point().mul(hash).neg() + sv; if rv.is_zero() { return false; } let rv = rv.into_affine(); - rv.y.into_repr().is_even() && rv.x == *rx + rv.y.into_bigint().is_even() && rv.x == *rx } /// Verify signature with legacy style @@ -406,11 +409,10 @@ pub mod common { msg: &TransactionUnionPayload, ) -> bool { use ::poseidon::hash::legacy; - use ark_ec::{AffineCurve, ProjectiveCurve}; - use ark_ff::{BigInteger, PrimeField, Zero}; + use ark_ff::{BigInteger, Zero}; use mina_curves::pasta::{Fq, Pallas}; use mina_signer::CurvePoint; - use std::ops::Neg; + use std::ops::{Mul, Neg}; let Pallas { x, y, .. } = pubkey.point(); let Signature { rx, s } = signature; @@ -423,15 +425,15 @@ pub mod common { inputs.append_field(*rx); let hash = legacy::hash_with_kimchi(signature_prefix, &inputs.to_fields()); - let hash: Fq = Fq::try_from(hash.into_repr()).unwrap(); // Never fail, `Fq` is larger than `Fp` + let hash: Fq = Fq::from(hash.into_bigint()); // Never fail, `Fq` is larger than `Fp` - let sv: CurvePoint = CurvePoint::prime_subgroup_generator().mul(*s).into_affine(); + let sv: CurvePoint = CurvePoint::generator().mul(*s).into_affine(); // Perform addition and infinity check in projective coordinates for performance - let rv = pubkey.point().mul(hash).neg().add_mixed(&sv); + let rv = pubkey.point().mul(hash).neg() + sv; if rv.is_zero() { return false; } let rv = rv.into_affine(); - rv.y.into_repr().is_even() && rv.x == *rx + rv.y.into_bigint().is_even() && rv.x == *rx } } diff --git a/macros/src/action_event.rs b/macros/src/action_event.rs index 8d3b1424ce..08be4f3881 100644 --- a/macros/src/action_event.rs +++ b/macros/src/action_event.rs @@ -52,7 +52,7 @@ enum FieldsSpec { Some(Vec<(Option, TokenStream)>), } -#[derive(Clone, Debug, Default)] +#[derive(Clone, Default)] struct ActionEventAttrs { level: Option, fields: Option, diff --git a/mina-p2p-messages/src/bigint.rs b/mina-p2p-messages/src/bigint.rs index 5ae5d73067..f8e1f09f86 100644 --- a/mina-p2p-messages/src/bigint.rs +++ b/mina-p2p-messages/src/bigint.rs @@ -10,7 +10,7 @@ impl std::fmt::Debug for BigInt { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let Self(bigint) = self; // Avoid vertical alignment - f.write_fmt(format_args!("BigInt({:?})", bigint.to_native())) + f.write_fmt(format_args!("BigInt({:?})", bigint.0)) } } @@ -35,22 +35,23 @@ impl BigInt { pub fn to_field(&self) -> Result where - F: ark_ff::Field + TryFrom, + F: ark_ff::Field + From, { let Self(biginteger) = self; - F::try_from(*biginteger) + Ok(F::from(*biginteger)) } pub fn to_bytes(&self) -> [u8; 32] { use ark_ff::ToBytes; let mut bytes = std::io::Cursor::new([0u8; 32]); - self.0.write(&mut bytes).unwrap(); // Never fail, there is 32 bytes + self.0 .0.write(&mut bytes).unwrap(); // Never fail, there is 32 bytes bytes.into_inner() } pub fn from_bytes(bytes: [u8; 32]) -> Self { use ark_ff::FromBytes; - Self(BigInteger256::read(&bytes[..]).unwrap()) // Never fail, we read from 32 bytes + let value = FromBytes::read(&bytes[..]).expect("Don't fail"); + Self(BigInteger256::new(value)) // Never fail, we read from 32 bytes } pub fn from_decimal(s: &str) -> Result { @@ -80,54 +81,58 @@ impl AsRef for BigInt { impl From for BigInt { fn from(field: mina_curves::pasta::Fp) -> Self { use ark_ff::PrimeField; - Self(field.into_repr()) + Self(field.into_bigint()) } } impl From for BigInt { fn from(field: mina_curves::pasta::Fq) -> Self { use ark_ff::PrimeField; - Self(field.into_repr()) + Self(field.into_bigint()) } } impl From<&mina_curves::pasta::Fp> for BigInt { fn from(field: &mina_curves::pasta::Fp) -> Self { use ark_ff::PrimeField; - Self(field.into_repr()) + Self(field.into_bigint()) } } impl From<&mina_curves::pasta::Fq> for BigInt { fn from(field: &mina_curves::pasta::Fq) -> Self { use ark_ff::PrimeField; - Self(field.into_repr()) + Self(field.into_bigint()) } } impl TryFrom for mina_curves::pasta::Fp { - type Error = >::Error; + // type Error = >::Error; + type Error = InvalidBigInt; fn try_from(bigint: BigInt) -> Result { bigint.to_field() } } impl TryFrom for mina_curves::pasta::Fq { - type Error = >::Error; + // type Error = >::Error; + type Error = InvalidBigInt; fn try_from(bigint: BigInt) -> Result { bigint.to_field() } } impl TryFrom<&BigInt> for mina_curves::pasta::Fp { - type Error = >::Error; + // type Error = >::Error; + type Error = InvalidBigInt; fn try_from(bigint: &BigInt) -> Result { bigint.to_field() } } impl TryFrom<&BigInt> for mina_curves::pasta::Fq { - type Error = >::Error; + // type Error = >::Error; + type Error = InvalidBigInt; fn try_from(bigint: &BigInt) -> Result { bigint.to_field() } @@ -190,7 +195,8 @@ impl binprot::BinProtRead for BigInt { Self: Sized, { use ark_ff::FromBytes; - Ok(Self(BigInteger256::read(r)?)) + let value = FromBytes::read(r)?; + Ok(Self(BigInteger256::new(value))) } } @@ -198,7 +204,7 @@ impl binprot::BinProtWrite for BigInt { fn binprot_write(&self, w: &mut W) -> std::io::Result<()> { use ark_ff::ToBytes; let Self(biginteger) = self; - biginteger.write(w) + biginteger.0.write(w) } } @@ -454,7 +460,7 @@ mod tests { let original_sexp = Sexp::Atom(hex_str.as_bytes().to_vec()); let result = BigInt::of_sexp(&original_sexp).expect("Failed to convert Sexp to BigInt"); - let expected_result = BigInt(BigInteger256::from_64x4(expected_array)); + let expected_result = BigInt(BigInteger256::new(expected_array)); assert_eq!(result, expected_result); diff --git a/mina-p2p-messages/src/v2/hashing.rs b/mina-p2p-messages/src/v2/hashing.rs index cd8be5b0a0..0c16e73267 100644 --- a/mina-p2p-messages/src/v2/hashing.rs +++ b/mina-p2p-messages/src/v2/hashing.rs @@ -402,7 +402,7 @@ impl StateHash { body_hash: &MinaBaseStateBodyHashStableV1, ) -> Result { Ok(Self::from_fp(fp_state_hash_from_fp_hashes( - pred_state_hash.to_field()?, + pred_state_hash.to_field().map_err(|_| InvalidBigInt)?, body_hash.to_field()?, ))) } @@ -467,7 +467,9 @@ impl MinaHash for MinaStateProtocolStateBodyValueStableV2 { impl MinaHash for MinaStateProtocolStateValueStableV2 { fn try_hash(&self) -> Result { Ok(fp_state_hash_from_fp_hashes( - self.previous_state_hash.to_field()?, + self.previous_state_hash + .to_field() + .map_err(|_| InvalidBigInt)?, MinaHash::try_hash(&self.body)?, )) } diff --git a/poseidon/Cargo.toml b/poseidon/Cargo.toml index 83fdb1281f..98647c56f2 100644 --- a/poseidon/Cargo.toml +++ b/poseidon/Cargo.toml @@ -8,5 +8,7 @@ workspace = true [dependencies] ark-ff = { workspace = true } +ark-serialize.workspace = true mina-curves = { workspace = true } once_cell = "1" +serde.workspace = true diff --git a/poseidon/src/hash.rs b/poseidon/src/hash.rs index 1f08ac5dd0..181fc07bd0 100644 --- a/poseidon/src/hash.rs +++ b/poseidon/src/hash.rs @@ -1,4 +1,4 @@ -use ark_ff::{BigInteger256, Field, FromBytes as _}; +use ark_ff::{BigInt, BigInteger256, Field, FromBytes}; use mina_curves::pasta::Fp; use crate::{PlonkSpongeConstantsKimchi, Sponge, SpongeParamsForField}; @@ -46,7 +46,8 @@ impl Item { Item::U48(v) => { let mut bytes = <[u8; 32]>::default(); bytes[..6].copy_from_slice(&v[..]); - BigInteger256::read(&bytes[..]).unwrap().to_64x4()[0] // Never fail with only 6 bytes + let value = FromBytes::read(&bytes[..]).expect("Must not go wrong"); + BigInteger256::new(value).0[0] // Never fail with only 6 bytes } Item::U64(v) => *v, } @@ -168,16 +169,14 @@ impl Inputs { // `current` are zero (we just shift-left them) current[0] |= item; } else { - self.fields - .push(BigInteger256::from_64x4(current).try_into().unwrap()); // Never fail + self.fields.push(BigInteger256::new(current).into()); // Never fail current = [item, 0, 0, 0]; nbits = item_nbits; } } if nbits > 0 { - self.fields - .push(BigInteger256::from_64x4(current).try_into().unwrap()); // Never fail + self.fields.push(BigInteger256::new(current).into()); // Never fail } self.fields @@ -191,7 +190,9 @@ fn param_to_field_impl(param: &str, default: &[u8; 32]) -> Fp { let mut fp = *default; fp[..len].copy_from_slice(param_bytes); - Fp::read(&fp[..]).expect("fp read failed") + let value = FromBytes::read(&fp[..]).expect("Error reading"); + let element = BigInt::new(value); + Fp::new(element) } pub fn param_to_field(param: &str) -> Fp { @@ -438,8 +439,6 @@ pub mod params { } pub mod legacy { - use ark_ff::fields::arithmetic::InvalidBigInt; - use super::*; #[derive(Clone, Debug)] @@ -499,7 +498,7 @@ pub mod legacy { } } - impl> Inputs { + impl> Inputs { pub fn to_fields(mut self) -> Vec { const NBITS: usize = 255 - 1; @@ -511,7 +510,7 @@ pub mod legacy { let bit_index = index % 64; field[limb_index] |= (*bit as u64) << bit_index; } - F::try_from(BigInteger256::from_64x4(field)).unwrap() // Never fail + F::from(BigInteger256::new(field)) // Never fail })); self.fields } diff --git a/poseidon/src/lib.rs b/poseidon/src/lib.rs index eabfe11b95..b06230dbe2 100644 --- a/poseidon/src/lib.rs +++ b/poseidon/src/lib.rs @@ -2,7 +2,7 @@ use std::marker::PhantomData; -use ark_ff::{BigInteger256, Field}; +use ark_ff::{BigInt, BigInteger256, Field}; use mina_curves::pasta::{Fp, Fq}; pub mod hash; @@ -274,7 +274,7 @@ impl + Into> FqSponge { limbs } else { let x: BigInteger256 = self.sponge.squeeze().into(); - let x: [u64; 4] = x.to_64x4(); + let BigInt(x) = x; self.last_squeezed .extend(&x.as_ref()[0..HIGH_ENTROPY_LIMBS]); self.squeeze_limbs::() diff --git a/snark/Cargo.toml b/snark/Cargo.toml index bf3309e1b6..0e4dd721f6 100644 --- a/snark/Cargo.toml +++ b/snark/Cargo.toml @@ -14,8 +14,8 @@ mina-signer = { workspace = true } o1-utils = { workspace = true } poly-commitment = { workspace = true } -ark-ec = { version = "0.3.0", features = ["std"] } -ark-poly = { version = "0.3.0", features = ["std"] } +ark-ec.workspace = true +ark-poly.workspace = true derive_more = "0.99.17" hex = "0.4" ledger = { workspace = true } diff --git a/snark/src/lib.rs b/snark/src/lib.rs index 20c3e2bada..bf1e55c2c8 100644 --- a/snark/src/lib.rs +++ b/snark/src/lib.rs @@ -109,7 +109,7 @@ pub use snark_state::*; mod snark_reducer; pub type VerifierIndex = ledger::proofs::VerifierIndex; -pub type VerifierSRS = poly_commitment::srs::SRS; +pub type VerifierSRS = poly_commitment::ipa::SRS; use redux::SubStore; pub trait SnarkStore: @@ -118,6 +118,6 @@ pub trait SnarkStore: } impl> SnarkStore for T {} -pub fn get_srs() -> std::sync::Arc> { +pub fn get_srs() -> std::sync::Arc> { ledger::verifier::get_srs::() } diff --git a/tools/fuzzing/Cargo.toml b/tools/fuzzing/Cargo.toml index 659bd7657f..79624f5246 100644 --- a/tools/fuzzing/Cargo.toml +++ b/tools/fuzzing/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" [dependencies] -ark-ec = { version = "0.3.0", features = ["std"] } +ark-ec.workspace = true ark-ff = { workspace = true } ark-serialize = "0.4.2" bitvec = "1.0.1" diff --git a/tools/fuzzing/src/transaction_fuzzer/generator.rs b/tools/fuzzing/src/transaction_fuzzer/generator.rs index 592e338cb4..c51a05d009 100644 --- a/tools/fuzzing/src/transaction_fuzzer/generator.rs +++ b/tools/fuzzing/src/transaction_fuzzer/generator.rs @@ -1,5 +1,5 @@ -use ark_ec::{AffineCurve, ProjectiveCurve}; -use ark_ff::{Field, SquareRootField, UniformRand}; +use ark_ec::{AffineRepr, CurveGroup}; +use ark_ff::{Field, UniformRand}; use ledger::{ generators::zkapp_command_builder::get_transaction_commitments, proofs::{ @@ -69,7 +69,11 @@ use mina_signer::{ CompressedPubKey, CurvePoint, Keypair, NetworkId, ScalarField, SecKey, Signature, Signer, }; use rand::{seq::SliceRandom, Rng}; -use std::{array, iter, ops::RangeInclusive, sync::Arc}; +use std::{ + array, iter, + ops::{Mul, RangeInclusive}, + sync::Arc, +}; use tuple_map::TupleMap2; use super::context::{FuzzerCtx, PermissionModel}; @@ -155,9 +159,7 @@ impl Generator for FuzzerCtx { fn gen(&mut self) -> Keypair { let sec_key: SecKey = self.gen(); let scalar = sec_key.into_scalar(); - let public: CurvePoint = CurvePoint::prime_subgroup_generator() - .mul(scalar) - .into_affine(); + let public: CurvePoint = CurvePoint::generator().mul(scalar).into_affine(); let keypair = Keypair::from_parts_unsafe(scalar, public); @@ -199,7 +201,7 @@ impl Generator for FuzzerCtx { pub struct CurvePointGenerator(F, F); -impl + SquareRootField> Generator> for FuzzerCtx { +impl> Generator> for FuzzerCtx { #[coverage(off)] fn gen(&mut self) -> CurvePointGenerator { /* @@ -223,10 +225,14 @@ impl + SquareRootField> Generator> f impl Generator<(Fp, Fp)> for FuzzerCtx { #[coverage(off)] fn gen(&mut self) -> (Fp, Fp) { + use std::ops::Mul; if let Some((x, y)) = self.state.cache_curve_point_fp { - let p = GroupAffine::::new(x, y, false); - let rand_scalar: u64 = self.gen.rng.gen(); - let new_p: GroupAffine = p.mul(rand_scalar).into(); + let p = GroupAffine::::new(x, y); + let rand_scalar: u64 = self.r#gen.rng.gen(); + let scalar_field_elem = + ::Scalar::from(rand_scalar); + + let new_p: GroupAffine = p.mul(scalar_field_elem).into(); (new_p.x, new_p.y) } else { let p: CurvePointGenerator = self.gen(); @@ -240,9 +246,11 @@ impl Generator<(Fq, Fq)> for FuzzerCtx { #[coverage(off)] fn gen(&mut self) -> (Fq, Fq) { if let Some((x, y)) = self.state.cache_curve_point_fq { - let p = GroupAffine::::new(x, y, false); + let p = GroupAffine::::new(x, y); let rand_scalar: u64 = self.gen.rng.gen(); - let new_p: GroupAffine = p.mul(rand_scalar).into(); + let scalar_field_elem = + ::Scalar::from(rand_scalar); + let new_p: GroupAffine = p.mul(scalar_field_elem).into(); (new_p.x, new_p.y) } else { let p: CurvePointGenerator = self.gen(); diff --git a/vrf/Cargo.toml b/vrf/Cargo.toml index f411b0cc22..5e9893a844 100644 --- a/vrf/Cargo.toml +++ b/vrf/Cargo.toml @@ -6,9 +6,9 @@ license = "Apache-2.0" [dependencies] anyhow = "1.0.70" -ark-ec = { version = "0.3.0", features = ["std"] } +ark-ec.workspace = true ark-ff = { workspace = true } -ark-serialize = { version = "0.3.0", features = ["std"] } +ark-serialize.workspace = true hex = "0.4.3" ledger = { workspace = true } mina-curves = { workspace = true } diff --git a/vrf/src/lib.rs b/vrf/src/lib.rs index a598272773..2d3ab9d61b 100644 --- a/vrf/src/lib.rs +++ b/vrf/src/lib.rs @@ -1,4 +1,4 @@ -use ark_ec::AffineCurve; +use ark_ec::AffineRepr; use ark_ff::PrimeField; use ledger::AccountIndex; use message::VrfMessage; @@ -19,8 +19,8 @@ mod serialize; mod threshold; type VrfResult = std::result::Result; -type BaseField = ::BaseField; -type ScalarField = ::ScalarField; +type BaseField = ::BaseField; +type ScalarField = ::ScalarField; #[derive(Error, Debug)] pub enum VrfError { @@ -138,7 +138,7 @@ pub fn evaluate_vrf(vrf_input: VrfEvaluationInput) -> VrfResult(hash); let repr = BigInteger256::from_bits_le(&bits[..bits.len() - 3]); - ScalarField::from_repr(repr).unwrap() + ScalarField::from_bigint(repr).unwrap() } pub fn truncated_with_prefix_and_checksum(&self) -> Vec { @@ -91,7 +91,7 @@ impl VrfOutput { let vrf_out: BigInt2048 = BigInt2048::from_bytes_be( num::bigint::Sign::Plus, - &self.truncated().into_repr().to_bytes_be(), + &self.truncated().into_bigint().to_bytes_be(), ); BigRational::new(vrf_out, two_tpo_256).to_f64().unwrap() diff --git a/vrf/src/serialize.rs b/vrf/src/serialize.rs index 6e3969d3a9..ae91038eaa 100644 --- a/vrf/src/serialize.rs +++ b/vrf/src/serialize.rs @@ -6,7 +6,8 @@ where S: Serializer, { let mut bytes = vec![]; - a.serialize(&mut bytes).map_err(serde::ser::Error::custom)?; + a.serialize_uncompressed(&mut bytes) + .map_err(serde::ser::Error::custom)?; s.serialize_bytes(&bytes) } @@ -15,6 +16,6 @@ where D: Deserializer<'de>, { let s: Vec = serde::de::Deserialize::deserialize(data)?; - let a = A::deserialize(s.as_slice()); + let a = A::deserialize_uncompressed(s.as_slice()); a.map_err(serde::de::Error::custom) }