zksecurity / noname

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

supporting debug var value #218

Closed katat closed 2 weeks ago

katat commented 2 weeks ago

Previously, the log function is to print out the compilation info, such as the type of a variable.

This update is to make it print out the witness value instead, which is more useful for debugging purpose.

For example:

fn mimc7_hash(values: [Field; LEN], key: Field) -> Field {
    // Initialize with the key.
    let mut res = key;
    // Iterate over each value in the input array.
    for value in values {
        // Update the result with the MIMC hash of the value and the current result.
        res = res + (value + mimc7_cipher(value, res));
        log(res);
    }
    // Return the final accumulated result.
    return res;
}

It will print out:

span:9904, val: -9648106414739122877149794902860786266420046965962985658208312984077979135149
span:9904, val: 5233261170300319370386085858846328736737478911451874673953613863492170606314
span:9904, val: -4718642457857295476661913076129034983054319651083126928208304929878678658037

Currently it only support logging Field type. These info is rough still. Later we can make it print out more meta data, such as which file the span belonging to and what type of the var etc.