noname icon indicating copy to clipboard operation
noname copied to clipboard

Require more precise type resolution in binary operation

Open katat opened this issue 11 months ago • 2 comments

In type checking phase, the type of a binary operation expression is only determined by the left hand side:

https://github.com/zksecurity/noname/blob/a2d31f7008cea52f6dda144a4db0864364318c90/src/type_checker/checker.rs#L389

However, in the following case, it can mistakenly seen a non constant expression as constant;

fn is_not_constant(val: Field) -> Field {
    // val can be non constant
    return 1 + val;
}

1 + val can be a non constant field type as val can be a non constant. Therefore, when computing the types for the binary operations, it should take cares of the both sides.

katat avatar Jan 04 '25 08:01 katat

mmm interesting, wondering if that means that "constant" shouldn't be in the type

mimoo avatar Jan 16 '25 22:01 mimoo

yeah, I think we still need to propagate whether it is a constant or not. For example, the functions support const attribute that enforce the argument to be constant.

katat avatar Jan 17 '25 12:01 katat