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

Incorrect bit length in .storeUint() and .storeInt() functions fails silently in presence of serialization/storage modifiers when doing parsing via Struct.fromCell() #472

Closed
novusnota opened this issue Jun 24, 2024 · 8 comments · Fixed by #507
Assignees
Labels
blueprint Blueprint-related things
Milestone

Comments

@novusnota
Copy link
Member

novusnota commented Jun 24, 2024

Consider the following snippet:

import "@stdlib/deploy";

struct Coin {
    first: Int as coins;
    second: Int as uint32;
}

fun directParse(payload: Cell): Coin {
    return Coin.fromCell(payload);
}

contract Example with Deployable {
    receive("example") {
        let coin = directParse(
            beginCell()
            .storeCoins(42)
            .storeUint(35, 31) // here, I only specified 31 bit for storing the Uint, but could've specified 33 bits and get the same issue
            .endCell()
        );
        dump(coin.first); // would display nothing!
        dump(coin.second); // neither would this!
    }
}

Although it's up to user to correctly specify serialization modifiers, such as uint32 and then use .storeUint(NUM_TO_STORE, 32) and similar, it would be nice to display an error when mistakes occur.

This may be an edge case of some bigger issue.

Also it's unknown what value coin has in the showcased example, because an attempt to dump(coin) will be prohibited as dump() doesn't support Structs and Messages directly and type of coin is still considered to be Coin.


P.S.: Kinda offtopic, but this reminded me that we may consider adding .storeUint32(), .storeUint64() and similar functions for convenience. Or, to make a special function for Ints, which would accept serialization modifiers, like so:

// Option 1
beginCell().storeValue(VALUE as uint32);

// Option 2
beginCell().storeValue(VALUE, uint32);
@Gusarich
Copy link
Member

What do you mean by "fails silently"?
I've just ran that code and it resulted exit code 9 - just as expected.

@anton-trunov
Copy link
Member

@Gusarich Let's add a failing test to the test suite to resolve the issue

@anton-trunov
Copy link
Member

@novusnota So it looks like indeed the dumps do not work because execution fails with the Cell Underflow error message

@anton-trunov anton-trunov removed the bug Something isn't working or isn't right label Jun 28, 2024
@novusnota
Copy link
Member Author

novusnota commented Jun 28, 2024

What do you mean by "fails silently"?

Testing in Blueprint via Sandbox and Jest don't show anything if one is looking at dump() output. I see that tact-emulator shows the error, but most of the Tact users are working in Blueprint

P.S.: It would be nice to synchronize those two (tact-emulator and sandbox) in the future somehow

@anton-trunov
Copy link
Member

@novusnota Please open an issue in Blueprint's repo (if it's somehow a sandbox issue we'll just move it there)

@anton-trunov
Copy link
Member

P.S.: It would be nice to syncronize those two (tact-emulator and sandbox) in the future somehow

It should be Sandbox

@novusnota
Copy link
Member Author

@novusnota Please open an issue in Blueprint's repo (if it's somehow a sandbox issue we'll just move it there)

ton-org/blueprint#129

@anton-trunov
Copy link
Member

@novusnota Thanks!

Btw, here is a new related issue: #510

@anton-trunov anton-trunov added the blueprint Blueprint-related things label Jun 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blueprint Blueprint-related things
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants