keep-starknet-strange / raito

Bitcoin ZK client written in Cairo.
https://raito.wtf
MIT License
40 stars 34 forks source link

TraceContext draft #162

Closed maciejka closed 1 month ago

maciejka commented 1 month ago

Draft of TraceContext. Maintains context which allows to construct more meaningful errors and trace messages.

Initialization:

        let mut context = TraceContextTrait::new();
        context.push(Frame::BlockHeight(block_height));

Errors:

    maturity_result = context
        .err_with_context(
            format!(
                "coinbase input not mature (current height: {}, coinbase height: {})",
                block_height,
                coinbase_block_height
            )
        );

Frame struct is a very rough draft, subject for discussion.

With macros or conditional compilation(to be added later to the prototype) most of the runtime cost can be eliminated for provable(vs test) executions.

Even with macros I don't see a clean way to get rid of explicit context argument. Any ideas? Maybe it is ok to add let's say 5% to the proving cost for current simplicity of the construction?

vercel[bot] commented 1 month ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
raito ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 10, 2024 1:03pm
m-kus commented 1 month ago

It would be nice to have this kind of inspection provided by the Cairo runtime :)

I wonder what would be the overhead if we replaced the context with an empty struct (Cairo seems to allow that) 🤔 Generally I really like the idea that you print the context only when you got an error, and that the context data kind is somewhat standardized.

Note also, that we will have a mutable context anyways (Utreexo and local cache), so it might not necessarily be an overhead in the end.

maciejka commented 1 month ago

Closing for now, we will probably go simple logging macro route.