o1-labs / o1js

TypeScript framework for zk-SNARKs and zkApps
https://docs.minaprotocol.com/en/zkapps/how-to-write-a-zkapp
Apache License 2.0
531 stars 121 forks source link

No-op foreign curve program fails to compile #1916

Open mitschabaude opened 5 days ago

mitschabaude commented 5 days ago

The code below fails with an error from Pickles that seems to be some consistency check regarding custom gates.

The error occurs when the zkprogram has a ForeignCurve point public input, but doesn't do any actual operations on that point. The error goes away when adding a single operation like point.double() to the circuit.

Failing line in wrap_main.ml:

assert_consistent range_check0_comm range_check0 ;

Reproduction code:

import { createForeignCurve, Crypto, ZkProgram } from "o1js";

class Secp256k1 extends createForeignCurve(Crypto.CurveParams.Secp256k1) {}

const Failing = ZkProgram({
  name: "failing-program",
  publicInput: Secp256k1,

  methods: {
    test: {
      privateInputs: [],

      async method(p: Secp256k1) {
        // if this is commented in, compiling works
        // p.double();
      },
    },
  },
});

await Failing.compile();
mitschabaude commented 5 days ago

Discovered by @egemengol