zksecurity / noname

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

Remove generate_asm from backend #44

Open katat opened 6 months ago

katat commented 6 months ago

We may not really require generate_asm to be implemented for the backend interface. It is not a must have interface to have in order to get the whole system work.

So we would just remove this backend interface.

mimoo commented 6 months ago

I think we might still want to keep it implemented for kimchi to at least be able to keep the tests we have running.

katat commented 5 months ago

It seems the asm is a must to have feature for all the backends for debugging purposes. So we'd better to keep it as part of the backend interface. Related PR: https://github.com/zksecurity/noname/pull/62

mimoo commented 5 months ago

On the other hand we could just require Backend: Display

katat commented 5 months ago

The Backend: Display may look like this:

impl Display for R1csBls12_381 {
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        let asm = self.asm(&crate::compiler::Sources::new(), true);
        write!(f, "{}", asm)
    }
}

impl R1csBls12_381 {
    fn asm(&self, sources: &crate::compiler::Sources, debug: bool) -> String {
       ...
    }

The problem is the sources argument can't be passed in to the fmt interface, unless sources is a field of the backend struct.

Alternatively, we just add a ASM trait for the backend structs to implement if the goal is just to separate these asm related code to its own file.

We could also simply move the asm related to be within impl R1csBls12_381 for example, but that is less generic when it comes to using it.

mimoo commented 5 months ago

wait why do we need sources? (oh for debug mode right... then nevermind ^^)