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

[Bug] getFunctionInputs needs to give register for nested inputs need #679

Closed
onetrickwolf opened this issue Jul 24, 2023 · 0 comments · Fixed by #682
Closed

[Bug] getFunctionInputs needs to give register for nested inputs need #679

onetrickwolf opened this issue Jul 24, 2023 · 0 comments · Fixed by #682

Comments

@onetrickwolf
Copy link
Collaborator

onetrickwolf commented Jul 24, 2023

program tictactoe.aleo;

struct Row:
    c1 as u8;
    c2 as u8;
    c3 as u8;

struct Board:
    d1 as Row;
    d2 as Row;
    d3 as Row;


function make_move:
    input r0 as u8.private;
    input r1 as u8.private;
    input r2 as u8.private;
    input r3 as Board.private;
    output r0 as u8.private;

The above program requires an input in this format:

"1u8" "2u8" "3u8" "{d1:{c1:1u8,c2:1u8,c3:1u8},d2:{c1:1u8,c2:1u8,c3:1u8},d3:{c1:1u8,c2:1u8,c3:1u8}}"

You need to denote the register as d1, d2, and d3, but the Aleo WASM getFunctionInputs (e.g. aleoWASM.Program.fromString(value).getFunctionInputs()) does not give the register names when nested. This is the result of just the Board from getFunctionInputs but you can see if gives the child registers but not the d registers within the Board struct.

{
    "type": "struct",
    "name": "Board",
    "members": [
        {
            "type": "struct",
            "name": "Row",
            "members": [
                {
                    "name": "c1",
                    "type": "u8"
                },
                {
                    "name": "c2",
                    "type": "u8"
                },
                {
                    "name": "c3",
                    "type": "u8"
                }
            ]
        },
        {
            "type": "struct",
            "name": "Row",
            "members": [
                {
                    "name": "c1",
                    "type": "u8"
                },
                {
                    "name": "c2",
                    "type": "u8"
                },
                {
                    "name": "c3",
                    "type": "u8"
                }
            ]
        },
        {
            "type": "struct",
            "name": "Row",
            "members": [
                {
                    "name": "c1",
                    "type": "u8"
                },
                {
                    "name": "c2",
                    "type": "u8"
                },
                {
                    "name": "c3",
                    "type": "u8"
                }
            ]
        }
    ],
    "visibility": "private"
}

I would propose possibly structuring it like this for consistency. Here's an example of one of the Rows updated to include the registry and also replacing name with registry reserving name for the named data types (which aren't needed for execution but could be useful for UIs).

{
    "register": "d1",
    "type": "struct",
    "name": "Row",
    "members": [
        {
            "register": "c1",
            "type": "u8"
        },
        {
            "register": "c2",
            "type": "u8"
        },
        {
            "register": "c3",
            "type": "u8"
        }
    ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant