zksecurity / noname

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

Enhancement for ITE #211

Open katat opened 3 weeks ago

katat commented 3 weeks ago

The current ITE requires the branches to be variables:

bits[index] = if bit_num == 1 {true_val} else {false_val};

This restriction makes it inconvenient to use the ITE in noname. Ideally, we should allow expressions in the branches.

Examples for feature enhancement:

Allow literals

bits[index] = if bit_num == 1 {true} else {false};
num = if cond == true {1} else {0};

Allow expressions

let mut counter = 0;
// func_a and func_b has to return the same type
num = if cond == true { 
    counter = counter + 1; 
    func_a(counter); 
} else { 
    func_b() 
};
mimoo commented 3 weeks ago

Can you label this as easy/medium/hard? Can we provide more info and ask the open source community to take a look at it?

katat commented 3 weeks ago

Sure, I added a few examples.