Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More flexible Rust<>Cairo types interface #6

Open
bilboquet opened this issue Sep 24, 2024 · 5 comments
Open

More flexible Rust<>Cairo types interface #6

bilboquet opened this issue Sep 24, 2024 · 5 comments
Assignees

Comments

@bilboquet
Copy link
Collaborator

From Ariel Elperin

  • Support sending various uints (not just u8) to riscv call (potentially make it generic over the param type, where the param type has to implement some kind of Serde trait)
  • User defined structs
  • The endgame here could be something like a type definition by the dev, e.g. in a proto file, and a cli command that generates rust + cairo modules with those types. That way, you know that whatever is generated can be used as arguments/return values of the externalized rust functions and as arguments/return values of riscv_call
@bilboquet bilboquet self-assigned this Oct 3, 2024
@bilboquet
Copy link
Collaborator Author

@damip please share your thoughts about this:

Let's focus on the use of a proto file to describe the interface between rust and cairo code.

On the rust side, we need

  1. a proto to rust code generator which is used at compile time
  2. a runtime support library written in rust to help serialize/deserialize data in protobuf format (that will be executed inside the riscv VM).
  3. some basic code (the actual format of a risc_call is [u8]->[u8]).

Points 1 and 2 can be filled by https://docs.rs/micropb/0.1.0/micropb/ (and integration is almost complete).
Point 3 is not a big problem and can even be done manually by the project developer.

On the cairo side, we have the same requirements.
Should we start writing a proto for the cairo code generator (in rust) and the corresponding cairo runtime (in cairo)?

@damip
Copy link
Member

damip commented Oct 3, 2024

OK For the rust side.

We need to check how proto works on the cairo side.
Looks like it is already used natively for hints: https://reilabs.io/blog/introducing-hints-in-cairo-programming-language/

https://github.com/reilabs/cairo-hints

In particular, here is the cairo proto codegen they use, conveniently written as a rust crate: https://github.com/reilabs/cairo-hints/tree/main/cairo-proto-build but let's make sure it generates the right version of cairo

@bilboquet
Copy link
Collaborator Author

@damip
Integration of cairo-proto-build went relatively fine.
But I just found that they are based on a different language edition (i.e. 2023_10) and that was the cause of the pain I had lately:

Something related to the visibility rules changed between edition 2023_10 and 2024_07:
given this cairo code:

// module mod1
struct A {
    a: u8,
}
// module main
mod mod1;
use mod1::A;

fn main2() -> bool {
    let x = A { a: 1 };
    x.a == 1
}

This code builds in edition 2023_10 but fails in edition 2024_07 because both A and A.a are not visible anymore.
This would work (but pub has to be added manually for the moment):

// module mod1
pub struct A {
    pub a: u8,
}

@bilboquet
Copy link
Collaborator Author

Added an issue to cairo-hints project reilabs/cairo-hints#35

@damip
Copy link
Member

damip commented Oct 8, 2024

@bilboquet could we work on a fork and propose a PR upstream ? To avoid blocking our progress

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

2 participants