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

[Feature] Support structs on input parameters when calling transitions from program #3269

Open
prajwolrg opened this issue Nov 2, 2023 · 2 comments
Assignees
Labels
bug Something isn't working feature A new feature.

Comments

@prajwolrg
Copy link

🚀 Feature

Support seamless passing of parameters of any types between programs.

Motivation

Consider a simple program that has transition one which takes input of type A.

program_a {
   struct A;
   transition one(a: A) {}
}

Another program should be able to call this program seamlessly:

import program_a;
program_b {
   transition two(a: A) {
       program_a/one(a);
    }
}
@prajwolrg prajwolrg added the feature A new feature. label Nov 2, 2023
@d0cd d0cd added the bug Something isn't working label Nov 2, 2023
@d0cd
Copy link
Collaborator

d0cd commented Nov 2, 2023

Failing code

// The 'test_program_a' program.
program test_program_a.aleo {
    struct A {
        data: [u8; 1];
    }

    mapping a_data: u8 => A;

    transition store(key: u8, data: [u8; 1]) {
        let a: A = A {
            data
        };
        return then finalize(key, a);
    }

    finalize store(key: u8, value: A) {
        Mapping::set(a_data, key, value);
    }
}

// The 'test_program_b' program.
import test_program_a.leo;

program test_program_b.aleo {
    transition store_in_a(key: u8, data: [u8; 1]) {
        test_program_a.leo/store(key, data);
    }
}
SnarkVM Error: Failed to execute instruction (call test_program_a.aleo/store r0 r1 into r2;): Struct 'A' is not defined in the program

@d0cd d0cd self-assigned this Nov 2, 2023
@d0cd
Copy link
Collaborator

d0cd commented Nov 11, 2023

Example: Using external structs in Aleo instructions

program points.aleo;

struct point:
    x as u8;
    y as u8;

function add_:
    input r0 as point.private;
    input r1 as point.private;
    add r0.x r1.x into r2;
    add r0.y r1.y into r3;
    cast r2 r3 into r4 as point;
    output r4 as point.private;

/////////////////////////////////////////////////

import points.aleo;

program point_arithmetic.aleo;

struct point:
    x as u8;
    y as u8;

function add_two_points:
    input r0 as point.private;
    input r1 as point.private;
    call points.aleo/add_ r0 r1 into r2;
    output r2 as point.private;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working feature A new feature.
Projects
None yet
Development

No branches or pull requests

2 participants