zksecurity / noname

Noname: a programming language to write zkapps
https://zksecurity.github.io/noname/
193 stars 50 forks source link

make log work with any types #228

Open mimoo opened 1 week ago

mimoo commented 1 week ago

currently the log function signature is hardcoded as:

const LOG_FN: &str = "log(var: Field)";

this makes the type checker forbid the function from being used with other types than Field.

To fix that, we need to:

  1. make it so that the arguments part of a hardcoded builtin signature can be ignored by the type checker
  2. while still making sure that the type checker can verify that the returned type of a builtin function matches the expected return type expected by the caller (the builtin function does not have that information so cannot do that type checking)

In get_parsed_fns we need a flag that signals this:

        for (code, fn_handle, ignore_args) in fns {

Then FnKind::BuiltIn needs to carry that information as well.

Finally, in the typechecker, we can ignore type checks on the function arguments if we see this flag.